Copyright (c) 2025, Software Tree
This guide explains how to interact with an ORMCP server running in HTTP mode using curl or other HTTP clients.
When your ORMCP server starts in HTTP mode, you'll see output like:
INFO: Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
First, establish a connection and initialize the MCP session:
curl -X POST \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl-client","version":"1.0.0"}}}' \
"http://127.0.0.1:8080/mcp/"Key Points:
- Use the
/mcp/endpoint (with trailing slash) - Include both
application/jsonandtext/event-streamin Accept header - The server will return a session ID in the
mcp-session-idheader
Expected Response:
event: message
data: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2024-11-05","capabilities":{"tools":{"listChanged":false},...},"serverInfo":{"name":"ORMCPServerDemo","version":"1.9.4"}}}
Save the mcp-session-id from the response headers (e.g., c97b99b7b9b343bd8cf590f5d5a40367).
After successful initialization, send the required initialized notification:
curl -X POST \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-H "mcp-session-id: YOUR_SESSION_ID_HERE" \
-d '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
"http://127.0.0.1:8080/mcp/"Note: This request has no id field since it's a notification, not a request expecting a response.
Now you can discover what tools are available:
curl --max-time 10 \
-X POST \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-H "mcp-session-id: YOUR_SESSION_ID_HERE" \
-d '{"jsonrpc":"2.0","id":"2","method":"tools/list"}' \
"http://127.0.0.1:8080/mcp/"Use the tools/call method to execute available tools:
curl --max-time 10 \
-X POST \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-H "mcp-session-id: YOUR_SESSION_ID_HERE" \
-d '{"jsonrpc":"2.0","id":"3","method":"tools/call","params":{"name":"TOOL_NAME","arguments":{"param1":"value1"}}}' \
"http://127.0.0.1:8080/mcp/"| Method | Description | Example Usage |
|---|---|---|
tools/list |
List all available tools | See step 3 above |
tools/call |
Execute a specific tool | See step 4 above |
resources/list |
List available resources | Similar to tools/list |
prompts/list |
List available prompts | Similar to tools/list |
Solution: Include both content types in Accept header:
-H "Accept: application/json, text/event-stream"
Solution:
- Ensure you've initialized first and captured the session ID
- Include the session ID in subsequent requests:
-H "mcp-session-id: YOUR_SESSION_ID_HERE"
Solution: Send the notifications/initialized notification after initialization but before making other requests.
This is normal for Server-Sent Events. Use --max-time 10 to set a timeout, or press Ctrl+C to cancel.
For browser-based interaction, you can use JavaScript:
// Initialize
fetch('http://127.0.0.1:8080/mcp/', {
method: 'POST',
headers: {
'Accept': 'application/json, text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"jsonrpc": "2.0",
"id": "1",
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "browser-client", "version": "1.0.0"}
}
})
})
.then(response => {
const sessionId = response.headers.get('mcp-session-id');
// Use sessionId for subsequent requests
});- Use double quotes for JSON strings and escape inner quotes with
\" - Use single-line commands to avoid copy-paste issues
- Add
--max-time 10to prevent hanging connections
This completes the basic interaction pattern with your MCP server in HTTP mode.