File tree Expand file tree Collapse file tree 4 files changed +91
-4
lines changed
auto-configurations/mcp/spring-ai-autoconfigure-mcp-server/src
main/java/org/springframework/ai/mcp/server/autoconfigure
test/java/org/springframework/ai/mcp/server/autoconfigure Expand file tree Collapse file tree 4 files changed +91
-4
lines changed Original file line number Diff line number Diff line change 20
20
import io .modelcontextprotocol .server .transport .WebFluxSseServerTransportProvider ;
21
21
import io .modelcontextprotocol .spec .McpServerTransportProvider ;
22
22
23
+ import org .springframework .beans .factory .ObjectProvider ;
23
24
import org .springframework .boot .autoconfigure .AutoConfiguration ;
24
25
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
25
26
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
@@ -73,8 +74,10 @@ public class McpWebFluxServerAutoConfiguration {
73
74
74
75
@ Bean
75
76
@ ConditionalOnMissingBean
76
- public WebFluxSseServerTransportProvider webFluxTransport (McpServerProperties serverProperties ) {
77
- return new WebFluxSseServerTransportProvider (new ObjectMapper (), serverProperties .getSseMessageEndpoint ());
77
+ public WebFluxSseServerTransportProvider webFluxTransport (ObjectProvider <ObjectMapper > objectMapperProvider ,
78
+ McpServerProperties serverProperties ) {
79
+ ObjectMapper objectMapper = objectMapperProvider .getIfAvailable (ObjectMapper ::new );
80
+ return new WebFluxSseServerTransportProvider (objectMapper , serverProperties .getSseMessageEndpoint ());
78
81
}
79
82
80
83
// Router function for SSE transport used by Spring WebFlux to start an HTTP server.
Original file line number Diff line number Diff line change 20
20
import io .modelcontextprotocol .server .transport .WebMvcSseServerTransportProvider ;
21
21
import io .modelcontextprotocol .spec .McpServerTransportProvider ;
22
22
23
+ import org .springframework .beans .factory .ObjectProvider ;
23
24
import org .springframework .boot .autoconfigure .AutoConfiguration ;
24
25
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
25
26
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
@@ -68,8 +69,9 @@ public class McpWebMvcServerAutoConfiguration {
68
69
69
70
@ Bean
70
71
@ ConditionalOnMissingBean
71
- public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider (ObjectMapper objectMapper ,
72
- McpServerProperties serverProperties ) {
72
+ public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider (
73
+ ObjectProvider <ObjectMapper > objectMapperProvider , McpServerProperties serverProperties ) {
74
+ ObjectMapper objectMapper = objectMapperProvider .getIfAvailable (ObjectMapper ::new );
73
75
return new WebMvcSseServerTransportProvider (objectMapper , serverProperties .getSseMessageEndpoint ());
74
76
}
75
77
Original file line number Diff line number Diff line change
1
+ package org .springframework .ai .mcp .server .autoconfigure ;
2
+
3
+ import com .fasterxml .jackson .databind .ObjectMapper ;
4
+ import io .modelcontextprotocol .server .transport .WebFluxSseServerTransportProvider ;
5
+ import org .junit .jupiter .api .Test ;
6
+
7
+ import org .springframework .boot .autoconfigure .AutoConfigurations ;
8
+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
9
+ import org .springframework .web .reactive .function .server .RouterFunction ;
10
+
11
+ import static org .assertj .core .api .Assertions .assertThat ;
12
+
13
+ class McpWebFluxServerAutoConfigurationIT {
14
+
15
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ().withConfiguration (
16
+ AutoConfigurations .of (McpWebFluxServerAutoConfiguration .class , McpServerAutoConfiguration .class ));
17
+
18
+ @ Test
19
+ void defaultConfiguration () {
20
+ this .contextRunner .run (context -> {
21
+ assertThat (context ).hasSingleBean (WebFluxSseServerTransportProvider .class );
22
+ assertThat (context ).hasSingleBean (RouterFunction .class );
23
+ });
24
+ }
25
+
26
+ @ Test
27
+ void objectMapperConfiguration () {
28
+ this .contextRunner .withBean (ObjectMapper .class , ObjectMapper ::new ).run (context -> {
29
+ assertThat (context ).hasSingleBean (WebFluxSseServerTransportProvider .class );
30
+ assertThat (context ).hasSingleBean (RouterFunction .class );
31
+ });
32
+ }
33
+
34
+ @ Test
35
+ void stdioEnabledConfiguration () {
36
+ this .contextRunner .withPropertyValues ("spring.ai.mcp.server.stdio=true" ).run (context -> {
37
+ assertThat (context ).doesNotHaveBean (WebFluxSseServerTransportProvider .class );
38
+ });
39
+ }
40
+
41
+ }
Original file line number Diff line number Diff line change
1
+ package org .springframework .ai .mcp .server .autoconfigure ;
2
+
3
+ import com .fasterxml .jackson .databind .ObjectMapper ;
4
+ import io .modelcontextprotocol .server .transport .WebMvcSseServerTransportProvider ;
5
+ import org .junit .jupiter .api .Test ;
6
+
7
+ import org .springframework .boot .autoconfigure .AutoConfigurations ;
8
+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
9
+ import org .springframework .web .servlet .function .RouterFunction ;
10
+
11
+ import static org .assertj .core .api .Assertions .assertThat ;
12
+
13
+ class McpWebMvcServerAutoConfigurationTest {
14
+
15
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ().withConfiguration (
16
+ AutoConfigurations .of (McpWebMvcServerAutoConfiguration .class , McpServerAutoConfiguration .class ));
17
+
18
+ @ Test
19
+ void defaultConfiguration () {
20
+ this .contextRunner .run (context -> {
21
+ assertThat (context ).hasSingleBean (WebMvcSseServerTransportProvider .class );
22
+ assertThat (context ).hasSingleBean (RouterFunction .class );
23
+ });
24
+ }
25
+
26
+ @ Test
27
+ void objectMapperConfiguration () {
28
+ this .contextRunner .withBean (ObjectMapper .class , ObjectMapper ::new ).run (context -> {
29
+ assertThat (context ).hasSingleBean (WebMvcSseServerTransportProvider .class );
30
+ assertThat (context ).hasSingleBean (RouterFunction .class );
31
+ });
32
+ }
33
+
34
+ @ Test
35
+ void stdioEnabledConfiguration () {
36
+ this .contextRunner .withPropertyValues ("spring.ai.mcp.server.stdio=true" ).run (context -> {
37
+ assertThat (context ).doesNotHaveBean (WebMvcSseServerTransportProvider .class );
38
+ });
39
+ }
40
+
41
+ }
You can’t perform that action at this time.
0 commit comments