-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(mcp): support read config from database (MySQL, etc.) #2368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 693c39c
Merge branch 'alibaba:main' into main
digitzh 6106b85
add license
digitzh 826dc0b
style(mcp): spring-javaformat fix
digitzh 97a4e5f
Merge branch 'alibaba:main' into main
digitzh 0992beb
Update auto-configurations/spring-ai-alibaba-autoconfigure-mcp-router…
digitzh 0962b8a
Removing placeholder comment
digitzh 3f3d8c5
Merge branch 'alibaba:main' into main
digitzh 05e8fb6
style: use English comments
digitzh 4c9ca11
feat: use auto configuration for discovery services
digitzh 6d9b95b
style: spring-javaformat fix
digitzh 5b61b40
style: spring-javaformat fix
digitzh 299a442
Merge branch 'main' of github.com:digitzh/spring-ai-alibaba
digitzh 885c380
Merge branch 'alibaba:main' into main
digitzh 7c46365
fix(mcp): merge @ConditionalOnExpression
digitzh 4661573
style: spring-javaformat fix
digitzh 6f7e836
feat(mcp): support read config from database (MySQL, etc.)
digitzh 1dcdd68
fix(mcp): 优化资源关闭逻辑
digitzh 95b6b81
fix(mcp): use @AutoConfiguration
digitzh e10260a
Merge branch 'alibaba:main' into feature/config_db
digitzh e2dd037
Merge branch 'main' into feature/config_db
digitzh e086c9a
feat(mcp): support multi-source read of MCP service
digitzh 00c46a1
Merge branch 'alibaba:main' into feature/config_db
digitzh a9c7069
fix(mcp): make log message generic
digitzh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...main/java/com/alibaba/cloud/ai/autoconfigure/mcp/router/DbMcpRouterAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '$" + "{" | ||
digitzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
+ McpRouterProperties.CONFIG_PREFIX + ".discovery-type}' == 'database'") | ||
digitzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...in/java/com/alibaba/cloud/ai/autoconfigure/mcp/router/FileMcpRouterAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
digitzh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
@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); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...baba-mcp-router/src/main/java/com/alibaba/cloud/ai/mcp/router/config/DbMcpProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.