Skip to content

Commit 2856343

Browse files
committed
multiple mcp docs improvements
1 parent 17e8f6a commit 2856343

File tree

3 files changed

+201
-347
lines changed

3 files changed

+201
-347
lines changed

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

Lines changed: 67 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
= Spring AI MCP Client Boot Starter
1+
= MCP Client Boot Starter
22

33
The Spring AI MCP (Model Context Protocol) Client Boot Starter provides auto-configuration for MCP client functionality in Spring Boot applications. It supports both synchronous and asynchronous client implementations with various transport options.
44

55
The MCP Client Boot Starter provides:
66

7+
* Management of multiple client instances
78
* Automatic client initialization (if enabled)
89
* Support for multiple named transports
910
* Integration with Spring AI's tool execution framework
10-
* Proper lifecycle management with automatic cleanup
11+
* Proper lifecycle management with automatic cleanup of resources when the application context is closed
1112
* Customizable client creation through customizers
1213
13-
== Dependencies
14+
== Starters
1415

15-
=== Core Starter
16+
=== Standard MCP Client
1617

1718
[source,xml]
1819
----
1920
<dependency>
2021
<groupId>org.springframework.ai</groupId>
2122
<artifactId>spring-ai-mcp-client-spring-boot-starter</artifactId>
22-
<version>${spring-ai.version}</version>
2323
</dependency>
2424
----
2525

26-
It will connect, simultaneously, to one or more MCP Servers over `STDIO` (in-process) and/or `SSE` (remote) transports.
26+
The core starter connects simultaneously to one or more MCP Servers over `STDIO` (in-process) and/or `SSE` (remote) transports.
2727
The SSE connection uses the HttpClient-based transport implementation.
28-
Every connection to an MCP Server creates a new MCP Client instance.
29-
You can opt for either `SYNC` or `ASYNC` MCP Clients (Note: you cannot mix sync and async clients).
30-
For more enterprise-ready deployment, it is recommended to use the WebFlux-based SSE connection using the `spring-ai-mcp-client-webflux-spring-boot-starter` starter.
28+
Each connection to an MCP Server creates a new MCP Client instance.
29+
You can choose either `SYNC` or `ASYNC` MCP Clients (note: you cannot mix sync and async clients).
30+
For enterprise-ready deployment, we recommend using the WebFlux-based SSE connection with the `spring-ai-mcp-client-webflux-spring-boot-starter`.
3131

32-
=== WebFlux Starter
32+
=== WebFlux Client
3333

34-
Similar to the core starter, it allows configuring one or more STDIO and SSE connections, but uses WebFlux-based SSE transport implementation.
34+
The WebFlux starter provides similar functionality to the core starter but uses a WebFlux-based SSE transport implementation.
3535

3636
[source,xml]
3737
----
3838
<dependency>
3939
<groupId>org.springframework.ai</groupId>
4040
<artifactId>spring-ai-mcp-client-webflux-spring-boot-starter</artifactId>
41-
<version>${spring-ai.version}</version>
4241
</dependency>
4342
----
4443

@@ -73,44 +72,14 @@ All common configuration properties are prefixed with `spring.ai.mcp.client`:
7372
|`20s`
7473

7574
|`type`
76-
|Client type (SYNC or ASYNC). You can not mix client type. All clients can be either sync or async
75+
|Client type (SYNC or ASYNC). All clients must be either sync or async; mixing is not supported
7776
|`SYNC`
7877

7978
|`root-change-notification`
8079
|Enable/disable root change notifications for all clients
8180
|`true`
8281
|===
8382

84-
=== SSE Transport Properties
85-
86-
Properties for Server-Sent Events (SSE) transport are prefixed with `spring.ai.mcp.client.sse`:
87-
88-
[cols="2,4"]
89-
|===
90-
|Property |Description
91-
92-
|`connections`
93-
|Map of named SSE connection configurations
94-
95-
|`connections.[name].url`
96-
|URL endpoint for SSE communication with the MCP server
97-
|===
98-
99-
Example configuration:
100-
[source,yaml]
101-
----
102-
spring:
103-
ai:
104-
mcp:
105-
client:
106-
sse:
107-
connections:
108-
server1:
109-
url: http://localhost:8080
110-
server2:
111-
url: http://otherserver:8081
112-
----
113-
11483
=== Stdio Transport Properties
11584

11685
Properties for Standard I/O transport are prefixed with `spring.ai.mcp.client.stdio`:
@@ -160,7 +129,7 @@ spring:
160129
DEBUG: "true"
161130
----
162131

163-
Alternatively, you can configure stdio connections using an external JSON file using the link:https://modelcontextprotocol.io/quickstart/user[Claude Desctop format]:
132+
Alternatively, you can configure stdio connections using an external JSON file using the link:https://modelcontextprotocol.io/quickstart/user[Claude Desktop format]:
164133

165134
[source,yaml]
166135
----
@@ -172,7 +141,7 @@ spring:
172141
servers-configuration: classpath:mcp-servers.json
173142
----
174143

175-
The Claude Destop format looks like this:
144+
The Claude Desktop format looks like this:
176145

