Skip to content

Commit 9f960bc

Browse files
authored
Merge pull request #239 from benthecarman/mcp-ping
Implement MCP ping method
2 parents 2a9da60 + d7d4ed1 commit 9f960bc

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

ldk-server-mcp/CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ src/
3535
- **Version**: `2025-11-25`
3636
- **Spec**: https://spec.modelcontextprotocol.io/
3737
- **Transport**: stdio (one JSON-RPC 2.0 message per line)
38-
- **Methods implemented**: `initialize`, `tools/list`, `tools/call`
38+
- **Methods implemented**: `initialize`, `tools/list`, `tools/call`, `ping`
3939
- **Notifications handled**: `notifications/initialized` (ignored, no response)
4040

4141
## Config

ldk-server-mcp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Streaming RPCs such as `subscribe_events` and non-RPC HTTP endpoints such as `me
101101

102102
- **Protocol version**: `2025-11-25`
103103
- **Transport**: stdio (one JSON-RPC 2.0 message per line)
104-
- **Methods**: `initialize`, `tools/list`, `tools/call`
104+
- **Methods**: `initialize`, `tools/list`, `tools/call`, `ping`
105105

106106
## Testing
107107

ldk-server-mcp/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ async fn main() {
124124
let resp = JsonRpcResponse::new(id, serde_json::json!({ "tools": tools }));
125125
serde_json::to_string(&resp).unwrap()
126126
},
127+
"ping" => {
128+
// Per the MCP spec, a ping must be answered with an empty result object.
129+
let resp = JsonRpcResponse::new(id, serde_json::json!({}));
130+
serde_json::to_string(&resp).unwrap()
131+
},
127132
"tools/call" => {
128133
let params = request.params.unwrap_or(Value::Null);
129134
match params.get("name").and_then(|v| v.as_str()) {

ldk-server-mcp/tests/integration.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,25 @@ fn test_tools_list() {
185185
}
186186
}
187187

188+
#[test]
189+
fn test_ping() {
190+
let mut proc = McpProcess::spawn();
191+
192+
proc.send(&json!({
193+
"jsonrpc": "2.0",
194+
"id": 1,
195+
"method": "ping"
196+
}));
197+
198+
let resp = proc.recv();
199+
assert_eq!(resp["jsonrpc"], "2.0");
200+
assert_eq!(resp["id"], 1);
201+
// Per the MCP spec, ping is answered with an empty result object.
202+
assert!(resp["result"].is_object(), "Expected result object, got: {}", resp["result"]);
203+
assert_eq!(resp["result"].as_object().unwrap().len(), 0, "Expected empty result object");
204+
assert!(resp.get("error").is_none(), "Ping must not return an error");
205+
}
206+
188207
#[test]
189208
fn test_tools_call_unknown_tool() {
190209
let mut proc = McpProcess::spawn();

0 commit comments

Comments
 (0)