Testing MCP Agents¶
How to test MCP Mesh agents using meshctl and curl
Note: This page shows Python examples. See meshctl man testing --typescript for TypeScript or meshctl man testing --java for Java/Spring Boot examples.
Quick Way: meshctl call¶
meshctl call hello_mesh_simple # Call tool by name (recommended)
meshctl call add '{"a": 1, "b": 2}' # With arguments
meshctl list --tools # List all available tools
See meshctl man cli for more CLI commands.
Protocol Details: curl¶
MCP agents expose a JSON-RPC 2.0 API over HTTP with Server-Sent Events (SSE) responses. This section shows the correct curl syntax - useful for understanding the underlying protocol.
Key Points¶
- Endpoint: Always POST to
/mcp(not REST-style paths like/tools/list) - Method: Always
POST - Headers: Must include both
Content-TypeANDAcceptheaders - Body: JSON-RPC 2.0 format with
jsonrpc,id,method,params - Response: Server-Sent Events format, requires parsing
List Available Tools¶
curl -s -X POST http://localhost:PORT/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}'
Call a Tool (No Arguments)¶
curl -s -X POST http://localhost:PORT/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_current_time",
"arguments": {}
}
}'
Call a Tool (With Arguments)¶
curl -s -X POST http://localhost:PORT/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "generate_report",
"arguments": {"title": "Test Report", "format": "markdown"}
}
}'
Available MCP Methods¶
| Method | Description |
|---|---|
tools/list | List all available tools |
tools/call | Invoke a tool with arguments |
prompts/list | List available prompts |
resources/list | List available resources |
resources/read | Read a resource |
Response Format¶
MCP responses use Server-Sent Events (SSE) format:
To parse the response, you can pipe through:
Common Errors¶
Missing Accept Header¶
Wrong Endpoint¶
Invalid JSON-RPC Format¶
Testing in Docker Compose¶
Calls route through the registry proxy by default:
meshctl call greet
meshctl call add '{"a": 1, "b": 2}'
# Bypass proxy (requires mapped ports)
meshctl call greet --use-proxy=false --agent-url http://localhost:9001
Testing in Kubernetes¶
For Kubernetes with ingress configured, use ingress mode:
# With DNS configured for the ingress domain
meshctl call greet --ingress-domain mcp-mesh.local
# Without DNS (direct IP or port-forwarded)
meshctl call greet --ingress-domain mcp-mesh.local --ingress-url http://localhost:9080
Testing with meshctl¶
See Also¶
meshctl man cli- CLI commands for developmentmeshctl man decorators- How to create toolsmeshctl man capabilities- Understanding capabilities