diff options
Diffstat (limited to 'src/mcp')
| -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 |
4 files changed, 99 insertions, 0 deletions
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 + |
