Pre-check

  • [x] I am sure that all the content I provide is in English.

Search before asking

  • [x] I had searched in the issues and found no similar feature requirement.

Apache Dubbo Component

Java SDK (apache/dubbo)

Descriptions

Background

To better help developers expose Dubbo services as AI capabilities and enhance the integration with AI systems, we propose integrating the MCP (Model Control Protocol) with Dubbo. This integration will: - Support automatic service export as MCP tools - Enable client-side invocation based on MCP SSE mode

Overview

This proposal outlines the integration of Apache Dubbo with MCP, enabling Dubbo services to be exposed as MCP tools. This integration facilitates seamless communication between Dubbo services and MCP-compatible systems.

Features

1. Configuration Options

  • dubbo.mcp.enabled: Enable/disable MCP integration (default: false)
  • dubbo.mcp.sse.endpoint: Server-Sent Events (SSE) endpoint path (default: /dubbo/mcp/sse)

Note: These configuration options are only available when using the Triple protocol. Non-Triple protocols will result in an error. This version only supports the Triple-REST protocol.

2. Core Functionality

  • Automatic SSE connection establishment through the configured endpoint
  • Support for @DubboService annotation to register Dubbo interface methods as MCP tools
  • Annotation attributes:
  • mcp: Enable/disable MCP server (default: false)
  • Automatic data retrieval from Triple OpenAPI when annotation attributes are empty

Implementation Details

Service Initialization

  1. During application startup, verify mcp.server.enabled=true
  2. If enabled, automatically register a Triple protocol server
  3. Expose the configured SSE endpoint

Service Registration

  1. Scan services for @DubboService annotations
  2. Validate methods to ensure Triple protocol compatibility
  3. For annotated services:
  4. Register name and description with MCP
  5. Convert method parameters to JSON Schema
  6. Register with McpServer using mcp-java-sdk

Impact

  • New feature addition
  • No breaking changes to existing functionality
  • Requires Triple protocol support

Alternatives Considered

  • Direct integration without MCP protocol
  • Custom protocol implementation

References

  • MCP Protocol Specification
  • Triple Protocol Documentation

Related issues

No response

Are you willing to submit a pull request to fix on your own?

  • [ ] Yes I am willing to submit a pull request on my own!

Code of Conduct

Comment From: heliang666s

Thank you for your proposal! I think adding the mcp.enabled attribute in the @DubboService annotation is a good start. However, to better support MCP functionality, I recommend nesting a @McpMethod annotation within @DubboService to describe the method's functionality and parameters. This can provide more detailed API documentation and reduce the user’s learning curve.

Furthermore, I suggest considering the reuse of OpenAPI annotations like @Operation and @Parameter, which would ensure compatibility with existing OpenAPI documentation generation tools, improving the consistency and maintainability of the documentation.

@DubboService(mcp = true)
public class PurchaseOrderServiceImpl implements PurchaseOrderService {

    @McpMethod(
        description = "Create a purchase order",
        parameters = {
            @McpParameter(name = "orderId", description = "Unique identifier for the order"),
            @McpParameter(name = "vendorCode", description = "Vendor code"),
            @McpParameter(name = "itemDescription", description = "Description of the item"),
            @McpParameter(name = "price", description = "Order amount"),
            @McpParameter(name = "currency", description = "Currency type")
        }
    )
    public void createPurchaseOrder(String orderId, String vendorCode, String itemDescription, double price, String currency) {
        // Method implementation
    }
}

This approach will not only reduce the user’s cost but also maintain a well-structured documentation, making it easier for integration with AI systems.

Comment From: Stellar1999

Thank you for your proposal! I think adding the mcp.enabled attribute in the @DubboService annotation is a good start. However, to better support MCP functionality, I recommend nesting a @McpMethod annotation within @DubboService to describe the method's functionality and parameters. This can provide more detailed API documentation and reduce the user’s learning curve.

Furthermore, I suggest considering the reuse of OpenAPI annotations like @Operation and @Parameter, which would ensure compatibility with existing OpenAPI documentation generation tools, improving the consistency and maintainability of the documentation.

