@@ -120,7 +120,97 @@ client.initialize()
120
120
</Tab >
121
121
</Tabs >
122
122
123
- ## Client Features
123
+ ## Client Transport
124
+
125
+ The transport layer handles the communication between MCP clients and servers, providing different implementations for various use cases. The client transport manages message serialization, connection establishment, and protocol-specific communication patterns.
126
+
127
+ <Tabs >
128
+ <Tab title = " STDIO" >
129
+ Creates transport for in-process based communication
130
+ ```java
131
+ ServerParameters params = ServerParameters.builder("npx")
132
+ .args("-y", "@modelcontextprotocol/server-everything ", "dir")
133
+ .build();
134
+ McpTransport transport = new StdioClientTransport(params);
135
+ ```
136
+ </Tab >
137
+ <Tab title = " SSE (HttpClient)" >
138
+ Creates a framework agnostic (pure Java API) SSE client transport. Included in the core mcp module.
139
+ ```java
140
+ McpTransport transport = new HttpClientSseClientTransport("http://your-mcp-server ");
141
+ ```
142
+ </Tab >
143
+ <Tab title = " SSE (WebFlux)" >
144
+ Creates WebFlux-based SSE client transport. Requires the mcp-webflux-sse-transport dependency.
145
+ ```java
146
+ WebClient.Builder webClientBuilder = WebClient.builder()
147
+ .baseUrl("http://your-mcp-server ");
148
+ McpTransport transport = new WebFluxSseClientTransport(webClientBuilder);
149
+ ```
150
+ </Tab >
151
+ </Tabs >
152
+
153
+ ## Client Capabilities
154
+
155
+ The client can be configured with various capabilities:
156
+
157
+ ``` java
158
+ var capabilities = ClientCapabilities . builder()
159
+ .roots(true ) // Enable filesystem roots support with list changes notifications
160
+ .sampling() // Enable LLM sampling support
161
+ .build();
162
+ ```
163
+
164
+ ### Roots Support
165
+
166
+ Roots define the boundaries of where servers can operate within the filesystem:
167
+
168
+ ``` java
169
+ // Add a root dynamically
170
+ client. addRoot(new Root (" file:///path" , " description" ));
171
+
172
+ // Remove a root
173
+ client. removeRoot(" file:///path" );
174
+
175
+ // Notify server of roots changes
176
+ client. rootsListChangedNotification();
177
+ ```
178
+
179
+ The roots capability allows servers to:
180
+
181
+ - Request the list of accessible filesystem roots
182
+ - Receive notifications when the root list changes
183
+ - Understand which directories and files they have access to
184
+
185
+
186
+ ### Sampling Support
187
+
188
+ Sampling enables servers to request LLM interactions ("completions" or "generations") through the client:
189
+
190
+ ``` java
191
+ // Configure sampling handler
192
+ Function<CreateMessageRequest , CreateMessageResult > samplingHandler = request - > {
193
+ // Sampling implementation that interfaces with LLM
194
+ return new CreateMessageResult (response);
195
+ };
196
+
197
+ // Create client with sampling support
198
+ var client = McpClient . sync(transport)
199
+ .capabilities(ClientCapabilities . builder()
200
+ .sampling()
201
+ .build())
202
+ .sampling(samplingHandler)
203
+ .build();
204
+ ```
205
+
206
+ This capability allows:
207
+ - Servers to leverage AI capabilities without requiring API keys
208
+ - Clients to maintain control over model access and permissions
209
+ - Support for both text and image-based interactions
210
+ - Optional inclusion of MCP server context in prompts
211
+
212
+
213
+ ## Using MCP Clients
124
214
125
215
### Tool Execution
126
216
@@ -134,7 +224,7 @@ var tools = client.listTools();
134
224
tools. forEach(tool - > System . out. println(tool. getName()));
135
225
136
226
// Execute a tool
137
- var result = client. executeTool (" calculator" , Map . of(
227
+ var result = client. callTool (" calculator" , Map . of(
138
228
" operation" , " add" ,
139
229
" a" , 1 ,
140
230
" b" , 2
@@ -151,7 +241,7 @@ client.listTools()
151
241
.subscribe();
152
242
153
243
// Execute a tool
154
- client. executeTool (" calculator" , Map . of(
244
+ client. callTool (" calculator" , Map . of(
155
245
" operation" , " add" ,
156
246
" a" , 1 ,
157
247
" b" , 2
0 commit comments