Skip to content

Commit dafca2e

Browse files
committed
Make server can handle _meta field and send notification to client
1 parent 1a1a88b commit dafca2e

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
@@ -139,6 +139,16 @@ public Mono<McpSchema.ListRootsResult> listRoots(String cursor) {
139139
LIST_ROOTS_RESULT_TYPE_REF);
140140
}
141141

142+
public Mono<Void> notification(String method, Object params) {
143+
if (method == null || method.isEmpty()) {
144+
return Mono.error(new McpError("Method must not be null or empty"));
145+
}
146+
if (params == null) {
147+
return Mono.error(new McpError("Params must not be null"));
148+
}
149+
return this.session.sendNotification(method, params);
150+
}
151+
142152
/**
143153
* Send a logging message notification to all connected clients. Messages below the
144154
* 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
@@ -783,6 +783,8 @@ private static JsonSchema parseSchema(String schema) {
783783
* tools/list.
784784
* @param arguments Arguments to pass to the tool. These must conform to the tool's
785785
* input schema.
786+
* @param _meta Optional metadata about the request. This can include additional
787+
* information like `progressToken`
786788
*/
787789
@JsonInclude(JsonInclude.Include.NON_ABSENT)
788790
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -1217,9 +1219,9 @@ public record PaginatedResult(@JsonProperty("nextCursor") String nextCursor) {
12171219
// ---------------------------
12181220

12191221
/**
1220-
* The Model Context Protocol (MCP) supports optional progress tracking for long-running
1221-
* operations through notification messages. Either side can send progress notifications
1222-
* to provide updates about operation status.
1222+
* The Model Context Protocol (MCP) supports optional progress tracking for
1223+
* long-running operations through notification messages. Either side can send
1224+
* progress notifications to provide updates about operation status.
12231225
*
12241226
* @param progressToken The original progress token
12251227
* @param progress The current progress value so far

0 commit comments

Comments
 (0)