Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a654819
feat(mcp): support read config from .yml
digitzh Aug 29, 2025
693c39c
Merge branch 'alibaba:main' into main
digitzh Sep 1, 2025
6106b85
add license
digitzh Sep 1, 2025
826dc0b
style(mcp): spring-javaformat fix
digitzh Sep 1, 2025
97a4e5f
Merge branch 'alibaba:main' into main
digitzh Sep 1, 2025
0992beb
Update auto-configurations/spring-ai-alibaba-autoconfigure-mcp-router…
digitzh Sep 2, 2025
0962b8a
Removing placeholder comment
digitzh Sep 2, 2025
3f3d8c5
Merge branch 'alibaba:main' into main
digitzh Sep 4, 2025
05e8fb6
style: use English comments
digitzh Sep 4, 2025
4c9ca11
feat: use auto configuration for discovery services
digitzh Sep 4, 2025
6d9b95b
style: spring-javaformat fix
digitzh Sep 4, 2025
5b61b40
style: spring-javaformat fix
digitzh Sep 4, 2025
299a442
Merge branch 'main' of github.com:digitzh/spring-ai-alibaba
digitzh Sep 4, 2025
885c380
Merge branch 'alibaba:main' into main
digitzh Sep 8, 2025
7c46365
fix(mcp): merge @ConditionalOnExpression
digitzh Sep 8, 2025
4661573
style: spring-javaformat fix
digitzh Sep 8, 2025
6f7e836
feat(mcp): support read config from database (MySQL, etc.)
digitzh Sep 9, 2025
1dcdd68
fix(mcp): 优化资源关闭逻辑
digitzh Sep 10, 2025
95b6b81
fix(mcp): use @AutoConfiguration
digitzh Sep 10, 2025
e10260a
Merge branch 'alibaba:main' into feature/config_db
digitzh Sep 11, 2025
e2dd037
Merge branch 'main' into feature/config_db
digitzh Sep 16, 2025
e086c9a
feat(mcp): support multi-source read of MCP service
digitzh Sep 18, 2025
00c46a1
Merge branch 'alibaba:main' into feature/config_db
digitzh Sep 18, 2025
a9c7069
fix(mcp): make log message generic
digitzh Sep 18, 2025
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
@@ -0,0 +1,47 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed 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
*
* https://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 com.alibaba.cloud.ai.autoconfigure.mcp.router;

