MCP Hello World Server Simulator
mcp-hello-world is a minimalist Model Context Protocol (MCP) server simulation, primarily designed as a test double or mock server for client-side unit and integration testing. Implemented in TypeScript, it offers a lightweight, predictable, and isolated environment for verifying MCP client logic without relying on real, complex, or potentially slow AI backend services. It currently stands at version 1.1.2 (released April 2025) with a recent cadence of small patches. Key differentiators include its support for both STDIO and HTTP/SSE MCP transport protocols, enabling comprehensive client testing across different connection methods. It provides simple `echo` and `debug` tools for predictable behavior, ensuring fast and reliable test execution. This package is explicitly *not* intended for production deployments or as a general-purpose MCP server.
Common errors
-
Error: spawn npx ENOENT
cause The `npx` command (or `pnpm dlx`/`bunx`) is not found in the system's PATH, or the Node.js environment is not correctly configured or accessible.fixEnsure Node.js and npm/pnpm/bun are correctly installed and their executables are available in your system's PATH. For CI/CD environments, verify the Node.js environment setup steps. -
ERR_STREAM_WRITE_AFTER_END
cause Attempting to write data to the `mcp-hello-world` child process's `stdin` stream after the stream has been closed, often because the server process exited prematurely or was explicitly killed.fixBefore sending data to the server, ensure the `mcp-hello-world` child process is still alive and its `stdin` stream is writable. Review your test lifecycle hooks to confirm processes are started before and terminated correctly after interaction. -
Error: connect ECONNREFUSED 127.0.0.1:3000
cause An attempt was made to connect to the HTTP/SSE server (which defaults to port 3000) when it was not running, was running in STDIO mode, or was listening on a different port.fixVerify that `mcp-hello-world` is started in HTTP/SSE mode (e.g., using `pnpm start:http`) and that your client is configured to connect to the correct `localhost:3000` endpoint. Check for potential port conflicts with other applications.
Warnings
- gotcha This package is explicitly designed as a 'test double' or 'mock server' and is not suitable for production deployments or as a general-purpose Model Context Protocol (MCP) server. Using it outside of a controlled testing environment is unsupported and may lead to unexpected behavior or security issues.
- gotcha The primary method of interacting with `mcp-hello-world` programmatically is by spawning it as a child process (e.g., using `child_process.spawn('npx', ['mcp-hello-world'])`) rather than direct JavaScript module imports. Developers expecting a programmatic API with `import { Server } from 'mcp-hello-world'` might find this unconventional.
- gotcha The package lists `react` and `react-dom` as peer dependencies. This is unusual for a server-side test utility and might cause unnecessary dependency warnings or conflicts in projects that don't use React, or use different versions.
Install
-
npm install mcp-hello-world -
yarn add mcp-hello-world -
pnpm add mcp-hello-world
Imports
- MCPHelloWorld
import * as MCPHelloWorld from 'mcp-hello-world'
- spawn
import { spawn } from 'child_process' - ChildProcess
import type { ChildProcess } from 'child_process'
Quickstart
import { spawn } from 'child_process';
// Assume './my-mcp-client' is your custom client implementation
// that connects to stdin/stdout streams.
import { MCPClient } from './my-mcp-client';
describe('My MCP Client (STDIO mode)', () => {
let mcpServerProcess: ReturnType<typeof spawn>;
let client: MCPClient; // Assume MCPClient accepts Readable/Writable streams
beforeAll(() => {
// Start mcp-hello-world as a child process in STDIO mode
mcpServerProcess = spawn('npx', ['mcp-hello-world']);
// Instantiate your client and connect it to the spawned process's stdio streams
client = new MCPClient(mcpServerProcess.stdin, mcpServerProcess.stdout);
// Optional: Log server output for debugging purposes
mcpServerProcess.stdout.on('data', (data) => console.log(`MCP Server STDOUT: ${data}`));
mcpServerProcess.stderr.on('data', (data) => console.error(`MCP Server STDERR: ${data}`));
});
afterAll(() => {
// Ensure the server process is terminated after all tests are done
if (mcpServerProcess) {
mcpServerProcess.kill();
}
});
it('should receive an echo response from the mock server', async () => {
const request = {
jsonrpc: '2.0',
id: 1,
method: 'tools/invoke',
params: { name: 'echo', parameters: { message: 'hello test' } }
};
// Assuming client.sendRequest handles JSON-RPC messaging over streams
const response = await client.sendRequest(request);
expect(response).toEqual({
jsonrpc: '2.0',
id: 1,
result: { content: [{ type: 'text', text: 'Hello hello test' }] }
});
});
});