MCP Hello World Server Simulator

1.1.2 · active · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

Demonstrates how to programmatically start `mcp-hello-world` as a child process in STDIO mode within a test suite (e.g., Jest) and interact with it to verify a custom MCP client implementation.

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' }] }
    });
  });
});

view raw JSON →