Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai-mcp, ai-harness-cli): use a harness from any MCP client #1554

ClosedAlemTuzlakwants to merge 4 commits intofeat/harness-p13-agent-middleware fromfeat/harness-p14-mcp-serveropened View on GitHub

AlemTuzlakcommented

You 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 with host.open(harness, { threadId }) and returns the createMCPServer server. Mount server.fetch on a route, or pass the server to serveMCPStdio.
  • Tools. chat, steer, cancel, approve, reject, resolve, answer, and status. Also agent_<name> for each agent in expose.agents, and command_<name> for each plugin command (connect:notion becomes command_connect_notion). Every tool takes an optional threadId.
  • chat waits 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. approve and reject answer all open approvals with one resolve. resolve refuses 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', ... }. Then answer continues that work and returns its result. Errors become MCP tool errors.

@tanstack/ai-harness-cli

  • --mcp serves the harness with serveMCPStdio until stdin ends. In this mode, stdout carries only MCP messages.
  • --yes approves every tool call in MCP mode (--mcp, and /mcp of --serve).
  • --serve also serves MCP at /mcp when @tanstack/ai-mcp is installed. The route uses the same bearer token. A request without the token gets a 401.
  • @tanstack/ai-mcp is an optional peer. Without it, --mcp fails 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 parseCliArgs and USAGE. The package description and keywords name MCP.

Choices to review

  1. createHarnessMcpServer is async. It opens the default session to read the agents and commands for the tool list.
  2. approvals defaults to 'ask'. The design did not name a default.
  3. Inline elicitation works only on MCP spec 2025 sessions. Stdio clients like Claude Code use spec 2025. On spec 2026, requestInput runs 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.
  4. Status values: completed or interrupted after a turn. waiting when work stops for a question. answered when answer resolves a question that no tool call waits on. agent_ and command_ tools return the plain result, or the waiting object. steer and cancel return the harness receipt as JSON.
  5. createHarnessMcpServer has no auth option, because the design did not name one. The doc sample checks a bearer token before server.fetch. A follow-up can pass the auth of createMCPServer through.

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 in docs/config.json, so the 7 later harness pages move down one in order. docs/harness/cli.md has the new flags, and its mode list is now two short lists. docs/harness/mcp.md links to the new page.
  • Changeset: minor for @tanstack/ai-mcp and @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 in src/harness.ts), and test:build (publint: all good).
  • @tanstack/ai-harness-cli: vitest run (5 files, 24 tests pass), test:types, test:oxlint (0 errors), build, and test: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), and oxfmt --check on 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:

  1. Run pnpm install, then pnpm build:all.
  2. Run pnpm -C packages/ai-mcp exec vitest run tests/harness.test.ts. Expect 10 passed tests.
  3. Run pnpm -C packages/ai-harness-cli exec vitest run tests/cli.test.ts. Expect every test to pass, with the new --mcp and /mcp tests.
  4. Make the entry file from docs/harness/cli.md. Then run claude mcp add assistant -- npx tsx /path/to/cli.ts --mcp.
  5. In Claude Code, ask "Ask assistant to say hello". Expect a chat tool 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/client client talks to server.fetch. The tests cover the tool list (control tools, agent_pricer, command_connect_notion), a chat answer, and a pending approval that approve runs.
  • The same file also covers: a resolve with a partial list is refused, approvals: 'auto', and 'ask' with an elicitation client that accepts. Also answer for a command question, agent_<name>, command_<name>, and one conversation per threadId.
  • packages/ai-harness-cli/tests/cli.test.ts (2 new tests): --mcp and --yes parse (both off by default). /mcp of --serve answers initialize with 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 --mcp has no automated test. Only the flag parse has one. serveMCPStdio itself has its own tests in @tanstack/ai-mcp.
  • answer keeps the work that waits for a question in memory. If the process restarts, answer returns status: 'answered' and not the result of that work.
  • createHarnessMcpServer does no auth. In your own server, check the token before server.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

https://claude.ai/code/session_01APYv1qshKyjPPpkFyRZhfZ

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository: TanStack/ai/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 8a1e31ba-1aca-4e46-a6aa-4dc2064a40be

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit d28914b0d905478d042a32216c122640548bbd95

      CommandStatusDurationResult
      nx run-many --targets=build --exclude=examples/...✅ Succeeded11sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-09-28 16:25:50 UTC

    3. Open in StackBlitz

      @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@1554

      commit: d66990e

    4. AlemTuzlakcommented

      Closed 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.

    5. AlemTuzlak closed this

Sign in to join this conversation.