Skip to content

Commit 0f1aca5

Browse files
committed
docs: enhance MCP documentation with customization details and examples
- Expand client customization documentation with detailed sections - Add comprehensive descriptions of MCP components and capabilities - Improve code examples and explanations - Add example applications sections for both client and server - Fix typos and enhance overall documentation structure Signed-off-by: Christian Tzolov <[email protected]>
1 parent fe377ee commit 0f1aca5

File tree

3 files changed

+79
-58
lines changed

3 files changed

+79
-58
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-client-boot-starter-docs.adoc

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,26 @@ The starter supports two types of clients:
203203

204204
=== Client Customization
205205

206-
The auto-configuration supports client spec customization.
207-
Implement the `McpSyncClientCustomizer` callback interface to customize the `McpClient.SyncSpec` spec for a named server connection.
208-
Similarly, the `McpAsyncClientCustomizer` interface allows customizing the `McpClient.AsyncSpec` spec for asynchronous clients.
206+
The auto-configuration provides extensive client spec customization capabilities through callback interfaces. These customizers allow you to configure various aspects of the MCP client behavior, from request timeouts to event handling and message processing.
207+
208+
==== Customization Types
209+
210+
The following customization options are available:
211+
212+
* *Request Configuration* - Set custom request timeouts
213+
* link:https://spec.modelcontextprotocol.io/specification/2024-11-05/client/sampling/[*Custom Sampling Handlers*] - standardized way for servers to request LLM sampling (`completions` or `generations`) from LLMs via clients. This flow allows clients to maintain control over model access, selection, and permissions while enabling servers to leverage AI capabilities — with no server API keys necessary.
214+
* link:https://spec.modelcontextprotocol.io/specification/2024-11-05/client/roots/[*File system (Roots) Access*] - standardized way for clients to expose filesystem `roots` to servers.
215+
Roots define the boundaries of where servers can operate within the filesystem, allowing them to understand which directories and files they have access to.
216+
Servers can request the list of roots from supporting clients and receive notifications when that list changes.
217+
* *Event Handlers* - client's handler to be notified when a certain server event occurs:
218+
- Tools change notifications - when the list of available server tools changes
219+
- Resources change notifications - when the list of available server resources changes.
220+
- Prompts change notifications - when the list of available server prompts changes.
221+
* link:https://spec.modelcontextprotocol.io/specification/2024-11-05/server/utilities/logging/[*Logging Handlers*] - standardized way for servers to send structured log messages to clients.
222+
Clients can control logging verbosity by setting minimum log levels
223+
224+
225+
You can implement either `McpSyncClientCustomizer` for synchronous clients or `McpAsyncClientCustomizer` for asynchronous clients, depending on your application's needs.
209226