177146
[source,json]
178147
----
@@ -190,23 +159,47 @@ The Claude Destop format looks like this:
190159
}
191160
}
192161
----
193-
Currently the Claude Destop supports only STDIO connection types.
162+
163+
Currently, the Claude Desktop format supports only STDIO connection types.
164+
165+
=== SSE Transport Properties
166+
167+
Properties for Server-Sent Events (SSE) transport are prefixed with `spring.ai.mcp.client.sse`:
168+
169+
[cols="2,4"]
170+
|===
171+
|Property |Description
172+
173+
|`connections`
174+
|Map of named SSE connection configurations
175+
176+
|`connections.[name].url`
177+
|URL endpoint for SSE communication with the MCP server
178+
|===
179+
180+
Example configuration:
181+
[source,yaml]
182+
----
183+
spring:
184+
ai:
185+
mcp:
186+
client:
187+
sse:
188+
connections:
189+
server1:
190+
url: http://localhost:8080
191+
server2:
192+
url: http://otherserver:8081
193+
----
194194

195195
== Features
196196

197-
=== Client Types
197+
=== Sync/Async Client Types
198198

199199
The starter supports two types of clients:
200200

201-
1. *Synchronous Client (SYNC)*
202-
* Default client type
203-
* Blocking operations
204-
* Suitable for traditional request-response patterns
205-
206-
2. *Asynchronous Client (ASYNC)*
207-
* Non-blocking operations
208-
* Suitable for reactive applications
209-
* Must be explicitly configured using `spring.ai.mcp.client.type=ASYNC`
201+
* Synchronous (`SYNC`) - Default client type, suitable for traditional request-response patterns with blocking operations
202+
* Asynchronous (`ASYNC`) - Suitable for reactive applications with non-blocking operations, configured using `spring.ai.mcp.client.type=ASYNC`
210203

211204
=== Client Customization
212205

@@ -215,11 +208,21 @@ The auto-configuration supports customization through:
215208
* `McpSyncClientCustomizer` for synchronous clients
216209
* `McpAsyncClientCustomizer` for asynchronous clients
217210

218-
== Usage Example
211+
=== Transport Support
219212

220-
1. Add the appropriate starter dependency to your project.
213+
The auto-configuration supports multiple transport types:
214+
215+
* Standard I/O (Stdio) (activated by the `spring-ai-mcp-client-spring-boot-starter`)
216+
* SSE HTTP (activated by the `spring-ai-mcp-client-spring-boot-starter`)
217+
* SSE WebFlux (activated by the `spring-ai-starter-mcp-client-webflux`)
218+
219+
=== Integration with Spring AI
220+
221+
The starter automatically configures tool callbacks that integrate with Spring AI's tool execution framework, allowing MCP tools to be used as part of AI interactions.
222+
223+
== Usage Example
221224

222-
2. Configure the client in `application.properties` or `application.yml`:
225+
Add the appropriate starter dependency to your project and configure the client in `application.properties` or `application.yml`:
223226

224227
[source,yaml]
225228
----
@@ -250,8 +253,8 @@ spring:
250253
API_KEY: your-api-key
251254
DEBUG: "true"
252255
----
253-
+
254-
3. The MCP client beans will be automatically configured and available for injection:
256+
257+
The MCP client beans will be automatically configured and available for injection:
255258

256259
[source,java]
257260
----
@@ -264,75 +267,14 @@ private List<McpSyncClient> mcpSyncClients; // For sync client
264267
private List<McpAsyncClient> mcpAsyncClients; // For async client
265268
----
266269

267-
== Transport Support
268-
269-
The auto-configuration supports multiple transport types:
270-
271-
* Standard I/O (Stdio)
272-
* SSE HTTP
273-
* SSE WebFlux (requires `spring-ai-starter-mcp-client-webflux`)
274-
275-
At least one transport must be available for the clients to be created.
276-
277-
== Integration with Spring AI
278-
279-
The starter automatically configures tool callbacks that integrate with Spring AI's tool execution framework, allowing MCP tools to be used as part of AI interactions.
280-
281-
== Lifecycle Management
282-
283-
The auto-configuration includes proper lifecycle management:
284-
285-
* Automatic initialization of clients (if enabled)
286-
* Proper cleanup of resources when the application context is closed
287-
* Management of multiple client instances
288-
289-
== Best Practices
290-
291-
1. Choose the appropriate client type based on your application's needs:
292-
* Use SYNC client for traditional applications
293-
* Use ASYNC client for reactive applications
294-
295-
2. Configure appropriate timeout values based on your use case:
296-
[source,yaml]
297-
----
298-
spring:
299-
ai:
300-
mcp:
301-
client:
302-
request-timeout: 30s
303-
----
304-
+
305-
3. Use customizers for advanced client configuration:
270+
Additionally, the registered MCP Tools with all MCP clients are provided as list of ToolCallback instances:
306271

307272
[source,java]
308273
----
309-
@Component
310-
public class MyMcpClientCustomizer implements McpSyncClientCustomizer {
311-
@Override
312-
public void customize(String name, McpClient.SyncSpec clientSpec) {
313-
// Custom configuration
314-
}
315-
}
274+
@Autowired
275+
private List<ToolCallback> toolCallbacks;
316276
----
317277

318-
== Troubleshooting
319-
320-
Common issues and solutions:
321-
322-
1. *Client Not Created*
323-
* Verify that at least one transport is available
324-
* Check if the client is enabled in configuration
325-
* Ensure required dependencies are present
326-
327-
2. *Timeout Issues*
328-
* Adjust the `request-timeout` property
329-
* Check network connectivity
330-
* Verify server response times
331-
332-
3. *Integration Issues*
333-
* Ensure proper transport configuration
334-
* Check client initialization status
335-
336278
== Additional Resources
337279

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

0 commit comments

Comments
 (0)