Commit graph java-sdk/mcp
Author SHA1 Message Date
Christian Tzolov
0c8968044c refactor: Add HttpServletSseServerTransport for generic Servlet integration
Introduces a new Server-Sent Events (SSE) Server transport implementation
based on the Servlet API that enables MCP integration with any Java HTTP
server application supporting Servlets.

This implementation complements the existing WebFlux and WebMvc transports
by providing a generic Servlet-based option that works with any Java web
server, not just Spring applications.

Key changes:

- Add HttpServletSseServerTransport with async Servlet 6.0 support
- Add integration tests with embedded Tomcat
- Add servlet dependencies with externalized versions:
  - jakarta.servlet-api 6.1.0 (provided)
  - tomcat-embed-core 11.0.2 (test)
  - tomcat-embed-websocket 11.0.2 (test)

Resolves #61
2025-01-12 19:33:46 +01:00
Christian Tzolov
299eee944a docs: improve transport layer documentation and code cleanup
- Add comprehensive Javadoc for SSE transport implementations
- Document key features and implementation details for WebFlux/WebMVC transports
- Refactor FlowSseClient to use records for better immutability
- Fix typo in prompt property name
- Remove unused code and improve readability
2025-01-12 08:46:43 +01:00
Christian Tzolov
edbd78465c refactor(transport): Replace SseEmitter with queue-based SSE implementation in WebMvc transport
Replaces Spring's SseEmitter with a custom BlockingQueue-based SSE implementation in
WebMvcSseServerTransport for improved event delivery control and connection management.

The new implementation:
- Uses BlockingQueue for reliable event queuing and delivery
- Adds proper session management with dedicated SSEEvent record
- Improves error handling and timeout management
- Adds comprehensive integration tests

Resolves #57
2025-01-11 15:12:14 +01:00
Christian Tzolov
37029523cb imporve test logging configuraitons 2025-01-09 18:30:34 +01:00
Christian Tzolov
611f3258d6 refactor: Split transport implementations into modules
Split the  transport implementations into dedicated modules to improve modularity
and reduce core dependencies.

Added shared test module for common test utilities.

Key changes:

- Create mcp-transport/mcp-webflux-sse-transport module
 - Move SseClientTransport → WebFluxSseClientTransport
 - Move SseServerTransport → WebFluxSseServerTransport
 - Move related tests and utilities

- Create mcp-transport/mcp-webmvc-sse-transport module
 - Add new WebMvcSseServerTransport implementation
 - Add corresponding tests and integration tests

- Add framework-independent SSE client implementations to core module
 - Add FlowSseClient using java.net.http
 - Add HttpClientSseClientTransport using java.net.http

- Keep StdioClientTransport/StdioServerTransport in core (no external deps)

- Create mcp-test module for shared test infrastructure
 - Move abstract test base classes
 - Move shared test utilities and mocks
 - Update test dependencies

The modular approach allows users to choose between:

- Framework-specific implementations (WebFlux/WebMVC)
- Pure Java implementations (java.net.http)
- Basic implementations (STDIO)

Add breaking changes readme: 0.5.0-BREAKING-CHANGES.md

Resolves #54
2025-01-09 15:38:34 +01:00
Christian Tzolov
85c4fb8713 Next development version 2025-01-07 10:55:08 +01:00
Christian Tzolov
a47eace440 Release version 0.4.2
Some checks failed
Deploy Docs / build (push) Has been cancelled
2025-01-07 10:54:53 +01:00
Christian Tzolov
aa26cfa848 feat: Improve Tool schema handling
- Make McpSchema final and add private constructor
- Add JsonSchema record for structured schema representation
- Change Tool.inputSchema type from Map<String, Object> to JsonSchema.
- Use the String JSON Schema constructor when creating the Tool programaticaly.
- Enhance StdioClientTransport error logging with more context
- Add ToolHelper utility class for:
  - Converting Spring AI FunctionCallbacks to MCP tools
  - Generating JSON schemas for tool input validation
  - Facilitating integration between Spring AI functions and MCP tools
- Update tests and samples to use the new Tool schema format

