Skip to content

Feat/mcp client support#59

Open
Nivesh353 wants to merge 5 commits into
open-gitagent:mainfrom
Nivesh353:feat/mcp-client-support
Open

Feat/mcp client support#59
Nivesh353 wants to merge 5 commits into
open-gitagent:mainfrom
Nivesh353:feat/mcp-client-support

Conversation

@Nivesh353

Copy link
Copy Markdown
Contributor

What

Adds MCP (Model Context Protocol) client support. Declare servers in agent.yaml (or via the SDK mcpServers option) 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 native AgentTool named <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.

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 shreyas-lyzr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/mcp.test.ts
Comment thread src/mcp/manager.ts Outdated
Comment thread src/env-utils.ts Outdated
Comment thread src/mcp/manager.ts
Comment thread src/mcp/manager.ts

@shreyas-lyzr shreyas-lyzr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants