MCPサーバーのサンプル。
- bundle install
bundle installruby servers/http_server.rbcurl -i -X POST http://localhost:9292 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "initialize",
"id": 1,
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test",
"version": "1.0"
}
}
}'curl -X POST http://localhost:9292 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 2
}'curl -X POST http://localhost:9292 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 3,
"params": {
"name": "add_numbers",
"arguments": {
"a": 5,
"b": 3
}
}
}'curl -X POST http://localhost:9292 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 4,
"params": {
"name": "echo",
"arguments": {
"message": "Hello, MCP!"
}
}
}'curl -X POST http://localhost:9292 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 5,
"params": {
"name": "get_weather",
"arguments": {
"city": "Tokyo"
}
}
}'curl -X POST http://localhost:9292 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "resources/list",
"id": 6
}'curl -X POST http://localhost:9292 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "resources/read",
"id": 7,
"params": {
"uri": "test_resource"
}
}'