Resolves #52
2025-01-07 10:39:21 +01:00
Christian Tzolov
8334e2ee96 Next development version 2025-01-04 18:13:19 +01:00
Christian Tzolov
25c9d8cc73 Release version 0.4.1
Some checks failed
Deploy Docs / build (push) Has been cancelled
2025-01-04 18:13:02 +01:00
Thomas Vitale
68ae239552 Remove Logback from production JAR
Move Logback dependency to test scope to make it possible for applications using this library to choose their implementation of the SLF4J API. For example, Spring Boot provides one out of the box already.

Fixes gh-49

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2025-01-04 18:02:20 +01:00
Christian Tzolov
580f95526f feat(McpAsyncServer): Add non-blocking execution for tools and resources
- Execute tool calls, resource reads and prompt handling in a non-blocking
  manner using Schedulers.boundedElastic(). This prevents blocking operations
  from impacting server responsiveness.
- Added integration tests to verify non-blocking behavior with tools that
  make HTTP calls to external services.

Related to #48
This is  a temp patch until #48 is resolved properly.
2025-01-04 17:56:48 +01:00
Christian Tzolov
b2082a0506 Next development version 2025-01-04 08:41:43 +01:00
Christian Tzolov
30c8fc32eb Release version 0.4.0
Some checks failed
Deploy Docs / build (push) Has been cancelled
2025-01-04 08:41:22 +01:00
Christian Tzolov
94f172a44e Enhance roots functionality and improve error handling
- Replace Utils.isEmpty check with null check for roots map
- Add specialized error messages for method not found errors
- Extend McpError to include JSONRPCError information
- Add comprehensive tests for roots functionality including:
  - Empty roots list handling
  - Missing capability scenarios
  - Multiple consumers
  - Server closure with active subscriptions
2025-01-04 08:16:02 +01:00
Christian Tzolov
2748260cda feat: Enhance MCP roots implementation and test coverage
- Add proper ListRootsResult wrapping in async client
- Implement paginated listRoots methods in server components
- Fix roots notification handling in async server
- Add roots integration tests
- Update architecture diagram and documentation layout

The changes improve the roots feature implementation with proper result
types,  and robust notification handling. Adds thorough
test coverage for roots functionality including async notifications and
root addition/removal scenarios.

Resolves #46
2025-01-04 01:11:38 +01:00
Christian Tzolov
c469f790b3 refactor: Improve MCP documentation and transport interfaces
- Add ClientMcpTransport and ServerMcpTransport marker interfaces
- Update client/server implementations to use appropriate transport interfaces
- Reorganize documentation structure and improve content clarity
- Move documentation images to mcp-docs/antora directory
- Update README files with links to online documentation

Resolves #44
2025-01-03 15:54:43 +01:00
Christian Tzolov
51b75dca19 feat: enforce sampling handler presence and add CreateMessageResult builder
Improves error handling by enforcing sampling handler presence when sampling capabilities are enabled. Adds a builder pattern for CreateMessageResult to improve API ergonomics.
2025-01-02 18:19:33 +01:00
Christian Tzolov
07769a651d feat(mcp): Add sampling capabilities to MCP server
Implement client-side sampling features in the Model Context Protocol (MCP) server:
- Add createMessage method to McpAsyncServer and McpSyncServer for LLM sampling
- Move MockMcpTransport to separate file for reusability
- Add integration tests for sampling functionality
- Test error handling for uninitialized clients and missing capabilities

The sampling implementation allows servers to request LLM completions from
clients while maintaining client-side control over model access and permissions.

Resolves #42
2025-01-02 16:52:36 +01:00
Christian Tzolov
0fd93a9f82 feat: Add roots change notification support to MCP server
- Implement roots change notification handler in McpAsyncServer
- Add rootsChangeConsumer builder methods to support single and multiple consumers
- Rename info() builder method to serverInfo() for clarity
- Add comprehensive tests for roots change notification functionality
- Add default server info implementation in Builder

