Feat/mcp client support#59
Conversation
Connect to MCP servers declared in agent.yaml / SDK mcpServers, register their tools as native AgentTools (namespaced <server>__<tool>), and tear connections down on exit. stdio + HTTP + SSE transports, pagination, name sanitization, abort forwarding, fail-soft connect, recursive JSON Schema conversion. Fully opt-in; SDK not loaded when unused.
shreyas-lyzr
left a comment
There was a problem hiding this comment.
Solid MCP client integration — the architecture is well-thought-out: lazy loading, fail-soft per-server, idempotent cleanup on every exit path, and a proper test suite exercising the in-memory transport. A few issues worth addressing before merge.
Two correctness issues: the test assertions are verifying the wrong shape (checking .content[0].text on a value that execute() returns as a plain string, not an MCP result object), and the withTimeout timer is not cancelled on success, which accumulates unresolved timer handles in long-running sessions. One security concern: env var interpolation uses || "" which silently replaces unset vars with empty string — a misconfigured auth token header becomes an empty string with no warning. Detailed notes inline.
shreyas-lyzr
left a comment
There was a problem hiding this comment.
All four issues from the previous review are addressed:
- withTimeout now clears the timer on both the resolve and reject paths — no more handle leak.
- interpolateEnvString warns when an env var is unset instead of silently substituting an empty string.
- PACKAGE_VERSION is sourced from package.json via createRequire rather than being hardcoded.
- Test assertions correctly use assert.equal(res, ...) on the flattened string return, not .content[0].text.
The new test suite looks solid — flattenToolResult unit tests cover all block types including the structuredContent fallback, buildToolsForConnection tests cover pagination, name sanitization, protocol errors, and the in-memory integration path. Code is clean and the fail-soft design is well-considered. Good to merge.
What
Adds MCP (Model Context Protocol) client support. Declare servers in
agent.yaml(or via the SDKmcpServersoption) and the agent automatically gains those servers' tools — no integration code.Why
Previously, every external capability (GitHub, Postgres, Slack, filesystem…) had to be hand-built and maintained by us as a custom tool/plugin. With MCP, users plug into the whole ecosystem of ready-made servers via a few lines of config, and we maintain none of it. Keeps gitagent aligned with the industry standard (Claude, Cursor, etc.).
How it works
On agent load, gitagent connects to each declared server (stdio / HTTP / SSE), calls
listTools, and registers every tool as a nativeAgentToolnamed<server>__<tool>. Execution forwards the call to the server and returns its result. Connections are pooled for the session and torn down on every exit path.