Commit graph java-sdk/mcp-core
Author SHA1 Message Date
Daniel Garnier-Moiroux
178fe219de Update author tags and copyright info
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
caafc85575 Make session-sweeping non-blocking
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
9948eecbb7 Streamable HTTP server: keep alive on, 30 minutes by default
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
1178539050 Skip session activity tracking when sessionSweepInterval is null
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
65c0856518 Fix hanging disconnected client during POST
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
b4d7ff6428 Error pending requests on session close
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
50991f9b6c Remove inactive sessions with a "sweeper" mechanism
- Sessions are marked active when a client makes a request
- A session with an open stream is also considered active
- Inactive sessions are removed at a regular interval

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
04bc1e8710 Close POST-related streams in McpStreamableServerSession
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
ca633db18c KeepAliveScheduler only pings sessions with an open stream
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
7961dc58af KeepAliveScheduler: align initial delay with interval
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-18 11:37:00 +02:00
Daniel Garnier-Moiroux
183935bf80 Fix Automatic-Module-Name without hypens
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-17 11:50:06 +02:00
Daniel Garnier-Moiroux
4186ca13d1 Fix stream leak when resuming streams with LAST_EVENT_ID
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-08 15:28:17 +02:00
Neeraj Bhatt
5be2fa0688 feat: introduce ServerHttpHeaderValidator replacing ServerTransportSecurityValidator
Same feature set as ServerTransportSecurityValidator but uses a lazy
"header accessor" function to read header values instead of extracting
all headers into a map. Matches more closely what modern frameworks and
JDK APIs do.

