Commit graph

315 commits

Author SHA1 Message Date
Daniel Garnier-Moiroux
b5a1e3b8f4 Add option for immediate execution in McpSyncServer
- The McpSyncServer wraps an async server. By default, reactive
  operations are scheduled on a bounded-elastic scheduler, to offload
  blocking work and prevent accidental blocking of non-blocking
  operations.
- With the default behavior, there will be thead ops, even in a blocking
  context, which means thread-locals from the request thread will be
  lost. This is inconenvient for frameworks that store state in
  thread-locals.
- This commit adds the ability to avoid offloading, when the user is
  sure they are executing code in a blocking environment. Work happens
  in the calling thread, and thread-locals are available throughout the
  execution.
2025-07-08 15:50:36 +02:00
Christian Tzolov
c711f8315a feat: implement Streamable HTTP HttpClient transport and improve error handling (#337)
- Add HttpClientStreamableHttpTransport implementing the 2025-03-26 MCP specification
- Add ResponseSubscribers utility for handling different HTTP response body types
- Refactor HttpClientSseClientTransport to use reactive streams instead of FlowSseClient
  - Remove FlowSseClient in favor of reactive stream patterns
  - Use Disposable-based connection management instead of CountDownLatch
  - Replace message endpoint discovery with Sinks.One approach
- Improve error handling by replacing doOnError/onErrorResume with onErrorComplete
- Add test coverage for new Streamable HTTP transport
- Add resiliency tests for connection handling and session invalidation

BREAKING CHANGE: FlowSseClient has been removed in favor of reactive streams

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>

Co-authored-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-07-03 21:55:02 +02:00
Christian Tzolov
b328051685 refactor: make McpSyncServerExchange.ping() return response value
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-07-01 17:00:41 +02:00
Christian Tzolov
c0b398c650 feat: add progress token support and extend Request interface (#352)
- Add PaginatedRequest and ReadResourceRequest to Request sealed interface
- Add default meta() and progressToken() methods to Request interface
- Add _meta parameter support to request classes:
  - ReadResourceRequest, GetPromptRequest, CallToolRequest
  - CreateMessageRequest, ElicitRequest, CompleteRequest, PaginatedRequest
- Add builder methods for progress token configuration
- Add message field to ProgressNotification
- Maintain backward compatibility with existing constructors
- Add _meta field to the InitialRequest record

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-07-01 15:23:00 +02:00
Christian Tzolov
d7bcb237b8 feat: add ping functionality to MCP server exchanges (#347)
- Add ping() method to McpAsyncServerExchange that sends ping requests to clients
- Add ping() method to McpSyncServerExchange as synchronous wrapper
- Add OBJECT_TYPE_REF constant for ping response type handling
- Create McpSyncServerExchangeTests.java with full test coverage
- Add ping integration tests across WebFlux, WebMVC, and HttpServlet transports

Follow up of #203

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-07-01 14:51:51 +02:00
Christian Tzolov
d9006ecb78
refactor: return immutable lists from list methods (#345)
- Wrap the list responses in immutable lists.
 - Add test to verify the immutable responses.
 - Better timeout handling

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-27 21:03:46 +02:00
bzsurbhi
2f55dd0015 feat: add ResourceLink content type and ResourceContent interface (#341)
- Add ResourceContent interface with common resource metadata methods
- Implement ResourceContent in existing Resource class
- Add new ResourceLink record class implementing Content and ResourceContent
- Update Content interface to support ResourceLink with "resource_link" type (breaking!)
- Add tests for ResourceLink serialization/deserialization
- Update test expectations to include new resource_link type

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-27 19:37:46 +02:00
or-givati
ebb9764c1b feat: implement ping request handler in MCP async client (#203)
- Add ping request handler that responds with empty Map instead of null
- Ensure compliance with MCP protocol requirement for ping responses
- Add test for ping message request handling

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-27 18:47:18 +02:00
Christian Tzolov
1cbace3353 feat: add pagination support for listRoots operation (#336)
- Add nextCursor field to ListRootsResult for cursor-based pagination
- Implement automatic pagination in McpAsyncServerExchange.listRoots()
 - Automatically fetches and combines all pages into single result
 - Refactor McpAsyncServerExchange.listRoots() to return Collections.unmodifiableList
- Update tests to verify pagination functionality

- Add test suite for McpAsyncServerExchange covering:
  - listRoots() pagination scenarios and edge cases
  - Logging notification with level filtering
  - Elicitation creation with various capabilities
  - Message creation with sampling capabilities
  - Error handling and validation scenarios
  - Verify sendNotification calls in logging notification tests
  - Verify sendRequest is never called when capabilities are missing

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-27 10:22:11 +02:00
John Goering
5bd64c2beb typo fix 2025-06-26 13:45:52 +02:00
Dariusz Jędrzejczyk
4f93ce8eea
feat: Propagate Context to eager connect via McpClientSession (#339)
* feat: Propagate Context to eager connect via McpClientSession

In order to allow the initial connection to have contextual information
in the reactive chain, the McpClientSession should be able to transform
the McpClientTransport#connect result, e.g. to attach Context items.
This change introduces a new constructor for sessions that makes it
possible.

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>

---------

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-06-26 13:10:17 +02:00
gongwn1
9ebff0c5d9 feat: implement resource update notifications (#264)
This enables servers to notify clients when specific resources are updated,
allowing clients to react to individual resource changes rather than just
list changes.

- Add ResourcesUpdatedNotification schema with uri field
- Add METHOD_NOTIFICATION_RESOURCES_UPDATED constant
- Implement notifyResourcesUpdated() methods in McpAsyncServer and McpSyncServer
- Add client-side support for resource update consumers and handlers
- Client automatically reads updated resource content when notification received
- Add tests for both async and sync server implementations

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-24 12:04:22 +02:00
Christian Tzolov
be719f53d8 refactor: consolidate MCP client initialization logic (#334)
- Move session setup, completion, and error callbacks into doInitialize method
- Rename variables in McpClientSession for better clarity (sink -> pendingResponseSink/deliveredResponseSink)

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-24 11:03:24 +02:00
Sun Yuhan
ba5bc94963 feat: Added the annotations attribute to McpSchema.Tool (#313)
Signed-off-by: Sun Yuhan <sunyuhan1998@users.noreply.github.com>
2025-06-24 09:58:32 +02:00
jookunshuai
fce7a6bad3 fix: copy request builder to prevent side effects in HTTP transports (#333)
- Add .copy() call before modifying requestBuilder in FlowSseClient
- Add .copy() call before modifying requestBuilder in HttpClientSseClientTransport
- Prevents unintended mutations of shared builder instances
2025-06-24 08:07:16 +02:00
Anurag Pant
d4a1bfa58f feat: Improve pagination support on client side (#306)
This change enhances the client API by providing both paginated access for fine-grained
control and convenience methods for retrieving complete result sets automatically.

- Implement "list all" methods that automatically handle pagination using expand/reduce operations
- Replace null parameters with McpSchema.FIRST_PAGE constant for better readability
- Add tests for both paginated and "list all" functionality
- Update method javadocs to clarify pagination behavior
- Maintain backward compatibility

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-24 07:57:31 +02:00
Luca Chang
aff24fdf2f fix: support freeform stopReason in sampling (#327)
- Add string values and JsonCreator method to StopReason enum
- Map unknown stop reason values to UNKNOWN constant for forward compatibility
- Add test coverage for unknown stop reason deserialization

Spec: f5ccad944f/schema/2024-11-05/schema.ts (L807)

Resolves #328
2025-06-24 06:41:14 +02:00
Luca Chang
6c330db5ad feat: add size field and builder pattern to Resource record (#331)
The size field helps hosts display file sizes and estimate context window usage.

- Add size parameter to Resource record for tracking raw content size in bytes
- Implement Builder pattern for Resource construction with validation
- Add deprecated constructor for backwards compatibility
- Add tests for builder pattern and field validation

Resolves #330

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-24 06:21:14 +02:00
Luca Chang
0fe76ba993 docs: update loggingNotification javadoc to specify single client 2025-06-23 09:07:10 +02:00
Christian Tzolov
b701a366c0 test: enhance resource reading tests (#314)
- Implement comprehensive resource content validation for text/plain and application/octet-stream MIME types
- Validate resource count expectations (10 resources)
- Add elicitation capability testing with ElicitRequest/ElicitResult support
- Clean up unused imports (ObjectMapper, ImageFromDockerfile)

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-18 11:26:07 +02:00
Christian Tzolov
aacc631c96 Bump the StdioMcpAsyncClientTests initialization timeout to 10s
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-17 17:43:22 +02:00
Luca Chang
fb40047c39 refactor: consolidate content annotations into Annotations (#242)
Updates all Content types to represent annotations as nested objects
instead of directly on the content itself.

- Refactor TextContent, ImageContent, and EmbeddedResource to use Annotations object instead of separate audience/priority fields
- Add backward-compatible deprecated methods for audience() and priority() accessors
- Add parameterized tests for message annotations across different message types (success, error, debug)
- Test both text and image content annotations with proper priority and audience validation

This brings the implementation in line with the content types as modeled by the specification:
c87a0da6d8/schema/2025-03-26/schema.json (L1970-L1973)
2025-06-17 17:37:23 +02:00
Christian Tzolov
b5ece766e7 fix: resolve type inference issues in StdioClientTransport
- Add explicit Void type parameter to Mono.defer() call
- Chain .then() to Mono.delay() to ensure consistent Mono<Void> return type

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-17 17:21:39 +02:00
Luca Chang
f3b0774a24 Add sampling functionality tests to MCP client test suites (#255)
- Add testSampling() methods to AbstractMcpAsyncClientTests and AbstractMcpSyncClientTests

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>

Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-16 15:52:36 +02:00
Dariusz Jędrzejczyk
8e9857f181 Fix Streamable HTTP WebClient GET SSE handling
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-06-16 15:48:49 +02:00
Luca Chang
9a63538840 feat: add AudioContent support to MCP schema (#243)
- Add AudioContent record class implementing Annotated and Content interfaces
- Update Content sealed interface to permit AudioContent
- Add audio type handling in Content.type() method
- Include AudioContent in JsonSubTypes annotation for polymorphic deserialization
- Add comprehensive tests for AudioContent serialization and deserialization
- Update error message test to include audio in known type ids

c87a0da6d8/schema/2025-03-26/schema.ts (L987-L1009)
2025-06-15 16:28:43 +02:00
Christian Tzolov
b539b9889e Fix broken link in README
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-14 11:17:29 +02:00
Christian Tzolov
697e0d1492 docs: restructure MCP Java SDK documentation references
- Replace single documentation link with organized list of sections
- Add direct links to Features, Architecture, Dependencies, Client, and Server docs
- Improve navigation and discoverability of specific documentation topics

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-06-14 11:15:05 +02:00
Dariusz Jędrzejczyk
2f944349cc
feat: WebClient Streamable HTTP support (#292)
An implementation of Streamable HTTP Client with WebFlux WebClient.
Aside from implementing the specification, several improvements have been incorporated throughout the client-side of the architecture.

The changes cover:
- resilience tests using toxiproxy in testcontainers
- integration tests using updated everything-server with streamableHttp support
- improved logging
- session invalidation handling (both transport session and JSON-RPC concept of session)
- implicit initialization and burst protection (in case of concurrent `Mcp(Sync|Async)Client` use
- more logging, e.g. stdio process lifecycle logs

Related #72, #273, #253, #107, #105

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-06-10 18:33:40 +02:00
Luca Chang
8a5a591d39 feat: Add elicitation support to MCP protocol
Implement elicitation capabilities allowing servers to request additional information
from users through clients during interactions. This feature provides a standardized
way for servers to gather necessary information dynamically while clients maintain
control over user interactions and data sharing.

- Add ElicitRequest and ElicitResult classes to McpSchema
- Implement elicitation handlers in client classes
- Add elicitation capabilities to server exchange classes
- Add tests for elicitation functionality with various scenarios
2025-06-10 13:37:23 +02:00
Dariusz Jędrzejczyk
07e7b8fd6b Add note about force pushes
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-05-16 11:47:39 +02:00
Dariusz Jędrzejczyk
1adfa8a047 Add Contributing Guidelines and Code of Conduct
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-05-16 11:47:39 +02:00
Dariusz Jędrzejczyk
2e13f9f9df Fix flaky WebFluxSse integration test
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-05-15 10:25:46 +02:00
Dariusz Jędrzejczyk
f34662555a
Fix stdio tests - proper server-everything argument (#237)
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-05-14 15:38:02 +02:00
Christian Tzolov
b2d3e0098e Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-05-12 15:04:05 +02:00
Dariusz Jędrzejczyk
0069c977ef Remove temporary delegate impl from McpAsyncServer
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-05-09 14:56:27 +02:00
Dennis Kawurek
eae3840e7d
fix: Mockito inline mocking for Java 21+ (#207)
Before this fix the execution of the maven surefire
plugin with Java 21 logged warnings that mockito should be added as
a java agent, because the self-attaching won't be supported in future
java releases.
In Java 24 the test just broke.

This problem is solved by modifying the pom.xml of the parent and doing
this changes:

* Adding mockito as a java agent.
* Removing the surefireArgLine from the properties. This can be
added back when it's needed (for example when JaCoCo will be used).

Furthermore, the pom.xml in the mcp-spring-* modules now have
the byte-buddy dependency included, as the test would otherwise break
when trying to mock McpSchema#CreateMessageRequest.

Fixes #187

Co-authored-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-05-08 12:44:51 +02:00
jito
e34babbe56
Add missing isInitialized method to McpSyncClient (#181)
The isInitialized method is present in McpAsyncClient and needs to be
mirrored in McpSyncClient.

Signed-off-by: jitokim <pigberger70@gmail.com>
2025-05-08 11:31:17 +02:00
Christian Tzolov
e610d853f9 feat: Add customizable URI template manager factory to MCP server
Implement URI template functionality for MCP resources, allowing dynamic
resource URIs with variables in the format {variableName}.

- Enable resource URIs with variable placeholders (e.g., "/api/users/{userId}")
- Automatic extraction of variable values from request URIs
- Validation of template arguments in completions
- Matching of request URIs against templates

- Add new URI template management interfaces and implementations
- Enhanced resource template listing to include templated resources
- Updated resource request handling to support template matching
- Test coverage for URI template functionality

- Adding a configurable uriTemplateManagerFactory field to both AsyncSpecification and SyncSpecification classes
- Adding builder methods to allow setting a custom URI template manager factory
- Modifying constructors to pass the URI template manager factory to the server implementation
- Updating the server implementation to use the provided factory
- Add bulk registration methods for async completions

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-29 07:11:39 +03:00
Francis Hodianto
261554bb7f
fix: propagate Reactor Context into client transport chain (#154) 2025-04-23 17:09:41 +02:00
wangzhi
9c92a2b8bf
Fix javadoc references and formatting (#149) 2025-04-23 17:03:10 +02:00
Richie Caputo
f70b98b4b4
feat(schema): add support for JSON Schema $defs and definitions (#146)
Added support for $defs and definitions properties in JsonSchema record to handle JSON Schema references properly. Added tests to verify both formats work correctly.

The JsonSchema test approach uses serialization/deserialization round-trip validation instead of property-by-property assertions. This makes tests more maintainable and less likely to break when new properties are added.

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-04-23 16:47:48 +02:00
jito
86e3e9048f
Fix typo in WebFluxSseIntegrationTests (#142)
Signed-off-by: jitokim <pigberger70@gmail.com>
2025-04-23 16:27:10 +02:00
Dariusz Jędrzejczyk
866732c383
Polish #33
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-04-23 11:06:26 +02:00
JermaineHua
04046ca05b
Optimize client nested streams in McpClientSession (#33)
Signed-off-by: JermaineHua <crazyhzm@apache.org>
2025-04-23 10:38:42 +02:00
JermaineHua
41c6bd9af0 Fix method not found error msg for server
Signed-off-by: JermaineHua <crazyhzm@apache.org>
2025-04-18 15:18:12 +02:00
jie.bao
e4091f458a feat(completion): fix the schema about CompleteResult
/**
 * The server's response to a completion/complete request
 */
export
interface CompleteResult extends Result {
  completion: {
    /**
     *
An array of completion values. Must not exceed 100 items.
     */

values: string[];
    /**
     * The total number of completion options
available. This can exceed the number of values actually sent in the
response.
     */
    total?: number;
    /**
     * Indicates whether
there are additional completion options beyond those provided in the
current response, even if the exact total is unknown.
     */

hasMore?: boolean;
  };
}
2025-04-18 15:13:56 +02:00
E550448
344f1b8383 feat(mcp): resolve absolute and relative message endpoint URIs (#150)
Improve endpoint URI handling by supporting both relative paths
and properly validated absolute URIs.

- Implement URI resolution in HttpClientSseClientTransport:
- Change baseUri field from String to URI type
- Add Utils.resolveUri method to handle both absolute and relative URIs
- Resolve relative URIs against the base URI
- Validate absolute URIs to ensure they match base URI's scheme, authority, and path
- Add parameterized tests for various URI resolution scenarios
- Add ByteBuddy dependency for HttpClient mocking and update Mockito

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-04-18 14:52:50 +02:00
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