mcp-hello-world

mcp-hello-world

A minimal MCP server mock for testing, providing echo, debug, and greeting resources to simulate MCP interactions.

Category
访问服务器

README

MCP Hello World - MCP Server Mock for Testing

This is a minimal Model Context Protocol (MCP) server implemented in TypeScript, primarily intended to serve as a Test Double / Mock Server.

Core Purpose: To provide a lightweight, controllable, and predictable MCP server environment for unit testing or integration testing client code that needs to interact with an MCP server.

Note: This project is not suitable for production environments or deployment as a general-purpose MCP server.

MCP Badge

Why Use mcp-hello-world in Tests?

When testing code related to MCP clients, you usually don't want to depend on a real, potentially complex, and unpredictably responsive AI backend service. Using mcp-hello-world as a test double offers several advantages:

  1. Isolation: Focus your tests on client logic without worrying about network issues or the availability of the real server.
  2. Predictability: The provided echo and debug tools have simple, fixed behaviors, making it easy to write assertions.
  3. Speed: Fast startup and response times, suitable for frequent use in unit tests.
  4. Lightweight: Few dependencies, easy to integrate into test environments.
  5. Protocol Coverage: Supports both STDIO and HTTP/SSE MCP transport protocols, allowing you to test client behavior under different connection methods.

Installation

Add this package as a dev dependency to your project:

# Using pnpm
pnpm add --save-dev mcp-hello-world

# Or using bun
bun add --dev mcp-hello-world

Manual Execution (for Debugging Tests)

You might want to run the server manually sometimes to debug your tests or client behavior.

STDIO Mode

This is the simplest way to run, especially during local development and debugging.

# Ensure it's installed (globally or in the project)
# Using npx (universal)
npx mcp-hello-world

# Or using pnpm dlx
pnpm dlx mcp-hello-world

# Or using bunx
bunx mcp-hello-world

The server will listen on standard input and output MCP responses to standard output. You can use tools like MCP Inspector to connect to the process.

To configure this server in your MCP client, add the following to your configuration:

{
  "mcpServers": {
    "mcp-hello-world": {
      "command": "npx",
      "args": ["mcp-hello-world"]
    }
  }
}

HTTP/SSE Mode

If you need to debug via a network interface or test HTTP-based MCP clients.

# 1. Clone the repository (if not already installed in the project)
# git clone https://github.com/lobehub/mcp-hello-world.git
# cd mcp-hello-world
# pnpm install / bun install

# 2. Build the project
# Using pnpm
pnpm build
# Or using bun
bun run build

# 3. Start the HTTP server
# Using pnpm
pnpm start:http
# Or using bun
bun run start:http

The server will start on http://localhost:3000 and provide:

  • SSE endpoint: /sse
  • Message endpoint: /messages

Usage in Tests

You can programmatically start and stop the mcp-hello-world server within your test framework (like Jest, Vitest, Mocha, etc.) for automated testing.

Example: Testing with STDIO Mode (Node.js)

// test/my-mcp-client.test.ts (Example using Jest)
import { spawn } from 'child_process';
import { MCPClient } from '../src/my-mcp-client'; // Assuming this is your client code

describe('My MCP Client (STDIO)', () => {
  let mcpServerProcess;
  let client: MCPClient;

  beforeAll(() => {
    // Start the mcp-hello-world process before tests
    // Using npx (or pnpm dlx / bunx) ensures the command is found and executed
    mcpServerProcess = spawn('npx', ['mcp-hello-world']);

    // Instantiate your client and connect to the subprocess's stdio
    client = new MCPClient(mcpServerProcess.stdin, mcpServerProcess.stdout);
  });

  afterAll(() => {
    // Shut down the mcp-hello-world process after tests
    mcpServerProcess.kill();
  });

  it('should receive echo response', async () => {
    const request = {
      jsonrpc: '2.0',
      id: 1,
      method: 'tools/invoke',
      params: { name: 'echo', parameters: { message: 'test message' } },
    };

    const response = await client.sendRequest(request); // Assuming your client has this method

    expect(response).toEqual({
      jsonrpc: '2.0',
      id: 1,
      result: { content: [{ type: 'text', text: 'Hello test message' }] },
    });
  });

  it('should get greeting resource', async () => {
    const request = {
      jsonrpc: '2.0',
      id: 2,
      method: 'resources/get',
      params: { uri: 'greeting://Alice' },
    };
    const response = await client.sendRequest(request);
    expect(response).toEqual({
      jsonrpc: '2.0',
      id: 2,
      result: { data: 'Hello Alice!' }, // Confirm return format based on actual implementation
    });
  });

  // ... other test cases
});

Example: Testing with HTTP/SSE Mode

For HTTP/SSE, you might need to:

  1. Use exec or spawn in beforeAll to start pnpm start:http or bun run start:http.
  2. Use an HTTP client (like axios, node-fetch, or your test framework's built-in client) to connect to http://localhost:3000/sse and /messages for testing.
  3. Ensure you shut down the started server process in afterAll.

Provided MCP Capabilities (for Test Assertions)

mcp-hello-world provides the following fixed capabilities for interaction and assertion in your tests:

Resources

  • hello://world
    • Description: A static Hello World resource.
    • Method: resources/get
    • Parameters: None
    • Returns: { data: 'Hello World!' }
  • greeting://{name}
    • Description: A dynamic greeting resource.
    • Method: resources/get
    • Parameters: name included in the URI, e.g., greeting://Bob.
    • Returns: { data: 'Hello {name}!' } (e.g., { data: 'Hello Bob!' })

Tools

  • echo
    • Description: Echoes the input message, prefixed with "Hello ".
    • Method: tools/invoke
    • Parameters: { name: 'echo', parameters: { message: string } }
    • Returns: { content: [{ type: 'text', text: 'Hello {message}' }] } (e.g., { content: [{ type: 'text', text: 'Hello test' }] })
  • debug
    • Description: Lists all available MCP method definitions on the server.
    • Method: tools/invoke
    • Parameters: { name: 'debug', parameters: {} }
    • Returns: A JSON structure containing definitions for all registered resources, tools, and prompts.

Prompts

  • helpful-assistant
    • Description: A basic assistant prompt definition.
    • Method: prompts/get
    • Parameters: None
    • Returns: A JSON structure for the prompt with predefined system and user roles.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选