Commit graph java-sdk/mcp-core
Author SHA1 Message Date
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
Dariusz Jędrzejczyk
5895b2edd2
fix: Return empty prompt completion result when prompt has no arguments (#934)
Recent changes don't coerce null completion arguments to empty lists so we have
to check for null when handling prompt completions.

Resolves #932

Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-04-24 14:05:12 +02:00
Dariusz Jędrzejczyk
4c8596306d feat!: consistent JSON forward/backward compatibility - 2.0 foundation (#972)
The MCP specification evolves continuously; domain types must absorb
new fields and subtypes without breaking existing clients or servers.
On the 1.x line this is structurally prevented by sealed interfaces,
which make it impossible to add a permitted subtype without breaking
exhaustive pattern-match switch expressions in caller code. This
commit opens the 2.0 release line, where those constraints are lifted
and serialization is made self-contained — independent of any global
ObjectMapper configuration.

Breaking changes for users migrating from 1.x

- Sealed interfaces removed from JSONRPCMessage, Request, Result,
  Notification, ResourceContents, CompleteReference and Content.
  Exhaustive switch expressions over these types must add a default
  branch.
- Prompt(name, description, null) no longer silently coerces null
  arguments to an empty list. Use Prompt.withDefaults() to preserve
  the previous behaviour.
- CompleteCompletion.total and .hasMore are now absent from the wire
  when not set, rather than being emitted as null.
- ServerParameters no longer carries Jackson annotations; it is an
  internal configuration class, not a wire type.

What now works that did not before

- CompleteReference polymorphic dispatch (PromptReference vs
  ResourceReference) works through a plain readValue or convertValue
  call — no hand-rolled map inspection required.
- LoggingLevel deserialization is lenient: unknown level strings
  produce null instead of throwing.
- All domain records now tolerate unknown JSON fields, so a client
  built against an older SDK version will not fail when a newer server
  sends fields it does not yet recognise.
- Null optional fields are consistently absent from serialized output
  regardless of ObjectMapper configuration.

Documentation

- CONTRIBUTING adds an "Evolving wire-serialized records" section: a
  9-rule recipe and example for adding a field safely.
- MIGRATION-2.0 documents all breaking changes listed above.

Follow-up coming next

Several spec-required fields (e.g. JSONRPCError.code/message,
ProgressNotification.progress, CreateMessageRequest.maxTokens,
CallToolResult.content) are stored as nullable Java types without a
null guard. If constructed with null, the NON_ABSENT rule silently
omits them, producing invalid wire JSON without throwing. Fix: compact
canonical constructors with Assert.notNull, following the pattern
already in JSONRPCRequest.

Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
2026-04-23 17:34:55 +03:00
ashakirin
d1823389a9
feat!: add tool input arguments validation (#873)
added tool input arguments validation causes tool execution error. Breaking change, because validation is activated by default

closes #697

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-13 16:58:04 +02:00
Bilal Oumehdi
95203233c8
fix: Remove JsonSchema and use a Map for inputSchema to support json schemas dialect (#749)
* feat: remove JsonSchema an use a Map for inputSchema

- Fixes #886

Co-authored-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-10 11:32:22 +02:00
Daniel Garnier-Moiroux
fcdc0d4c14 Polish gh-906 2026-04-09 11:11:07 +02:00
smohite04
eaa0c691f0
feat: add support for meta parameter in client paginated list queries (#906)
* feat: add support for meta parameter in client paginated list queries#

- resources/list
- resources/templates/list
- prompts/list
- tools/list

paginated list operations extended in this review:
- listResources(String cursor, Map<String, Object> meta)
- listResourceTemplates(String cursor, Map<String, Object> meta)
- listPrompts(String cursor, Map<String, Object> meta)

Closes #907

Co-authored-by: SHEETAL MOHITE <mohishee@amazon.com>
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-09 10:40:35 +02:00
RameshReddy Adutla
8fd9903e62 Fix UTF-8 encoding for non-ASCII tool names in HTTP client transports
Both HttpClientSseClientTransport and HttpClientStreamableHttpTransport
set Content-Type to 'application/json' without specifying the charset.
While Java's BodyPublishers.ofString() uses UTF-8 by default, the
missing charset in the header can cause the server to interpret the
request body using a different encoding (e.g., ISO-8859-1), corrupting
non-ASCII characters such as Chinese tool names.

Explicitly set Content-Type to 'application/json; charset=utf-8' in
POST requests on both client transports.

Fixes #260

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Daniel Garnier-Moiroux <git@garnier.wf>
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-08 15:02:23 +02:00
Daniel Garnier-Moiroux
5e77762eeb HttpClientStreamableHttpTransport: handle HTTP 405
- Forward-port of #900

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-02 17:26:53 +02:00
Daniel Garnier-Moiroux
8c7774ad5f Server transports: remove deprecated methods from builder
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-02 15:50:57 +02:00
300:29:1
301dbe46ce
Deprecate Builder.customizeRequest() in favor of httpRequestCustomizer() (#791)
Deprecate Builder.customizeRequest() in HttpClientSseClientTransport and HttpClientStreamableHttpTransport

customizeRequest() executes its consumer once at build time, freezing
headers into the shared requestBuilder. This silently breaks OAuth
token refresh scenarios where the Authorization header needs to be
updated after the transport is built.

Add @Deprecated and update Javadoc to clarify the build-time-only
semantics and guide users toward httpRequestCustomizer() or
asyncHttpRequestCustomizer() which run on every request.

Closes #788

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-04-02 11:38:53 +02:00
Daniel Garnier-Moiroux
685b1899f9
Merge commit from fork 2026-03-27 18:19:47 +00:00
Christian Tzolov
cbb235fd32 Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-03-13 13:31:03 +01:00
Christian Tzolov
c4b585795e
fix: prepare POMs for Maven Central release readiness (#863)
- Fix malformed SCM developerConnection URL (slash → colon) across all modules
- Add mcp-json-jackson3 to mcp-bom dependency management
- Update license URL to HTTPS
- Fix POM's scm definitions

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



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

---------

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-03-13 12:41:49 +01:00
Daniel Garnier-Moiroux
abcd19c0c2
HttpClientStreamHttpTransport: add authorization error handler (#861)
HttpClientStreamHttpTransport: add authorization error handler

- Closes #240

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-03-13 10:12:57 +01:00
조형준
05f37ad027
Use explicit UTF-8 charset in StdioServerTransportProvider (#826)
Also add a test simulating a different locale in an isolated process.

Resolves #295
2026-03-02 16:57:08 +01:00
Dariusz Jędrzejczyk
7f68ea5bc0
Support resource subscriptions (#839)
Clients can now subscribe to specific resources and receive targeted
notifications when those resources change. Previously, calling
`notifyResourceUpdated` on the server would broadcast the notification
to every connected client regardless of interest — now only sessions
that have explicitly subscribed to a given resource URI receive the
update, making resource change propagation both correct and efficient.
The subscription lifecycle is fully handled: clients can subscribe and
unsubscribe at any time, and the server cleans up subscription state
when a session closes.

Supersedes #838.
Resolves #837, #776.

---------

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2026-03-02 15:26:03 +01:00
Christian Tzolov
d689cddd8b Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-02-23 10:32:26 +01:00
Christian Tzolov
7e08a8e63f Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-02-20 22:04:21 +01:00
Christian Tzolov
479e52e6d5 Release version 1.0.0-RC3
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-02-20 22:03:40 +01:00
Christian Tzolov
acb7e4d2a0 Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-02-20 21:41:35 +01:00
Christian Tzolov
11b597cd77 Release version 1.0.0-RC2
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-02-20 21:37:56 +01:00
Dariusz Jędrzejczyk
4c1c3d8d5c
Remove deprecated APIs and modules for 1.0.0 release (#807)
- Remove mcp-json-jackson module (JacksonMcpJsonMapper, DefaultJsonSchemaValidator)
- Remove deprecated session interfaces (McpServerSession, McpClientSession methods)
- Remove deprecated server methods (loggingNotification, McpAsyncServerExchange constructor)
- Remove deprecated schema definitions and constructors (McpSchema, McpError, tool/content classes)
- Replace generic McpError with appropriate exception types (IllegalStateException, IllegalArgumentException)
- Update all tests to use current APIs

---------

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2026-02-20 17:32:40 +01:00
Scott Lewis
159eb964cc Fix and simplification for osgi manifest.mf
contents generation.
2026-02-18 17:18:11 +01:00
Christian Tzolov
3ab829285d Bump version from 0.18.0-SNAPSHOT to 1.0.0-SNAPSHOT
Update project version across all POM files, documentation, and CI
workflow to prepare for the 1.0.x release

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-02-18 12:45:20 +01:00
Sébastien Deleuze
e60a0743a5
Refine McpJsonDefaults method names (#789)
As a follow-up of #779, this commit refines McpJsonDefaults
method names by shortening them to not repeat the qualifiers
already expressed at type level.
2026-02-13 16:54:01 +01:00
Daniel Garnier-Moiroux
f6c3fde7f4 DNS rebinding protection: check host header
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-12 11:00:42 +01:00
Daniel Garnier-Moiroux
b57b1269d0 Polish gh-771
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-12 10:46:09 +01:00
Daniel Garnier-Moiroux
82102a18f5 Remove unused abstract test classes in mcp-core
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-12 10:44:03 +01:00
Daniel Garnier-Moiroux
6f3906480d Move mcp-core integration tests to mcp-test package
- The integration tests pass with both Jackson 2 and Jackson 3.
- Modified McpSchemaTests.testContentDeserializationWrongType to work
  with both Jackson 2 and Jackson 3.

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-12 09:13:38 +01:00
Scott Lewis
c3b9ab09ea Move mcp-json into mcp-core, add OSGi support
Co-authored-by: Luca Chang <131398524+LucaButBoring@users.noreply.github.com>
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-12 09:13:38 +01:00
Daniel Garnier-Moiroux
be5ec12e1b Polish gh-764
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-10 11:29:26 +01:00
ashakirin
09a853f555
Add tool name validation SEP-986 (#764)
* feat: added tools name format validation accordingly #SEP-986

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-10 10:52:58 +01:00
Luca Chang
ef8399c1cb
feat: broadcast 2025-11-25 as latest supported client version (#758)
* feat: broadcast 2025-11-25 as latest supported client version
* fix: ignore empty SSE events
2026-02-06 10:55:37 +01:00
Daniel Garnier-Moiroux
96c9bbe745 Add Origin header validation
- Fixes #695
- Does not implement Host header validation yet

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2026-02-05 10:20:27 +01:00
Filip Hrisafov
2456a0e433
Add Support for Jackson 3 (#742)
This change adds Jackson 3 support and aligns package naming in the existing Jackson 2 module.

Specific changes:
* Deprecated classes for removal in `io.modelcontextprotocol.json.jackson`/`io.modelcontextprotocol.json.schema.jackson`
* Copied the above to `io.modelcontextprotocol.json.jackson2`/`io.modelcontextprotocol.json.schema.jackson2` in non-deprecated form.
* Added tests for the default McpJsonMapper and JsonSchemaValidator
2026-01-26 11:43:35 +01:00
Dariusz Jędrzejczyk
af65356416
Fix everything-server-based integration tests (#756)
* Pin `npx @modelcontextprotocol/server-everything` version to `2025.12.18`.
* Replace `tzolov/mcp-everything-server` Docker image with `node:lts-alpine` + `npx` command.
* Handle HTTP 202 special case.
* Fix test assertions.

The recent rollout of everything-server broke integration tests which take the latest version from the node registry.
This PR unifies the everything-server usage - the Testcontainers Docker setup uses the same version as the STDIO npx-based tests and no longer relies on tzolov/mcp-everything-server.

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2026-01-20 16:09:41 +01:00
Jordan Zimmerman
b518393cfd
Expose resourcesUpdateConsumer() in sync client (#735)
`resourcesUpdateConsumer()` was missing from the sync client. Add it.
2026-01-08 20:29:05 +01:00
Christian Tzolov
cb533b2e0e Fix fomratting
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2026-01-08 20:26:39 +01:00
Sergio del Amo
dce48929a5
add 2025-11-25 version to ProtocolVersions (#733) 2026-01-08 20:25:43 +01:00
Rohit
e7901da010
fix: Support form and url fields in Elicitation capability per 2025-11-25 spec (#731)
Update the ClientCapabilities.Elicitation record to accept optional "form"
and "url" fields as defined in the MCP 2025-11-25 specification.

Previously, deserializing an InitializeRequest with
`{"capabilities":{"elicitation":{"form":{}}}}` would fail with
UnrecognizedPropertyException because the Elicitation record was empty.

Changes:
- Add nested Form and Url marker records to Elicitation
- Add no-arg constructor for backward compatibility (serializes to {})
- Add elicitation(boolean form, boolean url) builder method
- Add comprehensive tests for deserialization and serialization

Fixes #724
2026-01-08 19:29:39 +01:00
Christian Tzolov
082444e18f Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-12-04 15:57:27 +01:00
Daniel Garnier-Moiroux
e6045f7287 Basic version negotiation capabilities
- We do not support full version negotiation, but this commit allows the
  client to the send the correct version to match that of the server.
- There is one limitation: the GET /mcp request happens too early,
  before we have deserialized the initialization response, so we do not
  know the negotiated version yet. This request will have the client
  latest version as Mcp-Protocol-Version value.

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2025-11-21 14:29:47 +01:00
codeboyzhou
7e950ebb6c
refactor: use builder pattern for CallToolResult and Resource (#652)
* use builder pattern for CallToolResult
* use builder pattern for Resource
* simplify lambda expressions in tests
2025-11-21 13:44:29 +01:00
lance
86991c1e49 fix the baseUrl is configured with a trailing slash
Signed-off-by: lance <leehaut@gmail.com>
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2025-11-19 14:20:16 +01:00
Daniel Garnier-Moiroux
87bdf1ee49
Client transports: make #protocolVersions() configurable (#669)
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2025-11-18 14:53:50 +01:00