Resolves #39
2025-01-02 09:12:42 +01:00
Christian Tzolov
0b0d5086ce feat: add server/client metadata getters to MCP clients
Add getter methods to expose server and client capabilities and implementation
info in McpAsyncClient and McpSyncClient. Store server metadata received during
initialization for later access.
2025-01-01 14:00:37 +01:00
Christian Tzolov
2b42379c57 feat: add getters for server/client capabilities and implementation info
Add getter methods to expose server and client capabilities and implementation
information in both McpAsyncServer and McpSyncServer classes. Store client
metadata received during initialization for later retrieval.
2025-01-01 13:33:54 +01:00
Christian Tzolov
86659344fc feat: add structured logging support with severity levels
- Add client and server-side logging capabilities with configurable severity levels
- Implement logging message notifications with DEBUG to EMERGENCY levels
- Add logging consumers for client-side log handling
- Update documentation with logging examples and configuration
- Add comprehensive tests for logging functionality
- Fix typo in README.md (notificaiotn -> notification)

- Centralize MCP method names as constants
  - Move all JSON-RPC method names to McpSchema class as static constants
  - Replace hardcoded method strings with constant references in McpAsyncClient
    and McpAsyncServer
  - Update test cases to use new method name constants

Resolves #35
2024-12-31 14:46:32 +01:00
Christian Tzolov
a5394fffd2 efactor(mcp): reorganize McpAsyncServer and enhance error handling
- Reorganize McpAsyncServer code into logical sections (Lifecycle, Tool, Resource, Prompt Management)
- (bug) Fix resource registration to use URI instead of name as map key
- Improve error logging in StdioServerTransport with helper methods
- Clean up documentation and add transport mode descriptions
- Update sample server configuration with clearer method names and organization
2024-12-30 17:22:26 +01:00
Christian Tzolov
d96222dcaf Next development version 2024-12-30 13:25:53 +01:00
Christian Tzolov
8dc9b979a8 Release version 0.3.1 2024-12-30 13:25:35 +01:00
Christian Tzolov
b6c9973cbf Fix code formatting 2024-12-30 13:16:08 +01:00
Christian Tzolov
c36d4677c1 docs(mcp) Improve McpServer and McpClient javadoc 2024-12-30 13:13:32 +01:00
Christian Tzolov
ad3cdd20a9 fix: Improve MCP server stability and test reliability
- Replace bounded elastic schedulers with single thread executors
- Add timeouts to MCP server tests
- Enhance error handling in StdioServerTransport
- Comment out unused PaginatedRequest unmarshalling
- Simplify shutdown logic in StdioServerTransport
2024-12-30 12:57:36 +01:00
Christian Tzolov
fcf0ff0ae2 refactor: simplify StdioServerTransport to only use System streams
Removes custom stream injection capability from StdioServerTransport and
simplifies it to only use System.in/out.
Updates related tests to use System streams instead of piped streams.
2024-12-30 11:52:48 +01:00
Christian Tzolov
dfa7435ad8 refactor(mcp) Disable stdio server sink draining on close 2024-12-30 09:23:42 +01:00
Christian Tzolov
47b09165c5 refactor(mcp) Increase the server stdio shutdown timeout 2024-12-30 09:08:56 +01:00
Christian Tzolov
9b6a0b537b refactor(mcp): improve StdioServerTransport shutdown and error handling
- Add specific error categorization for pipe closed errors
- Enhance shutdown sequence with proper stream and scheduler cleanup
- Add debug logging for shutdown-related stream errors
- Improve isClosing state management
2024-12-29 21:40:53 +01:00
Christian Tzolov
2de1d637c0 Fix javadoc issues 2024-12-29 21:05:57 +01:00
Christian Tzolov
f7551839c5 docs Update pom version in docs 2024-12-29 18:56:38 +01:00
Christian Tzolov
e6cb56c4b1 Next development version 2024-12-29 18:17:34 +01:00
Christian Tzolov
f5e121f3c0 Release version 0.3.0 2024-12-29 18:16:15 +01:00
Christian Tzolov
36b951558d refactor: improve MCP client code organization and robustness
- Add null parameter validation in client builders
- Enhance JavaDoc documentation for tools and resources
- Reorganize McpAsyncClient methods by functionality
- Fix sampling handler test setup
2024-12-29 17:53:43 +01:00
Christian Tzolov
9130e742fd fix(mcp): Improve transport shutdown and error handling
- Add isClosing flag to coordinate graceful shutdown
- Synchronize output stream writes to prevent race conditions
- Enhance error handling in stream processing
- Add delay for pending message processing during shutdown
- Improve connection state tracking in tests
2024-12-29 10:53:16 +01:00
Christian Tzolov
759fbf13d1 adjust diagram size 2024-12-29 00:25:49 +01:00
Christian Tzolov
bc75b27e53 docs(mcp) add class diagram 2024-12-29 00:25:24 +01:00
Christian Tzolov
347f86ff19 docs Improve MCP readme 2024-12-28 23:56:16 +01:00
Christian Tzolov
abd0facf4e feat: Add MCP server with Server stdio/sse transport improve MCP client
- Implement MCP server with async/sync support and builder pattern configuration
 - Add Server stdio/SSE transport layers with robust error handling
 - Convert McpClient and McpServer to interfaces for better extensibility
 - Add sampling capabilities for LLM interactions (text/image)
 - Implement dynamic root management and runtime tool management
 - Add comprehensive prompt and resource capabilities
 - Add support for dynamic root management (add/remove roots at runtime)

 Architecture Changes

 - Introduce registration records for tools, resources, and prompts
 - Improve thread safety with concurrent collections
 - Enhance resource template handling
 - Implement builder patterns for Server/Client capabilities
 - Add support for server capabilities and implementation info

