ramu11 commented on code in PR #2094: URL: https://github.com/apache/camel-spring-boot/pull/2094#discussion_r4577172364
########## components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerTransportAutoConfiguration.java: ########## @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.springboot.mcp.server; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import io.modelcontextprotocol.json.jackson3.JacksonMcpJsonMapper; +import io.modelcontextprotocol.server.transport.DefaultServerTransportSecurityValidator; +import io.modelcontextprotocol.server.transport.ServerTransportSecurityValidator; +import org.apache.camel.component.mcp.server.McpServerOrigins; +import org.springframework.ai.mcp.server.common.autoconfigure.McpServerStdioDisabledCondition; +import org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerStreamableHttpProperties; +import org.springframework.ai.mcp.server.webmvc.transport.WebMvcStreamableServerTransportProvider; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import tools.jackson.databind.json.JsonMapper; + +/** + * Installs a principal-aware Spring AI WebMVC MCP transport. + * <p> + * This configuration runs before Spring AI's default WebMVC transport configuration. + * It preserves the Spring AI endpoint and keep-alive settings while adding a transport + * context extractor for authenticated caller identity. + * <p> + * An application-defined {@link WebMvcStreamableServerTransportProvider} takes precedence. + */ +@AutoConfiguration( + beforeName = "org.springframework.ai.mcp.server.webmvc.autoconfigure." + + "McpServerStreamableHttpWebMvcAutoConfiguration") +@ConditionalOnClass({ + WebMvcStreamableServerTransportProvider.class, + JacksonMcpJsonMapper.class +}) +@Conditional(McpServerStdioDisabledCondition.class) +@ConditionalOnProperty( + prefix = "camel.mcp-server", + name = "enabled", + havingValue = "true", + matchIfMissing = true) +@ConditionalOnProperty( + prefix = "spring.ai.mcp.server", + name = "protocol", + havingValue = "STREAMABLE", + matchIfMissing = false) +@EnableConfigurationProperties({ + McpServerStreamableHttpProperties.class, + McpServerConfigurationProperties.class +}) +public class CamelMcpServerTransportAutoConfiguration { + + private static final List<String> DEFAULT_ALLOWED_ORIGINS = List.of( + "http://localhost:*", "https://localhost:*", + "http://127.0.0.1:*", "https://127.0.0.1:*", + "http://[::1]:*", "https://[::1]:*"); + + @Bean + @ConditionalOnMissingBean(WebMvcStreamableServerTransportProvider.class) + WebMvcStreamableServerTransportProvider webMvcStreamableServerTransportProvider( Review Comment: Thanks for raising this. Addressed the transport-replacement concern by adding the separate `camel.mcp-server.transport-enabled` property. When unset, Camel replaces Spring AI's default transport only when Camel MCP tags are configured. Setting it to `true` enables Camel's transport even without Camel routes, while setting it to `false` preserves Spring AI's provider without disabling the Camel bridge. I also documented the behavior in the starter documentation. I'm clarifying the Camel 4.24 upgrade-guide entry to explain the default activation condition and make clear that Spring-only MCP applications are not affected by transport replacement when no Camel tags are configured. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