@DubboService(mcp = true) public class PurchaseOrderServiceImpl implements PurchaseOrderService {

@McpMethod(
    description = "Create a purchase order",
    parameters = {
        @McpParameter(name = "orderId", description = "Unique identifier for the order"),
        @McpParameter(name = "vendorCode", description = "Vendor code"),
        @McpParameter(name = "itemDescription", description = "Description of the item"),
        @McpParameter(name = "price", description = "Order amount"),
        @McpParameter(name = "currency", description = "Currency type")
    }
)
public void createPurchaseOrder(String orderId, String vendorCode, String itemDescription, double price, String currency) {
    // Method implementation
}

} This approach will not only reduce the user’s cost but also maintain a well-structured documentation, making it easier for integration with AI systems.

Thank you for your feedback. Based on my understanding of your suggestions, I will split it into two parts: the first part is to add a new annotation to identify MCP services, and the second part is to add new OpenAPI-like annotations to generate new documentation for MCP.

For the first part, I prefer to use the existing annotations because they better align with Dubbo's specifications and are more easily accepted by users. If we use a new annotation, considering that this annotation would seem particularly disconnected from the Dubbo framework and could even exist independently of Dubbo, I prefer to implement this as an extension rather than in the main repository.

For the second part, my thoughts are similar to yours, but based on the code, your suggestion is to extend an annotation within @Parameter. I prefer to directly use annotations like @Parameter, as this would require less modification and provide a better user experience.

Comment From: Gucvii

Thank you for your proposal! I think the idea of extending Dubbo with MCP functionality is fantastic, and I've carefully read the proposal and comments. I particularly appreciate the approach of leveraging OpenAPI annotations to provide method descriptions. However, I have a couple of questions and suggestions for consideration:

  1. MCP Primitives: In MCP, there are three primary primitives for server-side functionality: Tool, Prompt, and Resource. The mcp-java-sdk utilizes distinct methods (addTool, addResource, addPrompt) for registering these different types. I believe it would be highly beneficial for Dubbo to consider adding either a new annotation or annotation attributes to better align with the MCP standard.

  2. Granular Control Over Exposed Methods: My second point concerns which methods within a class annotated with @DubboService will be exposed to the MCP server endpoint. Users might have sensitive methods within their Dubbo services that they would not want large language models (LLMs) or other AI systems to be able to access (as this could potentially be hacked). Therefore, I think it's important to consider mechanisms for more granular control over which specific methods are exposed as MCP tools.

These are just my initial thoughts, and I'm eager to hear the community's perspectives on these points. I believe addressing these aspects will make the Dubbo MCP integration even more robust and secure.

Comment From: Stellar1999

Thank you for your proposal! I think the idea of extending Dubbo with MCP functionality is fantastic, and I've carefully read the proposal and comments. I particularly appreciate the approach of leveraging OpenAPI annotations to provide method descriptions. However, I have a couple of questions and suggestions for consideration:

  1. MCP Primitives: In MCP, there are three primary primitives for server-side functionality: Tool, Prompt, and Resource. The mcp-java-sdk utilizes distinct methods (addTool, addResource, addPrompt) for registering these different types. I believe it would be highly beneficial for Dubbo to consider adding either a new annotation or annotation attributes to better align with the MCP standard.
  2. Granular Control Over Exposed Methods: My second point concerns which methods within a class annotated with @DubboService will be exposed to the MCP server endpoint. Users might have sensitive methods within their Dubbo services that they would not want large language models (LLMs) or other AI systems to be able to access (as this could potentially be hacked). Therefore, I think it's important to consider mechanisms for more granular control over which specific methods are exposed as MCP tools.

These are just my initial thoughts, and I'm eager to hear the community's perspectives on these points. I believe addressing these aspects will make the Dubbo MCP integration even more robust and secure.

Thank you for your feedback. Regarding the first point, since this is our first integration, we are considering to first integrate with Tool, while temporarily not considering the other two options.

For the second point, I share your view. We might add parameters on the @DubboService to control which methods to expose.

Comment From: AlbumenJ

Great proposal, waiting for PR~

Comment From: Stellar1999

We have completed the first part of the project, which is available at: https://github.com/Stellar1999/dubbo-mcp-server. You can refer to the demo for an example of how to use a Dubbo application as an MCP server. We welcome any advice or feedback you may have!