MCP.so
Sign In
Servers

MCP Server E2E Testing Example

@mkusaka

Overview

What is MCP Server E2E Testing Example?

MCP Server E2E Testing Example is a minimal reference repository that demonstrates two end‑to‑end testing patterns for a TypeScript Model Context Protocol (MCP) server using Vitest. It is intended for developers who build MCP servers and want to validate them via automated tests.

How to use MCP Server E2E Testing Example?

Clone the repository, install dependencies with pnpm install, then run the desired test suite: pnpm vitest run tests/e2e/raw.spec.ts (spawn‑based raw tests) or pnpm vitest run tests/e2e/sdk.spec.ts (in‑memory SDK tests). Convenience scripts (pnpm run test:raw, pnpm run test:sdk, pnpm run test) can be added to package.json.

Key features of MCP Server E2E Testing Example

  • Two E2E testing approaches: raw and SDK
  • Uses Vitest as the test runner
  • Raw approach spawns CLI with tsx and uses stdio
  • SDK approach uses Client and InMemoryTransport
  • Includes an example server with resources, prompts, and tools
  • Ready‑to‑run test suites and a reproducible layout

Use cases of MCP Server E2E Testing Example

  • E2E testing of a TypeScript MCP server before deployment
  • Verifying server responses to JSON‑RPC messages over stdio
  • Comparing raw process‑spawn testing with in‑memory SDK testing
  • Adapting as a template for adding E2E tests to existing MCP servers
  • Integrating MCP server tests into a continuous integration pipeline

FAQ from MCP Server E2E Testing Example

What are the prerequisites for using MCP Server E2E Testing Example?

Node.js ≥ 16, pnpm installed globally, and Git are required.

How do I run the raw (spawn + stdio) tests?

Execute pnpm vitest run tests/e2e/raw.spec.ts from the repository root.

How do I run the SDK (in‑memory) tests?

Execute pnpm vitest run tests/e2e/sdk.spec.ts to run tests that use the MCP SDK’s Client and InMemoryTransport.

What is the difference between the raw and SDK testing approaches?

The raw approach spawns a child process (npx tsx src/cli.ts) and communicates over stdin/stdout via JSON‑RPC. The SDK approach invokes the same server logic in‑process using the MCP SDK’s InMemoryTransport, avoiding process spawning.

Is MCP Server E2E Testing Example intended for production use?

No, it is explicitly a minimal example and template. Users are encouraged to adapt the server factory (src/server.ts) and expand the test suites for their own MCP servers.

More from Other