Skip to content

Commit c04e062

Browse files
committed
Remove deprecations and adjust error handling
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
1 parent 90ad2be commit c04e062

File tree

49 files changed

+383
-1985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+383
-1985
lines changed

mcp-core/src/main/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransport.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,7 @@ public static class Builder {
185185
// Default constructor
186186
}
187187

188-
/**
189-
* Creates a new builder with the specified base URI.
190-
* @param baseUri the base URI of the MCP server
191-
* @deprecated Use {@link HttpClientSseClientTransport#builder(String)} instead.
192-
* This constructor is deprecated and will be removed or made {@code protected} or
193-
* {@code private} in a future release.
194-
*/
195-
@Deprecated(forRemoval = true)
196-
public Builder(String baseUri) {
197-
Assert.hasText(baseUri, "baseUri must not be empty");
198-
this.baseUri = baseUri;
199-
}
200-
201-
/**
202-
* Sets the base URI.
188+
/** Sets the base URI.
203189
* @param baseUri the base URI
204190
* @return this builder
205191
*/

mcp-core/src/main/java/io/modelcontextprotocol/server/DefaultMcpStatelessServerHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public Mono<McpSchema.JSONRPCResponse> handleRequest(McpTransportContext transpo
3232
McpSchema.JSONRPCRequest request) {
3333
McpStatelessRequestHandler<?> requestHandler = this.requestHandlers.get(request.method());
3434
if (requestHandler == null) {
35-
return Mono.error(new McpError("Missing handler for request type: " + request.method()));
35+
return Mono.error(McpError.builder(McpSchema.ErrorCodes.METHOD_NOT_FOUND)
36+
.message("Missing handler for request type: " + request.method())
37+
.build());
3638
}
3739
return requestHandler.handle(transportContext, request.params())
3840
.map(result -> new McpSchema.JSONRPCResponse(McpSchema.JSONRPC_VERSION, request.id(), result, null))

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public Mono<Void> addTool(McpServerFeatures.AsyncToolSpecification toolSpecifica
326326
if (toolSpecification.tool() == null) {
327327
return Mono.error(new IllegalArgumentException("Tool must not be null"));
328328
}
329-
if (toolSpecification.call() == null && toolSpecification.callHandler() == null) {
329+
if (toolSpecification.callHandler() == null) {
330330
return Mono.error(new IllegalArgumentException("Tool call handler must not be null"));
331331
}
332332
if (this.serverCapabilities.tools() == null) {
@@ -869,32 +869,6 @@ private McpRequestHandler<McpSchema.GetPromptResult> promptsGetRequestHandler()
869869
// Logging Management
870870
// ---------------------------------------
871871

872-
/**
873-
* This implementation would, incorrectly, broadcast the logging message to all
874-
* connected clients, using a single minLoggingLevel for all of them. Similar to the
875-
* sampling and roots, the logging level should be set per client session and use the
876-
* ServerExchange to send the logging message to the right client.
877-
* @param loggingMessageNotification The logging message to send
878-
* @return A Mono that completes when the notification has been sent
879-
* @deprecated Use
880-
* {@link McpAsyncServerExchange#loggingNotification(LoggingMessageNotification)}
881-
* instead.
882-
*/
883-
@Deprecated
884-
public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageNotification) {
885-
886-
if (loggingMessageNotification == null) {
887-
return Mono.error(new McpError("Logging message must not be null"));
888-
}
889-
890-
if (loggingMessageNotification.level().level() < minLoggingLevel.level()) {
891-
return Mono.empty();
892-
}
893-
894-
return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_MESSAGE,
895-
loggingMessageNotification);
896-
}
897-
898872
private McpRequestHandler<Object> setLoggerRequestHandler() {
899873
return (exchange, params) -> {
900874
return Mono.defer(() -> {

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

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,7 @@ public class McpAsyncServerExchange {
4949
public static final TypeRef<Object> OBJECT_TYPE_REF = new TypeRef<>() {
5050
};
5151

52-
/**
53-
* Create a new asynchronous exchange with the client.
54-
* @param session The server session representing a 1-1 interaction.
55-
* @param clientCapabilities The client capabilities that define the supported
56-
* features and functionality.
57-
* @param clientInfo The client implementation information.
58-
* @deprecated Use
59-
* {@link #McpAsyncServerExchange(String, McpLoggableSession, McpSchema.ClientCapabilities, McpSchema.Implementation, McpTransportContext)}
60-
*/
61-
@Deprecated
62-
public McpAsyncServerExchange(McpSession session, McpSchema.ClientCapabilities clientCapabilities,
63-
McpSchema.Implementation clientInfo) {
64-
this.sessionId = null;
65-
if (!(session instanceof McpLoggableSession)) {
66-
throw new IllegalArgumentException("Expecting session to be a McpLoggableSession instance");
67-
}
68-
this.session = (McpLoggableSession) session;
69-
this.clientCapabilities = clientCapabilities;
70-
this.clientInfo = clientInfo;
71-
this.transportContext = McpTransportContext.EMPTY;
72-
}
73-
74-
/**
75-
* Create a new asynchronous exchange with the client.
52+
/** Create a new asynchronous exchange with the client.
7653
* @param session The server session representing a 1-1 interaction.
7754
* @param clientCapabilities The client capabilities that define the supported
7855
* features and functionality.
@@ -142,10 +119,10 @@ public String sessionId() {
142119
*/
143120
public Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessageRequest createMessageRequest) {
144121
if (this.clientCapabilities == null) {
145-
return Mono.error(new McpError("Client must be initialized. Call the initialize method first!"));
122+
return Mono.error(new IllegalStateException("Client must be initialized. Call the initialize method first!"));
146123
}
147124
if (this.clientCapabilities.sampling() == null) {
148-
return Mono.error(new McpError("Client must be configured with sampling capabilities"));
125+
return Mono.error(new IllegalStateException("Client must be configured with sampling capabilities"));
149126
}
150127
return this.session.sendRequest(McpSchema.METHOD_SAMPLING_CREATE_MESSAGE, createMessageRequest,
151128
CREATE_MESSAGE_RESULT_TYPE_REF);
@@ -167,10 +144,10 @@ public Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessage
167144
*/
168145
public Mono<McpSchema.ElicitResult> createElicitation(McpSchema.ElicitRequest elicitRequest) {
169146
if (this.clientCapabilities == null) {
170-
return Mono.error(new McpError("Client must be initialized. Call the initialize method first!"));
147+
return Mono.error(new IllegalStateException("Client must be initialized. Call the initialize method first!"));
171148
}
172149
if (this.clientCapabilities.elicitation() == null) {
173-
return Mono.error(new McpError("Client must be configured with elicitation capabilities"));
150+
return Mono.error(new IllegalStateException("Client must be configured with elicitation capabilities"));
174151
}
175152
return this.session.sendRequest(McpSchema.METHOD_ELICITATION_CREATE, elicitRequest,
176153
ELICITATION_RESULT_TYPE_REF);
@@ -215,7 +192,7 @@ public Mono<McpSchema.ListRootsResult> listRoots(String cursor) {
215192
public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageNotification) {
216193

217194
if (loggingMessageNotification == null) {
218-
return Mono.error(new McpError("Logging message must not be null"));
195+
return Mono.error(new IllegalStateException("Logging message must not be null"));
219196
}
220197

221198
return Mono.defer(() -> {
@@ -234,7 +211,7 @@ public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageN
234211
*/
235212
public Mono<Void> progressNotification(McpSchema.ProgressNotification progressNotification) {
236213
if (progressNotification == null) {
237-
return Mono.error(new McpError("Progress notification must not be null"));
214+
return Mono.error(new IllegalStateException("Progress notification must not be null"));
238215
}
239216
return this.session.sendNotification(McpSchema.METHOD_NOTIFICATION_PROGRESS, progressNotification);
240217
}

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

Lines changed: 6 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
* Example of creating a basic synchronous server: <pre>{@code
6767
* McpServer.sync(transportProvider)
6868
* .serverInfo("my-server", "1.0.0")
69-
* .tool(Tool.builder().name("calculator").title("Performs calculations").inputSchema(schema).build(),
70-
* (exchange, args) -> CallToolResult.builder()
71-
* .content(List.of(new McpSchema.TextContent("Result: " + calculate(args))))
69+
* .toolCall(Tool.builder().name("calculator").title("Performs calculations").inputSchema(schema).build(),
70+
* (exchange, request) -> CallToolResult.builder()
71+
* .content(List.of(new McpSchema.TextContent("Result: " + calculate(request.arguments()))))
7272
* .isError(false)
7373
* .build())
7474
* .build();
@@ -77,8 +77,8 @@
7777
* Example of creating a basic asynchronous server: <pre>{@code
7878
* McpServer.async(transportProvider)
7979
* .serverInfo("my-server", "1.0.0")
80-
* .tool(Tool.builder().name("calculator").title("Performs calculations").inputSchema(schema).build(),
81-
* (exchange, args) -> Mono.fromSupplier(() -> calculate(args))
80+
* .toolCall(Tool.builder().name("calculator").title("Performs calculations").inputSchema(schema).build(),
81+
* (exchange, request) -> Mono.fromSupplier(() -> calculate(request.arguments()))
8282
* .map(result -> CallToolResult.builder()
8383
* .content(List.of(new McpSchema.TextContent("Result: " + result)))
8484
* .isError(false)
@@ -441,46 +441,6 @@ public AsyncSpecification<S> capabilities(McpSchema.ServerCapabilities serverCap
441441
return this;
442442
}
443443

444-
/**
445-
* Adds a single tool with its implementation handler to the server. This is a
446-
* convenience method for registering individual tools without creating a
447-
* {@link McpServerFeatures.AsyncToolSpecification} explicitly.
448-
*
449-
* <p>
450-
* Example usage: <pre>{@code
451-
* .tool(
452-
* Tool.builder().name("calculator").title("Performs calculations").inputSchema(schema).build(),
453-
* (exchange, args) -> Mono.fromSupplier(() -> calculate(args))
454-
* .map(result -> CallToolResult.builder()
455-
* .content(List.of(new McpSchema.TextContent("Result: " + result)))
456-
* .isError(false)
457-
* .build()))
458-
* )
459-
* }</pre>
460-
* @param tool The tool definition including name, description, and schema. Must
461-
* not be null.
462-
* @param handler The function that implements the tool's logic. Must not be null.
463-
* The function's first argument is an {@link McpAsyncServerExchange} upon which
464-
* the server can interact with the connected client. The second argument is the
465-
* map of arguments passed to the tool.
466-
* @return This builder instance for method chaining
467-
* @throws IllegalArgumentException if tool or handler is null
468-
* @deprecated Use {@link #toolCall(McpSchema.Tool, BiFunction)} instead for tool
469-
* calls that require a request object.
470-
*/
471-
@Deprecated
472-
public AsyncSpecification<S> tool(McpSchema.Tool tool,
473-
BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<CallToolResult>> handler) {
474-
Assert.notNull(tool, "Tool must not be null");
475-
Assert.notNull(handler, "Handler must not be null");
476-
validateToolName(tool.name());
477-
assertNoDuplicateTool(tool.name());
478-
479-
this.tools.add(new McpServerFeatures.AsyncToolSpecification(tool, handler));
480-
481-
return this;
482-
}
483-
484444
/**
485445
* Adds a single tool with its implementation handler to the server. This is a
486446
* convenience method for registering individual tools without creating a
@@ -1064,45 +1024,6 @@ public SyncSpecification<S> capabilities(McpSchema.ServerCapabilities serverCapa
10641024
return this;
10651025
}
10661026

1067-
/**
1068-
* Adds a single tool with its implementation handler to the server. This is a
1069-
* convenience method for registering individual tools without creating a
1070-
* {@link McpServerFeatures.SyncToolSpecification} explicitly.
1071-
*
1072-
* <p>
1073-
* Example usage: <pre>{@code
1074-
* .tool(
1075-
* Tool.builder().name("calculator").title("Performs calculations".inputSchema(schema).build(),
1076-
* (exchange, args) -> CallToolResult.builder()
1077-
* .content(List.of(new McpSchema.TextContent("Result: " + calculate(args))))
1078-
* .isError(false)
1079-
* .build())
1080-
* )
1081-
* }</pre>
1082-
* @param tool The tool definition including name, description, and schema. Must
1083-
* not be null.
1084-
* @param handler The function that implements the tool's logic. Must not be null.
1085-
* The function's first argument is an {@link McpSyncServerExchange} upon which
1086-
* the server can interact with the connected client. The second argument is the
1087-
* list of arguments passed to the tool.
1088-
* @return This builder instance for method chaining
1089-
* @throws IllegalArgumentException if tool or handler is null
1090-
* @deprecated Use {@link #toolCall(McpSchema.Tool, BiFunction)} instead for tool
1091-
* calls that require a request object.
1092-
*/
1093-
@Deprecated
1094-
public SyncSpecification<S> tool(McpSchema.Tool tool,
1095-
BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> handler) {
1096-
Assert.notNull(tool, "Tool must not be null");
1097-
Assert.notNull(handler, "Handler must not be null");
1098-
validateToolName(tool.name());
1099-
assertNoDuplicateTool(tool.name());
1100-
1101-
this.tools.add(new McpServerFeatures.SyncToolSpecification(tool, handler));
1102-
1103-
return this;
1104-
}
1105-
11061027
/**
11071028
* Adds a single tool with its implementation handler to the server. This is a
11081029
* convenience method for registering individual tools without creating a
@@ -1123,7 +1044,7 @@ public SyncSpecification<S> toolCall(McpSchema.Tool tool,
11231044
validateToolName(tool.name());
11241045
assertNoDuplicateTool(tool.name());
11251046

1126-
this.tools.add(new McpServerFeatures.SyncToolSpecification(tool, null, handler));
1047+
this.tools.add(new McpServerFeatures.SyncToolSpecification(tool, handler));
11271048

11281049
return this;
11291050
}

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

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,8 @@ record Sync(McpSchema.Implementation serverInfo, McpSchema.ServerCapabilities se
223223
* map of tool arguments.
224224
*/
225225
public record AsyncToolSpecification(McpSchema.Tool tool,
226-
@Deprecated BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> call,
227226
BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> callHandler) {
228227

229-
/**
230-
* @deprecated Use {@link AsyncToolSpecification(McpSchema.Tool, null,
231-
* BiFunction)} instead.
232-
**/
233-
@Deprecated
234-
public AsyncToolSpecification(McpSchema.Tool tool,
235-
BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> call) {
236-
this(tool, call, (exchange, toolReq) -> call.apply(exchange, toolReq.arguments()));
237-
}
238-
239228
static AsyncToolSpecification fromSync(SyncToolSpecification syncToolSpec) {
240229
return fromSync(syncToolSpec, false);
241230
}
@@ -247,21 +236,14 @@ static AsyncToolSpecification fromSync(SyncToolSpecification syncToolSpec, boole
247236
return null;
248237
}
249238

250-
BiFunction<McpAsyncServerExchange, Map<String, Object>, Mono<McpSchema.CallToolResult>> deprecatedCall = (syncToolSpec
251-
.call() != null) ? (exchange, map) -> {
252-
var toolResult = Mono
253-
.fromCallable(() -> syncToolSpec.call().apply(new McpSyncServerExchange(exchange), map));
254-
return immediate ? toolResult : toolResult.subscribeOn(Schedulers.boundedElastic());
255-
} : null;
256-
257239
BiFunction<McpAsyncServerExchange, McpSchema.CallToolRequest, Mono<McpSchema.CallToolResult>> callHandler = (
258240
exchange, req) -> {
259241
var toolResult = Mono
260242
.fromCallable(() -> syncToolSpec.callHandler().apply(new McpSyncServerExchange(exchange), req));
261243
return immediate ? toolResult : toolResult.subscribeOn(Schedulers.boundedElastic());
262244
};
263245

264-
return new AsyncToolSpecification(syncToolSpec.tool(), deprecatedCall, callHandler);
246+
return new AsyncToolSpecification(syncToolSpec.tool(), callHandler);
265247
}
266248

267249
/**
@@ -304,7 +286,7 @@ public AsyncToolSpecification build() {
304286
Assert.notNull(tool, "Tool must not be null");
305287
Assert.notNull(callHandler, "Call handler function must not be null");
306288

307-
return new AsyncToolSpecification(tool, null, callHandler);
289+
return new AsyncToolSpecification(tool, callHandler);
308290
}
309291

310292
}
@@ -523,26 +505,16 @@ static AsyncCompletionSpecification fromSync(SyncCompletionSpecification complet
523505
* }</pre>
524506
*
525507
* @param tool The tool definition including name, description, and parameter schema
526-
* @param call (Deprected) The function that implements the tool's logic, receiving
527-
* arguments and returning results. The function's first argument is an
528-
* {@link McpSyncServerExchange} upon which the server can interact with the connected
529508
* @param callHandler The function that implements the tool's logic, receiving a
530509
* {@link McpSyncServerExchange} and a
531510
* {@link io.modelcontextprotocol.spec.McpSchema.CallToolRequest} and returning
532511
* results. The function's first argument is an {@link McpSyncServerExchange} upon
533-
* which the server can interact with the client. The second arguments is a map of
534-
* arguments passed to the tool.
512+
* which the server can interact with the client. The second argument is a request
513+
* object containing the arguments passed to the tool.
535514
*/
536515
public record SyncToolSpecification(McpSchema.Tool tool,
537-
@Deprecated BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call,
538516
BiFunction<McpSyncServerExchange, CallToolRequest, McpSchema.CallToolResult> callHandler) {
539517

540-
@Deprecated
541-
public SyncToolSpecification(McpSchema.Tool tool,
542-
BiFunction<McpSyncServerExchange, Map<String, Object>, McpSchema.CallToolResult> call) {
543-
this(tool, call, (exchange, toolReq) -> call.apply(exchange, toolReq.arguments()));
544-
}
545-
546518
/**
547519
* Builder for creating SyncToolSpecification instances.
548520
*/
@@ -583,7 +555,7 @@ public SyncToolSpecification build() {
583555
Assert.notNull(tool, "Tool must not be null");
584556
Assert.notNull(callHandler, "CallTool function must not be null");
585557

586-
return new SyncToolSpecification(tool, null, callHandler);
558+
return new SyncToolSpecification(tool, callHandler);
587559
}
588560

589561
}

mcp-core/src/main/java/io/modelcontextprotocol/server/McpSyncServer.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,6 @@ public void notifyPromptsListChanged() {
230230
this.asyncServer.notifyPromptsListChanged().block();
231231
}
232232

233-
/**
234-
* This implementation would, incorrectly, broadcast the logging message to all
235-
* connected clients, using a single minLoggingLevel for all of them. Similar to the
236-
* sampling and roots, the logging level should be set per client session and use the
237-
* ServerExchange to send the logging message to the right client.
238-
* @param loggingMessageNotification The logging message to send
239-
* @deprecated Use
240-
* {@link McpSyncServerExchange#loggingNotification(LoggingMessageNotification)}
241-
* instead.
242-
*/
243-
@Deprecated
244-
public void loggingNotification(LoggingMessageNotification loggingMessageNotification) {
245-
this.asyncServer.loggingNotification(loggingMessageNotification).block();
246-
}
247-
248233
/**
249234
* Close the server gracefully.
250235
*/

0 commit comments

Comments
 (0)