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
### Customize HTTP requests beyond MCP Security's OAuth2 support
511
534
512
535
MCP Security's default client support integrates with Spring Security to add OAuth2 support. Essentially, it gets a
@@ -560,7 +583,8 @@ As such, thread-locals are not available in these lambda functions.
560
583
If you would like to use thread-locals in this context, use a `McpTransportContextProvider` bean.
561
584
It can extract thread-locals and make them available in an `McpTransportContext` object.
562
585
563
-
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):
564
588
565
589
```java
566
590
@@ -619,41 +643,9 @@ class McpConfiguration {
619
643
}
620
644
```
621
645
622
-
### Work around Spring AI autoconfiguration
623
-
624
-
Spring AI integrates MCP tools as if they were regular "tools" (e.g. `@Tool` methods).
625
-
As such, they are discovered when application starts up.
626
-
This means that any MCP client that is configured through configuration properties, such
627
-
as `spring.ai.mcp.client.streamable-http.connections.<SERVER-NAME>.url=...` will be initialized.
628
-
In practice, there will be multiple calls issued to the MCP Server (`initialize` followed by `tools/list`).
629
-
The server will require a token for these calls, and, without a user present, this is an issue in the general case.
630
-
631
-
To avoid this, you first need to ensure that the clients are not initialized on startup.
632
-
You can do so by setting the property `spring.ai.mcp.client.initialized=false`.
633
-
Then, you need to ensure tools are not listed. There are a few ways to avoid this:
634
-
635
-
**Disable the @Tool auto-configuration**
636
-
637
-
You can turn off Spring AI's `@Tool` autoconfiguration altogether.
638
-
This will disable all method and function-based tool calling, and only MCP tools will be available.
639
-
The easiest way to do so is to publish an empty `ToolCallbackResolver` bean:
640
-
641
-
```java
642
-
643
-
@Configuration
644
-
publicclassMcpConfiguration {
645
-
646
-
@Bean
647
-
ToolCallbackResolverresolver() {
648
-
returnnewStaticToolCallbackResolver(List.of());
649
-
}
650
-
651
-
}
652
-
```
653
-
654
-
**Programmatically configure MCP clients**
646
+
### Programmatically configure MCP clients
655
647
656
-
You may also forego Spring AI's autoconfiguration altogether, and create the MCP clients programmatically.
648
+
If you'd like to use Spring AI's autoconfiguration altogether, you can create the MCP clients programmatically.
657
649
The easiest way is to draw some inspiration on the transport
Copy file name to clipboardExpand all lines: mcp-client-security/src/main/java/org/springaicommunity/mcp/security/client/sync/AuthenticationMcpTransportContextProvider.java
0 commit comments