Skip to content

Commit 2fa9278

Browse files
authored
Merge pull request #177 from mkouba/fix-list-notifications-stdio
stdio: fix list changed notifications
2 parents 06ec424 + e0475dd commit 2fa9278

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

transports/stdio/integration-tests/src/main/java/io/quarkiverse/mcp/server/stdio/it/ServerFeatures.java

+11
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@
1010
import io.quarkiverse.mcp.server.Resource;
1111
import io.quarkiverse.mcp.server.TextContent;
1212
import io.quarkiverse.mcp.server.Tool;
13+
import io.quarkiverse.mcp.server.ToolManager;
14+
import io.quarkiverse.mcp.server.ToolResponse;
1315
import io.quarkus.logging.Log;
1416

1517
public class ServerFeatures {
1618

1719
@Inject
1820
CodeService codeService;
1921

22+
@Inject
23+
ToolManager toolManager;
24+
2025
@Tool
2126
TextContent toLowerCase(String value) {
27+
// Just register another tool
28+
toolManager.newTool("testTool")
29+
.setDescription("This tool does nothing.")
30+
.setHandler(
31+
ta -> ToolResponse.success("OK"))
32+
.register();
2233
return new TextContent(value.toLowerCase());
2334
}
2435

transports/stdio/integration-tests/src/test/java/io/quarkiverse/mcp/server/stdio/it/ServerFeaturesIT.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void testTool() {
149149
assertEquals("string", valueProperty.getString("type"));
150150
});
151151

152-
assertToolCall(
152+
assertToolCallAndNotification(
153153
"loop", "toLowerCase", new JsonObject()
154154
.put("value", "LooP"));
155155
}
@@ -226,13 +226,17 @@ private void assertTool(JsonObject tool, String name, String description, Consum
226226
}
227227
}
228228

229-
private void assertToolCall(String expectedText, String name, JsonObject arguments) {
229+
private void assertToolCallAndNotification(String expectedText, String name, JsonObject arguments) {
230230
JsonObject toolGetMessage = newMessage("tools/call")
231231
.put("params", new JsonObject()
232232
.put("name", name)
233233
.put("arguments", arguments));
234234
sendMessage(toolGetMessage);
235235

236+
// Since we're using stdio we need to await the notification first
237+
JsonObject notification = awaitResponse();
238+
assertEquals("notifications/tools/list_changed", notification.getString("method"));
239+
236240
JsonObject toolGetResponse = awaitResponse();
237241

238242
JsonObject toolGetResult = assertResponseMessage(toolGetMessage, toolGetResponse);

transports/stdio/runtime/src/main/java/io/quarkiverse/mcp/server/stdio/runtime/StdioMcpMessageHandler.java

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void initialize(PrintStream stdout, McpRuntimeConfig config) {
6565
String connectionId = Base64.getUrlEncoder().encodeToString(UUID.randomUUID().toString().getBytes());
6666
StdioMcpConnection connection = new StdioMcpConnection(connectionId, config.clientLogging().defaultLevel(),
6767
trafficLogger, config.autoPingInterval(), stdout, vertx);
68+
connectionManager.add(connection);
6869
InputStream in = System.in;
6970
executor.submit(new Runnable() {
7071

0 commit comments

Comments
 (0)