feat(ai-mcp, ai-harness-cli): use a harness from any MCP client #1554
feat/harness-p13-agent-middleware fromfeat/harness-p14-mcp-server·opened View on GitHubYou can now use a harness from any MCP client: Claude Code, Claude Desktop, Cursor, or another agent. Run harness --mcp for stdio, use /mcp on harness --serve, or mount createHarnessMcpServer from @tanstack/ai-mcp/harness in your own server. The client gets the full control surface as tools: chat, steer, cancel, approvals, questions, status, agents, and commands.
Stacked on #1550 (Phase 13) → #1549 → #1546 → #1540 → #1538 → #1524 → #1523 → #1522 → #1521 → #1520 → #1519 → #1518 → #1515 → #1513. Merge those first. The combined PR #1551 covers phases 0 to 13 only. It does not include this PR.
🎯 Changes#
@tanstack/ai-mcp: new subpath ./harness
createHarnessMcpServer({ host, harness, threadId?, approvals?, name?, version? }). It opens sessions withhost.open(harness, { threadId })and returns thecreateMCPServerserver. Mountserver.fetchon a route, or pass the server toserveMCPStdio.- Tools.
chat,steer,cancel,approve,reject,resolve,answer, andstatus. Alsoagent_<name>for each agent inexpose.agents, andcommand_<name>for each plugin command (connect:notionbecomescommand_connect_notion). Every tool takes an optionalthreadId. chatwaits for the turn. It returns{ status, text, approvals: [{ id, tool, args, message }], questions: [{ id, message, schema }] }.- Approvals. With
approvals: 'ask', a client with elicitation asks the user about each approval inline ("Answer yes or no"). If the client cannot ask, the approvals come back in the result.'auto'approves all.approveandrejectanswer all open approvals with one resolve.resolverefuses a partial list:resolve must answer every open approval. Missing: <ids>. - Questions and errors. A command or turn that asks a question returns
{ status: 'waiting', ... }. Thenanswercontinues that work and returns its result. Errors become MCP tool errors.
@tanstack/ai-harness-cli
--mcpserves the harness withserveMCPStdiountil stdin ends. In this mode, stdout carries only MCP messages.--yesapproves every tool call in MCP mode (--mcp, and/mcpof--serve).--servealso serves MCP at/mcpwhen@tanstack/ai-mcpis installed. The route uses the same bearer token. A request without the token gets a 401.@tanstack/ai-mcpis an optional peer. Without it,--mcpfails with--mcp needs @tanstack/ai-mcp. Install it next to @tanstack/ai-harness-cli.It is also a devDependency, so the lockfile changes.- Both flags are in
parseCliArgsandUSAGE. The package description and keywords name MCP.
Choices to review
createHarnessMcpServeris async. It opens the default session to read the agents and commands for the tool list.approvalsdefaults to'ask'. The design did not name a default.- Inline elicitation works only on MCP spec 2025 sessions. Stdio clients like Claude Code use spec 2025. On spec 2026,
requestInputruns the whole tool call again, and a second run sends the chat message twice. So on 2026, and when the user declines or the client has no elicitation, the approvals come back pending. - Status values:
completedorinterruptedafter a turn.waitingwhen work stops for a question.answeredwhenanswerresolves a question that no tool call waits on.agent_andcommand_tools return the plain result, or thewaitingobject.steerandcancelreturn the harness receipt as JSON. createHarnessMcpServerhas noauthoption, because the design did not name one. The doc sample checks a bearer token beforeserver.fetch. A follow-up can pass theauthofcreateMCPServerthrough.
Also in this PR
- Docs: a new page
docs/harness/mcp-server.md, "Use a harness from any MCP client" (nav label "Use from any MCP client"). It comes after the MCP connectors page indocs/config.json, so the 7 later harness pages move down one inorder.docs/harness/cli.mdhas the new flags, and its mode list is now two short lists.docs/harness/mcp.mdlinks to the new page. - Changeset: minor for
@tanstack/ai-mcpand@tanstack/ai-harness-cli. - Agent skill: one subpath line in
packages/ai-mcp/skills/ai-mcp/SKILL.md.
✅ 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.
Not ticked:
- Contributing guide: the guide asks for E2E coverage on every feature. This PR has no new E2E test (see Testing).
pnpm test:pr: not run as one command. The package checks ran one by one (see Testing).- The understanding box is for the author to tick after review.
🚀 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 on the pushed head d66990e08:
@tanstack/ai-mcp:build,vitest run(30 files, 302 tests pass),test:types,test:oxlint(0 errors, no warning insrc/harness.ts), andtest:build(publint: all good).@tanstack/ai-harness-cli:vitest run(5 files, 24 tests pass),test:types,test:oxlint(0 errors),build, andtest:build(publint: all good).- Root:
test:docs(no broken links),kiira check docs/harness/mcp-server.md docs/harness/cli.md docs/harness/mcp.md(3 snippets pass, 4 ignored),test:knip(pass, config hints only), andoxfmt --checkon the changed files. - Skipped: the full
pnpm test:pr, because it is slow on this machine. CI runs it. Coverage runs in CI only. - No new E2E test: this is a server-side protocol, and no browser app uses it.
Manual test
Nobody tried a real MCP client (Claude Code, Claude Desktop, Cursor) by hand yet. The tests use the real MCP SDK client over server.fetch. To check it yourself:
- Run
pnpm install, thenpnpm build:all. - Run
pnpm -C packages/ai-mcp exec vitest run tests/harness.test.ts. Expect 10 passed tests. - Run
pnpm -C packages/ai-harness-cli exec vitest run tests/cli.test.ts. Expect every test to pass, with the new--mcpand/mcptests. - Make the entry file from
docs/harness/cli.md. Then runclaude mcp add assistant -- npx tsx /path/to/cli.ts --mcp. - In Claude Code, ask "Ask assistant to say hello". Expect a
chattool call and the answer of the harness.
How this PR makes testing easy
packages/ai-mcp/tests/harness.test.ts(10 new tests). A real@modelcontextprotocol/clientclient talks toserver.fetch. The tests cover the tool list (control tools,agent_pricer,command_connect_notion), achatanswer, and a pending approval thatapproveruns.- The same file also covers: a
resolvewith a partial list is refused,approvals: 'auto', and'ask'with an elicitation client that accepts. Alsoanswerfor a command question,agent_<name>,command_<name>, and one conversation perthreadId. packages/ai-harness-cli/tests/cli.test.ts(2 new tests):--mcpand--yesparse (both off by default)./mcpof--serveanswersinitializewith the token and gives a 401 without it.
Risk / rollback#
Low. The stack is not released yet. Existing modes do not change. Known limits:
- The stdio loop of
--mcphas no automated test. Only the flag parse has one.serveMCPStdioitself has its own tests in@tanstack/ai-mcp. answerkeeps the work that waits for a question in memory. If the process restarts,answerreturnsstatus: 'answered'and not the result of that work.createHarnessMcpServerdoes no auth. In your own server, check the token beforeserver.fetch, as the doc sample does.
Revert the PR to undo.
Public API change#
Before
A harness spoke the HTTP session protocol (AG-UI) and ACP:
node harness.js --serve # HTTP session protocol
node harness.js --acp # ACP for editors
After
Any MCP client can use the harness:
claude mcp add my-harness -- node harness.js --mcp
import { createHarnessMcpServer } from '@tanstack/ai-mcp/harness'
const server = await createHarnessMcpServer({ host, harness })
export function handleMcp(request: Request) {
return server.fetch(request)
}
harness --serve also serves the same server at /mcp, behind its bearer token.
🤖 Generated with Claude Code
- 1
View your CI Pipeline Execution ↗ for commit d28914b0d905478d042a32216c122640548bbd95
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 11s View ↗
☁️ Nx Cloud last updated this comment at
2026-09-28 16:25:50UTC@tanstack/ai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@1554@tanstack/ai-acp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@1554@tanstack/ai-angular
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@1554@tanstack/ai-anthropic
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@1554@tanstack/ai-bedrock
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@1554@tanstack/ai-byteplus
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@1554@tanstack/ai-claude-code
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@1554@tanstack/ai-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@1554@tanstack/ai-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@1554@tanstack/ai-code-mode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@1554@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@1554@tanstack/ai-codex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@1554@tanstack/ai-cohere
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@1554@tanstack/ai-compaction
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@1554@tanstack/ai-dashboard
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-dashboard@1554@tanstack/ai-devtools-core
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@1554@tanstack/ai-durable-stream
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@1554@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@1554@tanstack/ai-event-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@1554@tanstack/ai-fal
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@1554@tanstack/ai-gemini
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@1554@tanstack/ai-grok
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@1554@tanstack/ai-grok-build
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@1554@tanstack/ai-groq
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@1554@tanstack/ai-harness
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@1554@tanstack/ai-harness-cli
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness-cli@1554@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@1554@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@1554@tanstack/ai-isolate-node
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@1554@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@1554@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@1554@tanstack/ai-llmgateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@1554@tanstack/ai-lovable
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@1554@tanstack/ai-mcp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@1554@tanstack/ai-memory
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@1554@tanstack/ai-mistral
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@1554@tanstack/ai-octane
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@1554@tanstack/ai-ollama
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@1554@tanstack/ai-openai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@1554@tanstack/ai-opencode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@1554@tanstack/ai-openrouter
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@1554@tanstack/ai-perplexity
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@1554@tanstack/ai-persistence
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@1554@tanstack/ai-preact
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@1554@tanstack/ai-react
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@1554@tanstack/ai-react-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@1554@tanstack/ai-reactor
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@1554@tanstack/ai-remix
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@1554@tanstack/ai-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@1554@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@1554@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@1554@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@1554@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@1554@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@1554@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@1554@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@1554@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@1554@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@1554@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@1554@tanstack/ai-skills
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@1554@tanstack/ai-solid
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@1554@tanstack/ai-solid-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@1554@tanstack/ai-svelte
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@1554@tanstack/ai-typesafe
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@1554@tanstack/ai-utils
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@1554@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@1554@tanstack/ai-vertex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@1554@tanstack/ai-vue
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@1554@tanstack/ai-vue-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@1554@tanstack/ai-worldlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@1554@tanstack/openai-base
npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@1554@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@1554@tanstack/react-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@1554@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@1554@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@1554commit:
d66990eClosed in favor of the combined PR #1555, which holds this phase and every other phase of the harness (P0 to P14) on one branch against main. All further fixes go there. This PR stays as the review record of P14.
AlemTuzlak closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository: TanStack/ai/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
8a1e31ba-1aca-4e46-a6aa-4dc2064a40beYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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.
❤️ Share