diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 14 | ||||
| -rw-r--r-- | src/app/main.c | 15 | ||||
| -rw-r--r-- | src/domain/README.md | 8 | ||||
| -rw-r--r-- | src/mcp/server.c | 52 | ||||
| -rw-r--r-- | src/mcp/server.h | 9 | ||||
| -rw-r--r-- | src/mcp/tools/health.c | 29 | ||||
| -rw-r--r-- | src/mcp/tools/health.h | 9 | ||||
| -rw-r--r-- | src/storage/README.md | 6 |
8 files changed, 142 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..ef54a08 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,14 @@ +add_executable(tiny-convmem-mcp + app/main.c + mcp/server.c + mcp/tools/health.c +) + +target_include_directories(tiny-convmem-mcp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") +target_link_libraries(tiny-convmem-mcp PRIVATE mcpc::mcpc) +target_compile_features(tiny-convmem-mcp PRIVATE c_std_17) + +if(MSVC) + target_compile_options(tiny-convmem-mcp PRIVATE /utf-8 /W4) +endif() + diff --git a/src/app/main.c b/src/app/main.c new file mode 100644 index 0000000..ab8688f --- /dev/null +++ b/src/app/main.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +#include "mcp/server.h" + +int +main(void) +{ + const int result = tiny_convmem_server_run(stdin, stdout); + if (result != 0) + { + fprintf(stderr, "tiny-convmem-mcp stopped with error code %d\n", result); + } + return result; +} + diff --git a/src/domain/README.md b/src/domain/README.md new file mode 100644 index 0000000..0d359af --- /dev/null +++ b/src/domain/README.md @@ -0,0 +1,8 @@ +# Domain layer + +This directory is reserved for the conversation-memory domain model and its +business rules. Conversation, message, retention, and search contracts will be +defined here only after the next design phase. + +The domain layer must not depend on mcpc or on a concrete storage engine. + diff --git a/src/mcp/server.c b/src/mcp/server.c new file mode 100644 index 0000000..57d197d --- /dev/null +++ b/src/mcp/server.c @@ -0,0 +1,52 @@ +#include "mcp/server.h" + +#include <mcpc/mcpc.h> +#include "mcp/tools/health.h" + +int +tiny_convmem_server_run(FILE *input, FILE *output) +{ + mcpc_server_t *server = mcpc_server_new_iostrm(input, output); + if (server == NULL) + { + return MCPC_EC_BUG; + } + + mcpc_errcode_t result = mcpc_server_set_nament( + server, + (const char8_t *)"tiny-convmem-mcp" + ); + if (result == MCPC_EC_0) + { + result = mcpc_server_capa_enable_tool(server); + } + + mcpc_tool_t *health = NULL; + if (result == MCPC_EC_0) + { + health = tiny_convmem_health_tool_create(); + if (health == NULL) + { + result = MCPC_EC_BUG; + } + } + + if (result == MCPC_EC_0) + { + result = mcpc_server_add_tool(server, health); + } + if (result == MCPC_EC_0) + { + result = mcpc_server_start(server); + } + + { + const mcpc_errcode_t close_result = mcpc_server_close(server); + if (result == MCPC_EC_0) + { + result = close_result; + } + } + + return (int)result; +} diff --git a/src/mcp/server.h b/src/mcp/server.h new file mode 100644 index 0000000..e3ff2c4 --- /dev/null +++ b/src/mcp/server.h @@ -0,0 +1,9 @@ +#ifndef TINY_CONVMEM_MCP_SERVER_H +#define TINY_CONVMEM_MCP_SERVER_H + +#include <stdio.h> + +int tiny_convmem_server_run(FILE *input, FILE *output); + +#endif + diff --git a/src/mcp/tools/health.c b/src/mcp/tools/health.c new file mode 100644 index 0000000..0309ea5 --- /dev/null +++ b/src/mcp/tools/health.c @@ -0,0 +1,29 @@ +#include "mcp/tools/health.h" + +#include <mcpc/ucbr.h> + +static void +health_call(const mcpc_tool_t *tool, mcpc_ucbr_t *result) +{ + (void)tool; + mcpc_ucbr_toolcall_add_text_printf8(result, (const char8_t *)"ok"); +} + +mcpc_tool_t * +tiny_convmem_health_tool_create(void) +{ + mcpc_tool_t *tool = mcpc_tool_new2( + (const char8_t *)"health", + (const char8_t *)"Check whether the tiny conversation memory server is running" + ); + if (tool == NULL) + { + return NULL; + } + + if (mcpc_tool_set_call_cb(tool, health_call) != MCPC_EC_0) + { + return NULL; + } + return tool; +} diff --git a/src/mcp/tools/health.h b/src/mcp/tools/health.h new file mode 100644 index 0000000..f4bfe0a --- /dev/null +++ b/src/mcp/tools/health.h @@ -0,0 +1,9 @@ +#ifndef TINY_CONVMEM_MCP_HEALTH_H +#define TINY_CONVMEM_MCP_HEALTH_H + +#include <mcpc/tool.h> + +mcpc_tool_t *tiny_convmem_health_tool_create(void); + +#endif + diff --git a/src/storage/README.md b/src/storage/README.md new file mode 100644 index 0000000..ceb8965 --- /dev/null +++ b/src/storage/README.md @@ -0,0 +1,6 @@ +# Storage layer + +This directory is reserved for persistence adapters. The storage engine and its +schema are intentionally undecided; SQLite or another dependency will be added +to `vcpkg.json` only after the storage contract is designed. + |
