mcp-server-e2e-testing-example

mcp-server-e2e-testing-example

3.3

A minimal example repository demonstrating two patterns for end-to-end (E2E) testing a TypeScript MCP server using Vitest.

The MCP Server E2E Testing Example is a repository designed to showcase two distinct methods for conducting end-to-end testing on a TypeScript-based Model Context Protocol (MCP) server. The repository utilizes Vitest, a testing framework, to implement these testing strategies. The first method, referred to as the 'Raw approach', involves spawning the command-line interface (CLI) using 'tsx' and communicating over standard input/output (stdio) using JSON-RPC. The second method, known as the 'SDK approach', leverages the official MCP SDK's 'Client' and 'InMemoryTransport' to perform in-memory remote procedure calls (RPC) without the need to spawn a child process. This repository serves as a template for developers looking to implement similar testing strategies in their own MCP server projects.

Features

  • Raw approach using stdio for JSON-RPC communication.
  • SDK approach with in-memory RPC using MCP SDK.
  • Comprehensive E2E testing with Vitest.
  • Template for MCP server testing.
  • Integration with CI pipelines.

Usage with Different Platforms

mcp

bash
# 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

# Run Raw (spawn + stdio) tests
pnpm vitest run tests/e2e/raw.spec.ts

# Run SDK (in-memory) tests
pnpm vitest run tests/e2e/sdk.spec.ts