From 5f80d3de8d36781a568d548645eae922a7243fe0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Jun 2025 23:10:41 +0000 Subject: [PATCH 1/2] Initial plan for issue From 44058d388736c9fc15f07344f35e8434f624b2fb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Jun 2025 23:28:12 +0000 Subject: [PATCH 2/2] Implement HTTP transport for mock MCP server Co-authored-by: f <196477+f@users.noreply.github.com> --- README.md | 21 ++- cmd/mcptools/commands/mock.go | 45 ++++-- pkg/mock/mock.go | 288 ++++++++++++++++++++++++++++++++++ pkg/mock/mock_test.go | 158 +++++++++++++++++++ 4 files changed, 499 insertions(+), 13 deletions(-) create mode 100644 pkg/mock/mock_test.go diff --git a/README.md b/README.md index fd00e03..d10b6e7 100644 --- a/README.md +++ b/README.md @@ -516,16 +516,28 @@ MCP Tools can operate as both a client and a server, with two server modes avail The mock server mode creates a simulated MCP server for testing clients without implementing a full server: ```bash -# Create a mock server with a simple tool +# Create a mock server with a simple tool (stdio transport - default) mcp mock tool hello_world "A simple greeting tool" -# Create a mock server with multiple entity types -mcp mock tool hello_world "A greeting tool" \ +# Create a mock server with HTTP transport (for Docker/Kubernetes deployment) +mcp mock --port 3000 tool hello_world "A greeting tool" \ prompt welcome "A welcome prompt" "Hello {{name}}, welcome to {{location}}!" \ resource docs://readme "Documentation" "Mock MCP Server\nThis is a mock server" ``` -Features of the mock server: +#### Transport Options + +The mock server supports two transport modes: + +- **Stdio transport (default)**: Uses stdin/stdout, suitable for direct command-line use +- **HTTP transport**: Uses HTTP with JSON-RPC, suitable for containerized deployments + +When using HTTP transport (`--port` flag), the server provides: +- **JSON-RPC endpoint**: `POST http://localhost:PORT/mcp` +- **SSE endpoint**: `GET http://localhost:PORT/sse` (for SSE-compatible clients) +- **Health check**: `GET http://localhost:PORT/health` + +#### Features - Full initialization handshake - Tool listing with standardized schema @@ -533,6 +545,7 @@ Features of the mock server: - Resource listing and reading - Prompt listing and retrieval with argument substitution - Detailed request/response logging to `~/.mcpt/logs/mock.log` +- Docker/Kubernetes ready with HTTP transport #### Using Prompt Templates diff --git a/cmd/mcptools/commands/mock.go b/cmd/mcptools/commands/mock.go index 3f03700..a130e19 100644 --- a/cmd/mcptools/commands/mock.go +++ b/cmd/mcptools/commands/mock.go @@ -10,6 +10,8 @@ import ( // MockCmd creates the mock command. func MockCmd() *cobra.Command { + var port string + cmd := &cobra.Command{ Use: "mock [type] [name] [description] [content]...", Short: "Create a mock MCP server with tools, prompts, and resources", @@ -31,11 +33,20 @@ Available types: - prompt