Fixes #870

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-07 14:35:15 +02:00
Nicolas Quinquenel
2bb1481ec3
Make STDIO transport sendMessage thread-safe (#304)
Concurrent calls to `sendMessage` on the STDIO transports raced on the
unicast sink and sporadically failed with `FAIL_NON_SERIALIZED`, dropping
the message with `RuntimeException("Failed to enqueue message")`.

Switch `tryEmitNext` to `emitNext` with a `busyLooping` EmitFailureHandler
so concurrent emissions are serialized as recommended by the Reactor
maintainers. Applied on both `StdioServerTransportProvider` and
`StdioClientTransport`.

Co-authored-by: Nicolas Quinquenel <nicolas.quinquenel@sonarsource.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2026-09-04 19:51:54 +02:00
Daniel Garnier-Moiroux
735a85190b Remove 2024-11-05 protocol from Streamable HTTP transport
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-09-04 18:55:37 +02:00
Daniel Garnier-Moiroux
2293cf70b5
Add filtering for MCP tool list (#1108)
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-31 10:19:49 +02:00
Sylwester Lachiewicz
b31841eec0 docs(core): document String structuredContent parsing in JsonSchemaValidator 2026-08-27 09:33:21 +02:00
Daniel Garnier-Moiroux
bb0ca87da5 Clarify McpTransportContext javadoc
See #1075

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-26 16:08:11 +02:00
Daniel Garnier-Moiroux
cceba3f695 Next development version
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-19 15:27:57 +02:00
Daniel Garnier-Moiroux
c7e1cfe90e Release version 2.0.1
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-19 15:25:35 +02:00
Daniel Garnier-Moiroux
3477fcd0cd Bound STDIO client reads
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-19 14:53:08 +02:00
Daniel Garnier-Moiroux
3b72eec0b8 Bound STDIO server reads
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-19 14:53:08 +02:00
Daniel Garnier-Moiroux
ef037dae7b Bound HTTP client reads
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-19 14:41:20 +02:00
Daniel Garnier-Moiroux
6a41dedaa0 Bound HTTP server reads
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-19 14:41:20 +02:00
Iuliia Sobolevska
8ee8ccbc17
Make McpTransportContext.metadata immutable (#1076)
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-08-07 18:36:22 +02:00
nanookclaw
27b91521c0
fix: stop pagination on empty cursors (#954)
Signed-off-by: Nanook <nanookclaw@users.noreply.github.com>
Co-authored-by: Nanook <nanookclaw@users.noreply.github.com>
2026-08-07 18:25:39 +02:00
jiajingda
f5aab36a2f
Fix SSE event classification to follow spec for missing event field (#913)
Per the SSE specification (WHATWG HTML Living Standard 9.2.6), an event with no explicit event field MUST be dispatched as a message event. HttpClientStreamableHttpTransport previously used strict equality and silently dropped such frames in the reconnect/GET stream path, causing server-initiated notifications to never reach the handler. Extract classification into a package-private isMessageEvent helper and cover with parameterized unit tests.

Closes gh-885
2026-08-07 17:48:03 +02:00
Minsung Son
fd004989b9
refactor: add notification handler to stateless servers. (#835)
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
Co-authored-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-07-10 17:51:38 +02:00
Mathias Geat
5d3decebd6
Fix error behavior on unregistered handlers in stateless server handler (#800)
Instead of throwing an McpError, it now returns with a JSON-RPC method not found error (-32601), aligned with the stateful implementation.

Closes #784
2026-07-08 14:42:06 +02:00
Daniel Garnier-Moiroux
ff78191ebd
Close response after sending error in McpStreamableServerSession#responseStream (#1041)
Closes #1040

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-06-26 16:06:36 +02:00
King Star
301f8b06c7 fix(server): return empty completion when handler is absent 2026-06-24 14:27:24 +02:00
Dariusz Jędrzejczyk
d1ef187c9c Next development version
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-06-11 13:41:15 +02:00
Dariusz Jędrzejczyk
f56d038409 Release version 2.0.0
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-06-11 13:37:50 +02:00
Dariusz Jędrzejczyk
d20af91512
Add 2025-11-25 spec version to all transports (#1025)
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-06-11 12:17:46 +02:00
Christian Tzolov
c42d313975
Return void from McpStatelessSyncServer#closeGracefully instead of Mono (#1019)
Co-authored-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-06-11 12:02:44 +02:00
Daniel Garnier-Moiroux
fe82ad508a
Add schemas for form-based elicitation (#1020)
* Add StringSchema, BooleanSchema and NumberSchema
* Add enum schemas for form-based elicitation matching SEP-1330

Closes #691

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-06-11 11:16:47 +02:00
Christian Tzolov
99faac65f7
Clarify tool validation error messages (#1023)
- DefaultJsonSchemaValidator now emits a neutral message;
- Call sites in ToolInputValidator and the server output handlers
  prepend their own context prefix,
- Integration test assertions strengthened accordingly.

Closes #986

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

* address review comments

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

* address review comments

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

---------

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-06-11 09:45:28 +02:00
Dariusz Jędrzejczyk
df75857fb1
fix: avoid dropped errors when transport is closed or uninitialized (#995)
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-06-04 14:11:32 +02:00
Daniel Garnier-Moiroux
dbb9bdad51
Add URL elicitation support (SEP-1036) (#993)
Add URL-type elicitation schema support allowing servers to request URL
input from users during tool execution. This enables out-of-band
interactions like payment processing or API key entry.

Breaking changes:

- `ElicitRequest` changed from a `record` to an `interface`.
- The original `ElicitRequest` record was renamed to `ElicitFormRequest`.
- `McpClient` builder `elicitation()` methods now accept `ElicitFormRequest` instead of `ElicitRequest`.

New APIs:

- `ElicitUrlRequest` record for URL-mode elicitation.
- `urlElicitation()` builder methods in `McpClient`.
- `elicitationCompleteConsumer()` and `elicitationCompleteConsumers()` builder methods in `McpClient`.
- `sendElicitationComplete()` methods in `McpAsyncServer` and `McpSyncServer`.
- `McpError.URL_ELICITATION_REQUIRED` and `McpSchema.ErrorCodes.URL_ELICITATION_REQUIRED`.
- `ElicitationCompleteNotification` record and `METHOD_NOTIFICATION_ELICITATION_COMPLETE` constant.

Co-authored-by: Daniel Garnier-Moiroux <git@garnier.wf>
Co-authored-by: Sainath Reddy Bobbala <bsnr@amazon.com>
2026-06-03 16:24:29 +02:00
Dariusz Jędrzejczyk
c8ab3411b9
feat: Refine logging levels (#985)
The logging is sometimes too verbose and uses inappropriate level. With this
change there should be less disturbing logs and less duplication.

Notable changes:

* `LifeCycleInitializer#handleException` - duplicated log, already handled in
  transports that use the initializer.
* `McpClientSession#sendRequest` - an MCP protocol level error in JSON-RPC is
  not really a reason for ERROR level log. Using INFO with more details.
* `DefaultJsonSchemaValidator` - ERROR logs in `validate` are always logged by
  the users of this method. `validateSchema` surfaces as
  `IllegalArgumentException` and can be logged at higher levels by the user.

Also: remove DEBUG logs from mcp-test module.

Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-05-27 11:50:48 +02:00
Dariusz Jędrzejczyk
c6d365c418
Unify logging config (#984)
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-05-27 11:15:53 +02:00
Daniel Garnier-Moiroux
4f3f7d9fa4 Expose request URI in McpHttpClientAuthorizationErrorHandler
Breaking change

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-05-26 11:00:49 +02:00
Dariusz Jędrzejczyk
accba74c8f
feat: client-side application of elicitation schema defaults (SEP-1034) (#976)
Adds an opt-in McpClient builder option `applyElicitationDefaults(boolean)`
that, when enabled, fills missing keys of an accepted ElicitResult.content
with `default` values declared in the requestedSchema before returning the
result to the server. Mirrors the TypeScript SDK's applyElicitationDefaults
behavior, but exposed as a local client config rather than a wire capability.

Co-authored-by: Sainath Reddy Bobbala <bsnr@amazon.com>
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-05-22 19:51:54 +02:00
sAInath
d81430a532
feat: Add SEP-973 icons and metadata support (#912)
Add Icon record and icons field to Implementation, Resource,
ResourceTemplate, Prompt, and Tool records per SEP-973. Add
websiteUrl and description fields to Implementation.

All fields are optional and backward compatible. Existing
constructors and builders continue to work unchanged.
Icon.src is validated as required per the spec.
Icon.theme field supports light/dark theme variants.

Includes serialization, deserialization, round-trip, and backward
compatibility tests for all modified records.

Closes modelcontextprotocol#694

Co-authored-by: Sainath Reddy Bobbala <bsnr@amazon.com>
2026-05-19 12:40:26 +02:00
Daniel Garnier-Moiroux
c09ee67f60 Deprecate SSE transports
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-05-13 17:52:17 +02:00
Dariusz Jędrzejczyk
87e2c7d4de
feat: validate embedded JSON Schema documents against 2020-12 meta-schema (SEP-1613) (#949)
MCP embeds JSON Schema documents in three places — Tool.inputSchema,
Tool.outputSchema, and ElicitRequest.requestedSchema — and SEP-1613
mandates that these documents conform to JSON Schema 2020-12 by default.

Servers now reject malformed schemas at both build time (McpServer.build())
and runtime (McpAsyncServer/McpStatelessAsyncServer.addTool()), returning
an IllegalArgumentException that identifies the offending field and
references SEP-1613.  Elicitation requests whose requestedSchema violates
the meta-schema are rejected before being sent to the client.

Schemas that explicitly declare a different dialect via $schema are accepted
without meta-schema validation, since 2020-12 is the default, not the only
permitted dialect.

Refine meta-schema loading and deprecate orphan JsonSchemaValidator

Resolves #700

Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-05-07 14:14:53 +02:00
Dariusz Jędrzejczyk
5d4a1cce42
Revert removed builders for Resource and ResourceTemplate (#947)
Instead of fully breaking the API, this is a step
which depreactes the existing non-argument builder.

It allows the users to gradually migrate while preserving
the necessary checks.

Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
Co-authored-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-05-05 11:22:48 +02:00
Dariusz Jędrzejczyk
22a0efa577 feat!: enforce required MCP spec fields in McpSchema; lenient wire deserialization (#928)
Every wire-serialized record in McpSchema now validates spec-required
fields at construction time. Wire deserialization is intentionally
lenient: a missing required field is replaced with a documented default
and a WARN is logged, instead of failing the parse. A required-first
builder convention is introduced across the schema so it is no longer
possible to obtain a builder that is missing required state.

Required-field guards
---------------------
Every wire record's compact constructor asserts non-null (and non-empty
for String identifiers like name, uri, uriTemplate, version) on its
spec-required components. Passing null now throws
IllegalArgumentException at construction time instead of silently
producing invalid JSON via @JsonInclude(NON_ABSENT). This applies to
the JSON-RPC envelopes, lifecycle types, resource/prompt/tool requests
and results, sampling and elicitation, content records, root, complete,
logging and progress notifications, and the two CompleteReference
implementations. See MIGRATION-2.0.md for the full list.

Lenient wire deserialization
----------------------------
For each of those records (except JSONRPCResponse.JSONRPCError, which
still fails fast) a @JsonCreator static `fromJson` factory substitutes
a documented default for any absent required field — "" for strings,
[] for collections, {} for maps, 0 / 0.0 for numerics, INFO for
LoggingLevel, USER for SamplingMessage.role, ASSISTANT for
CreateMessageResult.role, CANCEL for ElicitResult.action, {values=[]}
for CompleteResult.completion — and logs a WARN naming the field and
the value used. Application code can still observe a malformed message
and react, but the SDK no longer halts the conversation.

Builder convention
------------------
Records that have a builder gain a required-first factory method
`builder(req1, req2, …)`; setters for required fields are removed from
the builder so it cannot be left in an invalid state. Existing no-arg
`builder()` factories and required-field setters are kept where source
compatibility demands it but are marked @Deprecated. New builders are
also added for several records that previously had none (ProgressNotification,
JSONRPCError, CompleteRequest, list/result types, content records, ...).

JSON-RPC envelope ergonomics
----------------------------
Previously every JSON-RPC envelope had to be constructed via the
canonical record constructor and the literal "2.0" string had to be
threaded through every call site, e.g.

    new JSONRPCRequest("2.0", "tools/call", id, params)
    new JSONRPCResponse("2.0", id, result, null)
    new JSONRPCResponse("2.0", id, null, new JSONRPCError(code, message, null))

Now:

    new JSONRPCRequest("tools/call", id, params)              // jsonrpc defaulted
    new JSONRPCNotification("notifications/initialized")       // params optional
    JSONRPCResponse.result(id, result)                        // factory
    JSONRPCResponse.error(id, new JSONRPCError(code, message)) // 2-arg error

JSONRPCResponse's compact constructor additionally enforces the
JSON-RPC invariant that exactly one of `result` / `error` is set —
previously the SDK could build envelopes that violated the protocol.

CompleteReference changes
-------------------------
- PromptReference.equals/hashCode now key on `name` only (previously
  derived from identifier()+type()). Two refs with the same name but
  different titles now compare equal — code using PromptReference as a
  map/set key should be audited.
- PromptReference's compact constructor pins `type` to "ref/prompt"
  and logs a WARN if the caller supplies a different non-null value.
  The legacy two-arg `PromptReference(String type, String name)`
  constructor remains @Deprecated.
- ResourceReference's record components are reduced from (type, uri)
  to (uri) — positional construction breaks. The legacy
  `ResourceReference(String type, String uri)` constructor stays
  @Deprecated and ignores `type`.
- CompleteReference.identifier() is @Deprecated and now returns null
  via a default method on the interface.

Tests / refactor
----------------
Conformance harness, integration tests, sample apps, and internal
callers were migrated to the new builder factories and convenience
constructors. No semantic changes to client/server runtime behaviour
beyond the McpSchema changes above.

Docs
----
- MIGRATION-2.0.md: required-field section now covers the broader
  record set and the lenient-deserialization behaviour; PromptReference
  WARN behaviour and ResourceReference component reduction are
  documented; the JSON-RPC envelope section is rewritten to compare the
  pre-2.0 surface with the new one.
- CONTRIBUTING.md: the "Evolving wire-serialized records" recipe is
  split into two cases — adding a new optional field (existing rules)
  and adding/maintaining a spec-required field (new rules covering
  Assert in compact constructor, @JsonCreator fromJson with defaults
  and WARN, required-first builder factory).

Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-05-04 21:01:46 +02:00
Daniel Garnier-Moiroux
bf30e21f0d DefaultSseMessageEndpointValidator allows same-origin message endpoints
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-05-04 13:54:03 +02:00
Daniel Garnier-Moiroux
563b1551a3 Validate message endpoint in SSE client transport
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-30 17:30:22 +02:00