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
@@ -345,29 +346,37 @@ Register an elicitation handler to respond to server requests:
345
346
346
347
```swift
347
348
// Register an elicitation handler in the client
348
-
await client.setElicitationHandler { parameters in
349
-
// Display the request to the user
350
-
print("Server requests: \(parameters.message)")
351
-
352
-
// If a schema was provided, validate against it
353
-
iflet schema = parameters.requestedSchema {
354
-
print("Required fields: \(schema.required?? [])")
355
-
print("Schema: \(schema.properties)")
356
-
}
357
-
358
-
// Present UI to collect user input
359
-
let userResponse =presentElicitationUI(parameters)
360
-
361
-
// Return the user's response
362
-
if userResponse.accepted {
363
-
return CreateElicitation.Result(
364
-
action: .accept,
365
-
content: userResponse.data
366
-
)
367
-
} elseif userResponse.canceled {
368
-
return CreateElicitation.Result(action: .cancel)
369
-
} else {
370
-
return CreateElicitation.Result(action: .decline)
349
+
await client.withElicitationHandler { parameters in
350
+
switch parameters {
351
+
case .form(let form):
352
+
// Display the request to the user
353
+
print("Server requests: \(form.message)")
354
+
355
+
// If a schema was provided, inspect it
356
+
iflet schema = form.requestedSchema {
357
+
print("Required fields: \(schema.required?? [])")
358
+
print("Schema: \(schema.properties)")
359
+
}
360
+
361
+
// Present UI to collect user input
362
+
let userResponse =presentElicitationUI(form)
363
+
364
+
// Return the user's response
365
+
if userResponse.accepted {
366
+
return CreateElicitation.Result(
367
+
action: .accept,
368
+
content: userResponse.data
369
+
)
370
+
} elseif userResponse.canceled {
371
+
return CreateElicitation.Result(action: .cancel)
372
+
} else {
373
+
return CreateElicitation.Result(action: .decline)
374
+
}
375
+
376
+
case .url(let url):
377
+
// Direct the user to an external URL (e.g., for OAuth)
378
+
openURL(url.url)
379
+
return CreateElicitation.Result(action: .accept)
371
380
}
372
381
}
373
382
```
@@ -379,6 +388,34 @@ Common use cases for elicitation:
379
388
-**Configuration**: Collect preferences or settings during operation
380
389
-**Missing information**: Request additional details not provided initially
381
390
391
+
### Roots
392
+
393
+
Roots define the filesystem boundaries that a client exposes to servers. Servers discover roots by sending a `roots/list` request to the client; clients notify servers when the list changes.
394
+
395
+
> [!TIP]
396
+
> To use roots, declare the `roots` capability when creating the client.
397
+
398
+
```swift
399
+
let client =Client(
400
+
name: "MyApp",
401
+
version: "1.0.0",
402
+
capabilities: .init(
403
+
roots: .init(listChanged: true)
404
+
)
405
+
)
406
+
407
+
// Register a handler for roots/list requests from servers
@@ -902,9 +939,6 @@ await server.withMethodHandler(Complete.self) { params in
902
939
903
940
Servers can request LLM completions from clients through sampling. This enables agentic behaviors where servers can ask for AI assistance while maintaining human oversight.
904
941
905
-
> [!NOTE]
906
-
> The current implementation provides the correct API design for sampling, but requires bidirectional communication support in the transport layer. This feature will be fully functional when bidirectional transport support is added.
907
-
908
942
```swift
909
943
// Enable sampling capability in server
910
944
let server =Server(
@@ -916,7 +950,7 @@ let server = Server(
916
950
)
917
951
)
918
952
919
-
// Request sampling from the client (conceptual - requires bidirectional transport)
953
+
// Request sampling from the connected client
920
954
do {
921
955
let result =tryawait server.requestSampling(
922
956
messages: [
@@ -983,6 +1017,35 @@ case .cancel:
983
1017
}
984
1018
```
985
1019
1020
+
For URL-based elicitation (e.g., OAuth flows), use the URL overload:
|`[StdioTransport](/Sources/MCP/Base/Transports/StdioTransport.swift)`| Implements [stdio transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#stdio) using standard input/output streams | Apple platforms, Linux with glibc | Local subprocesses, CLI tools |
1231
-
|`[HTTPClientTransport](/Sources/MCP/Base/Transports/HTTPClientTransport.swift)`| Implements [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http) using Foundation's URL Loading System | All platforms with Foundation | Remote servers, web applications |
1232
-
|`[InMemoryTransport](/Sources/MCP/Base/Transports/InMemoryTransport.swift)`| Custom in-memory transport for direct communication within the same process | All platforms | Testing, debugging, same-process client-server communication |
1233
-
|`[NetworkTransport](/Sources/MCP/Base/Transports/NetworkTransport.swift)`| Custom transport using Apple's Network framework for TCP/UDP connections | Apple platforms only | Low-level networking, custom protocols |
1291
+
| Transport | Description | Platforms | Best for |
|`[StdioTransport](/Sources/MCP/Base/Transports/StdioTransport.swift)`| Implements [stdio transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#stdio) using standard input/output streams | Apple platforms, Linux with glibc | Local subprocesses, CLI tools |
1294
+
|`[HTTPClientTransport](/Sources/MCP/Base/Transports/HTTPClientTransport.swift)`| Implements [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http) using Foundation's URL Loading System | All platforms with Foundation | Remote servers, web applications |
1295
+
|`[StatelessHTTPServerTransport](/Sources/MCP/Base/Transports/HTTPServer/StatelessHTTPServerTransport.swift)`| HTTP server transport with simple request-response semantics; no session management or SSE streaming | All platforms with Foundation | Simple HTTP servers, serverless/edge functions |
1296
+
|`[StatefulHTTPServerTransport](/Sources/MCP/Base/Transports/HTTPServer/StatefulHTTPServerTransport.swift)`| HTTP server transport with full session management and SSE streaming for server-initiated messages | All platforms with Foundation | Full-featured HTTP servers, streaming notifications |
1297
+
|`[InMemoryTransport](/Sources/MCP/Base/Transports/InMemoryTransport.swift)`| Custom in-memory transport for direct communication within the same process | All platforms | Testing, debugging, same-process client-server communication |
1298
+
|`[NetworkTransport](/Sources/MCP/Base/Transports/NetworkTransport.swift)`| Custom transport using Apple's Network framework for TCP/UDP connections | Apple platforms only | Low-level networking, custom protocols |
0 commit comments