Commit Graph

16 Commits

Author SHA1 Message Date
Soby Chacko
bd82e73193 Rename spring-ai parent from spring-ai to spring-ai-parent
Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
2025-04-03 10:11:03 -04:00
Mark Pollack
85555003ad rename spring-ai-core to spring-ai-client-chat 2025-04-03 10:11:03 -04:00
Christian Tzolov
fc955c74eb feat(mcp): Refactor MCP server API to use Specification pattern
- Rename Registration classes to Specification (SyncToolRegistration → SyncToolSpecification)
- Update transport classes to use Provider suffix (WebFluxSseServerTransport → WebFluxSseServerTransportProvider)
- Add exchange parameter to handler methods for better context passing
- Introduce McpBackwardCompatibility class to maintain backward compatibility
- Update MCP Server documentation to reflect new API patterns
- Add tests for backward compatibility
- Update mcp version to 0.8.0
- Add mcp 0.8.0 breaking change note-

The changes align with the MCP specification evolution while maintaining backward compatibility through deprecated APIs.

refactor: Extract MCP tool callback configuration into separate auto-configuration

Extracts the MCP tool callback functionality from McpClientAutoConfiguration into a
new dedicated McpToolCallbackAutoConfiguration that is disabled by default.

- Created new McpToolCallbackAutoConfiguration class that handles tool callback registration
- Made tool callbacks opt-in by requiring explicit configuration with spring.ai.mcp.client.toolcallback.enabled=true
- Removed deprecated tool callback methods from McpClientAutoConfiguration
- Updated ClientMcpTransport references to McpClientTransport to align with MCP library changes
- Added tests for the new auto-configuration and its conditions

refactor: standardize tool names to use underscores instead of hyphens

