Skip to content

Add MCP client support to ds4-agent#573

Open
aovestdipaperino wants to merge 2 commits into
antirez:mainfrom
aovestdipaperino:mcp-support
Open

Add MCP client support to ds4-agent#573
aovestdipaperino wants to merge 2 commits into
antirez:mainfrom
aovestdipaperino:mcp-support

Conversation

@aovestdipaperino

Copy link
Copy Markdown

Summary

Adds Model Context Protocol (MCP) client support to ds4-agent, so external stdio MCP servers can extend the agent with new tools without touching C code.

  • Config: servers are declared in a .mcp.json file (same shape Claude Code uses: mcpServers: {name: {command, args, env}}), read from the working directory or via the new --mcp-config FILE flag. MCP is fully optional: a missing file is silently fine, a malformed one warns and is skipped, and a server that fails to spawn or handshake is dropped with a warning instead of aborting the agent.
  • Transport: each server is a long-lived subprocess speaking newline-delimited JSON-RPC 2.0 on stdin/stdout (the MCP stdio transport), driven by a small self-contained JSON parser/writer added to ds4_agent.c. Tool calls stay synchronous like every other agent tool; requests carry a 30s whole-exchange deadline so a misbehaving server cannot hang a turn.
  • Tool exposure: discovered tools are namespaced mcp__<server>__<tool> and rendered into the system prompt in the same function-call JSON shape as the native tools. Dispatch plugs into agent_execute_tool_call, and results flatten to plain text like every other tool.
  • Prompt-size control: an optional per-server primaryTools list splits tools into primary (full schema in the prompt) and directory entries (one line each); the model fetches directory schemas on demand with the new native mcp_describe tool. With tokensave's 81 tools this shrinks the MCP prompt block by ~71%.

Testing

  • make stays warning-clean; ds4_agent_test grows 13 unit tests covering the JSON round-trip, config parsing (including rejection of __ in server names), DSML-args→JSON-RPC conversion, primary/directory prompt rendering, and mcp_describe resolution.
  • Live-checked end to end against a scripted stdio MCP server (spawn, handshake, tools/list, tools/call round trip) and against a real 81-tool server, including the on-demand schema path.

🤖 Generated with Claude Code

aovestdipaperino and others added 2 commits July 18, 2026 11:37
Load stdio MCP servers from a .mcp.json file (or --mcp-config FILE),
advertise their tools to the model as mcp__<server>__<tool> alongside
the native DSML tools, and dispatch calls over newline-delimited
JSON-RPC. Servers that fail to spawn or handshake are dropped with a
warning instead of aborting the agent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A per-server primaryTools list in .mcp.json controls prompt cost:
listed tools keep their full schema in the system prompt, the rest
appear as one-line directory entries, and the model fetches a full
schema on first use via the new mcp_describe tool. With tokensave's
81 tools this shrinks the MCP prompt block by ~71%.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant