mcp-mock

mcp-mock

A lightweight mock MCP server for local testing and resilience experiments, providing predictable tool responses with simulated latency and errors.

Category
访问服务器

README

mcp-mock

mcp-mock is a lightweight synthetic mock server for the Model Context Protocol (MCP). It is designed for local testing, demos, and resilience experiments where you want a predictable MCP endpoint without depending on a real backend.

The current codebase includes:

  • a MockMCPServer implementation for registering tools and serving responses
  • a synthetic response generator powered by Faker
  • a chaos layer for latency and injected failures
  • a CLI entry point for running a mock server from a schema file
  • a pytest suite covering the core behaviors

Project layout

mcp-mock/
├── pyproject.toml
├── README.md
├── LICENSE
├── src/
│   └── mcp_mock/
│       ├── __init__.py
│       ├── chaos.py
│       ├── cli.py
│       ├── generator.py
│       └── server.py
└── tests/
    ├── test_chaos.py
    ├── test_cli.py
    ├── test_generator.py
    └── test_server.py

Installation

Install the package from the project root:

python -m pip install -e .

Install development dependencies as well:

python -m pip install -e ".[dev]"

Usage

mcp-mock is most useful when you want a predictable MCP server for local development, test automation, or demos. You can either run it from the command line with a schema file or create a server directly in Python.

CLI usage

The CLI entry point is mcp-mock serve. It reads a JSON file that describes the tools you want to expose and starts a mock MCP server over stdio.

Run a server from a schema file:

mcp-mock serve --schema ./tools_schema.json

Add simulated latency and failure injection:

mcp-mock serve --schema ./tools_schema.json --latency 100 --error-rate 0.1

CLI options

  • --schema or -s: required path to a JSON schema file
  • --latency: adds a delay in milliseconds before each tool response
  • --error-rate: injects failures probabilistically, from 0.0 to 1.0

Python API usage

You can also create a server programmatically in Python.

from mcp_mock.chaos import ChaosConfig
from mcp_mock.server import MockMCPServer

chaos = ChaosConfig(latency_ms=50, error_rate=0.05)
server = MockMCPServer(name="DemoServer", chaos=chaos)
server.register_tool(name="get_user", description="Get a user")
server.run_stdio()

This example does the following:

  • creates a mock server named DemoServer
  • attaches a chaos configuration with 50ms latency and a 5% error rate
  • registers a tool called get_user
  • starts the server over stdio

Registering custom handlers

If you want more control than the built-in synthetic responses, you can provide a custom handler when registering a tool.

from mcp_mock.server import MockMCPServer

server = MockMCPServer(name="DemoServer")

async def get_user_handler(user_id: str):
    return {"id": user_id, "name": "Ada Lovelace"}

server.register_tool(
    name="get_user",
    description="Return a user record",
    handler=get_user_handler,
)

Schema file format

A schema file should contain a top-level object with a server name and a list of tools. A simple example is shown below:

{
  "name": "ToolServer",
  "tools": [
    {
      "name": "get_user",
      "description": "Get a user by ID"
    },
    {
      "name": "execute_sql",
      "description": "Execute a SQL query"
    }
  ]
}

You can expand this format with additional metadata if you want to describe more complex tools, but the current implementation focuses on simple tool registration and synthetic responses.

When to use mcp-mock

Use mcp-mock when you want to:

  • test MCP integrations locally without a real backend
  • simulate slow or flaky tool responses
  • create demos with predictable tool outputs
  • validate client behavior under latency and injected errors

Development

Run the test suite:

pytest -q

License

This project is licensed under the MIT License. See LICENSE for details.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选