Skip to content

Commit 62e6c9c

Browse files
committed
README: document chatClient...stream() usage
Signed-off-by: Daniel Garnier-Moiroux <[email protected]>
1 parent de4a454 commit 62e6c9c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,27 @@ class McpConfiguration {
509509
}
510510
```
511511

512+
### Use with streaming chat client
513+
514+
When using the `.stream()` method of the chat client, you will be using Reactor under the hood. Reactor does not
515+
guarantee on which thread the work is executed, and will lose thread locals. You need to manually extract the
516+
information and inject it in the Reactor context:
517+
518+
```java
519+
class Example {
520+
521+
void doTheThing() {
522+
chatClient
523+
.prompt("<your prompt>")
524+
.stream()
525+
.content()
526+
// ... any streaming operation ...
527+
.contextWrite(AuthenticationMcpTransportContextProvider.writeToReactorContext());
528+
}
529+
530+
}
531+
```
532+
512533
### Customize HTTP requests beyond MCP Security's OAuth2 support
513534

514535
MCP Security's default client support integrates with Spring Security to add OAuth2 support. Essentially, it gets a
@@ -562,7 +583,8 @@ As such, thread-locals are not available in these lambda functions.
562583
If you would like to use thread-locals in this context, use a `McpTransportContextProvider` bean.
563584
It can extract thread-locals and make them available in an `McpTransportContext` object.
564585

565-
For HttpClient-based request customizers, the `McpTransportContext` will be available in the `customize` method. See, for example, with a Sync client (async works similarly):
586+
For HttpClient-based request customizers, the `McpTransportContext` will be available in the `customize` method. See,
587+
for example, with a Sync client (async works similarly):
566588

567589
```java
568590

0 commit comments

Comments
 (0)