mcpmock
by: strowk
Rapid prototyping for Model Context Protocol server
📌Overview
Purpose: To provide a command-line interface (CLI) tool for generating a mock Model Context Protocol (MCP) server using case definitions from a YAML file.
Overview: mcpmock is a versatile CLI tool designed to facilitate the creation of a mock MCP server that can simulate various scenarios as outlined in a user-defined YAML file. This enables developers to test and validate interactions with MCP without needing a fully functional backend.
Key Features:
-
YAML Case Definition: Users define test cases and expected outcomes in a structured YAML format, allowing for clear and organized test scenarios.
-
Dynamic Response Handling: The tool automatically adjusts the response
id
in accordance with the request, ensuring consistency and accurate testing of RPC calls.
mcpmock
CLI tool that generates a mock Model Context Protocol server from a 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 put it in a folder named testdata
(make sure the file ends with _test.yaml
) and run mcpmock like this:
mcpmock serve testdata
This will start a mock MCP server with stdio transport that serves the cases defined in the YAML file.
Now if you send this JSON request:
{"jsonrpc": "2.0", "method": "tools/list", "id": 1}
You should see the list of tools as defined in the first MCP case.
Sending this request:
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "hello", "arguments": {}}, "id": 1}
Should return the output as defined in the second case.
The server also replaces the id
field in the response with the id
from the request. For example, if you send:
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "hello", "arguments": {}}, "id": 2}
You will get the output from the second case, but with the id
set to 2
.