Skip to content

Commit 7a6203b

Browse files
authored
Merge pull request modelcontextprotocol#312 from tzolov/mcp-0.9.0-updates
Add MCP Java SDK 0.9.0 updates
2 parents e611c18 + 658e040 commit 7a6203b

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

docs/development/updates.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ title: "What's New"
33
description: 'The latest updates and improvements to MCP'
44
---
55

6+
<Update label="2025-04-10" description="Java SDK 0.9.0 released">
7+
- Version [0.9.0](https://github.com/modelcontextprotocol/java-sdk/releases/tag/v0.9.0) of the MCP Java SDK has been released.
8+
- Refactored logging system to use exchange mechanism
9+
- Custom Context Paths
10+
- Server Instructions
11+
- CallToolResult Enhancement
12+
</Update>
613
<Update label="2025-03-26" description="Kotlin SDK 0.4.0 released">
714
- Fix issues and cleanup API
815
- Added binary compatibility tracking to avoid breaking changes

docs/sdk/java/mcp-client.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,28 @@ This capability allows:
214214
- Support for both text and image-based interactions
215215
- Optional inclusion of MCP server context in prompts
216216

217+
218+
### Logging Support
219+
220+
The client can register a logging consumer to receive log messages from the server and set the minimum logging level to filter messages:
221+
222+
```java
223+
var mcpClient = McpClient.sync(transport)
224+
.loggingConsumer(notification -> {
225+
System.out.println("Received log message: " + notification.data());
226+
})
227+
.build();
228+
229+
mcpClient.initialize();
230+
231+
mcpClient.setLoggingLevel(McpSchema.LoggingLevel.INFO);
232+
233+
// Call the tool that can sends logging notifications
234+
CallToolResult result = mcpClient.callTool(new McpSchema.CallToolRequest("logging-test", Map.of()));
235+
```
236+
Clients can control the minimum logging level they receive through the `mcpClient.setLoggingLevel(level)` request. Messages below the set level will be filtered out.
237+
Supported logging levels (in order of increasing severity): DEBUG (0), INFO (1), NOTICE (2), WARNING (3), ERROR (4), CRITICAL (5), ALERT (6), EMERGENCY (7)
238+
217239
## Using MCP Clients
218240

219241
### Tool Execution

docs/sdk/java/mcp-overview.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Add the BOM to your project:
145145
<dependency>
146146
<groupId>io.modelcontextprotocol.sdk</groupId>
147147
<artifactId>mcp-bom</artifactId>
148-
<version>0.8.1</version>
148+
<version>0.9.0</version>
149149
<type>pom</type>
150150
<scope>import</scope>
151151
</dependency>
@@ -157,7 +157,7 @@ Add the BOM to your project:
157157
<Tab title="Gradle">
158158
```groovy
159159
dependencies {
160-
implementation platform("io.modelcontextprotocol.sdk:mcp-bom:0.8.1")
160+
implementation platform("io.modelcontextprotocol.sdk:mcp-bom:0.9.0")
161161
//...
162162
}
163163
```

docs/sdk/java/mcp-server.mdx

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ syncServer.addTool(syncToolSpecification);
4949
syncServer.addResource(syncResourceSpecification);
5050
syncServer.addPrompt(syncPromptSpecification);
5151

52-
// Send logging notifications
53-
syncServer.loggingNotification(LoggingMessageNotification.builder()
54-
.level(LoggingLevel.INFO)
55-
.logger("custom-logger")
56-
.data("Server initialized")
57-
.build());
58-
5952
// Close the server when done
6053
syncServer.close();
6154
```
@@ -87,13 +80,6 @@ asyncServer.addPrompt(asyncPromptSpecification)
8780
.doOnSuccess(v -> logger.info("Prompt registered"))
8881
.subscribe();
8982

90-
// Send logging notifications
91-
asyncServer.loggingNotification(LoggingMessageNotification.builder()
92-
.level(LoggingLevel.INFO)
93-
.logger("custom-logger")
94-
.data("Server initialized")
95-
.build());
96-
9783
// Close the server when done
9884
asyncServer.close()
9985
.doOnSuccess(v -> logger.info("Server closed"))
@@ -526,6 +512,60 @@ The `CreateMessageRequest` object allows you to specify: `Content` - the input t
526512
`Model Preferences` - hints and priorities for model selection, `System Prompt` - instructions for the model's behavior and
527513
`Max Tokens` - maximum length of the generated response.
528514

515+
### Logging Support
516+
517+
The server provides structured logging capabilities that allow sending log messages to clients with different severity levels. The
518+
log notifications can only be sent from within an existing client session, such as tools, resources, and prompts calls.
519+
520+
For example, we can send a log message from within a tool handler function.
521+
On the client side, you can register a logging consumer to receive log messages from the server and set the minimum logging level to filter messages.
522+
523+
```java
524+
var mcpClient = McpClient.sync(transport)
525+
.loggingConsumer(notification -> {
526+
System.out.println("Received log message: " + notification.data());
527+
})
528+
.build();
529+
530+
mcpClient.initialize();
531+
532+
mcpClient.setLoggingLevel(McpSchema.LoggingLevel.INFO);
533+
534+
// Call the tool that sends logging notifications
535+
CallToolResult result = mcpClient.callTool(new McpSchema.CallToolRequest("logging-test", Map.of()));
536+
```
537+
538+
The server can send log messages using the `McpAsyncServerExchange`/`McpSyncServerExchange` object in the tool/resource/prompt handler function:
539+
540+
```java
541+
var tool = new McpServerFeatures.AsyncToolSpecification(
542+
new McpSchema.Tool("logging-test", "Test logging notifications", emptyJsonSchema),
543+
(exchange, request) -> {
544+
545+
exchange.loggingNotification( // Use the exchange to send log messages
546+
McpSchema.LoggingMessageNotification.builder()
547+
.level(McpSchema.LoggingLevel.DEBUG)
548+
.logger("test-logger")
549+
.data("Debug message")
550+
.build())
551+
.block();
552+
553+
return Mono.just(new CallToolResult("Logging test completed", false));
554+
});
555+
556+
var mcpServer = McpServer.async(mcpServerTransportProvider)
557+
.serverInfo("test-server", "1.0.0")
558+
.capabilities(
559+
ServerCapabilities.builder()
560+
.logging() // Enable logging support
561+
.tools(true)
562+
.build())
563+
.tools(tool)
564+
.build();
565+
```
566+
567+
Clients can control the minimum logging level they receive through the `mcpClient.setLoggingLevel(level)` request. Messages below the set level will be filtered out.
568+
Supported logging levels (in order of increasing severity): DEBUG (0), INFO (1), NOTICE (2), WARNING (3), ERROR (4), CRITICAL (5), ALERT (6), EMERGENCY (7)
529569

530570
## Error Handling
531571

0 commit comments

Comments
 (0)