Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai-mcp): send server instructions with createMCPServer #2271

Closedchirag-zenskar(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2271/headopened View on GitHub

chirag-zenskar(GitHub profile, opens in a new tab)commented

createMCPServer takes an instructions option. The server sends it to the client as the MCP instructions field.

🎯 Changes

Why we need it: we serve data tools to MCP hosts from a createMCPServer server, and we want to tell the host's model how the tools relate. MCP has a core field for this, instructions, returned in the initialize result (spec 2025) and the server/discover result (spec 2026-07-28). createMCPServer builds the SDK McpServer with only { name, version } and its capabilities. The SDK keeps instructions in a private field that it sets at construction, so the setup hook cannot set it. Today there is no way to send it.

  • New optional instructions?: string on MCPServerOptions. buildMcpServer passes it to new McpServer(info, { capabilities, instructions }).
  • Without instructions, the server sends none, as before.
  • Docs: "Send instructions to the client" in docs/mcp/server.md, and the option in the createMCPServer doc comment.
  • Minor changeset for @tanstack/ai-mcp.

Not in this PR: SDK PR modelcontextprotocol/typescript-sdk#3066 will add extensions to the McpServer options, and createMCPServer will then need to pass that too.

I found no existing issue or PR for server-side instructions. #1567 is about the client side only.

✅ 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 in packages/ai-mcp:

  • pnpm vitest run: 54 files, 698 tests passed.
  • pnpm test:types: passed.
  • pnpm test:oxlint: no errors, and no warnings in the changed files.
  • Repo root: pnpm test:docs (no broken links) and kiira check docs/mcp/server.md (10 snippets passed).
  • Not run locally: the root pnpm test:pr and the rest of the E2E suite (only mcp-typed.spec.ts ran). CI runs them. For this reason the test:pr box is not ticked.

Manual test:

  1. In packages/ai-mcp, run pnpm vitest run tests/server/create-server.test.ts -t instructions.
  2. Make sure both tests pass. The first checks client.getInstructions() on spec 2026 (server/discover), spec 2025 stateless, and spec 2025 memory sessions. The second checks that an omitted option gives undefined.
  3. Remove the instructions, line in serverOptions in create-server.ts, then run step 1 again. The first test fails with expected undefined to be 'Call echo first.'.

E2E: testing/e2e/tests/mcp-typed.spec.ts has a new test, "a client reads the instructions that the server sends". The e2e stateless server is built with instructions, and a createMCPClient over HTTP reads them from client.instructions. Run with pnpm --filter @tanstack/ai-e2e exec playwright test tests/mcp-typed.spec.ts: 9 passed. With the instructions, line removed from serverOptions, the new test fails (instructions is null) and the other 8 pass.

Risk / rollback

Low. instructions is opt-in. Without it the server builds as before. Revert the PR to undo.

Public API change

Before

// No way to send MCP `instructions` from createMCPServer.
const server = createMCPServer({ name: 'notes', version: '1.0.0' })

After

const server = createMCPServer({
  name: 'notes',
  version: '1.0.0',
  instructions: 'Call `search_notes` before `read_note`.',
})
    1. 🦋 Changeset detected

      Latest commit: 6fe2901ef47a54887656a102b88fa2f59a6d9b1f

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/ai-mcpMinor

      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

    2. tanstack-source added labelsfeature

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      Caution

      Review failed

      The pull request is closed.

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

      Share

Sign in to join this conversation.