Transport Layer:
 - Implement SseServerTransport with SSE endpoints
 - Add StdioServerTransport for process-based communication
 - Reorganize transport packages for better organization
 - Improve transport error handling and shutdown processes

Documentation:

 - Add detailed MCP reference documentation
 - Include architecture diagrams and API documentation
 - Add comprehensive test coverage for all components
 - Include sample projects demonstrating stdio/SSE transports

BREAKING CHANGES:

 Transport Package Reorganization

 - Move StdioClientTransport to o.s.ai.mcp.client.transport
 - Move SseClientTransport to o.s.ai.mcp.client.transport
 - Move ServerParameters to o.s.ai.mcp.client.transport
 - StdioClientTransport.errorHandler changed to private with
   setter method Migration: Use setErrorHandler() method
   instead of direct field access

 API Changes

 - Replace static factory methods with builder pattern
 - Update ServerCapabilities to use builder pattern
 - Make StdioClientTransport.errorHandler private with setter
 - Replace rootsListProvider with direct root management
 - Remove deprecated static factory methods

Resolves #27,#25,#24,#11
Related to #12
2024-12-28 21:03:29 +01:00
Christian Tzolov
c83a45f880 Next development version 2024-12-21 18:19:21 +01:00
Christian Tzolov
9d20ca8dc4 Release version 0.2.0 2024-12-21 18:19:01 +01:00
Christian Tzolov
890350c634 minor javadoc 2024-12-21 16:35:22 +01:00
Christian Tzolov
12fd8e51f3 refactor: rename artifacts and restructure modules
- Rename spring-ai-mcp-core to mcp for simpler artifact naming
- Rename spring-ai-mcp-spring to spring-ai-mcp for clarity
- Rename parent artifact from spring-ai-mcp to mcp-parent
- Update artifact references in pom files and documentation
- Update directory structure and paths in GitHub workflow

Resolves #31

chore: improve module descriptions and update dependencies

- Update parent pom description to better reflect overall project scope
- Update mcp module description to detail core Java SDK capabilities
- Update spring-ai-mcp module description to emphasize Spring integration features
- Update dependency versions to stable releases:
  * JUnit: 5.11.3 -> 5.10.2
  * Jackson: 2.18.2 -> 2.17.0
2024-12-21 16:30:19 +01:00
Christian Tzolov
1d7ab91314 rename mcp to mcp-core and spring into mcp-spring 2024-12-10 18:56:38 +01:00
Christian Tzolov
0dec9420c6 Add simple StdioServerTransportTest 2024-12-10 14:20:52 +01:00
Christian Tzolov
7c9cf46e8a Factor out the McpSession into an inteface with DefaultMcpSession impl. 2024-12-10 14:03:11 +01:00