From c2a694900c368446cbe1d9991e18082b9b1651fc Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Sat, 17 May 2025 13:26:52 +0200 Subject: [PATCH] docs: Document the MCP ToolContext support Resolves #3209 Signed-off-by: Christian Tzolov --- .../api/mcp/mcp-server-boot-starter-docs.adoc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-server-boot-starter-docs.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-server-boot-starter-docs.adoc index 42493036a..d9344f2d8 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-server-boot-starter-docs.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-server-boot-starter-docs.adoc @@ -146,7 +146,7 @@ It automatically converts custom capability handlers registered as Spring beans Allows servers to expose tools that can be invoked by language models. The MCP Server Boot Starter provides: * Change notification support -* Tools are automatically converted to sync/async specifications based on server type +* xref:api/tools.adoc[Spring AI Tools] are automatically converted to sync/async specifications based on server type * Automatic tool specification through Spring beans: [source,java] @@ -158,17 +158,6 @@ public ToolCallbackProvider myTools(...) { } ---- -or directly as individual tool callbacks: - -[source,java] ----- -@Bean -public ToolCallback myTool(...) { - // Create and return a single tool callback - return new ToolCallback(...); -} ----- - or using the low-level API: [source,java] @@ -187,6 +176,10 @@ The auto-configuration will automatically detect and register all tool callbacks Tools are de-duplicated by name, with the first occurrence of each tool name being used. +==== Tool Context Support + +The xref:api/tools.adoc#_tool_context[ToolContext] is supported, allowing contextual information to be passed to tool calls. It contains an `McpSyncServerExchange` instance under the `exchange` key, accessible via `McpToolUtils.getMcpExchange(toolContext)`. See this https://github.com/spring-projects/spring-ai-examples/blob/3fab8483b8deddc241b1e16b8b049616604b7767/model-context-protocol/sampling/mcp-weather-webmvc-server/src/main/java/org/springframework/ai/mcp/sample/server/WeatherService.java#L59-L126[example] demonstrating `exchange.loggingNotification(...)` and `exchange.createMessage(...)`. + === link:https://spec.modelcontextprotocol.io/specification/2024-11-05/server/resources/[Resource Management] Provides a standardized way for servers to expose resources to clients.