/* 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);
/* Claude Code's --mcp-config VALUES (each a file or a JSON object of mcpServers), servers for
* this run beside the user's (each replacing one of the same name), and --strict-mcp-config
* (STRICT: theirs only, not the user's nor a project's). Their values are as given, not sealed;
* their tool lists are kept like a project's. Call before pic_mcp_register. 0, or -1 with err. */
int pic_mcp_configs(const char *const *values, size_t n, int strict, char *err, size_t errcap);
/* The configs as JSON text, for a child pic's --mcp-config. */
const char *const *pic_mcp_config_texts(size_t *n);
/* The registered servers' prompts (each enabled one's that is not hidden) as get_commands
* entries, {name: "mcp__SERVER__PROMPT", description, source: "mcp", argumentHint}: a JSON array
* (malloc'd). */
char *pic_mcp_prompt_commands(void);
/* Claude Code's /mcp__SERVER__PROMPT ARGS: the words of ARGS fill the prompt's arguments in order
* (the rest joined into the last), and prompts/get's messages become one text. 1 with *OUT
* (malloc'd); 0 when TEXT names no MCP prompt; -1 with err (a required argument missing, the
* server not reached). */
int pic_mcp_prompt_expand(const char *workspace, const char *text, char **out, char *err, size_t errcap);
/* Claude Code's @SERVER:URI mentions in TEXT: each names a resource of a registered server that
* has resources (at most 16), read and added after the text as <resource server uri>...</resource>.
* 1 with *OUT (malloc'd); 0 when TEXT mentions none; -1 with err when one cannot be read. */
int pic_mcp_mentions(const char *workspace, const char *text, char **out, char *err, size_t errcap);
/* 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