- Change separator in McpToolUtils.prefixedToolName from hyphen to underscore
- Add conversion of any remaining hyphens to underscores in formatted tool names
- Update affected tests to reflect the new naming convention
- Add comprehensive tests for McpToolUtils.prefixedToolName method
- Add integration test for payment transaction tools with Vertex AI Gemini

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-25 14:23:12 -04:00
Alexandros Pappas
29002dfc0d chore: remove unused imports (#2542)
Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
2025-03-21 12:20:29 +00:00
gongzhongqiang
3f344a311d fix: Fix validate prefix and toolName logic in prefixedToolName method
Signed-off-by: gongzhongqiang <gongzhongqiang@apache.org>
2025-03-17 15:47:31 +00:00
ivy
127f7009eb fix: Improve error handling in MCP tool callbacks
- Add null check for isError() method in SyncMcpToolCallback
- Implement consistent error handling in AsyncMcpToolCallback to match SyncMcpToolCallback behavior
- Throw IllegalStateException with error content when tool calls fail

Resolves #2447

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Co-authored-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-12 14:17:00 +01:00
Christian Tzolov
3f7f2f1bff fix(mcp): standardize MCP tool name formatting and improve error handling
- Add prefixedToolName utility method to ensure consistent tool name formatting
- E nforce alphanumeric, underscore, and hyphen characters only in tool names
- Limit tool names to 64 characters maximum
- Use original tool name in actual calls while using formatted names in definitions
- Add error handling for tool call responses in SyncMcpToolCallback
- Update tests to reflect the changes

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-11 17:28:47 +01:00
Christian Tzolov
957150128b feat(mcp): Prefix tool names with client name to avoid naming conflicts
Enhances MCP tool naming by prefixing tool names with their client + transport name
to prevent conflicts when multiple MCP clients expose tools with the same name.

- Modifies client info in McpClientAutoConfiguration to include transport name
- Updates SyncMcpToolCallback and AsyncMcpToolCallback to prefix tool names with client + transport name
- Adds test coverage for tools with identical names but different client info

Resolves #2393

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-11 13:14:52 +01:00
Christian Tzolov
58ed5ea59f feat(mcp): handle ToolContext in MCP tool callbacks
- Implement the new ToolCallback.call(String, ToolContext) method in both Sync and Async MCP tool callbacks.
- Since MCP tools don't support tool context, the implementation ignores the context parameter and
  delegates to the existing call(String) method. Added test to verify the behavior.

Resolves #2378

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-10 15:04:26 +01:00
Christian Tzolov
72bb5ca296 feat(mcp): Update to MCP SDK 0.8.0-SNAPSHOT and fix client initialization
- Make MCP client initialization blocking with .block() call
- Upgrade MCP SDK version from 0.7.0 to 0.8.0-SNAPSHOT

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-10 10:46:09 +00:00
jonghoon park
bf0558bb79 fix typo in McpToolUtils.java
Signed-off-by: jonghoon park <dev@jonghoonpark.com>
2025-03-06 16:34:34 +09:00
Christian Tzolov
53bb6a5b00 feat(mcp): add support for custom MIME types in tool responses
Add capability to specify MIME types for MCP tool responses, with special handling for image content.

This enhancement allows tools to return different content types, particularly images, by:
- Adding a new toolResponseMimeType map property to configure response MIME types per tool
- Extending tool registration methods to accept and use MIME type information
- Adding special handling for image content in tool responses
- Updating documentation with the new configuration options

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-03-01 19:55:26 +01:00
Christian Tzolov
1fdda61db8 feat(autoconfigure): Support both FunctionCallback and ToolCallback in ToolCallingAutoConfiguration
- Extends the ToolCallingAutoConfiguration to support both FunctionCallback and ToolCallback types.
- The toolCallbackResolver bean now handles both callback types through ObjectProvider injection.
- Added comprehensive tests to verify the resolution of multiple function and tool callbacks.
- Introduce new StaticToolCallbackProvider implementation
- Update ToolCallbackProvider to return FunctionCallback[]
- Migrate from List to ToolCallbackProvider in configurations
- Update tests to use new provider pattern
- Enhance tool callback providers to support multiple clients
  - Refactor AsyncMcpToolCallbackProvider and SyncMcpToolCallbackProvider to handle multiple MCP clients
  - Add ToolCallbackProvider support to ChatClient API
  - Deprecate direct tool callback list methods in favor of providers
  - Fix typos in Closeable class names
  - Update MCP documentation with new examples and usage patterns

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-13 20:31:20 +01:00
Christian Tzolov
fe377ee5e1 Refactor: MCP Autoconfig Modularization
Core Architecture Changes:
- Split MCP into dedicated client/server modules
- Created separate starters: spring-ai-starter-mcp-webmvc and spring-ai-starter-mcp-webflux
- Removed property-based transport configuration in favor of auto-configuration
- Added support for multiple transport types (STDIO, WebMVC, WebFlux)

Client Improvements:
- Added support for both synchronous and asynchronous MCP clients
- Fixed client auto-configuration issues
- Added root change notification property to common properties

Configuration Enhancements:
- Improved configuration properties organization and validation
- Added ConditionalOnMissingBean for WebMvc/WebFlux configurations
- Enhanced lifecycle management and customization support

Testing and Documentation:
- Added comprehensive integration tests for McpClientAutoConfiguration
- Updated McpServerAutoConfigurationIT
- Added extensive JavaDoc documentation
- Improved MCP client/server starter documentation
- Added documentation for common utilities
- Updated navigation for new MCP documentation sections

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-11 00:52:00 -05:00
Ilayaperumal Gopinathan
dc83eb3713 Update MCP dependency management
- Move MCP BOM dependency management configuration into spring-ai parent

Resolves #2180
2025-02-07 09:26:52 +01:00
Christian Tzolov
f40945bd63 Add Spring AI MCP Integration
Adds comprehensive Model Context Protocol (MCP) integration to Spring AI, including:

Core Features:
- MCP client implementation with Spring AI tool calling capabilities
- Spring-friendly abstractions for MCP clients and servers
- Both synchronous and asynchronous MCP server operation modes
- Add MCP client autoconfiguration with support for STDIO, WebMVC and WebFlux transports
- Auto-configuration for MCP server components
- Spring Boot starter (spring-ai-starter-mcp) with WebFlux and WebMVC support
- MCP dependency management with BOM
- Add close() method to McpToolCallback for proper resource cleanup
- Add initialize flag to control MCP client initialization
- Add comprehensive integration tests and documentation for MCP client configuration

Technical Improvements:
- Split WebMvc and WebFlux configurations into separate auto-configuration classes
- Server type configurable via 'spring.ai.mcp.server.type' property (SYNC/ASYNC)
- Comprehensive test coverage including McpServerAutoConfigurationIT
- Utility classes for converting between Spring AI tools and MCP tools
- MCP SDK version management in parent pom

Reorganize MCP tool utilities and client configuration

- Rename ToolUtils to McpToolUtils for better MCP-specific naming
- Rename McpToolCallbackProvider to SyncMcpToolCallbackProvider
- Add utility methods for handling tool callbacks in McpToolUtils
- Extract client configuration logic into new McpClientDefinitions class
- Add tool callback support to ChatClient interface and implementations
- Remove redundant integration test

Introduce MCP client customization support

- Add McpSyncClientCustomizer interface for customizing MCP sync clients
- Replace McpClientDefinitions with McpSyncClientConfigurer
- Refactor MCP client initialization to support customization
- Remove redundant close() method from McpToolCallback
- Fix conditional class dependencies in WebMvc/Flux configurations

Add MCP AOT hints

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
2025-02-05 15:54:48 -05:00