Skip to content

Commit c994454

Browse files
committed
Correct tests and remaining problems
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
1 parent 30dc805 commit c994454

File tree

7 files changed

+34
-35
lines changed

7 files changed

+34
-35
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public static class Builder {
185185
// Default constructor
186186
}
187187

188-
/** Sets the base URI.
188+
/**
189+
* Sets the base URI.
189190
* @param baseUri the base URI
190191
* @return this builder
191192
*/

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

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

52-
/** Create a new asynchronous exchange with the client.
52+
/**
53+
* Create a new asynchronous exchange with the client.
5354
* @param session The server session representing a 1-1 interaction.
5455
* @param clientCapabilities The client capabilities that define the supported
5556
* features and functionality.
@@ -119,7 +120,8 @@ public String sessionId() {
119120
*/
120121
public Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessageRequest createMessageRequest) {
121122
if (this.clientCapabilities == null) {
122-
return Mono.error(new IllegalStateException("Client must be initialized. Call the initialize method first!"));
123+
return Mono
124+
.error(new IllegalStateException("Client must be initialized. Call the initialize method first!"));
123125
}
124126
if (this.clientCapabilities.sampling() == null) {
125127
return Mono.error(new IllegalStateException("Client must be configured with sampling capabilities"));
@@ -144,7 +146,8 @@ public Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessage
144146
*/
145147
public Mono<McpSchema.ElicitResult> createElicitation(McpSchema.ElicitRequest elicitRequest) {
146148
if (this.clientCapabilities == null) {
147-
return Mono.error(new IllegalStateException("Client must be initialized. Call the initialize method first!"));
149+
return Mono
150+
.error(new IllegalStateException("Client must be initialized. Call the initialize method first!"));
148151
}
149152
if (this.clientCapabilities.elicitation() == null) {
150153
return Mono.error(new IllegalStateException("Client must be configured with elicitation capabilities"));

mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public interface NotificationHandler {
9696

9797
}
9898

99-
/** Creates a new McpClientSession with the specified configuration and handlers.
99+
/**
100+
* Creates a new McpClientSession with the specified configuration and handlers.
100101
* @param requestTimeout Duration to wait for responses
101102
* @param transport Transport implementation for message exchange
102103
* @param requestHandlers Map of method names to request handlers

mcp-core/src/test/java/io/modelcontextprotocol/server/AsyncToolSpecificationBuilderTest.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ void builtSpecificationShouldExecuteCallToolCorrectly() {
106106

107107
McpServerFeatures.AsyncToolSpecification specification = McpServerFeatures.AsyncToolSpecification.builder()
108108
.tool(tool)
109-
.callHandler((exchange, request) -> {
110-
return Mono.just(CallToolResult.builder()
111-
.content(List.of(new TextContent(expectedResult)))
112-
.isError(false)
113-
.build());
114-
})
109+
.callHandler((exchange, request) -> Mono.just(
110+
CallToolResult.builder().content(List.of(new TextContent(expectedResult))).isError(false).build()))
115111
.build();
116112

117113
CallToolRequest request = new CallToolRequest("calculator", Map.of());
@@ -129,30 +125,28 @@ void builtSpecificationShouldExecuteCallToolCorrectly() {
129125
@Test
130126
void fromSyncShouldConvertSyncToolSpecificationCorrectly() {
131127
Tool tool = McpSchema.Tool.builder()
132-
.name("sync-tool")
133-
.title("A sync tool")
134-
.inputSchema(EMPTY_JSON_SCHEMA)
135-
.build();
128+
.name("sync-tool")
129+
.title("A sync tool")
130+
.inputSchema(EMPTY_JSON_SCHEMA)
131+
.build();
136132
String expectedResult = "sync result";
137133

138134
// Create a sync tool specification
139135
McpServerFeatures.SyncToolSpecification syncSpec = McpServerFeatures.SyncToolSpecification.builder()
140-
.tool(tool)
141-
.callHandler((exchange, request) -> CallToolResult.builder()
142-
.content(List.of(new TextContent(expectedResult)))
143-
.isError(false)
144-
.build())
145-
.build();
136+
.tool(tool)
137+
.callHandler((exchange, request) -> CallToolResult.builder()
138+
.content(List.of(new TextContent(expectedResult)))
139+
.isError(false)
140+
.build())
141+
.build();
146142

147143
// Convert to async using fromSync
148144
McpServerFeatures.AsyncToolSpecification asyncSpec = McpServerFeatures.AsyncToolSpecification
149-
.fromSync(syncSpec);
145+
.fromSync(syncSpec);
150146

151147
assertThat(asyncSpec).isNotNull();
152148
assertThat(asyncSpec.tool()).isEqualTo(tool);
153149
assertThat(asyncSpec.callHandler()).isNotNull();
154-
assertThat(asyncSpec.call()).isNull(); // should be null since sync spec doesn't
155-
// have deprecated call
156150

157151
// Test that the converted async specification works correctly
158152
CallToolRequest request = new CallToolRequest("sync-tool", Map.of("param", "value"));

mcp-core/src/test/java/io/modelcontextprotocol/server/McpAsyncServerExchangeTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void testGetClientInfo() {
215215
@Test
216216
void testLoggingNotificationWithNullMessage() {
217217
StepVerifier.create(exchange.loggingNotification(null)).verifyErrorSatisfies(error -> {
218-
assertThat(error).isInstanceOf(McpError.class).hasMessage("Logging message must not be null");
218+
assertThat(error).isInstanceOf(IllegalStateException.class).hasMessage("Logging message must not be null");
219219
});
220220
}
221221

@@ -310,7 +310,7 @@ void testCreateElicitationWithNullCapabilities() {
310310

311311
StepVerifier.create(exchangeWithNullCapabilities.createElicitation(elicitRequest))
312312
.verifyErrorSatisfies(error -> {
313-
assertThat(error).isInstanceOf(McpError.class)
313+
assertThat(error).isInstanceOf(IllegalStateException.class)
314314
.hasMessage("Client must be initialized. Call the initialize method first!");
315315
});
316316

@@ -333,7 +333,7 @@ void testCreateElicitationWithoutElicitationCapabilities() {
333333
.build();
334334

335335
StepVerifier.create(exchangeWithoutElicitation.createElicitation(elicitRequest)).verifyErrorSatisfies(error -> {
336-
assertThat(error).isInstanceOf(McpError.class)
336+
assertThat(error).isInstanceOf(IllegalStateException.class)
337337
.hasMessage("Client must be configured with elicitation capabilities");
338338
});
339339

@@ -478,7 +478,7 @@ void testCreateMessageWithNullCapabilities() {
478478

479479
StepVerifier.create(exchangeWithNullCapabilities.createMessage(createMessageRequest))
480480
.verifyErrorSatisfies(error -> {
481-
assertThat(error).isInstanceOf(McpError.class)
481+
assertThat(error).isInstanceOf(IllegalStateException.class)
482482
.hasMessage("Client must be initialized. Call the initialize method first!");
483483
});
484484

@@ -503,7 +503,7 @@ void testCreateMessageWithoutSamplingCapabilities() {
503503
.build();
504504

505505
StepVerifier.create(exchangeWithoutSampling.createMessage(createMessageRequest)).verifyErrorSatisfies(error -> {
506-
assertThat(error).isInstanceOf(McpError.class)
506+
assertThat(error).isInstanceOf(IllegalStateException.class)
507507
.hasMessage("Client must be configured with sampling capabilities");
508508
});
509509

mcp-core/src/test/java/io/modelcontextprotocol/server/McpSyncServerExchangeTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void testGetClientInfo() {
214214

215215
@Test
216216
void testLoggingNotificationWithNullMessage() {
217-
assertThatThrownBy(() -> exchange.loggingNotification(null)).isInstanceOf(McpError.class)
217+
assertThatThrownBy(() -> exchange.loggingNotification(null)).isInstanceOf(IllegalStateException.class)
218218
.hasMessage("Logging message must not be null");
219219
}
220220

@@ -306,7 +306,7 @@ void testCreateElicitationWithNullCapabilities() {
306306
.build();
307307

308308
assertThatThrownBy(() -> exchangeWithNullCapabilities.createElicitation(elicitRequest))
309-
.isInstanceOf(McpError.class)
309+
.isInstanceOf(IllegalStateException.class)
310310
.hasMessage("Client must be initialized. Call the initialize method first!");
311311

312312
// Verify that sendRequest was never called due to null capabilities
@@ -329,7 +329,7 @@ void testCreateElicitationWithoutElicitationCapabilities() {
329329
.build();
330330

331331
assertThatThrownBy(() -> exchangeWithoutElicitation.createElicitation(elicitRequest))
332-
.isInstanceOf(McpError.class)
332+
.isInstanceOf(IllegalStateException.class)
333333
.hasMessage("Client must be configured with elicitation capabilities");
334334

335335
// Verify that sendRequest was never called due to missing elicitation
@@ -478,7 +478,7 @@ void testCreateMessageWithNullCapabilities() {
478478
.build();
479479

480480
assertThatThrownBy(() -> exchangeWithNullCapabilities.createMessage(createMessageRequest))
481-
.isInstanceOf(McpError.class)
481+
.isInstanceOf(IllegalStateException.class)
482482
.hasMessage("Client must be initialized. Call the initialize method first!");
483483

484484
// Verify that sendRequest was never called due to null capabilities
@@ -503,7 +503,7 @@ void testCreateMessageWithoutSamplingCapabilities() {
503503
.build();
504504

505505
assertThatThrownBy(() -> exchangeWithoutSampling.createMessage(createMessageRequest))
506-
.isInstanceOf(McpError.class)
506+
.isInstanceOf(IllegalStateException.class)
507507
.hasMessage("Client must be configured with sampling capabilities");
508508

509509
// Verify that sendRequest was never called due to missing sampling capabilities

mcp-test/src/test/java/io/modelcontextprotocol/server/transport/StdioServerTransportProviderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void shouldHandleNotificationBeforeSessionFactoryIsSet() {
185185
// Send notification before setting session factory
186186
StepVerifier.create(transportProvider.notifyClients("testNotification", Map.of("key", "value")))
187187
.verifyErrorSatisfies(error -> {
188-
assertThat(error).isInstanceOf(McpError.class);
188+
assertThat(error).isInstanceOf(IllegalStateException.class);
189189
});
190190
}
191191

0 commit comments

Comments
 (0)