import com.alibaba.cloud.ai.mcp.router.config.McpRouterProperties;
import com.alibaba.cloud.ai.mcp.router.config.DbMcpProperties;
import com.alibaba.cloud.ai.mcp.router.core.discovery.McpServiceDiscovery;
import com.alibaba.cloud.ai.mcp.router.core.discovery.DbMcpServiceDiscovery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author digitzh
*/
@Configuration
@EnableConfigurationProperties({ McpRouterProperties.class, DbMcpProperties.class })
@ConditionalOnExpression("$" + "{" + McpRouterProperties.CONFIG_PREFIX + ".enabled:true} == true " + "and '$" + "{"
+ McpRouterProperties.CONFIG_PREFIX + ".discovery-type}' == 'database'")
public class DbMcpRouterAutoConfiguration {

private static final Logger log = LoggerFactory.getLogger(DbMcpRouterAutoConfiguration.class);

@Bean
public McpServiceDiscovery mySqlMcpServiceDiscovery(DbMcpProperties dbMcpProperties) {
log.info("Creating DB MCP service discovery with configuration: {}", dbMcpProperties);
return new DbMcpServiceDiscovery(dbMcpProperties);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed 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
*
* https://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 com.alibaba.cloud.ai.autoconfigure.mcp.router;

import com.alibaba.cloud.ai.mcp.router.config.McpRouterProperties;
import com.alibaba.cloud.ai.mcp.router.core.discovery.FileConfigMcpServiceDiscovery;
import com.alibaba.cloud.ai.mcp.router.core.discovery.McpServiceDiscovery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author digitzh
*/
@Configuration
@EnableConfigurationProperties(McpRouterProperties.class)
@ConditionalOnExpression("${" + McpRouterProperties.CONFIG_PREFIX + ".enabled:true} == true " + "and '${"
+ McpRouterProperties.CONFIG_PREFIX + ".discovery-type}' == 'file'")
public class FileMcpRouterAutoConfiguration {

private static final Logger log = LoggerFactory.getLogger(FileMcpRouterAutoConfiguration.class);

@Bean
public McpServiceDiscovery fileConfigMcpServiceDiscovery(McpRouterProperties properties) {
return new FileConfigMcpServiceDiscovery(properties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# limitations under the License.
#
com.alibaba.cloud.ai.autoconfigure.mcp.router.NacosMcpRouterAutoConfiguration
com.alibaba.cloud.ai.autoconfigure.mcp.router.FileMcpRouterAutoConfiguration
com.alibaba.cloud.ai.autoconfigure.mcp.router.DbMcpRouterAutoConfiguration

com.alibaba.cloud.ai.autoconfigure.mcp.gateway.core.McpGatewayServerAutoConfiguration
#com.alibaba.cloud.ai.autoconfigure.mcp.gateway.core.McpGatewaySseServerAutoConfiguration
#com.alibaba.cloud.ai.autoconfigure.mcp.gateway.core.McpGatewayStreamableServerAutoConfiguration
com.alibaba.cloud.ai.autoconfigure.mcp.gateway.nacos.NacosMcpGatewayAutoConfiguration

Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void testStreamImageResponse() {

/**
* Integration test for image processing with URL This test will only run if
* DASHSCOPE_API_KEY environment variable is set
* AI_DASHSCOPE_API_KEY environment variable is set
*/
@Test
@Tag("integration")
Expand Down
4 changes: 4 additions & 0 deletions spring-ai-alibaba-mcp/spring-ai-alibaba-mcp-router/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed 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
*
* https://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 com.alibaba.cloud.ai.mcp.router.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = DbMcpProperties.CONFIG_PREFIX)
public class DbMcpProperties {

public static final String CONFIG_PREFIX = "spring.ai.alibaba.mcp.router.database";

private String url;

private String username;

private String password;

private String driverClassName = "com.mysql.cj.jdbc.Driver";

private String tableName = "mcp_server_info";

private String querySql;

private int maxPoolSize = 10;

private int minIdle = 2;

private long connectionTimeout = 30000;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getDriverClassName() {
return driverClassName;
}

public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}

public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

public String getQuerySql() {
return querySql;
}

public void setQuerySql(String querySql) {
this.querySql = querySql;
}

public int getMaxPoolSize() {
return maxPoolSize;
}

public void setMaxPoolSize(int maxPoolSize) {
this.maxPoolSize = maxPoolSize;
}

public int getMinIdle() {
return minIdle;
}

public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}

public long getConnectionTimeout() {
return connectionTimeout;
}

public void setConnectionTimeout(long connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.alibaba.cloud.ai.mcp.router.config;

import com.alibaba.cloud.ai.mcp.router.model.McpServerInfo;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
Expand All @@ -27,13 +28,10 @@ public class McpRouterProperties {

public static final String CONFIG_PREFIX = "spring.ai.alibaba.mcp.router";

/**
* 是否启用 MCP 路由器
*/
private boolean enabled = true;

/**
* MCP 路由器服务名称
* MCP router service names
*/
private List<String> serviceNames = new ArrayList<>();

Expand All @@ -53,4 +51,30 @@ public void setServiceNames(final List<String> serviceNames) {
this.serviceNames = serviceNames;
}

/**
* MCP router service configurations
*/
private List<McpServerInfo> services = new ArrayList<>();

public List<McpServerInfo> getServices() {
return services;
}

public void setServices(List<McpServerInfo> services) {
this.services = services;
}

/**
* MCP router service discovery type (nacos, file, database)
*/
private String discoveryType = "nacos"; // Nacos for default

public String getDiscoveryType() {
return discoveryType;
}

public void setDiscoveryType(String discoveryType) {
this.discoveryType = discoveryType;
}

}
Loading
Loading