MCP双离合器
](https://www.npmjs.com/package/mcp-doppelganger) ](https://www.npmjs.com/package/mcp-doppelganger)
每个MCP服务器都有一个二重身!
二重身是一种模仿 主控程序 服务器由一个简单的配置文件创建。使用它来测试AI代理、从已弃用的服务迁移或在本地模拟任何MCP服务器。您可以克隆现有服务器,修改配置以自定义响应,并为其提供服务。
快速开始
使用启动模拟MCP服务器 doppelganger.yaml 此repo中包含的配置:
npx -y mcp-doppelganger serve -f https://raw.githubusercontent.com/rinormaloku/mcp-doppelganger/main/doppelganger.yaml就是这样。立即用 MCP检查员:
# List all tools
npx -y @modelcontextprotocol/inspector \
--cli "http://localhost:3000/mcp" --transport http --method tools/list
# Call a tool
npx -y @modelcontextprotocol/inspector \
--cli "http://localhost:3000/mcp" --transport http --method tools/call --tool-name "hello_user" --tool-arg "username=user-42"服务器会根据您在配置中定义的内容进行响应。不需要真正的后端。
克隆现有MCP服务器
想要创建真实服务器的假版本吗?使用 clone 命令。它连接到真实的服务器,读取其所有工具、资源和提示,并编写 doppelganger.yaml 为你。
# Clone a server running via stdio
npx -y mcp-doppelganger clone "npx -y @modelcontextprotocol/server-everything"
# Clone a server running over HTTP
npx -y mcp-doppelganger clone "http://localhost:3000/mcp" --transport http
# Clone with authentication
npx -y mcp-doppelganger clone "http://localhost:3000/mcp" --transport http \
-H "Authorization: Bearer $TOKEN"
# Set a default response message for every tool, resource, and prompt
npx -y mcp-doppelganger clone "npx -y @modelcontextprotocol/server-everything" \
--response "This service has been decommissioned. Please contact support."编辑生成的文件以自定义响应,然后提供它:
npx -y mcp-doppelganger serve -f doppelganger.yaml配置参考
完整示例
看 examples/complete.yaml 对于一个完整的配置文件,您可以将其用作起点。
version: "2025-11-25"
server:
name: "my-fake-server"
description: "Description shown to the AI agent"
version: "1.0.0"
tools:
- name: "send_notification"
description: "Sends a notification (DEPRECATED)"
inputSchema:
type: "object"
properties:
userId:
type: "string"
message:
type: "string"
response:
isError: true
content:
- type: "text"
text: "Notifications tool moved to the new Messaging MCP. CANNOT notify {{args.userId}}: '{{args.message}}'"
resources:
- uri: "config://app"
name: "Application Config"
mimeType: "application/json"
response:
text: '{"status": "deprecated", "migration": "Use environment variables instead"}'
mimeType: "application/json"
prompts:
- name: "generate_report"
description: "Generate a report (DEPRECATED)"
arguments:
- name: "reportType"
- name: "dateRange"
response:
messages:
- role: "assistant"
content:
type: "text"
text: "Reports moved to https://analytics.example.com."运输选项
# stdio (default) — for use with AI agents and MCP clients
npx -y mcp-doppelganger serve --stdio -f doppelganger.yaml
# HTTP — for browser or REST-based access
npx -y mcp-doppelganger serve --http -p 3000 -f doppelganger.yaml
# Both at the same time
npx -y mcp-doppelganger serve --stdio --http -f doppelganger.yaml示例用例:弃用带代理的MCP服务器
启发此软件包的一个用例是弃用现有的MCP服务器,并通知使用它的AI代理弃用情况,并将其引导到新服务器或替代解决方案。
使用此软件包,您只需克隆旧服务器,为每个工具自定义弃用消息,并在MCP代理后面为二重身提供服务。客户端不断到达同一个端点——人工智能代理得到了关于迁移到哪里的明确指示。
请参阅中的完整演练(包括验证命令) docs/deprecent-with-proxy.md.
码头工人
docker build -t mcp-doppelganger .
# Mount a local config file
docker run -v $(pwd):/config mcp-doppelganger serve -f /config/doppelganger.yaml
# Pull config from a URL
docker run mcp-doppelganger serve -f https://example.com/doppelganger.yamlCLI命令参考
mcp-doppelganger clone
连接到实时MCP服务器并“研究”其模式以生成配置文件。
| 选项 | 简写 | 描述 | 默认值 |
|---|---|---|---|
--transport | -t | 运输类型: stdio 或 http | stdio |
--output | -o | 输出文件路径 | doppelganger.yaml |
--format | -f | 输出格式: yaml 或 json | yaml |
--header | -H | HTTP标头(可重复多次) | [] |
--response | -r | 所有捕获实体的默认响应文本 | None |
mcp-doppelganger serve
启动二重身服务器以托管模拟界面。
| 选项 | 简写 | 描述 | 默认值 |
|---|---|---|---|
--file | -f | 配置文件的路径或URL | doppelganger.yaml |
--stdio | 启用 stdio 运输(供当地代理商使用) | false | |
--http | 启用HTTP传输(用于浏览器/远程使用) | false | |
--port | -p | 启用HTTP传输时使用的端口 | 3000 |
发展
# Install dependencies
bun install
# Run locally
bun run dev
# Type check
bun run typecheck
# Build
bun run build______________________________________________________________________
许可证
麻省理工学院
