Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public JsonRpcResponse handleRequest(
var method = req.getMethod();
return switch (method) {
case "initialize" -> handleInitialize(req);
case "ping" -> handlePing(req);
default -> {
initializeProxies(rpcResponse -> {});
yield switch (method) {
Expand Down Expand Up @@ -218,6 +219,14 @@ private JsonRpcResponse handleInitialize(JsonRpcRequest req) {
return createSuccessResponse(req.getId(), result);
}

private JsonRpcResponse handlePing(JsonRpcRequest req) {
return JsonRpcResponse.builder()
.id(req.getId())
.result(Document.of(Map.of()))
.jsonrpc("2.0")
.build();
}

private JsonRpcResponse handlePromptsList(JsonRpcRequest req) {
var result = ListPromptsResult.builder()
.prompts(prompts.values().stream().map(Prompt::promptInfo).toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ private void initializeWithProtocolVersion(ProtocolVersion protocolVersion) {
assertEquals(expectedPv, pv);
}

@Test
public void testPing() {
server = McpServer.builder()
.name("smithy-mcp-server")
.input(input)
.output(output)
.addService("test-mcp",
ProxyService.builder()
.service(ShapeId.from("smithy.test#TestService"))
.proxyEndpoint("http://localhost")
.model(MODEL)
.build())
.build();

server.start();

write("ping", Document.of(Map.of()), Document.of(42));
var response = read();
assertEquals(42, response.getId().asNumber().intValue());
assertNotNull(response.getResult());
assertTrue(response.getResult().asStringMap().isEmpty());
assertEquals("2.0", response.getJsonrpc());

write("ping", Document.of(Map.of()), Document.of("ping-id"));
response = read();
assertEquals("ping-id", response.getId().asString());
assertNotNull(response.getResult());
assertTrue(response.getResult().asStringMap().isEmpty());
}

@Test
public void noOutputSchemaWithUnsupportedProtocolVersion() {
server = McpServer.builder()
Expand Down