Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,23 +516,36 @@ 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
- Tool calling with simple responses
- 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

Expand Down
45 changes: 36 additions & 9 deletions cmd/mcptools/commands/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -31,11 +33,20 @@ Available types:
- prompt <name> <description> <template>
- resource <uri> <description> <content>

Example:
Transport options:
- Default: stdin/stdout (stdio transport)
- --port <port>: HTTP SSE transport on specified port

Examples:
# Stdio transport (default)
mcp mock tool hello_world "when user says hello world, run this tool"
mcp mock tool hello_world "A greeting tool" \

# HTTP transport
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"`,
resource docs:readme "Documentation" "# Mock MCP Server\nThis is a mock server"

# Then connect to http://localhost:3000/sse`,
Args: cobra.MinimumNArgs(2),
Run: func(_ *cobra.Command, args []string) {
tools := make(map[string]string)
Expand Down Expand Up @@ -111,16 +122,32 @@ Example:
os.Exit(1)
}

fmt.Fprintf(os.Stderr, "Starting mock MCP server with %d tool(s), %d prompt(s), and %d resource(s)\n",
len(tools), len(prompts), len(resources))
fmt.Fprintf(os.Stderr, "Use Ctrl+C to exit\n")
if port != "" {
fmt.Fprintf(os.Stderr, "Starting HTTP mock MCP server with %d tool(s), %d prompt(s), and %d resource(s) on port %s\n",
len(tools), len(prompts), len(resources), port)
fmt.Fprintf(os.Stderr, "JSON-RPC endpoint: http://localhost:%s/mcp\n", port)
fmt.Fprintf(os.Stderr, "SSE endpoint: http://localhost:%s/sse (for SSE-compatible clients)\n", port)
fmt.Fprintf(os.Stderr, "Health check: http://localhost:%s/health\n", port)
fmt.Fprintf(os.Stderr, "Use Ctrl+C to exit\n")

if err := mock.RunMockServer(tools, prompts, resources); err != nil {
fmt.Fprintf(os.Stderr, "Error running mock server: %v\n", err)
os.Exit(1)
if err := mock.RunMockServerHTTP(tools, prompts, resources, port); err != nil {
fmt.Fprintf(os.Stderr, "Error running HTTP mock server: %v\n", err)
os.Exit(1)
}
} else {
fmt.Fprintf(os.Stderr, "Starting mock MCP server with %d tool(s), %d prompt(s), and %d resource(s)\n",
len(tools), len(prompts), len(resources))
fmt.Fprintf(os.Stderr, "Use Ctrl+C to exit\n")

if err := mock.RunMockServer(tools, prompts, resources); err != nil {
fmt.Fprintf(os.Stderr, "Error running mock server: %v\n", err)
os.Exit(1)
}
}
},
}

cmd.Flags().StringVar(&port, "port", "", "Start HTTP server on specified port (e.g., 3000). If not specified, uses stdio transport.")

return cmd
}
Loading