Commit graph java-sdk/mcp-core
Author SHA1 Message Date
Viliam Sun
738525308d
fix(docs): Remove broken @see link in resourceTemplates Javadoc (#614) 2025-11-12 14:44:35 +01:00
Michael Vorburger
afa00902a4
fix: JSONRPCResponse JavaDoc (#657) 2025-11-12 14:21:57 +01:00
Christian Tzolov
476f9db36f
feat: enhance error handling with custom error code preservation (#653)
- Improve McpClientSession error handling to preserve custom error codes
and data from McpError instances.
- Add aggregated exception messages to error data field for better debugging.
- Include test coverage for various McpClientSession error scenarios.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-11-07 11:56:21 +02:00
Christian Tzolov
6e9af40bcb Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-10-30 19:02:32 +01:00
Christian Tzolov
5c46626260
chore: standardize client/server implementation names and version (#642)
Unifies client/server implementation names under "Java SDK" branding
and updates all versions to 0.15.0.

Resolves: #638

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-10-30 12:17:42 +01:00
lance
e91fe7fbc5
Fix: McpAsyncClient#listTools prevent infinite recursion (#631)
* Fix: prevent infinite recursion in listTools() when nextCursor is empty string

Signed-off-by: lance <leehaut@gmail.com>
2025-10-30 11:59:34 +01:00
Daniel Garnier-Moiroux
9bbfbe573a
Close McpTransportSession on transport close (#632)
* Client HTTP transports: use McpTransportSession interface instead of concrete types
* Streamable HTTP tranports: .closeGracefully closes the session

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2025-10-28 14:26:21 +01:00
Christian Tzolov
2ee58533d0
fix: allow additional properties by default per JSON Schema spec (#617)
- Remove automatic additionalProperties: false injection (JSON Schema spec compliance)
- Support String input for structuredContent in validate() method
- Move tests to mcp-json-jackson2 module with proper dependencies
- Replace wildcard imports with explicit imports

Complies with JSON Schema Test Suite:
15e4505/tests/draft2020-12/additionalProperties.json\#L112

Fixes #584

BREAKING CHANGE: Additional properties now allowed by default when not explicitly specified.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-10-14 09:30:59 +02:00
Sheegan Sri G M
19a8c00a47 fix: improve URI template matching to properly escape special characters (#599)
- Enhanced DefaultMcpUriTemplateManager to use Pattern.quote() for escaping special regex characters like '?'
- Replaced simple string replacement regex generation with robust pattern building
- Added test case to verify URI matching with query parameters (e.g., "file://name/search?={search}")
- Fixed typo: renamed DeafaultMcpUriTemplateManagerFactory to DefaultMcpUriTemplateManagerFactory
- Updated all references across server classes and tests

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-10-07 00:21:51 +02:00
Christian Tzolov
a63d32a5ea
refactor: change int to Integer for optional numeric fields (#604)
Convert primitive int types to Integer wrapper class for:
- JSONRPCError.code
- CreateMessageRequest.maxTokens (including constructor and builder)

This allows these fields to be nullable, properly representing
optional parameters in the MCP protocol schema.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-10-06 23:04:42 +02:00
Sergio del Amo
94a8b53d88
fix remove name when using deduction (#600)
This pull-request removes the name member from the @JsonSubTypes.Type annotations when using JsonTypeInfo.Id.DEDUCTION.

With DEDUCTION, Jackson ignores the name entirely because it's inferring the type from the structure.
2025-10-06 23:00:54 +02:00
Sergio del Amo
83fc4f79de
define explicitely that values should always be included in code completions (#601)
* define explicitely that values should always be included

* spring  apply
2025-10-06 21:55:23 +02:00
Christian Tzolov
c734b2a5c1 Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-10-02 00:03:36 +01:00
Anurag Pant
8e11fa82ae feat(client): add client tool output schema validation and caching (#302)
- Add JSON schema validation for tool call results against output schemas
- Implement automatic tool output schema caching during initialization
- Add `enableCallToolSchemaCaching` configuration option to enable/disable
  schema caching
- Add `JsonSchemaValidator` integration to McpClient builder APIs
- Introduce post-initialization hook mechanism for performing operations
  after successful client initialization
- Cache tool output schemas during `listTools` operations when caching
  is enabled
- Validate tool results against cached schemas in `callTool` operations
- Return error CallToolResult when validation fails
- Add test coverage
- Convert validateToolResult from Mono to synchronous method
- Throw IllegalArgumentException on validation errors

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

Co-authored-by: Anurag Pant <pantanurag555@github>
Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Daniel Garnier-Moiroux <git@garnier.wf>
Co-authored-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2025-10-01 23:12:33 +01:00
Christian Tzolov
3f7578b3ce
fix: Handle non-compliant notification responses (#589)
Ensure warnings are logged for all non-compliant responses to JSON-RPC
notifications, including empty responses. Empty responses now display
as "[empty]" in log messages for better clarity.

Resolves #586

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-10-01 23:14:29 +02:00
Daniel Garnier-Moiroux
080098e48c Client: handle server responses with Content-Length: 0
- When the client sends `notification/initalized`, servers must respond
  with HTTP 202 and an empty body. We checked for the absence of a
  Content-Type header to verify whether the body was empty.
- However, some servers will send an empty body with a Content-Type
  header, and that header may have an unsupported, default type such as
  `text/html` or `text/plain`.
- Now we we also use the Content-Length header to check for an empty
  body. This header is optional in HTTP/2, so we do not make it our
  primary mechanism for detecting empty bodies.
- As part of this PR, we also move hard-coded HTTP header names to the
  HttpHeaders interface. While they are not defined by the MCP spec,
  they are used by it and are core to implementing the protocol.
  Therefore, they have their place in a core interface.
- Fixes #582

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
2025-10-01 13:09:30 +02:00
Sergio del Amo
12292ab598
fix: when using JsonTypeInfo.DEDUCTION don’t add include (#587)
From the JSonTypeInfo Javadocs:

> If deduction is being used annotation properties visible, property and include are ignored.

This is causing issues with serialization downstream.
2025-09-30 15:59:17 +02:00
Christian Tzolov
c1cde20002
refactor: improve MCP server resilience and error handling (#579)
- Replace McpError with appropriate standard exceptions (IllegalArgumentException, IllegalStateException) for validation errors
- Change tool/prompt registration to replace existing items instead of rejecting duplicates with warningsi
  - Change addTool behavior to replace existing tools instead of throwing errors
  - Change addPrompt() to allow replacing existing prompts with warning instead of throwing error
- Make removal operations idempotent - log warnings instead of throwing errors for non-existent items
  - Change removePrompt() to log warning instead of throwing error for non-existent prompts
  - Change removeTool() to gracefully handle non-existent tools with warnings instead of errors
- Add listTools() and listPrompts() methods to all server variants (async, sync, stateless)
  - Add listTools() method to all server classes for tool enumeration
  - Add listPrompts() method to all server implementations for retrieving registered prompts
- Improve error construction using McpError.builder() pattern for protocol-specific errors
- Update error handling in session classes to properly propagate McpError JSON-RPC errors
  - Use proper error codes (INVALID_PARAMS) for prompt not found scenarios
- Update tests to reflect new lenient behavior for duplicate registrations and removals
- Add aggregateExceptionMessages() utility method utility to aggregate the exception chains
- Update McpServerSession and McpStreamableServerSession to use the aggregated errors in the json-rpc-error data section

This change makes the MCP server APIs more resilient and user-friendly by using appropriate exception types,
supporting item replacement, and providing listing capabilities while maintaining backward compatibility.

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-09-30 11:10:04 +02:00
Christian Tzolov
ff98e294f5 refactor: Improve resource template support (#576)
- Provide separation of concerns between static resources and parameterized resource templates.
- Add AsyncResourceTemplateSpecification and SyncResourceTemplateSpecification for both McpServerFeatures and McpStatelessServerFeatures
- Change resource template storage from List to Map to acomodate the resource read handler.
- Add runtime management methods: addResourceTemplate(), removeResourceTemplate(), listResourceTemplates()
- Improve error handling by using IllegalArgumentException/IllegalStateException instead of McpError
- Add new interfaces (Meta, Identifier) and reorganize schema hierarchy
- Enhance completion request validation with better error messages
- Add ResourceTemplate.Builder for easier template construction
- Update all server implementations (Async, Sync, Stateless) consistently
- Add type-safe constants for reference types (PromptReference.TYPE, ResourceReference.TYPE)
- Add tests for new resource template management functionality
- Clean up imports and remove unused dependencies

Co-authored-by: Pascal Vantrepote <pascal@confluent.io>

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-09-28 09:17:24 +02:00
Liujunjie
7f16cd0b9d
fix: typo MCP_SESSION_ID, keep consistent style with other identifiers (#564) 2025-09-22 17:18:53 +02:00
Christian Tzolov
a90b922be9
feat: add optional lastModified field to Annotations record with backward compatibility (#568)
Resolves #565

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-09-22 17:07:19 +02:00
Sergio del Amo
d327fff6f7
fix: handle resource not found according to spec (#567)
see: https://modelcontextprotocol.io/specification/2025-06-18/server/resources#error-handling

Resource not found should send a JSON RPC response such as:

```json
{
  "jsonrpc": "2.0",
  "id": 5,
  "error": {
    "code": -32002,
    "message": "Resource not found",
    "data": {
      "uri": "file:///nonexistent.txt"
    }
  }
}
```

This PR also changes some instances where a `McpError` was thrown instead of being passed in the reactive chain with `Mono.error`

functional style
2025-09-22 16:43:44 +02:00
Christian Tzolov
a0afdcd493 Next development version
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-09-18 19:28:56 +02:00
Christian Tzolov
8159bcbb05
feat: add MCP protocol version 2025-06-18 support for streamable-http and stateless transports (#558)
- Set MCP_2025_06_18 as upper supported protocol version for streamable-http and stateless transport
- Update LATEST_PROTOCOL_VERSION constant to reflect new upper bound
- Update test expectations for new protocol version usage

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-09-18 08:57:10 +02:00
Christian Tzolov
8ac7eae47c
refactor: standardize test parameterization and fix package naming (#556)
- Replace @ValueSource with @MethodSource for parameterized tests
- Add clientsForTesting() methods to provide test arguments consistently
- Remove hardcoded Spring-related labels from framework-agnostic mcp-test module
- Move mcp-test's utility classes from io.modelcontextprotocol.utils to io.modelcontextprotocol.util

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-09-17 12:26:55 +02:00
Sergio del Amo
1499df22c7
extract mcp-core (#557)
* extract mcp-core
  - This change extracts classes previously in `mcp` to `mcp-core`; a new module which does not depend on `mcp-json-jackon2`.
  - `mcp` module is now an umbrella module that brings `mcp-json-jackon2` and `mcp-core`
* add mcp-core to bom

BREAKING CHANGE: All source code in the previously `mcp` module is moved to the `mcp-core`.  the `mcp` now is just an aggregation for `mcp-core` + `mcp-json-jackson2` for backward compatibility. 
This change won't affect the end users, but will cause conflicts for the existing PRs.
2025-09-17 11:32:08 +02:00
Christian Tzolov
949f961c04 fix docs 2024-12-11 00:56:06 +01:00
Christian Tzolov
a922b1aa7a Add doc diagrams 2024-12-11 00:51:24 +01:00
Mark Pollack
910be3cee7 Rename modules, update .gitignore 2024-12-10 18:46:49 -05:00
Christian Tzolov
49e0291611 Update READEME 2024-12-11 00:28:23 +01: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
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