MCP协议模拟服务器生成工具

一个从YAML文件中的案例列表生成模拟Model Context Protocol服务器的CLI工具,用于开发和测试环境。

  • by strowk
  • Go
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 strowk/mcpmock

使用说明

mcpmock

CLI tool that generates a mock Model Context Protocol server from list of cases in a YAML file.

安装

来自npm: npm install -g @strowk/mcpmock

Github发布: 下载,解压缩并将二进制文件放入PATH中

来源:

go get github.com/strowk/mcpmock
go install github.com/strowk/mcpmock

用法

例如,如果你在YAML文件中定义了这样的东西:

case: List tools

# requesting list of tools
in: {"jsonrpc": "2.0", "method": "tools/list", "id": 1}

# expect one tool in the list
out: {"jsonrpc": "2.0", "result":{ "tools": [{"description": "Hello MCP", "inputSchema": {"type": "object"}, "name": "hello"}] }, "id": 1}

---

case: Call Hello tool

# calling the tool
in: {"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "hello", "arguments": {}}, "id": 1}

# expect "Hi!" as output
out: {
  "jsonrpc": "2.0", 
  "id": 1,
  "result": {
    "content": [
      {"type": "text", "text": "Hi!"}
    ],
    "isError": false
  }, 
}

然后,如果你把它放在文件夹里 testdata (确保文件也以结尾 _test.yaml)然后像这样运行mcpmock:

mcpmock serve testdata

它将启动一个带有stdio传输的模拟MCP服务器,为YAML文件中定义的情况提供服务。

如果您现在将此内容复制并粘贴到您的终端中:

{"jsonrpc": "2.0", "method": "tools/list", "id": 1}

,您应该看到第一个MCP案例中定义的工具列表。

并发送以下内容:

{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "hello", "arguments": {}}, "id": 1}

,您应该得到第二种情况中定义的输出。

它还将注意更换 id 响应中的字段 id 根据请求,如果您发送以下内容:

{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "hello", "arguments": {}}, "id": 2}

,您应该得到第二种情况中定义的输出,但 id 字段设置为 2.