210227
[tabs]
211228
======
@@ -216,27 +233,34 @@ Sync::
216233
@Component
217234
public class CustomMcpSyncClientCustomizer implements McpSyncClientCustomizer {
218235
@Override
219-
public void customize(String name, McpClient.SyncSpec spec) {
236+
public void customize(String serverConfiurationName, McpClient.SyncSpec spec) {
220237
221-
// Customize the sync client configuration
238+
// Customize the request configuration
222239
spec.requestTimeout(Duration.ofSeconds(30));
223240
224-
// Adds a consumer to be notified when the available tools change. This allows the
225-
// client to react to changes in the server's tool capabilities, such as tools
226-
// being added or removed.
241+
// Sets the root URIs that the server connecto this client can access.
242+
spec.roots(roots);
243+
244+
// Sets a custom sampling handler for processing message creation requests.
245+
spec.sampling((CreateMessageRequest messageRequest) -> {
246+
// Handle sampling
247+
CreateMessageResult result = ...
248+
return result;
249+
});
250+
251+
// Adds a consumer to be notified when the available tools change, such as tools
252+
// being added or removed.
227253
spec.toolsChangeConsumer((List<McpSchema.Tool> tools) -> {
228254
// Handle tools change
229255
});
230256
231-
// Adds a consumer to be notified when the available resources change. This allows the
232-
// client to react to changes in the server's resource capabilities, such as resources
257+
// Adds a consumer to be notified when the available resources change, such as resources
233258
// being added or removed.
234259
spec.resourcesChangeConsumer((List<McpSchema.Resource> resources) -> {
235260
// Handle resources change
236261
});
237262
238-
// Adds a consumer to be notified when the available prompts change. This allows the
239-
// client to react to changes in the server's prompt capabilities, such as prompts
263+
// Adds a consumer to be notified when the available prompts change, such as prompts
240264
// being added or removed.
241265
spec.promptsChangeConsumer((List<McpSchema.Prompt> prompts) -> {
242266
// Handle prompts change
@@ -246,18 +270,6 @@ public class CustomMcpSyncClientCustomizer implements McpSyncClientCustomizer {
246270
spec.loggingConsumer((McpSchema.LoggingMessageNotification log) -> {
247271
// Handle log messages
248272
});
249-
250-
// Sets a custom sampling handler for processing message creation requests.
251-
spec.sampling((CreateMessageRequest messageRequest) -> {
252-
// Handle sampling
253-
CreateMessageResult result = ...
254-
return result;
255-
});
256-
257-
// Sets the root URIs that the server connecto this client can access.
258-
// Roots define the base URIs for resources that the server can request.
259-
// For example, a root might be "file://workspace" for accessing workspace files.
260-
spec.roots(roots);
261273
}
262274
}
263275
----
@@ -269,13 +281,14 @@ Async::
269281
@Component
270282
public class CustomMcpAsyncClientCustomizer implements McpAsyncClientCustomizer {
271283
@Override
272-
public void customize(String name, McpClient.AsyncSpec spec) {
284+
public void customize(String serverConfiurationName, McpClient.AsyncSpec spec) {
273285
// Customize the async client configuration
274286
spec.requestTimeout(Duration.ofSeconds(30));
275287
}
276288
}
277289
----
278290
======
291+
The `serverConfiurationName` parameter is the name of the server configuration that the customizer is being applied to and the the MCP Client is created for.
279292

280293
The MCP client auto-configuration automatically detects and applies any customizers found in the application context.
281294

@@ -346,6 +359,12 @@ Additionally, the registered MCP Tools with all MCP clients are provided as a li
346359
private List<ToolCallback> toolCallbacks;
347360
----
348361

362+
== Example Applications
363+
364+
- link:https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/web-search/brave-chatbot[Brave Wet Search Chatbot] - A chatbot that uses the Model Context Protocol to interact with a web search server.
365+
- link:https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/client-starter/starter-default-client[Default MCP Client Starter] - A simple example of using the the default `spring-ai-mcp-client-spring-boot-starter` MCP Client Boot Starter.
366+
- link:https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/client-starter/starter-webflux-client[WebFlux MCP Client Starter] - A simple example of using the `spring-ai-mcp-client-webflux-spring-boot-starter` the MCP Client Boot Starter.
367+
349368
== Additional Resources
350369

351370
* link:https://docs.spring.io/spring-ai/reference/[Spring AI Documentation]

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-overview.adoc

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
= Model Context Protocol (MCP)
22

33
The link:https://modelcontextprotocol.org/docs/concepts/architecture[Model Context Protocol] (MCP) is a standardized protocol that enables AI models to interact with external tools and resources in a structured way.
4-
It supports multiple transport mechanisms for flexibility in different environments.
5-
6-
The link:https://modelcontextprotocol.github.io/sdk/java[Java MCP] provides a Java SDK implementation of the Model Context Protocol, enabling standardized interaction with AI models and tools through both synchronous and asynchronous communication.
4+
It supports multiple transport mechanisms to provide flexibility across different environments.
75

86
== MCP Java SDK
97

8+
The link:https://modelcontextprotocol.github.io/sdk/java[MCP Java SDK] provides a Java implementation of the Model Context Protocol, enabling standardized interaction with AI models and tools through both synchronous and asynchronous communication patterns.
9+
1010
The Java MCP implementation follows a three-layer architecture:
1111

12-
// [cols="2,10"]
1312
|===
1413
| |
1514
^a| image::mcp/mcp-stack.svg[MCP Stack Architecture]
16-
a| * *Client/Server Layer*: The McpClient handles client-side and the McpServer manages server-side protocol operations.
17-
Both utilize McpSession for operations
18-
* *Session Layer (McpSession)*: Manages communication patterns and state.
19-
Uses the DefaultMcpSession implementation.
20-
* *Transport Layer (McpTransport)*: Handles JSON-RPC message serialization/deserialization.
21-
Supports multiple transport implementations.
15+
a| * *Client/Server Layer*: The McpClient handles client-side operations while the McpServer manages server-side protocol operations. Both utilize McpSession for communication management.
16+
* *Session Layer (McpSession)*: Manages communication patterns and state through the DefaultMcpSession implementation.
17+
* *Transport Layer (McpTransport)*: Handles JSON-RPC message serialization and deserialization with support for multiple transport implementations.
2218
|===
2319

24-
// [cols="10,2"]
2520
|===
26-
| MCP Client |
21+
| link:https://modelcontextprotocol.io//sdk/java/mcp-client[MCP Client] |
2722

2823
a| The MCP Client is a key component in the Model Context Protocol (MCP) architecture, responsible for establishing and managing connections with MCP servers. It implements the client-side of the protocol, handling:
2924

@@ -33,31 +28,32 @@ a| The MCP Client is a key component in the Model Context Protocol (MCP) archite
3328
* Tool discovery and execution
3429
* Resource access and management
3530
* Prompt system interactions
36-
* Optional features like roots management and sampling support
31+
* Optional features:
32+
** Roots management
33+
** Sampling support
3734
* Synchronous and asynchronous operations
38-
* Multiple transport options:
35+
* Transport options:
3936
** Stdio-based transport for process-based communication
4037
** Java HttpClient-based SSE client transport
4138
** WebFlux SSE client transport for reactive HTTP streaming
4239

4340
^a| image::mcp/java-mcp-client-architecture.jpg[Java MCP Client Architecture, width=500]
4441
|===
4542

46-
// [cols="10,2"]
4743
|===
48-
| MCP Server |
44+
| link:https://modelcontextprotocol.io//sdk/java/mcp-server[MCP Server] |
4945

5046
a| The MCP Server is a foundational component in the Model Context Protocol (MCP) architecture that provides tools, resources, and capabilities to clients. It implements the server-side of the protocol, responsible for:
5147

52-
* Exposing tools that clients can discover and execute
53-
* Managing resources with URI-based access patterns
54-
* Providing prompt templates and handling prompt requests
55-
* Supporting capability negotiation with clients
56-
* Implementing server-side protocol operations
57-
* Managing concurrent client connections
58-
* Providing structured logging and notifications
59-
* Supporting both synchronous and asynchronous APIs for flexible integration
60-
* Multiple transport options:
48+
* Server-side protocol operations implementation
49+
** Tool exposure and discovery
50+
** Resource management with URI-based access
51+
** Prompt template provision and handling
52+
** Capability negotiation with clients
53+
** Structured logging and notifications
54+
* Concurrent client connection management
55+
* Synchronous and Asynchronous API support
56+
* Transport implementations:
6157
** Stdio-based transport for process-based communication
6258
** Servlet-based SSE server transport
6359
** WebFlux SSE server transport for reactive HTTP streaming
@@ -66,21 +62,21 @@ a| The MCP Server is a foundational component in the Model Context Protocol (MCP
6662
^a| image::mcp/java-mcp-server-architecture.jpg[Java MCP Server Architecture, width=600]
6763
|===
6864

69-
For manual SDK implementation, refer to the link:https://modelcontextprotocol.github.io/sdk/java[MCP Java SDK documentation].
70-
For simplified setup, use the Spring AI MCP Boot Starters below.
65+
For detailed implementation guidance, using the low-level MCP Client/Server APIs, refer to the link:https://modelcontextprotocol.github.io/sdk/java[MCP Java SDK documentation].
66+
For simplified setup using Spring Boot, use the MCP Boot Starters described below.
7167

7268
== Spring AI MCP Integration
7369

74-
The Spring AI MCP integration is provided through Spring Boot starters:
70+
Spring AI provides MCP integration through the following Spring Boot starters:
7571

7672
=== link:mcp-client-boot-starter-docs.html[Client Starters]
77-
* `spring-ai-mcp-client-spring-boot-starter` - Core starter with STDIO and HTTP-based SSE support
78-
* `spring-ai-mcp-client-webflux-spring-boot-starter` - WebFlux-based SSE transport
73+
* `spring-ai-mcp-client-spring-boot-starter` - Core starter providing STDIO and HTTP-based SSE support
74+
* `spring-ai-mcp-client-webflux-spring-boot-starter` - WebFlux-based SSE transport implementation
7975

8076
=== link:mcp-server-boot-starter-docs.html[Server Starters]
81-
* `spring-ai-mcp-server-spring-boot-starter` - Core server with STDIO transport
82-
* `spring-ai-mcp-server-webmvc-spring-boot-starter` - Spring MVC-based SSE transport
83-
* `spring-ai-mcp-server-webflux-spring-boot-starter` - WebFlux-based SSE transport
77+
* `spring-ai-mcp-server-spring-boot-starter` - Core server with STDIO transport support
78+
* `spring-ai-mcp-server-webmvc-spring-boot-starter` - Spring MVC-based SSE transport implementation
79+
* `spring-ai-mcp-server-webflux-spring-boot-starter` - WebFlux-based SSE transport implementation
8480

8581
== Additional Resources
8682

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-server-boot-starter-docs.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ public class McpServerApplication {
211211
The auto-configuration will automatically register the toolcallbacs as MCP tools.
212212
You can have multiple beans producing list of ToolCallbacks. The autoconfiguration will merge them.
213213

214+
== Example Applicaitons
215+
* link:https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/weather/starter-webflux-server[Weather Server (WebFlux)] - Spring AI MCP Server Boot Starter with WebFlux transport.
216+
* link:https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/weather/starter-stdio-server[Weather Server (STDIO)] - Spring AI MCP Server Boot Starter with STDIO transport.
217+
* link:https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/book-library/starter-webflux-server[Book Library Server (WebFlux)] - Spring AI MCP Server Boot Starter with WebFlux transport.
218+
* link:https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol/weather/manual-webflux-server[Weather Server Manual Configuraiton] - Spring AI MCP Server Boot Starter that doesn't use autoconfiguration but the Java SDK to configure the server manually.
219+
214220
== Additional Resources
215221

216222
* link:https://docs.spring.io/spring-ai/reference/[Spring AI Documentation]

0 commit comments

Comments
 (0)