[feat]: shenyu mcp plugin auto register#6163
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces ShenYu MCP (Message Communication Protocol) plugin auto-registration functionality, enabling automatic service discovery and registration for MCP tools and services.
- Add complete MCP client and server-side auto-registration infrastructure
- Implement OpenAPI-based MCP tool configuration and metadata generation
- Create comprehensive example application demonstrating MCP integration
Reviewed Changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-mcp/ | Spring Boot starter module for MCP client integration |
| shenyu-register-center/ | Core registration DTOs and client repository support for MCP tools |
| shenyu-examples/shenyu-examples-mcp/ | Example application showcasing MCP plugin usage |
| shenyu-common/ | Added MCP RPC type enum and plugin name adapter support |
| shenyu-client/shenyu-client-mcp/ | Complete MCP client implementation with OpenAPI generators |
| shenyu-admin/ | Server-side MCP registration service and controller endpoints |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
.../main/java/org/apache/shenyu/springboot/starter/client/mcp/ShenyuMcpClientConfiguration.java
Outdated
Show resolved
Hide resolved
| this.doPersistMcpTools(registerDTO); | ||
| } catch (Exception ex) { | ||
| logger.warn("Failed to persistMcpTools {}, cause:{}", registerDTO, ex.getMessage()); | ||
| this.addFailureApiDocRegister(registerDTO); |
There was a problem hiding this comment.
The method call addFailureApiDocRegister(registerDTO) should be addFailureMcpToolsRegister(registerDTO) to properly handle MCP tools registration failures, not API doc registration failures.
There was a problem hiding this comment.
hi, this suggestion is right, u should do this
...lient-mcp/src/main/java/org/apache/shenyu/client/mcp/common/annotation/OpenApiParameter.java
Outdated
Show resolved
Hide resolved
| String MCP_TOOLS_TYPE = "mcp"; | ||
|
|
There was a problem hiding this comment.
There is trailing whitespace after the constant declaration. This should be removed to maintain code consistency.
...t/shenyu-client-mcp/src/main/java/org/apache/shenyu/client/mcp/common/annotation/Header.java
Outdated
Show resolved
Hide resolved
...u-client-mcp/src/main/java/org/apache/shenyu/client/mcp/common/annotation/OpenApiConfig.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 35 out of 36 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| /** | ||
| * the required of parameter key. | ||
| */ | ||
| public static final String OPEN_API_PATH_PATH_METHOD_PARAMETERS_REQUIRED_KEY = "description"; |
There was a problem hiding this comment.
The constant value should be 'required' instead of 'description' as this represents the required field of a parameter, not its description.
| public static final String OPEN_API_PATH_PATH_METHOD_PARAMETERS_REQUIRED_KEY = "description"; | |
| public static final String OPEN_API_PATH_PATH_METHOD_PARAMETERS_REQUIRED_KEY = "required"; |
| * | ||
| * @param clientConfig the client config | ||
| * @param shenyuClientRegisterRepository the shenyu client register repository | ||
| * @return the apache dubbo service bean listener |
There was a problem hiding this comment.
The return type documentation incorrectly mentions 'apache dubbo service bean listener' but should reference 'MCP service event listener' since this is for MCP, not Dubbo.
| * @return the apache dubbo service bean listener | |
| * @return the MCP service event listener |
| return superUrl; | ||
| } | ||
| return ""; |
There was a problem hiding this comment.
The logic is inverted. When superUrl is blank, it returns the blank value, but when it's not blank, it returns an empty string. This should return superUrl when it's not blank and empty string when it is blank.
| return superUrl; | |
| } | |
| return ""; | |
| return ""; | |
| } | |
| return superUrl; |
| /** | ||
| * the summary of method key. | ||
| */ | ||
| public static final String OPEN_API_PATH_PATH_METHOD_SUMMARY_KEY = "summary"; |
| /** | ||
| * the description of method key. | ||
| */ | ||
| public static final String OPEN_API_PATH_PATH_METHOD_DESCRIPTION_KEY = "description"; |
There was a problem hiding this comment.
double PATH, is that right?
| /** | ||
| * the operationId of method key. | ||
| */ | ||
| public static final String OPEN_API_PATH_PATH_METHOD_OPERATION_ID_KEY = "operationId"; |
| /** | ||
| * the tag of method key. | ||
| */ | ||
| public static final String OPEN_API_PATH_PATH_METHOD_TAG_KEY = "tag"; |
| /** | ||
| * the openApi generator. | ||
| */ | ||
| public class McpOpenApiGenerator { |
There was a problem hiding this comment.
this class should be put in a single module. such as mcp common or mcp core. cause this class may be general
| /** | ||
| * the mcpRequestConfig generator. | ||
| */ | ||
| public class McpRequestConfigGenerator { |
There was a problem hiding this comment.
this class should be put in a single module. such as mcp common or mcp core. cause this class may be general
| /** | ||
| * When register by http, the mcpTools path. | ||
| */ | ||
| String MCP_TOOLS_PATH = "/shenyu-client/register-mcpTools"; |
There was a problem hiding this comment.
just "/shenyu-client/register-mcp" is fine
| * @return the order dto | ||
| */ | ||
| @GetMapping("/findById") | ||
| @ShenyuMcpClient( |
There was a problem hiding this comment.
ShenyuMcpClient is confusing, i think it is better to be called such as: ShenyuMcpTool.
|
hi, u can take a look at this link: https://docs.spring.io/spring-ai/reference/1.1-SNAPSHOT/api/mcp/mcp-annotations-overview.html |
There was a problem hiding this comment.
why rename? maybe u want to copy from this file? but made a mistake?
| JsonObject method = path.getAsJsonObject(operation.method()); | ||
| JsonArray parameters = method.getAsJsonArray(OpenApiConstants.OPEN_API_PATH_OPERATION_METHOD_PARAMETERS_KEY); | ||
|
|
||
| root.addProperty("name", classMcpClient.toolName()); |
|
|
||
| io.swagger.v3.oas.annotations.media.Schema schemaAnn = annotation.schema(); | ||
| if (!schemaAnn.implementation().equals(Void.class) | ||
| || !"".equals(schemaAnn.type()) |
|
|
||
| <dependency> | ||
| <groupId>org.springdoc</groupId> | ||
| <artifactId>springdoc-openapi-starter-common</artifactId> |
…into mcp-auto-register
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.