Skip to content

Commit 3297830

Browse files
committed
Make server can handle _meta field and send notification to client
1 parent 70bde69 commit 3297830

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private McpServerSession.RequestHandler<CallToolResult> toolsCallRequestHandler(
360360
return Mono.error(new McpError("Tool not found: " + callToolRequest.name()));
361361
}
362362

363-
return toolSpecification.map(tool -> tool.call().apply(exchange, callToolRequest.arguments()))
363+
return toolSpecification.map(tool -> tool.call().apply(exchange, callToolRequest))
364364
.orElse(Mono.error(new McpError("Tool not found: " + callToolRequest.name())));
365365
};
366366
}

mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ public Mono<McpSchema.ListRootsResult> listRoots(String cursor) {
111111
LIST_ROOTS_RESULT_TYPE_REF);
112112
}
113113

114+
public Mono<Void> notification(String method, Object params) {
115+
if (method == null || method.isEmpty()) {
116+
return Mono.error(new McpError("Method must not be null or empty"));
117+
}
118+
if (params == null) {
119+
return Mono.error(new McpError("Params must not be null"));
120+
}
121+
return this.session.sendNotification(method, params);
122+
}
123+
114124
/**
115125
* Send a logging message notification to all connected clients. Messages below the
116126
* current minimum logging level will be filtered out.

mcp/src/main/java/io/modelcontextprotocol/server/McpServer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public AsyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabi
309309
* Example usage: <pre>{@code
310310
* .tool(
311311
* new Tool("calculator", "Performs calculations", schema),
312-
* (exchange, args) -> Mono.fromSupplier(() -> calculate(args))
312+
* (exchange, request) -> Mono.fromSupplier(() -> calculate(request))
313313
* .map(result -> new CallToolResult("Result: " + result))
314314
* )
315315
* }</pre>
@@ -323,7 +323,7 @@ public AsyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabi
323323
* @throws IllegalArgumentException if tool or handler is null
324324
*/
325325
public AsyncSpecification tool(McpSchema.Tool tool,
326-
BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<CallToolResult>> handler) {
326+
BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<CallToolResult>> handler) {
327327
Assert.notNull(tool, "Tool must not be null");
328328
Assert.notNull(handler, "Handler must not be null");
329329

@@ -801,7 +801,7 @@ public SyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabil
801801
* Example usage: <pre>{@code
802802
* .tool(
803803
* new Tool("calculator", "Performs calculations", schema),
804-
* (exchange, args) -> new CallToolResult("Result: " + calculate(args))
804+
* (exchange, request) -> new CallToolResult("Result: " + calculate(request))
805805
* )
806806
* }</pre>
807807
* @param tool The tool definition including name, description, and schema. Must
@@ -814,7 +814,7 @@ public SyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabil
814814
* @throws IllegalArgumentException if tool or handler is null
815815
*/
816816
public SyncSpecification tool(McpSchema.Tool tool,
817-
BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> handler) {
817+
BiFunction<McpSyncServerExchange, McpSchema.CallToolRequest, McpSchema.CallToolResult> handler) {
818818
Assert.notNull(tool, "Tool must not be null");
819819
Assert.notNull(handler, "Handler must not be null");
820820

mcp/src/main/java/io/modelcontextprotocol/server/McpServerFeatures.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ record Sync(McpSchema.Implementation serverInfo, McpSchema.ServerCapabilities se
222222
* .required("expression")
223223
* .property("expression", JsonSchemaType.STRING)
224224
* ),
225-
* (exchange, args) -> {
226-
* String expr = (String) args.get("expression");
225+
* (exchange, request) -> {
226+
* String expr = (String) request.arguments().get("expression");
227227
* return Mono.fromSupplier(() -> evaluate(expr))
228228
* .map(result -> new CallToolResult("Result: " + result));
229229
* }
@@ -237,7 +237,7 @@ record Sync(McpSchema.Implementation serverInfo, McpSchema.ServerCapabilities se
237237
* connected client. The second arguments is a map of tool arguments.
238238
*/
239239
public record AsyncToolSpecification(McpSchema.Tool tool,
240-
BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> call) {
240+
BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> call) {
241241

242242
static AsyncToolSpecification fromSync(SyncToolSpecification tool) {
243243
// FIXME: This is temporary, proper validation should be implemented
@@ -413,7 +413,7 @@ static AsyncCompletionSpecification fromSync(SyncCompletionSpecification complet
413413
* client. The second arguments is a map of arguments passed to the tool.
414414
*/
415415
public record SyncToolSpecification(McpSchema.Tool tool,
416-
BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call) {
416+
BiFunction<McpSyncServerExchange, McpSchema.CallToolRequest, McpSchema.CallToolResult> call) {
417417
}
418418

419419
/**

mcp/src/main/java/io/modelcontextprotocol/spec/McpSchema.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ private static JsonSchema parseSchema(String schema) {
753753
* tools/list.
754754
* @param arguments Arguments to pass to the tool. These must conform to the tool's
755755
* input schema.
756+
* @param _meta Optional metadata about the request. This can include additional
757+
* information like `progressToken`
756758
*/
757759
@JsonInclude(JsonInclude.Include.NON_ABSENT)
758760
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -1114,9 +1116,9 @@ public record PaginatedResult(@JsonProperty("nextCursor") String nextCursor) {
11141116
// ---------------------------
11151117

11161118
/**
1117-
* The Model Context Protocol (MCP) supports optional progress tracking for long-running
1118-
* operations through notification messages. Either side can send progress notifications
1119-
* to provide updates about operation status.
1119+
* The Model Context Protocol (MCP) supports optional progress tracking for
1120+
* long-running operations through notification messages. Either side can send
1121+
* progress notifications to provide updates about operation status.
11201122
*
11211123
* @param progressToken The original progress token
11221124
* @param progress The current progress value so far

0 commit comments

Comments
 (0)