You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-client-boot-starter-docs.adoc
+44-25Lines changed: 44 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -203,9 +203,26 @@ The starter supports two types of clients:
203
203
204
204
=== Client Customization
205
205
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.
209
226
210
227
[tabs]
211
228
======
@@ -216,27 +233,34 @@ Sync::
216
233
@Component
217
234
public class CustomMcpSyncClientCustomizer implements McpSyncClientCustomizer {
218
235
@Override
219
-
public void customize(String name, McpClient.SyncSpec spec) {
236
+
public void customize(String serverConfiurationName, McpClient.SyncSpec spec) {
220
237
221
-
// Customize the sync client configuration
238
+
// Customize the request configuration
222
239
spec.requestTimeout(Duration.ofSeconds(30));
223
240
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.
// 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);
261
273
}
262
274
}
263
275
----
@@ -269,13 +281,14 @@ Async::
269
281
@Component
270
282
public class CustomMcpAsyncClientCustomizer implements McpAsyncClientCustomizer {
271
283
@Override
272
-
public void customize(String name, McpClient.AsyncSpec spec) {
284
+
public void customize(String serverConfiurationName, McpClient.AsyncSpec spec) {
273
285
// Customize the async client configuration
274
286
spec.requestTimeout(Duration.ofSeconds(30));
275
287
}
276
288
}
277
289
----
278
290
======
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.
279
292
280
293
The MCP client auto-configuration automatically detects and applies any customizers found in the application context.
281
294
@@ -346,6 +359,12 @@ Additionally, the registered MCP Tools with all MCP clients are provided as a li
346
359
private List<ToolCallback> toolCallbacks;
347
360
----
348
361
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
+
349
368
== Additional Resources
350
369
351
370
* link:https://docs.spring.io/spring-ai/reference/[Spring AI Documentation]
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-overview.adoc
+29-33Lines changed: 29 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,24 @@
1
1
= Model Context Protocol (MCP)
2
2
3
3
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.
7
5
8
6
== MCP Java SDK
9
7
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
+
10
10
The Java MCP implementation follows a three-layer architecture:
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.
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:
29
24
@@ -33,31 +28,32 @@ a| The MCP Client is a key component in the Model Context Protocol (MCP) archite
33
28
* Tool discovery and execution
34
29
* Resource access and management
35
30
* Prompt system interactions
36
-
* Optional features like roots management and sampling support
31
+
* Optional features:
32
+
** Roots management
33
+
** Sampling support
37
34
* Synchronous and asynchronous operations
38
-
* Multiple transport options:
35
+
* Transport options:
39
36
** Stdio-based transport for process-based communication
40
37
** Java HttpClient-based SSE client transport
41
38
** WebFlux SSE client transport for reactive HTTP streaming
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:
51
47
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:
61
57
** Stdio-based transport for process-based communication
62
58
** Servlet-based SSE server transport
63
59
** 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
66
62
^a| image::mcp/java-mcp-server-architecture.jpg[Java MCP Server Architecture, width=600]
67
63
|===
68
64
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.
71
67
72
68
== Spring AI MCP Integration
73
69
74
-
The Spring AI MCP integration is provided through Spring Boot starters:
70
+
Spring AI provides MCP integration through the following Spring Boot starters:
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/mcp/mcp-server-boot-starter-docs.adoc
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,12 @@ public class McpServerApplication {
211
211
The auto-configuration will automatically register the toolcallbacs as MCP tools.
212
212
You can have multiple beans producing list of ToolCallbacks. The autoconfiguration will merge them.
213
213
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
+
214
220
== Additional Resources
215
221
216
222
* link:https://docs.spring.io/spring-ai/reference/[Spring AI Documentation]
0 commit comments