Skip to content
pi-c Artifact [7849099e21]
Login

Artifact [7849099e21]

Artifact 7849099e215351936ae26bef54ecd46440356928de08a30c9fbe6b1550174f1c:


/* The MCP client (mcp.c over mcp_wire.c): servers the person added with pic mcp add, kept as rows
 * of picu_mcp_server in ~/.pic/pic.sqlite, their header and environment values sealed under the
 * credential store's key (bound to the server's name and origin) and never kept or shown in
 * plain text. Each enabled server's tools, as its last tools/list gave them, are registered with
 * the tool registry as mcp__SERVER__TOOL, so building a request needs no connection; a call
 * connects, asks tools/call and returns the result, journaled like any tool's. A tool the server
 * marks readOnlyHint is replay-safe; every other one becomes "outcome unknown" after a crash.
 * A server's exposure, and toolExposure for single tools, say whether a tool is declared, waits
 * for tool_search or for codemode, or is left out. Servers whose capabilities name resources are reached
 * through list_mcp_resources, list_mcp_resource_templates and read_mcp_resource.
 * pic does not sign in to servers (OAuth): a token is given as a header. */
#ifndef PIC_MCP_H
#define PIC_MCP_H

#include "rpc.h"

/* Registers the tools of every enabled server from their saved lists, with the tool registry: the
 * user's, and a trusted WORKSPACE's own (.mcp.json, then .pic/mcp.json; NULL: none), which replace
 * the user's of the same name. The number registered, or -1 when ~/.pic/pic.sqlite cannot be read. */
int pic_mcp_register(const char *workspace);

/* The system prompt's section of the instructions the registered servers gave when last listed
 * (each enabled one that is not hidden, up to 8 KB of each), as Claude Code words it (malloc'd), or
 * NULL when none gave any. */
char *pic_mcp_prompt_section(void);

/* pic mcp add | add-json | list | get | remove | call in WORKSPACE (NULL: the current directory):
 * the process's exit status. */
int pic_mcp_command(int argc, char **argv, const char *workspace);

/* The RPC commands: get_mcp_servers, add_mcp_server, remove_mcp_server, refresh_mcp_servers,
 * set_mcp_server_enabled, set_mcp_tool_exposure. */
extern const pic_rpc_command pic_get_mcp_servers_rpc, pic_add_mcp_server_rpc, pic_remove_mcp_server_rpc,
    pic_refresh_mcp_servers_rpc, pic_set_mcp_server_enabled_rpc, pic_set_mcp_tool_exposure_rpc;

#endif