MCP ExplorerExplorer

Mcpmock

@strowkon 9 months ago
6 MIT
FreeCommunity
AI Systems
“模型上下文协议服务器的快速原型开发”

Overview

What is Mcpmock

mcpmock is a CLI tool designed for rapid prototyping of a Model Context Protocol server, allowing users to generate a mock server from a list of cases defined in a YAML file.

Use cases

mcpmock can be used for testing and development purposes, allowing developers to simulate server responses without needing a fully implemented backend. It is particularly useful for frontend developers working with APIs or for testing integrations.

How to use

To use mcpmock, define your test cases in a YAML file and place it in a folder named ‘testdata’. Ensure the file ends with ‘_test.yaml’. Run the command ‘mcpmock serve testdata’ to start the mock server. You can then send JSON-RPC requests to interact with the server.

Key features

Key features of mcpmock include the ability to quickly generate a mock server from YAML definitions, support for JSON-RPC requests, automatic response ID handling, and a straightforward command-line interface.

Where to use

undefined

Content

mcpmock

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

Installation

From npm: npm install -g @strowk/mcpmock

From Github Releases: Download, unpack and put binary in your PATH

From sources:

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

Usage

For example if you define something like this in a YAML file:

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
  }, 
}

Then if you put it in the folder testdata (make sure file also ends with _test.yaml) and run mcpmock like this:

mcpmock serve testdata

It would start a mock MCP server with stdio transport that would serve the cases defined in the YAML file.

If you now copy and paste this into your terminal:

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

, you should see list of tools as is defined in first MCP case.

And sending this:

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

, you should get the output as defined in second case.

It would also take care to replace the id field in the response with the id from the request, so if you send this:

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

, you should get the output as defined in second case, but with id field set to 2.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers