mcp-harness
In-memory testing toolkit for MCP servers in TypeScript - supertest for MCP
claude mcp add --transport stdio gabry-ts-mcp-harness node dist/server.js \ --env API_KEY="<your-api-key>"
How to use
mcp-harness provides an in-memory test harness for MCP servers written in TypeScript. It lets you import your McpServer instance and connect a harness directly to it, avoiding subprocesses, ports, and I/O. This makes it ideal for fast, reliable tests and CI integration, acting similarly to supertest but tailored for the MCP (Model Context Protocol) ecosystem. You can register tools, resources, prompts, and then invoke tools or read resources through a unified harness API, inspect results, and assert on text content or errors without dealing with serializing or socket communication.
In practice, you typically create a McpServer in your test code, attach tools that return structured MCP results, and then instantiate a harness via createHarness. In in-memory mode, you pass your McpServer instance directly to createHarness and interact entirely in-process. In subprocess mode, you can test a real MCP server executable by supplying a SubprocessConfig with a command, arguments, and environment, mirroring how a client would connect in production. The harness exposes methods like listTools, callTool, listResources, readResource, listPrompts, and getServerCapabilities, enabling end-to-end testing of your server’s behavior and responses.
Whether you’re validating tool outputs, resource reads, or prompt resolution, mcp-harness provides assertion helpers to examine text within tool results, verify errors, and check for the existence of tools, resources, and prompts. It’s designed to be framework-agnostic, so you can use Vitest, Jest, node:assert, or your preferred test runner to write expressive MCP tests.
How to install
Prerequisites:
- Node.js (>= 14.x or newer) and npm or pnpm
- A TypeScript-based MCP server project, or a compiled MCP server that exports an McpServer instance
Step-by-step:
-
Create a project directory (if starting fresh) and initialize npm:
mkdir my-mcp-project cd my-mcp-project npm init -y
-
Install the harness and its peer dependency:
npm install --save-dev mcp-harness npm install --save @modelcontextprotocol/sdk
-
If you’re building a TypeScript MCP server, ensure your server exports an McpServer instance that can be consumed by the harness. See the library’s integration guide for how to expose the server for testing.
-
(Optional) If you plan to run a real MCP server as a subprocess, ensure you have a runnable entrypoint (e.g., dist/server.js) and that your environment variables are configured as needed for tests.
-
Add a test script or test files that use createHarness to connect to your in-memory server or to a subprocess configuration as demonstrated in the README.
Additional notes
Tips and notes:
- In-memory mode is the fastest and most deterministic way to test MCP servers; use it for unit and integration tests where possible.
- Subprocess mode is useful to validate your server’s runtime behavior, startup, and CLI/transport interactions against a real process.
- If your server requires API keys or environment-specific settings, supply them via the env object in SubprocessConfig or set them in your test environment for in-memory mode.
- When testing, you can rely on helper assertions like hasText, getFirstText, resourceExists, and promptExists to quickly verify common MCP results.
- The npm package name is mcp-harness and it expects @modelcontextprotocol/sdk to be installed as a peer dependency for full compatibility.
Related MCP Servers
obsidian -tools
Add Obsidian integrations like semantic search and custom Templater prompts to Claude or any MCP client.
Matryoshka
MCP server for token-efficient large document analysis via the use of REPL state
pluggedin-app
The Crossroads for AI Data Exchanges. A unified, self-hostable web interface for discovering, configuring, and managing Model Context Protocol (MCP) servers—bringing together AI tools, workspaces, prompts, and logs from multiple MCP sources (Claude, Cursor, etc.) under one roof.
Agentic -Skill
Agentic-MCP, Progressive MCP client with three-layer lazy loading. Validates AgentSkills.io pattern for efficient token usage. Use MCP without pre-install & wasting full-loading
mongo
MCP server that provide tools to LLMs such as claude in cursor to interact with MongoDB
vscode-context
MCP Server to Connect with VS Code IDE