feat(typescript): add MCPToolProvider for MCP server integration#566
feat(typescript): add MCPToolProvider for MCP server integration#566cornelcroi wants to merge 1 commit into
Conversation
Adds MCPToolProvider as a drop-in AgentTools subclass that connects to one or more MCP servers (stdio or SSE) and exposes their tools transparently inside the existing toolConfig mechanism — no changes to existing agents. Closes #299 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83b7e89c52
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Start with an empty tools array; populated lazily on first use | ||
| super([], callbacks); |
There was a problem hiding this comment.
Populate tools before formatting agent requests
When MCPToolProvider is passed to toolConfig.tool as shown, the constructor leaves tools empty and the only lazy connection points are to*Format() and toolHandler(). I checked the existing Bedrock and Anthropic flows: they build the initial request from tools.tools directly (BedrockLLMAgent.formatTools / AnthropicAgent.formatTools) and never call these new to*Format() methods, so the model receives an empty tool list and cannot produce a tool-use block that would trigger toolHandler(). This makes the advertised drop-in usage silently disable all MCP tools unless callers manually call ensureConnected() first.
Useful? React with 👍 / 👎.
| transport = new SSEClientTransport(new URL(serverConfig.url), { | ||
| headers: serverConfig.headers ?? {}, | ||
| }); |
There was a problem hiding this comment.
Pass SSE headers via requestInit
When an SSE MCP server requires headers such as Authorization, these headers are ignored because the v1 SSEClientTransport options read custom request headers from requestInit.headers (and SSE setup from eventSourceInit), not from a top-level headers field. I checked the upstream v1 SDK source for SSEClientTransportOptions; passing { headers: ... } here means authenticated SSE servers still connect without the configured headers and fail with 401s.
Useful? React with 👍 / 👎.
Issue Link (REQUIRED)
Fixes #299
Summary
Changes
Adds
MCPToolProvider— a subclass ofAgentToolsthat connects to one or more MCP servers (stdio or SSE transport) and exposes their tools transparently inside the existingtoolConfigmechanism. No changes to any existing agent, classifier, or orchestrator.typescript/src/tools/mcpToolProvider.tsMCPServerConfiginterface covering stdio (command,args,env) and SSE (url,headers) transportsMCPToolProvider extends AgentToolswith lazy connection, tool caching, and routing back to the correct server per tool calltoBedrockFormat(),toAnthropicFormat(),toOpenAIFormat()— pass MCP's JSON Schema through directlyisErrorresults from MCP surfaced as error strings to the modeldisconnect()for clean shutdowntypescript/package.json:@modelcontextprotocol/sdk >=1.0.0inpeerDependencies(optional, never forced)typescript/src/index.ts: exportsMCPToolProviderandMCPServerConfigUser experience
Before: no MCP support.
After:
Install:
npm install agent-squad && npm install @modelcontextprotocol/sdkChecklist
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.