mcp-server-e2e-testing-example
A minimal example repository demonstrating two patterns for end-to-end (E2E) testing a TypeScript MCP server using Vitest.
MCP 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
tsx
and communicating overstdio
(JSON‑RPC). - SDK approach: Using the official MCP SDK’s
Client
andInMemoryTransport
for 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.ts
factory for your own MCP server - Expand
raw.spec.ts
andsdk.spec.ts
with additional test cases - Integrate into your CI pipeline
📄 License
Released under the .
Related MCP Servers
View all developer_tools servers →context7
by upstash
Context7 MCP provides up-to-date, version-specific documentation and code examples directly into your prompt, enhancing the capabilities of LLMs by ensuring they use the latest information.
git-mcp
by idosal
GitMCP is a free, open-source, remote Model Context Protocol (MCP) server that transforms GitHub projects into documentation hubs, enabling AI tools to access up-to-date documentation and code.
exa-mcp-server
by exa-labs
A Model Context Protocol (MCP) server allows AI assistants to use the Exa AI Search API for real-time web searches in a secure manner.
Sequential Thinking
by modelcontextprotocol
An MCP server implementation that provides a tool for dynamic and reflective problem-solving through a structured thinking process.
Everything MCP Server
by modelcontextprotocol
The Everything MCP Server is a comprehensive test server designed to demonstrate the full capabilities of the Model Context Protocol (MCP). It is not intended for production use but serves as a valuable tool for developers building MCP clients.
gateway
by centralmind
CentralMind Gateway is a tool designed to expose databases to AI agents via MCP or OpenAPI protocols, providing secure, LLM-optimized APIs.
mcpdoc
by langchain-ai
MCP LLMS-TXT Documentation Server provides a structured way to manage and retrieve LLM documentation using the Model Context Protocol.