About MCP Server E2E Testing Example
A TypeScript example repository for developers who want to test MCP servers end to end with Vitest. It demonstrates both subprocess-based stdio testing and in-memory testing with the MCP SDK.
Key features
- 01Raw stdio JSON-RPC tests
- 02In-memory MCP SDK tests
- 03Vitest-based test suites
- 04Reusable server factory example
Use cases
- 01Test a server through its CLI and stdio
- 02Test server logic without spawning a process
MCP support
Demonstrates two ways to test a TypeScript MCP server: JSON-RPC over stdio and in-memory RPC using the MCP SDK Client and InMemoryTransport.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP Server E2E Testing Example
A minimal example repository demonstrating two patterns for end‑to‑end (E2E) testing a TypeScript MCP (Model Context Protocol) server using Vitest:
- Raw approach: Spawning the CLI with
tsxand communicating overstdio(JSON‑RPC). - SDK approach: Using the official MCP SDK’s
ClientandInMemoryTransportfor in‑memory RPC.
Repository: https://github.com/mkusaka/mcp-server-e2e-testing-example
📁 Repository Layout
.
├── LICENSE
├── README.md
├── package.json
├── pnpm-lock.yaml
├── src
│ ├── cli.ts # CLI entrypoint (tsx + stdio transport)
│ └── server.ts # createServer() factory (resources, prompts, tools)
├── tests
│ └── e2e
│ ├── raw.spec.ts # spawn‑based E2E tests
│ └── sdk.spec.ts # SDK/InMemoryTransport‑based E2E tests
└── tsconfig.json
🚀 Getting Started
Prerequisites
- Node.js ≥ 16
- pnpm installed globally
- Git
Installation
# Clone the repo
git clone https://github.com/mkusaka/mcp-server-e2e-testing-example.git
cd mcp-server-e2e-testing-example
# Install dependencies
pnpm install
🧪 Running E2E Tests
1. Raw (spawn + stdio) tests
This suite launches the CLI (src/cli.ts) via npx tsx and sends JSON‑RPC over stdin/stdout.
pnpm vitest run tests/e2e/raw.spec.ts
2. SDK (in‑memory) tests
This suite uses the MCP SDK’s Client + InMemoryTransport to invoke the same server logic without spawning a child process.
pnpm vitest run tests/e2e/sdk.spec.ts
🛠️ Scripts
Add these to package.json if desired:
{
"scripts": {
"test:raw": "vitest run tests/e2e/raw.spec.ts",
"test:sdk": "vitest run tests/e2e/sdk.spec.ts",
"test": "vitest run"
}
}
pnpm run test:raw– Run only the raw/stdio testspnpm run test:sdk– Run only the in‑memory SDK testspnpm run test– Run all tests
📦 Publishing & Usage
This repository is intended as an example/template. Feel free to:
- Adapt the
src/server.tsfactory for your own MCP server - Expand
raw.spec.tsandsdk.spec.tswith additional test cases - Integrate into your CI pipeline
📄 License
Released under the MIT License.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.