feat(ai-mcp): toolName, requestOptions, and a strict toolFilter list for createMCPClient #1720
main fromrefs/pull/1720/head·merged by AlemTuzlak View on GitHubYou can now name MCP tools yourself, set a timeout for slow MCP servers, and list the exact tools a client keeps. createMCPClient gets toolName and requestOptions, and toolFilter also takes a list of server tool names. An MCP server resource template can also parse its variables with argsSchema.
This piece is split out of #1555. It has only the @tanstack/ai-mcp client and server parts. Elicitation (onElicit, askInput), the harness plugin, the connector, and RFC 9207 iss handling are not in this PR.
🎯 Changes#
toolName: (tool) => stringsets the name the model sees. It wins overprefix.metadata.mcp.serverToolNamekeeps the server name, socallTool()and MCP Apps widget calls still reach the tool.requestOptions: { timeout, resetTimeoutOnProgress }goes to the connect handshake, tool lists, tool calls, resources, and prompts. A server that does not answer at connect now fails aftertimeout.toolFilter: ['a', 'b']keeps exactly those tools, in list order. A missing or repeated name throws the newMCPToolFilterError.resourceDefinition({ uriTemplate, argsSchema })runsargsSchema.parseon the template variables. A{ text | blob, mimeType }read result sets the MIME type of that answer.- Defaults: an input schema without
propertiesortypegetsproperties: {}andtype: 'object'.metadata.mcp.annotationsis a frozen copy.
toolName and requestOptions also work per server in createMCPClients and in MCP Apps widget calls. Docs: docs/tools/mcp.md (Timeouts, Name Tools Yourself, list filter), docs/tools/mcp-managed.md, docs/mcp/server-content.md, and the package skill.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm run test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
- Docs: I updated
docs/for this change, or this change is not user-facing. - Changeset: I added a changeset (
pnpm changeset), or this PR does not change a published package.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Testing#
Commands run. None. The maintainer said to skip local runs and rely on CI. CI is the first signal for unit tests, types, lint, build, and E2E. Only pnpm format ran.
Manual test.
- Run
pnpm --filter @tanstack/ai-mcp test:lib. - Run
pnpm --filter @tanstack/ai-e2e test:e2e --grep "mcp: toolName". - Expect the names
['mcp__store__get_guitar_price']and anMCPToolFilterErrorforno_such_tool.
How this PR makes testing easy.
- Unit tests in
packages/ai-mcp/tests/:client.test.ts(connect timeout, request timeouts, progress reset,toolName),tool-policy.test.ts(list filter),tools.test.ts,pool.test.ts,apps/call-handler.test.ts,server/*.test.ts(argsSchema, MIME type). - E2E:
testing/e2e/tests/mcp-tool-options-wire.spec.tswith the routeapi.mcp-tool-options-wire.ts. It coverstoolNameand the strict list. TheargsSchemaand per-answer MIME type have unit tests only.
Risk / rollback#
- A short
timeoutcan now fail at connect. On astdioserver, connect can take up to two timestimeout. - Code that changed
metadata.mcp.annotationsin place now gets a frozen object. - Rollback: revert this PR.
Public API change#
Before
const mcp = await createMCPClient({
transport: { type: 'http', url },
prefix: 'github',
toolFilter: (tool) => ['search_issues', 'get_issue'].includes(tool.name),
})
After
import { createMCPClient } from '@tanstack/ai-mcp'
const mcp = await createMCPClient({
transport: { type: 'http', url },
toolName: (tool) => `mcp__github__${tool.name}`,
toolFilter: ['search_issues', 'get_issue'],
requestOptions: { timeout: 120_000, resetTimeoutOnProgress: true },
})
🤖 Generated with Claude Code
Summary by CodeRabbit#
- New Features
- Configure MCP request timeouts, including resetting them when server progress is reported.
- Customize tools’ names and select tools using an ordered list; invalid or repeated names now produce a specific filter error.
- Validate resource-template arguments before reading resources, and return text or binary resources with their specified MIME types.
- Bug Fixes
- MCP tool schemas missing
typeorpropertiesnow receive defaults during discovery. - Server annotations are copied and protected from modification.
- MCP tool schemas missing
- Documentation
- Updated MCP guides with details on timeouts, tool selection, naming, and resource templates.
- 1
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Repository: TanStack/ai/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
981c0000-cbd4-484e-9a7e-7d920b9b4be2
📥 Commits
-
Reviewing files that changed from the base of the PR and between 5bd27f2fc94ebfb6d11bfb28d46d5d858310805e and 1cf0e9711a25a2f19e9033e469ef2c2ee1ae0509.
📒 Files selected for processing (29)
-
.changeset/mcp-connect-timeout.md.changeset/mcp-resource-template-args.md.changeset/mcp-tool-options.mddocs/config.jsondocs/mcp/server-content.mddocs/tools/mcp-managed.mddocs/tools/mcp.mdpackages/ai-mcp/skills/ai-mcp/SKILL.mdpackages/ai-mcp/src/apps/call-handler.tspackages/ai-mcp/src/apps/session-store.tspackages/ai-mcp/src/client.tspackages/ai-mcp/src/errors.tspackages/ai-mcp/src/index.tspackages/ai-mcp/src/pool.tspackages/ai-mcp/src/server/create-server.tspackages/ai-mcp/src/server/definitions.tspackages/ai-mcp/src/tools.tspackages/ai-mcp/src/types.tspackages/ai-mcp/tests/apps/call-handler.test.tspackages/ai-mcp/tests/client.test.tspackages/ai-mcp/tests/pool.test.tspackages/ai-mcp/tests/server/create-server.test.tspackages/ai-mcp/tests/server/definitions.test.tspackages/ai-mcp/tests/tool-policy.test.tspackages/ai-mcp/tests/tools.test.tspackages/ai-mcp/tests/types.test-d.tstesting/e2e/src/routeTree.gen.tstesting/e2e/src/routes/api.mcp-tool-options-wire.tstesting/e2e/tests/mcp-tool-options-wire.spec.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
-
📝 Walkthrough
-
Walkthrough#
The MCP client adds custom tool naming, ordered tool filters, and configurable request options. MCP resource templates add parsed arguments and result-level MIME types. Documentation, changesets, unit tests, and an end-to-end route cover these changes.
Changes#
MCP client options
Layer / File(s) Summary Tool naming and filtering
packages/ai-mcp/src/types.ts,packages/ai-mcp/src/client.ts,packages/ai-mcp/src/tools.ts,packages/ai-mcp/src/errors.ts,packages/ai-mcp/src/index.ts,packages/ai-mcp/tests/*,packages/ai-mcp/tests/types.test-d.ts,docs/tools/mcp.md,docs/tools/mcp-managed.md,packages/ai-mcp/skills/ai-mcp/SKILL.md,docs/config.json,testing/e2e/src/routes/api.mcp-tool-options-wire.ts,testing/e2e/src/routeTree.gen.ts,testing/e2e/tests/mcp-tool-options-wire.spec.ts,.changeset/mcp-tool-options.mdtoolNamesets the exposed name and takes precedence over the prefix. List-formtoolFilterpreserves the requested order and reports missing or repeated names withMCPToolFilterError. Tool conversion adds defaults for missing schema fields and freezes copied annotation metadata. The end-to-end route and tests cover list filtering and its error response.Request settings and propagation
packages/ai-mcp/src/types.ts,packages/ai-mcp/src/tools.ts,packages/ai-mcp/src/client.ts,packages/ai-mcp/src/apps/*,packages/ai-mcp/src/session-store.ts,packages/ai-mcp/src/pool.ts,packages/ai-mcp/tests/*,docs/tools/mcp.md,packages/ai-mcp/skills/ai-mcp/SKILL.md,.changeset/mcp-connect-timeout.mdrequestOptionsconfigures timeouts and progress-based timeout resets for connection and selected requests. Client, pool, and app paths retain or forward the settings. Tests cover timeout behavior and propagation.Resource templates
Layer / File(s) Summary Template arguments and resource content
packages/ai-mcp/src/server/definitions.ts,packages/ai-mcp/src/server/create-server.ts,packages/ai-mcp/tests/server/*,docs/mcp/server-content.md,docs/config.json,.changeset/mcp-resource-template-args.mdTemplate definitions accept argsSchemaand pass parsed variables toread. Text and blob results can specify a MIME type. Tests and documentation cover parsed arguments and returned resource content.Priority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature
Sequence Diagram(s)#
sequenceDiagram participant Caller participant MCPClient participant MCPServer Caller->>MCPClient: tools() MCPClient->>MCPServer: tools/list MCPServer-->>MCPClient: tool definitions MCPClient->>MCPClient: applyToolFilter MCPClient-->>Caller: selected tools or MCPToolFilterErrorSuggested reviewers:
shubhdeep12
Merge Risk: ⚪ Minimal · up to
1cf0eNo specific issue remains that would prevent merging after normal checks.
Pre-merge checks |
4 | 1-
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 21 files. (8 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
-
Check name Status Explanation Description check The description follows the required template and clearly documents the changes, testing status, release impact, risks, rollback, and public API changes. The unchecked test item is explained because l… Title check The title is concise, specific, and accurately summarizes the main changes to tool naming, request options, and strict tool filtering in createMCPClient. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 21 files. (8 skipped: 8 unsupported.)
-
- Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
-
📝 Generate docstrings 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit 1cf0e9711a25a2f19e9033e469ef2c2ee1ae0509
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 5s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-12 17:06:46UTCCoverage#
✅ Coverage held across 1 compared package(s).
Each package is measured twice in this job — on this PR and on its merge-base with
main— and compared. A metric fails only when it is at or above 60% on the merge-base and under 60% on this PR. Other drops are listed but do not fail. Packages your PR doesn't affect are not measured and not listed.package statements branches functions lines ai-mcp 96.91% (+0.39) 92.43% (+0.75) 97.33% (+0.45) 98.72% (+0.24) ok @tanstack/ai
npm i https://pkg.pr.new/@tanstack/ai@1720@tanstack/ai-acp
npm i https://pkg.pr.new/@tanstack/ai-acp@1720@tanstack/ai-angular
npm i https://pkg.pr.new/@tanstack/ai-angular@1720@tanstack/ai-anthropic
npm i https://pkg.pr.new/@tanstack/ai-anthropic@1720@tanstack/ai-bedrock
npm i https://pkg.pr.new/@tanstack/ai-bedrock@1720@tanstack/ai-byteplus
npm i https://pkg.pr.new/@tanstack/ai-byteplus@1720@tanstack/ai-claude-code
npm i https://pkg.pr.new/@tanstack/ai-claude-code@1720@tanstack/ai-client
npm i https://pkg.pr.new/@tanstack/ai-client@1720@tanstack/ai-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-cloudflare@1720@tanstack/ai-code-mode
npm i https://pkg.pr.new/@tanstack/ai-code-mode@1720@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/@tanstack/ai-code-mode-snippets@1720@tanstack/ai-codex
npm i https://pkg.pr.new/@tanstack/ai-codex@1720@tanstack/ai-cohere
npm i https://pkg.pr.new/@tanstack/ai-cohere@1720@tanstack/ai-compaction
npm i https://pkg.pr.new/@tanstack/ai-compaction@1720@tanstack/ai-devtools-core
npm i https://pkg.pr.new/@tanstack/ai-devtools-core@1720@tanstack/ai-durable-stream
npm i https://pkg.pr.new/@tanstack/ai-durable-stream@1720@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@1720@tanstack/ai-event-client
npm i https://pkg.pr.new/@tanstack/ai-event-client@1720@tanstack/ai-fal
npm i https://pkg.pr.new/@tanstack/ai-fal@1720@tanstack/ai-gemini
npm i https://pkg.pr.new/@tanstack/ai-gemini@1720@tanstack/ai-grok
npm i https://pkg.pr.new/@tanstack/ai-grok@1720@tanstack/ai-grok-build
npm i https://pkg.pr.new/@tanstack/ai-grok-build@1720@tanstack/ai-groq
npm i https://pkg.pr.new/@tanstack/ai-groq@1720@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@1720@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@1720@tanstack/ai-isolate-e2b
npm i https://pkg.pr.new/@tanstack/ai-isolate-e2b@1720@tanstack/ai-isolate-node
npm i https://pkg.pr.new/@tanstack/ai-isolate-node@1720@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@1720@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@1720@tanstack/ai-llmgateway
npm i https://pkg.pr.new/@tanstack/ai-llmgateway@1720@tanstack/ai-lovable
npm i https://pkg.pr.new/@tanstack/ai-lovable@1720@tanstack/ai-mcp
npm i https://pkg.pr.new/@tanstack/ai-mcp@1720@tanstack/ai-memory
npm i https://pkg.pr.new/@tanstack/ai-memory@1720@tanstack/ai-mistral
npm i https://pkg.pr.new/@tanstack/ai-mistral@1720@tanstack/ai-octane
npm i https://pkg.pr.new/@tanstack/ai-octane@1720@tanstack/ai-ollama
npm i https://pkg.pr.new/@tanstack/ai-ollama@1720@tanstack/ai-ollaya
npm i https://pkg.pr.new/@tanstack/ai-ollaya@1720@tanstack/ai-openai
npm i https://pkg.pr.new/@tanstack/ai-openai@1720@tanstack/ai-opencode
npm i https://pkg.pr.new/@tanstack/ai-opencode@1720@tanstack/ai-openrouter
npm i https://pkg.pr.new/@tanstack/ai-openrouter@1720@tanstack/ai-perplexity
npm i https://pkg.pr.new/@tanstack/ai-perplexity@1720@tanstack/ai-persistence
npm i https://pkg.pr.new/@tanstack/ai-persistence@1720@tanstack/ai-preact
npm i https://pkg.pr.new/@tanstack/ai-preact@1720@tanstack/ai-react
npm i https://pkg.pr.new/@tanstack/ai-react@1720@tanstack/ai-react-ui
npm i https://pkg.pr.new/@tanstack/ai-react-ui@1720@tanstack/ai-reactor
npm i https://pkg.pr.new/@tanstack/ai-reactor@1720@tanstack/ai-remix
npm i https://pkg.pr.new/@tanstack/ai-remix@1720@tanstack/ai-sandbox
npm i https://pkg.pr.new/@tanstack/ai-sandbox@1720@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/@tanstack/ai-sandbox-blaxel@1720@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/@tanstack/ai-sandbox-boxd@1720@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@1720@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@1720@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@1720@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/@tanstack/ai-sandbox-e2b@1720@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@1720@tanstack/ai-sandbox-railway
npm i https://pkg.pr.new/@tanstack/ai-sandbox-railway@1720@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@1720@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/@tanstack/ai-sandbox-upstash-box@1720@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@1720@tanstack/ai-skills
npm i https://pkg.pr.new/@tanstack/ai-skills@1720@tanstack/ai-solid
npm i https://pkg.pr.new/@tanstack/ai-solid@1720@tanstack/ai-solid-ui
npm i https://pkg.pr.new/@tanstack/ai-solid-ui@1720@tanstack/ai-svelte
npm i https://pkg.pr.new/@tanstack/ai-svelte@1720@tanstack/ai-typesafe
npm i https://pkg.pr.new/@tanstack/ai-typesafe@1720@tanstack/ai-utils
npm i https://pkg.pr.new/@tanstack/ai-utils@1720@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/@tanstack/ai-vercel-gateway@1720@tanstack/ai-vertex
npm i https://pkg.pr.new/@tanstack/ai-vertex@1720@tanstack/ai-vue
npm i https://pkg.pr.new/@tanstack/ai-vue@1720@tanstack/ai-vue-ui
npm i https://pkg.pr.new/@tanstack/ai-vue-ui@1720@tanstack/ai-worldlabs
npm i https://pkg.pr.new/@tanstack/ai-worldlabs@1720@tanstack/openai-base
npm i https://pkg.pr.new/@tanstack/openai-base@1720@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@1720@tanstack/react-ai-devtools
npm i https://pkg.pr.new/@tanstack/react-ai-devtools@1720@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@1720@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/@tanstack/svelte-ai-devtools@1720commit:
1cf0e97github-actions[bot](GitHub profile, opens in a new tab) assignedjherr
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
jherr approved these changes
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
AlemTuzlak merged thisdce9fbe
AlemTuzlak closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 1cf0e9711a25a2f19e9033e469ef2c2ee1ae0509
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR