Commit graph java-sdk/mcp-spring
Author SHA1 Message Date
Christian Tzolov
734d1732d6 Refactor: Simplify ServerCapabilities builder API for completions
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-17 09:28:08 +02:00
jitokim
7853efefda feat(completion): implement completion API support (#141)
Add completion API support to the MCP protocol implementation:

- Add CompleteRequest and CompleteResult schema classes
- Implement completion capabilities in ServerCapabilities
- Add completion handlers in McpAsyncServer and McpServer
- Add completion client methods in McpAsyncClient and McpSyncClient
- Add CompletionRefKey and completion specifications in McpServerFeatures
- Add integration test for completion functionality
- Fix isPresent() check to use isEmpty() in WebMvcSseServerTransportProvider
- Replace McpServerFeatures.CompletionRefKey by McpSchemaCompleteReference

Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>

Signed-off-by: jitokim <pigberger70@gmail.com>
2025-04-16 21:16:21 +02:00
mackey0225
84adde16a5 fix: correct typos in variable names, method names, and commentsj (#159) 2025-04-16 08:07:24 +02:00
Dariusz Jędrzejczyk
f7f8ccd0ac Fix flaky test running blocking code in event loop (#155)
- Replace StepVerifier with assertWith for cleaner test assertions
- Add try-with-resources blocks for proper client resource management
- Use closeGracefully().block() for proper server shutdown

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-04-16 07:57:54 +02:00
mipengcheng3
472f07ec6d feat(mcp): add configurable request timeout to MCP server (#134)
Adds the ability to configure request timeouts for MCP server operations. This enhancement
allows setting a custom duration to wait for server responses before timing out requests,
which applies to all requests made through the client including tool calls, resource access,
and prompt operations.

- Add requestTimeout parameter to McpServerSession constructor
- Add requestTimeout field and builder method to server classes
- Pass timeout configuration through to session creation
- Add tests for both success and failure scenarios across different transport implementations
- Default timeout is set to 10 seconds if not explicitly configured.
2025-04-15 12:47:02 +02:00
a.darafeyeu
263e3741b2 feat(test): Use dynamic port allocation in integration tests (#133)
- Add TestUtil class with findAvailablePort() method to the mcp-test module
- Add findAvailablePort() method to TomcatTestUtil classes
- Replace hardcoded port numbers with dynamic port allocation

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-15 12:26:03 +02:00
Christian Tzolov
f348a83e5a Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-10 18:06:46 +02:00
Christian Tzolov
63724f17a4 refactor(tests): improve notification assertions in WebFluxSseIntegrationTests
Replace index-based assertions with content-based lookups using a notification map.
This change makes the tests more resilient by removing the dependency on
notification order, which is important for asynchronous messaging tests.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-10 16:54:28 +02:00
Christian Tzolov
c88ac937f3 feat(mcp): refactor logging to use exchange for targeted client notifications (#132)
Refactors the MCP logging system to use the exchange mechanism for sending
logging notifications only to specific client sessions rather than broadcasting to all clients.

- Move logging notification delivery from server-wide broadcast to per-session exchange
- Implement per-session minimum logging level tracking and filtering
- Add proper logging level filtering at the exchange level
- Change setLoggingLevel from notification to request/response pattern (breaking change)
- Deprecate global server.loggingNotification in favor of exchange.loggingNotification
- Add SetLevelRequest record to McpSchema
- Add integration test demonstrating filtered logging notifications

Resolves #131

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-04-10 15:46:32 +02:00
Christian Tzolov
2895d1589a
fix: Add null check for session in WebFluxSseServerTransportProvider (#138)
Add error handling to return a 404 NOT_FOUND response when a request
is made with a non-existent session ID. This prevents potential
NullPointerExceptions when processing requests with invalid session IDs.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-10 13:18:55 +02:00
Christian Tzolov
391ec19fdc
refactor: change notification params type from Map<String,Object> to Object (#137)
* refactor: change notification params type from Map<String,Object> to Object

This change generalizes the parameter type for notification methods across the MCP framework,
allowing for more flexible parameter passing. Instead of requiring parameters to be structured
as a Map<String,Object>, the API now accepts any Object as parameters.

The primary motivation is to simplify client usage by allowing direct passing of strongly-typed
 objects without requiring conversion to a Map first, as demonstrated in the McpAsyncServer
logging notification implementation.

Affected components:

- McpSession interface and implementations
- McpServerTransportProvider interface and implementations
- McpSchema JSONRPCNotification record
---------

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-10 12:26:29 +02:00
a.darafeyeu
fab434c088 refactor(client): enhance HttpClientSseClientTransport with flexible customization API (#117)
- Add builder customizeClient() and customizeRequest() methods
- Enable HTTP client and request configuration through consumer-based customization
- Deprecate direct constructors in favor of the more flexible builder approach
- Add test coverage for customization capabilities

Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-09 16:40:52 +02:00
Christian Tzolov
fbea833384 Fix compilation issue introduced by the previous commit
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-09 16:17:16 +02:00
Christian Tzolov
13c4474b3e Change the URLs used to test blocking rest calls
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-09 16:05:39 +02:00
Christian Tzolov
b21cfab10e refactor(webmvc): Rename messageBaseUrl to baseUrl for consistency
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-06 17:51:24 +02:00
zhangzhenhua
3fa4152287 feat(webflux): Add base URL support to WebFluxSseServerTransportProvider (#102)
Adds the ability to specify a base URL prefix for message endpoints in the
WebFlux SSE server transport provider. This enhancement allows for proper
URL construction when the server is running behind a proxy or in a context
with a base path.

- Add new constructor with baseUrl parameter
- Add basePath() method to Builder class
- Modify SSE endpoint event to include baseUrl prefix

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-06 16:27:26 +02:00
minguncle
0db4c0f70d feat(webmvc): Add support for custom context paths in WebMvcSseServerTransportProvider
Adds the ability to specify a base URL for message endpoints in WebMvcSseServerTransportProvider,
enabling proper handling of custom servlet context paths in Spring WebMVC applications.
This ensures that clients receive the correct full endpoint URL when connecting through SSE.

- Add messageBaseUrl field to WebMvcSseServerTransportProvider
- Create new constructor that accepts messageBaseUrl parameter
- Update endpoint event to include base URL in the message endpoint
- Add TomcatTestUtil class to simplify test server creation
- Add WebMvcSseCustomContextPathTests to verify custom context path functionality
- Refactor WebMvcSseIntegrationTests to use the new TomcatTestUtil

Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-06 15:31:49 +02:00
jitokim
734153a445 fix typo in WebFluxSseIntegrationTests
Signed-off-by: jitokim <pigberger70@gmail.com>
2025-04-06 10:51:52 +02:00
jitokim
c3a7c1ac1e perf(webflux): optimize session broadcasting with Flux.fromIterable (#109)
Replace Flux.fromStream(sessions.values().stream()) with more efficient
Flux.fromIterable(sessions.values()) to eliminate unnecessary stream
conversion when broadcasting messages to active sessions

Signed-off-by: jitokim <pigberger70@gmail.com>
2025-04-06 08:54:30 +02:00
Christian Tzolov
55ee15604a feat(webflux): Add configurable SSE endpoints to WebFlux transport (#41, #67)
Enhances WebFlux SSE transport implementation with customizable endpoint paths:
- Add configurable SSE endpoint support in both client and server transports
- Update tests to verify custom SSE endpoint functionality
- Implement builder pattern to support the new configuration options

Co-authored-by: haidao <wwulfric@gmail.com>
Co-authored-by: Harry <34418180+HarryFQG@users.noreply.github.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-27 14:31: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
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
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
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
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
JermaineHua
7165fea5ec Fix some typos
Signed-off-by: JermaineHua <crazyhzm@apache.org>
2025-02-25 12:33:25 +01:00
Dennis Kawurek
bb6514e808 Remove closed sessions from list in WebMvcSseServerTransport 2025-02-25 10:56:51 +01:00
zeko.zhang
dac5c545b0 Fix issue, SSE connection will terminate after 30 seconds (DEFAULT). 2025-02-25 10:33:04 +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
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
Mark Pollack
910be3cee7 Rename modules, update .gitignore 2024-12-10 18:46:49 -05:00
Mark Pollack
ba10954305 Refactor maven project structure 2024-12-10 17:46:11 -05:00
Christian Tzolov
305b80aaf8 refactor: rename project artifacts to follow spring-ai naming convention
- Rename mcp-core to spring-ai-mcp-core
- Rename mcp-spring to spring-ai-mcp-spring
- Rename mcp-spring-boot to spring-ai-mcp-spring-boot
- Rename parent artifact from mcp-parent to spring-ai-mcp
- Remove unused spring-ai.version property
2024-12-10 22:11:21 +01:00
Christian Tzolov
1d4aea3d1d chore: update project metadata for Spring projects alignment
Change groupId to org.springframework.experimental
Bump version to 0.1.0-SNAPSHOT
Add proper SCM, license, and developer information
Configure distribution, issue, and CI management
Clean up empty XML tags
2024-12-10 21:41:19 +01:00
Christian Tzolov
52e6644b22 dongrade java version from 21 to 17 2024-12-10 21:11:27 +01:00
Christian Tzolov
3abd93a323 Add mcp-spring that contains the McpFunctionCallback and mcp-spring-boot which is just boot demo 2024-12-10 19:52:35 +01:00
Christian Tzolov
22bddca5e4 fix dependecies and doc 2024-12-10 19:22:53 +01:00
Christian Tzolov
1d7ab91314 rename mcp to mcp-core and spring into mcp-spring 2024-12-10 18:56:38 +01:00