Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.modelcontextprotocol.server.transport.WebFluxSseServerTransportProvider;
import io.modelcontextprotocol.spec.McpServerTransportProvider;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand Down Expand Up @@ -60,9 +61,9 @@
* }</pre>
*
* @author Christian Tzolov
* @since 1.0.0
* @see McpServerProperties
* @see WebFluxSseServerTransportProvider
* @since 1.0.0
*/
@AutoConfiguration
@ConditionalOnClass({ WebFluxSseServerTransportProvider.class })
Expand All @@ -73,8 +74,10 @@ public class McpWebFluxServerAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public WebFluxSseServerTransportProvider webFluxTransport(McpServerProperties serverProperties) {
return new WebFluxSseServerTransportProvider(new ObjectMapper(), serverProperties.getSseMessageEndpoint());
public WebFluxSseServerTransportProvider webFluxTransport(ObjectProvider<ObjectMapper> objectMapperProvider,
McpServerProperties serverProperties) {
ObjectMapper objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new);
return new WebFluxSseServerTransportProvider(objectMapper, serverProperties.getSseMessageEndpoint());
}

// Router function for SSE transport used by Spring WebFlux to start an HTTP server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.modelcontextprotocol.server.transport.WebMvcSseServerTransportProvider;
import io.modelcontextprotocol.spec.McpServerTransportProvider;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand Down Expand Up @@ -68,8 +69,9 @@ public class McpWebMvcServerAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider(ObjectMapper objectMapper,
McpServerProperties serverProperties) {
public WebMvcSseServerTransportProvider webMvcSseServerTransportProvider(
ObjectProvider<ObjectMapper> objectMapperProvider, McpServerProperties serverProperties) {
ObjectMapper objectMapper = objectMapperProvider.getIfAvailable(ObjectMapper::new);
return new WebMvcSseServerTransportProvider(objectMapper, serverProperties.getSseMessageEndpoint());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.springframework.ai.mcp.server.autoconfigure;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.modelcontextprotocol.server.transport.WebFluxSseServerTransport;
import io.modelcontextprotocol.server.transport.WebFluxSseServerTransportProvider;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.web.reactive.function.server.RouterFunction;

import static org.assertj.core.api.Assertions.assertThat;

class McpWebFluxServerAutoConfigurationIT {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(McpWebFluxServerAutoConfiguration.class, McpServerAutoConfiguration.class));

@Test
void defaultConfiguration() {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(WebFluxSseServerTransportProvider.class);
assertThat(context).hasSingleBean(RouterFunction.class);
});
}

@Test
void objectMapperConfiguration() {
this.contextRunner.withBean(ObjectMapper.class, ObjectMapper::new).run(context -> {
assertThat(context).hasSingleBean(WebFluxSseServerTransportProvider.class);
assertThat(context).hasSingleBean(RouterFunction.class);
});
}

@Test
void stdioEnabledConfiguration() {
this.contextRunner.withPropertyValues("spring.ai.mcp.server.stdio=true").run(context -> {
assertThat(context).doesNotHaveBean(WebFluxSseServerTransportProvider.class);
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.springframework.ai.mcp.server.autoconfigure;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.modelcontextprotocol.server.transport.WebMvcSseServerTransportProvider;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.web.servlet.function.RouterFunction;
import static org.assertj.core.api.Assertions.assertThat;

class McpWebMvcServerAutoConfigurationIT {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(McpWebMvcServerAutoConfiguration.class, McpServerAutoConfiguration.class));

@Test
void defaultConfiguration() {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(WebMvcSseServerTransportProvider.class);
assertThat(context).hasSingleBean(RouterFunction.class);
});
}

@Test
void objectMapperConfiguration() {
this.contextRunner.withBean(ObjectMapper.class, ObjectMapper::new).run(context -> {
assertThat(context).hasSingleBean(WebMvcSseServerTransportProvider.class);
assertThat(context).hasSingleBean(RouterFunction.class);
});
}

@Test
void stdioEnabledConfiguration() {
this.contextRunner.withPropertyValues("spring.ai.mcp.server.stdio=true").run(context -> {
assertThat(context).doesNotHaveBean(WebMvcSseServerTransportProvider.class);
});
}

}