sorry ,i want get your help
In stdio mode
I init the program
{"jsonrpc": "2.0", "id": "req_initialize_1", "method": "initialize", "params": {"protocolVersion": "1.12.0", "clientInfo": {"name": "MyClient", "version": "1.0.0"}, "capabilities": {"toolCall": {"dynamicRegistration": true, "version": "1.0.0"}, "resource": {"dynamicRegistration": true, "version": "1.0.0"}, "prompt": {"dynamicRegistration": true, "version": "1.0.0"}}}}
get
{"jsonrpc":"2.0","id":"req_initialize_1","result":{"protocolVersion":"2025-06-18","capabilities":{"experimental":{},"prompts":{"listChanged":false},"resources":{"subscribe":false,"listChanged":false},"tools":{"listChanged":false}},"serverInfo":{"name":"weather","version":"1.12.0"}}}
i think the init is finished
then i send the request
{"jsonrpc": "2.0", "id": "req_call_weather_ops_1", "method": "tools/call", "params": {"name": "weather_list_operations", "parameters": {}}} WARNING:root:Failed to validate request: Received request before initialization was complete
i get
WARNING:root:Failed to validate request: Received request before initialization was complete {"jsonrpc":"2.0","id":"req_list_tools_1","error":{"code":-32602,"message":"Invalid request parameters","data":""}}
can you give me 1 gourp of send contains how to init and a send message demo,very thank you
Hi! Thanks for trying out OpenAPI-MCP. The error you're seeing indicates that the MCP client is sending requests before the initialization process is complete.
The MCP protocol requires a specific initialization sequence. Here's a complete example of how to properly initialize and use the server:
1. First, ensure your configuration is correct:
{
"mcpServers": {
"weather": {
"command": "/path/to/your/python",
"args": ["/path/to/openapi-mcp/src/server.py"],
"env": {
"SERVER_NAME": "weather",
"OPENAPI_URL": "https://api.weather.gov/openapi.json"
},
"transport": "stdio"
}
}
}
2. The correct initialization sequence:
The MCP protocol requires this exact order:
Step 1: Initialize the connection
{
"jsonrpc": "2.0",
"id": "init_1",
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "your-client",
"version": "1.0"
}
}
}
Wait for the response before proceeding.
Step 2: Notify initialization complete
{
"jsonrpc": "2.0",
"method": "notifications/initialized",
"params": {}
}
Step 3: Now you can list tools
{
"jsonrpc": "2.0",
"id": "req_list_tools_1",
"method": "tools/list",
"params": {}
}
Step 4: Call a specific tool
{
"jsonrpc": "2.0",
"id": "req_call_weather_ops_1",
"method": "tools/call",
"params": {
"name": "weather:weather_list_operations",
"arguments": {}
}
}
Common issues:
-
Make sure you're using the correct method names:
- Use
tools/listnottools_list - Use
tools/callnottools_call
- Use
-
Tool names include the server prefix: When calling tools, use the full name like
weather:weather_list_operations -
Arguments vs parameters: Use
argumentsin the tools/call params, notparameters
Testing with stdio:
If you're testing manually via stdio, you can use this script:
import json
import subprocess
import time
# Start the server
proc = subprocess.Popen(
["python", "/path/to/server.py"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={
"SERVER_NAME": "weather",
"OPENAPI_URL": "https://api.weather.gov/openapi.json"
}
)
# Send initialization
init_request = {
"jsonrpc": "2.0",
"id": "init_1",
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "1.0"}
}
}
proc.stdin.write((json.dumps(init_request) + "\n").encode())
proc.stdin.flush()
# Read response
response = proc.stdout.readline()
print("Init response:", response.decode())
# Send initialized notification
proc.stdin.write((json.dumps({
"jsonrpc": "2.0",
"method": "notifications/initialized",
"params": {}
}) + "\n").encode())
proc.stdin.flush()
# Now you can send other requests...
Let me know if you need more help with the initialization sequence!