
mcp server e2e testing example
展示使用 TypeScript 和 Vitest 对 MCP 服务器进行端到端测试的两种方法。
Repository Info
About This Server
展示使用 TypeScript 和 Vitest 对 MCP 服务器进行端到端测试的两种方法。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
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
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.
Quick Start
Clone the repository
git clone https://github.com/mkusaka/mcp-server-e2e-testing-exampleInstall dependencies
cd mcp-server-e2e-testing-example
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.