#ifndef CST_MCP_H #define CST_MCP_H /* * MCP (Model Context Protocol) client over stdio: newline-delimited * JSON-RPC 2.0. Each server is spawned with its command/args/env, gets * initialize + notifications/initialized + tools/list, and every tool is * registered as mcp____ (approved like network tools). * * Config, merged in this order (first name wins): * /.agent/mcp.json (trusted workspaces only), /mcp.json, * plugin "mcpServers". Format: {"mcpServers": {"name": {"command": "npx", * "args": ["-y", "pkg"], "env": {"K": "V"}, "cwd": "...", * "disabled": false}}} */ #include #ifdef __cplusplus extern "C" { #endif #define CST_MCP_MAX 16 typedef enum { CST_MCP_OFF = 0, CST_MCP_STARTING, CST_MCP_READY, CST_MCP_FAILED, CST_MCP_EXITED } cst_mcp_state_t; typedef struct { char name[64]; char source[48]; /* "workspace" | "user" | "plugin:" */ char command[256]; int state; /* cst_mcp_state_t */ int ntools; char error[200]; } cst_mcp_info_t; /* One server from a JSON object text ({"command":..., "args":[...], ...}). * cwd: default working directory (NULL = workspace). Returns 0, or -1 when * the name exists / the config is invalid. */ int cst_mcp_add_config_json(const char *name, const char *server_json, const char *cwd, const char *source); /* Read the mcp.json files for workspace (the workspace one only when * trusted). Returns servers added; *untrusted counts skipped ones. */ int cst_mcp_load_configs(const char *workspace, int ws_trusted, int *untrusted); /* Start every configured server in the background; tools appear as each * one finishes its handshake. */ void cst_mcp_start_all(const char *workspace); /* Wait up to ms for servers still starting (headless runs). */ void cst_mcp_wait_ready(int ms); /* Stop servers, unregister their tools and forget the configs. */ void cst_mcp_stop_all(void); int cst_mcp_info(cst_mcp_info_t *out, int max); /* Ready / configured counts (for the sidebar). */ void cst_mcp_counts(int *ready, int *total); #ifdef __cplusplus } #endif #endif