Skip to content

docs(server): add unit testing guide using InMemoryTransport#1627

Open
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:docs/1126-unit-testing-guide
Open

docs(server): add unit testing guide using InMemoryTransport#1627
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:docs/1126-unit-testing-guide

Conversation

@nielskaspers
Copy link
Contributor

Summary

Closes #1126

There was no documentation explaining how to unit-test MCP servers without spawning subprocesses or opening ports. This adds a ## Testing section to the server guide that:

  • Explains InMemoryTransport.createLinkedPair() as the recommended approach
  • Shows a complete vitest/jest example for testing a registered tool end-to-end
  • Lists what this approach does and does not test (so readers know when they need HTTP integration tests too)
  • Links to the existing createInMemoryTaskEnvironment helper for task-related tests

Changes

  • docs/server.md: new ## Testing section before ## More server features

Test plan

  • Read through the new section — the code example should be copy-paste runnable in a project that depends on @modelcontextprotocol/server and @modelcontextprotocol/core

Adds a ## Testing section to the server guide explaining how to
unit-test MCP servers in-process using InMemoryTransport, without
spawning subprocesses or opening ports.

Includes a working vitest/jest example for testing a tool, and notes
on what the approach does and does not cover.

Closes modelcontextprotocol#1126
@nielskaspers nielskaspers requested a review from a team as a code owner March 4, 2026 22:14
@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2026

⚠️ No Changeset found

Latest commit: e74a4bb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1627

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1627

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1627

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1627

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1627

commit: e23bdfb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

What is the recommended way of writing unit tests for MCP endpoints?

1 participant