Commit graph

110 commits

Author SHA1 Message Date
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
a2a8be2155 Improve README 2024-12-30 13:53:23 +01:00
Christian Tzolov
d96222dcaf Next development version 2024-12-30 13:25:53 +01:00
Christian Tzolov
8dc9b979a8 Release version 0.3.1 v0.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 v0.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
2ea5527ade feat: Add default logging for MCP notification handlers
- Adds default logging for tools, resources and prompts change notifications.
- Introduces Utils class with collection and string helper methods.
- Ensures notification handlers are always registered with at least a default logging consumer.
2024-12-20 10:39:26 +01:00
Christian Tzolov
975578b64b feat: Add resources and prompts change notification support
- Add resourcesChangeNotificationHandler and promptsChangeNotificationHandler with non-blocking execution
- Add builder methods for resources and prompts change consumers
- Add test coverage for all notification handlers
- Update documentation to cover all three notification types (tools, resources, prompts)
- Consolidate notification documentation under unified Change Notifications section
- Ensure consistent non-blocking behavior using boundedElastic scheduler

All notification handlers follow the same pattern of non-blocking execution and error handling,
providing a consistent approach to change notifications across the system.

Resolves #20
2024-12-19 14:26:40 +01:00
Christian Tzolov
383d6a7eff feat(mcp-client): Add non-blocking tools change notification support
- Add toolsChangeNotificationHandler with non-blocking consumer execution using boundedElastic scheduler
- Add toolsChangeConsumer builder method to McpClient for easy configuration
- Add comprehensive test coverage for tools change notifications
- Update documentation with tools change notification features and examples

The implementation ensures consumers are executed non-blockingly on the boundedElastic scheduler,
preventing performance impact from blocking implementations while maintaining proper error handling and logging.

Part of #20
2024-12-19 13:56:16 +01:00
Christian Tzolov
9adcc5b9c4 fix(sdtio-client) Escape any embedded newlines in the JSON message
Resolves #21
2024-12-19 12:21:24 +01:00
Christian Tzolov
05085b76e6 remove folder duplication 2024-12-19 12:13:58 +01:00
Christian Tzolov
82c64f5ad3 feat(core): add roots list support and improve documentation
- Add roots list capability to allow servers to understand filesystem boundaries
- Move architecture diagram and add detailed documentation for transports and sessions
- Enhance client capabilities with roots and sampling features
- Rename withRequestTimeout to requestTimeout for better API consistency
- Add tests for roots list functionality

Resolves #8
2024-12-19 12:12:51 +01:00
Dariusz Jędrzejczyk
7a98a935af Refactor the mcp-core module
- The core module has been refactored to remove unnecessary abstraction
  between the SSE transport and the STDIO transport.
- Tests have been improved and no longer complain about multiple
  subscriptions to single-subscriber Sink.
- SSE transport layer is now assuming non-blocking execution and no longer
  makes thread hops when not needed.
- Decouple ObjectMapper and error handling from AbstractMcpTransport
  and remove later.

Additional improvements:

- Rename transport classes to better reflect client-side role (*ServerTransport -> *ClientTransport)
- Introduce fluent builder pattern for client configuration
- Simplify DefaultMcpSession by removing ObjectMapper dependency
- Move unmarshal responsibility to transport layer
- Update documentation and diagrams to reflect new architecture
- Clean up test implementations
2024-12-19 09:07:11 +01:00
Dariusz Jędrzejczyk
8b2ce26e8a
Fix tests by restarting the container in each test
The reason is that the server performs shutdown after SSE connection is
closed.
2024-12-17 15:33:41 +01:00
Christian Tzolov
716d1a0e7f Enhance DefaultMcpSession with request/response handling
- Add comprehensive documentation for MCP session components in MCP-SESSION.md
- Add logging and error handling in McpAsyncClient
- Update test configurations and dependencies
- Add reactor-netty-http and spring-context test dependencies

Resolves #6
2024-12-17 13:42:59 +01:00
Christian Tzolov
0ebb38ce0e Fix the docker.io/tzolov/mcp-everything-server:v1 url 2024-12-15 23:32:11 +01:00
Christian Tzolov
bc281dee54 feat: add SSE transport and improve documentation
- Add Server-Sent Events (SSE) transport implementation with test coverage
- Add detailed documentation for both SSE and STDIO transports
- Extract common test logic into abstract base classes
- Add testcontainers support for SSE integration tests
- Replace System.out with SLF4J logging
- Externalize dependency versions to properties
- Implement endpoint event handling per MCP spec
- Add message endpoint sink for reliable message routing
- Improve error handling and graceful shutdown
- Update core module README with expanded features and examples
- Add dependency version properties and logging configuration
- Update architecture and class diagrams

Resolves #4
2024-12-15 22:54:48 +01:00
Christian Tzolov
be31c6119c feat(mcp): add convenience methods without cursor parameter
Add overloaded methods for list operations (tools, resources, templates, prompts)
 that don't require a cursor parameter, simplifying the API for basic use cases
 where pagination is not needed.
2024-12-13 09:15:37 +01:00
Christian Tzolov
c332300651 Delete outdated test 2024-12-13 00:02:35 +01:00
Christian Tzolov
59319e5509 refactor: process output writing 2024-12-12 23:27:46 +01:00
Christian Tzolov
8a0cd4ef06 refactor: improve resource management in StdioServerTransport
- Use try-with-resources for proper reader cleanup
- Remove unnecessary reader/writer instance variables
- Access process streams directly when needed
2024-12-12 23:18:25 +01:00
Dariusz Jędrzejczyk
8397849d6e Properly dispose Schedulers for IO and skip closing BufferedReader as they deadlocked on Ubuntu
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@gmail.com>
2024-12-12 22:54:28 +01:00
Christian Tzolov
a4950c04a5 test: increase MCP client timeout to 20s and enable tests
- Doubles the default timeout from 10s to 20s in McpAsyncClient
- Updates corresponding timeout values in test classes
- Enables previously disabled async client tests
2024-12-12 21:45:51 +01:00
Christian Tzolov
c41f3fe738 Temp disable the entire McpAsyncClientTests 2024-12-12 21:32:06 +01:00
Christian Tzolov
4a1763d355 Temp disable testMcpAsyncClientState 2024-12-12 21:29:18 +01:00
Christian Tzolov
a55379745f Fix javadoc 2024-12-12 21:13:02 +01:00