Commit graph java-sdk/mcp
Author SHA1 Message Date
codeboyzhou
e401e9e848 feat(tests): Add unit tests for Assert and Utils classes (#70)
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-27 14:53:00 +01:00
or-givati
2934635d99 feat(mcp): customize transport endpoints and improve URI handling (#69)
- Add support for customizable SSE endpoints in HttpClientSseClientTransport
- Replace pathInfo with requestURI in HttpServletSseServerTransportProvider for more reliable endpoint matching
- Implement builder pattern to support the customization options

Related to #40

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-27 12:58:22 +01:00
Christian Tzolov
25f3bad68d refactor: remove deprecated 0.7.0 code
These changes are part of the planned deprecation cycle announced in 0.8.0,
with the deprecated classes scheduled for removal in 0.9.0

- Delete WebFluxSseServerTransport, WebMvcSseServerTransport, StdioServerTransport, and HttpServletSseServerTransport
- Remove deprecated interfaces: ServerMcpTransport, ClientMcpTransport
- Delete DefaultMcpSession implementation
- Remove all deprecated test classes for the removed implementations
- Update references to use McpServerTransport and McpClientTransport interfaces
- Split MockMcpTransport into client and server implementations
  * Rename MockMcpTransport to MockMcpClientTransport in mcp/src/test
  * Create new MockMcpServerTransport implementation
  * Add MockMcpServerTransportProvider for server tests
  * Mark MockMcpTransport in mcp-test module as deprecated
  * Update all test classes to use the new implementations

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-27 00:01:45 +01:00
Christian Tzolov
7827cdc113
refactor(server): Fi StdioServerTransportProvider initialization flow (#74)
Extract message processing initialization from StdioMcpSessionTransport constructor into a
separate initProcessing() method.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-26 12:09:46 +01:00
Christian Tzolov
a94163b282 Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-21 18:11:30 +01:00
Christian Tzolov
33329bfabb
feat(mcp): Add builder for CreateMessageRequest (#60)
- Implements a builder pattern for CreateMessageRequest
- Updates corresponding tests to use the new builder syntax
- Add ModelPreferences builder and ModelHint helper
- Use builder pattern for CreateMessageRequest in integration tests

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-21 16:43:27 +01:00
Christian Tzolov
3e2139fa27 refactor(McpSchema): convert StopReason enum values to camelCase
Change format from snake_case to camelCase:
- end_turn → endTurn
- stop_sequence → stopSequence
- max_tokens → maxTokens

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-20 21:59:55 +01:00
ryan xu
5bd950d668 Update PING request handler, return empty map instead of empty string
Co-authored-by: NAME <NAME@EXAMPLE.COM>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-20 21:50:16 +01:00
Christian Tzolov
64f424d91b fix: update McpSchemaTests to align with changes in #9
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-20 21:50:16 +01:00
Piotr Roterski
c35e896aa2 Fix CreateMessageRequest includeContext enum values to match MCP specification 2025-03-20 21:50:16 +01:00
Dariusz Jędrzejczyk
34a733509d refactor: introduce session-based architecture for MCP server (#31)
This commit introduces a major refactoring of the MCP Java SDK to implement a session-based architecture
for server-side implementations. The changes improve the SDK's ability to handle multiple concurrent
client connections and provide an API better aligned with the MCP specification.

Key changes:

- Introduce McpServerTransportProvider interface to manage client connections
- Rename ClientMcpTransport to McpClientTransport and ServerMcpTransport to McpServerTransport
- Add exchange objects (McpAsyncServerExchange, McpSyncServerExchange) for client interaction
- Update handler signatures to include exchange parameter: (args) -> result to (exchange, args) -> result
- Rename Registration classes to Specification classes
- Update method names (e.g., rootsChangeConsumers to rootsChangeHandlers)
- Deprecate old interfaces and classes for removal in 0.9.0
- Add migration guide (migration-0.8.0.md)

Resolves #9, #15

Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-20 21:49:51 +01:00
Dariusz Jędrzejczyk
9c2b836e41 Sync async client tests between mcp and mcp-test module
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-03-20 09:48:09 +01:00
Dariusz Jędrzejczyk
e996a5de1e Follow-up fix client tests reliability
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-03-20 09:15:35 +01:00
Dariusz Jędrzejczyk
37120f2ae5 Improve client test reliability and execution time
This change uses VirtualTimeScheduler and pretends enough time has
passed to trigger a timeout on the initialization.
Another problem with reliability of the tests was that the used
testcontainer for the SSE server does not support multiple clients and
the existence of both the global client for the entire suite and some
customized local clients in some tests caused responses to be delivered
to the other client at some racing situations. Now each test creates a
dedicated client and performs cleanup locally.
While these tests were improved, two other issues were found and fixed.
The first one is that the closeGracefully of DefaultMcpSession was not
lazy and would trigger connection disposal before the returned Mono was
subscribed. The second one was dealing with closing the StdIo client
before the process was started. In such a case there should not be an
error but rather a warning and successful completion.
2025-03-19 18:33:18 +01:00
Christian Tzolov
92ec67a965 Increase the request timeout to 14 sec
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-19 12:19:24 +01:00
Christian Tzolov
264a0c9041 Address review comments
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-19 12:19:24 +01:00
Christian Tzolov
914a14a92a adjust test timeout values
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-19 12:19:24 +01:00
Christian Tzolov
1a673b3567 refactor: improve MCP client timeout handling and reactive testing
- Add configurable initialization timeout separate from request timeout
- Rename ServletSse* test classes to HttpSse* for better naming consistency
- Replace direct .block() calls with StepVerifier for better reactive testing
- Change ping() method to return Mono instead of Mono
- Improve error handling and reactive programming patterns throughout tests
- Chain reactive operations for cleaner test flow

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-19 12:19:24 +01:00
He-Pin(kerr)
ab0baf9d8e chore: Make closeLatch a final. 2025-03-13 16:29:35 +01:00
Christian Tzolov
109aab20e8
feat(client): Improve initialization state handling in McpAsyncClient (#39)
- Add proper initialization state tracking using AtomicBoolean and Sinks
- Implement timeout handling for requests requiring initialization
- Ensure all client methods verify initialization state before proceeding
- Fix rootsListChangedNotification to check initialization state
- Improve error messages for uninitialized client operations
- improve JavaDoc
- Add tests to verify proper error handling for uninitialized clients
  - Replace hardcoded timeout constants with configurable getTimeoutDuration() method
  - Remove automatic initialization in setUp methods to allow explicit testing

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-13 15:13:50 +01:00
Christian Tzolov
4eff00c8da
feat(mcp): relax MCP Schema JSON deserialization constraints (#37)
* feat(mcp):  relax MCP Schema JSON deserialization constraints

- Add @JsonIgnoreProperties(ignoreUnknown = true) annotation to all record
classes in McpSchema to make JSON deserialization more robust by ignoring
unknown properties.
- Make the JsonSchema record public

Resolves #36

This improves compatibility with third-party implementations like Cursor that are not MCP Schema compliant.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-10 12:36:54 +01:00
Christian Tzolov
1bee8d4744
refactor(mcp): remove redundant type field from Content implementations (#27)
- The type field and associated methods were redundant in Content implementations (TextContent, ImageContent, EmbeddedResource)
  as the type information is already handled by Jackson's polymorphic type handling via @JsonSubTypes annotation.
- Add default implementation that returns the appropriate type string based on the implementing class (text, image, or resource)
- Added comprehensive unit tests for McpSchema to validate serialization/deserialization behavior of all schema components.
- Add deserialization tests for all content types
- Add json-unit-assertj for flexible JSON testing -  ignores array order and extra array items, reducing test brittleness while
maintaining functional validation.

Resolves #26
Resolve https://github.com/spring-projects/spring-ai/issues/2350

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-03 13:57:41 +01:00
Christian Tzolov
718042644a
refactor(client): improve validation and remove server methods (#14)
Add client initialization and capability validation checks

- New isInitialized() method to check client state
- Validate server capabilities before tool/resource operations
- Add clear error messages for common failure cases
- Remove server-side notification methods from client: sendResourcesListChanged(), promptListChangedNotification()
- Improve protocol version handling
- Testing improvements and new initialization tests
- Redesign MockMcpTransport internals and adapt tests
- Correct McpError messages
- clean unused imports

Resolves #13

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Co-authored-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-02-27 10:00:04 +01:00
konczdev
d9c4818607 Generate OSGi metadata 2025-02-26 18:55:46 +01:00
Mariano Gonzalez
2c500b9cdc
Resources and prompts cannot be added after server start (#18)
* Resources and prompts cannot be added after server start #17
2025-02-26 11:49:30 +01:00
Christian Tzolov
352ec2db09 Next development version 0.8.0-SNAPSHOT
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-14 13:39:20 +01:00
Christian Tzolov
01aa720862 clean the Readme
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-13 20:44:34 +01:00
Christian Tzolov
871add4e45 refactor: reduce log verbosity by adjusting log levels
- Change most INFO logs to DEBUG level for operational messages
- Keep stderr messages at INFO level
- Rename errorHandler to stdErrorHandler in StdioClientTransport
- Add debug logging for JSON message deserialization

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-11 16:45:11 +01:00
Christian Tzolov
585f30cf33 Module and Package restructoring
- mcp-transport -> mcp-spring
- mcp-webflux-sse-transport -> mcp-spring-webflux
 - pom coordinates changed accordingly
- mpc-webmvc-sse-transport -> mcp-spring-webmvc
 - pom coordinates changed accordingly
- docs contains the mdx version of the documentation
2025-01-29 13:40:53 +01:00
Christian Tzolov
181e1f25ab Change the top domain from org to io 2025-01-28 17:25:58 +01:00
Dariusz Jędrzejczyk
c8766098f6 Reorder StdioServerTransport shutdown procedure to avoid errors
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-01-28 15:59:52 +01:00
Christian Tzolov
01592fff45 Disable the mcp-docs as pom module 2025-01-28 14:08:47 +01:00
Christian Tzolov
2d7228d47c Clean the pom 2025-01-28 13:06:05 +01:00
Christian Tzolov
f91fe15ec6 Remove redundand code
Resolves #4

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-01-24 23:26:21 +01:00
Christian Tzolov
413d138d0c Change license from Apache to MIT
Resolves #1

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-01-24 23:05:15 +01:00
Christian Tzolov
3112e5ede7 Refactor package structure and dependencies
- Updated package prefix: `org.springframework.ai.mcp` → `org.modelcontextprotocol`
- Changed POM groupId: `org.springframework.experimental` → `org.modelcontextprotocol.sdk`
- Update all dependecies and BOM
- Updated documentation references accordingly

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-01-24 22:14:44 +01:00
Christian Tzolov
dd64cd88c2 Next development version 2025-01-24 18:40:03 +01:00
Christian Tzolov
e7505ba247 Release version 0.6.0
Some checks failed
Deploy Docs / build (push) Has been cancelled
2025-01-24 18:39:38 +01:00
Christian Tzolov
d75adb68c7 feat(sse): expand accepted HTTP status codes for SSE stream connection
Accept HTTP status codes 200, 201, 202, and 206 as valid responses
for SSE stream connection. Improves error message to include actual
status code. Removes unused main method.

Resolves #68
2025-01-24 18:25:40 +01:00
Christian Tzolov
a424b36653 feat: Add protocol version negotiation
Implement protocol version negotiation between MCP client and server to ensure
compatibility and graceful version handling.
The server will now suggest the latest supported version when an
unsupported version is requested, while the client will verify
version compatibility during initialization.

- Support multiple protocol versions in both client and server
- Negotiate compatible version during initialization
- Fall back to latest version when unsupported version requested
- Add comprehensive test coverage for version negotiation

Resolves #71

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-01-24 18:17:30 +01:00
Christian Tzolov
48ab97bf23 fix(transport): Add cleanup logic for inbound processing in StdioServerTransport
Resolves #72

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-01-24 13:10:52 +01:00
Dariusz Jędrzejczyk
a83f41381a
Align abstract tests in mcp-test with mcp-core (#70)
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-01-23 14:57:25 +01:00
Dariusz Jędrzejczyk
919433437c Polish
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-01-23 14:02:13 +01:00
Dariusz Jędrzejczyk
6839d3b740 Refactor McpClient for async and sync interactions
Introduce new builder patterns and enhance type safety

- Add new builder patterns for McpClient and McpServer with sync/async variants
- Introduce dedicated McpClientFeatures and McpServerFeatures classes
- Enhance type safety and reactive support with proper Mono integration
- Add migration guide for 0.6.0 release
- Mark old builder methods as deprecated
- Update documentation to reflect new APIs

BREAKING CHANGE: The old builder patterns using McpClient.using() and McpServer.using()
are now deprecated in favor of new sync() and async() builders that provide
better type safety and clearer sync/async separation. Follow the migration guide.

Resolves #48

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Co-authored-by: Christian Tzolov <ctzolov@vmware.com>
2025-01-23 12:27:06 +01:00
Alexandros Pappas
c2ece20cc2 feat: Make SSE endpoint configurable in server transports
This commit updates the WebFluxSseServerTransport, WebMvcSseServerTransport, and HttpServletSseServerTransport classes to accept the SSE endpoint path as a constructor argument.

This change provides more flexibility in configuring the SSE endpoint, allowing it to be customized instead of being hardcoded to "/sse".
It also aligns the Java SDK's behavior with the Python SDK's SseServerTransport, which already supports this customization.

A default SSE endpoint of "/sse" is maintained for backward compatibility.

Also, addressed minor code quality issues identified by SonarLint and reordered modifiers for static final fields to conform with the Java Language Specification.

Signed-off-by: Alexandros Pappas <alexandros.pappas@yiluhub.com>
2025-01-16 19:05:57 +01:00
“JermaineHua”
f3e3a65ca6 Set method scope properly
Signed-off-by: “JermaineHua” <crazyhzm@apache.org>
2025-01-15 09:49:49 +01:00
Christian Tzolov
26460e640b feat(mcp): add JsonIgnoreProperties to schema records for resilient deserialization 2025-01-14 14:43:59 +01:00
Christian Tzolov
9d90e4875f Next development version 2025-01-13 12:27:18 +01:00
Christian Tzolov
c4e2c79845 Release version 0.5.0
Some checks failed
Deploy Docs / build (push) Has been cancelled
2025-01-13 12:27:03 +01:00
Christian Tzolov
9aba371660 feat: Add SSE transport tests for MCP client and server
- Add tests for HttpServletSseServerTransport implementation
- Add tests for HttpClientSseClientTransport implementation
- Rename STDIO transport test classes for clarity
2025-01-13 11:13:06 +01:00