Manage MCP services

Updated at:

Microservices Engine (MSE) Nacos Enterprise Edition supports registration and configuration management for MCP services, providing a standardized way to integrate external tools with a large language model (LLM).

Create an MCP service

This feature is available only in Microservices Engine (MSE) Nacos Enterprise Edition 3.0 and later. Based on your business needs, choose one of the following three ways to create an MCP service:

Create a standard MCP service

  1. Log on to the MSE console and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Registry > Instances, and then click the name of the target instance.

  3. In the left-side navigation pane, click MCP Registry, select a Namespaces, click Create MCP Service, and then click the Standard MCP Service tab.

  4. On the Standard MCP Service page, configure the basic information. Key parameters:

    • MCP Protocol Type:

      • Stdio: Lacks network capabilities, making it suitable for local development, debugging, and offline validation.

      • SSE: Used for unidirectional real-time communication scenarios, such as pushing configurations from an API Gateway. It offers low latency and high compatibility but only supports server-to-client streaming.

      • Streamable HTTP: Suitable for production environments and cross-network communication (such as in a hybrid cloud or cross-VPC scenario). It supports bidirectional communication.

    • Backend Service:

      • Use Existing Service: Select this option if your MCP service is already registered with MSE Nacos through the console or an SDK.

      • Create New Service: If your MCP service is not yet registered with MSE Nacos, you must configure the Service IP/Service Domain, Service Port, and Access Path. The path must start with a forward slash (/), for example, /v1/mcp.

  5. Click Save and Publish.

Create an HTTP-to-MCP service

  1. Log on to the MSE console and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Registry > Instances, and then click the name of the target instance.

  3. In the left-side navigation pane, click MCP Registry, select a Namespaces, click Create MCP Service, and then click the HTTP-to-MCP Service tab.

  4. On the HTTP-to-MCP Service tab, configure the basic information. Key parameters:

    • HTTPS Service: Specifies whether the original HTTP service uses HTTPS.

    • MCP Protocol:

      • SSE: Used for unidirectional real-time communication scenarios, such as pushing configurations from an API Gateway. It offers low latency and high compatibility but only supports server-to-client streaming.

      • Streamable HTTP: Suitable for production environments and cross-network communication (such as in a hybrid cloud or cross-VPC scenario). It supports bidirectional communication.

    • Backend Service:

      • Use Existing Service: Select this option if your HTTP service is already registered with MSE Nacos through the console or an SDK.

      • Create New Service: If your HTTP service is not yet registered with MSE Nacos, you must configure the Service IP/Service Domain and Service Port.

    • MCP Tool Configuration Encryption: When enabled, this feature uses Key Management Service (KMS) for encryption and decryption to reduce the risk of sensitive data leakage. For KMS Key, select an existing key name. If no key is available, you must first purchase and enable a KMS instance and then create a software-protected key.

  5. (Optional) Create an MCP tool.

  6. Click Save and Publish.

Dynamically register an MCP service

The Spring AI Alibaba framework and the Nacos MCP Wrapper for Python let you dynamically register an MCP Server with Nacos upon startup for centralized management. This approach supports the following capabilities:

  • Dynamic service management: Add, delete, modify, and query service information through the MCP service list.

  • Hot-update metadata: Update metadata such as tool descriptions and parameter definitions at runtime without restarting the service.

  • Dynamic toggling of MCP Server Tools: Enable or disable MCP Server tools at runtime without a service restart.

  • End-to-end integration: Service registration information is automatically synchronized with the Nacos configuration center and service discovery modules to accept calls from AI Agents.

MCP services can be deployed on Function Compute. For more information, see Deploy an MCP service in Function Compute and register it with MSE Nacos.

We recommend assigning a dedicated RAM user to the application, separate from the RAM user for console access, to prevent permission escalation risks.

  • If RAM authentication is enabled, you must use an AccessKey ID and AccessKey secret for identity verification.

  • If authentication is not enabled, use the open source username and password. The username is nacos. To get the password, go to the Instance List page, click the ID of the instance, and on the Basic Information page, click Reset next to Open Source Console Password. Then, copy the password.

Develop an MCP Server with Spring AI Alibaba

The spring-ai-alibaba version must be 1.0.0.3 or later.
1. Add dependencies
<dependency>
    <groupId>com.alibaba.cloud.ai</groupId>
    <artifactId>spring-ai-alibaba-starter-mcp-registry</artifactId>
    <version>{1.0.0.3 or later}</version>
</dependency>
<!-- MCP Server (WebMVC) -->
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
    <version>{1.0.0 or later}</version>
</dependency>
2. Define a service (example)
@Service
public class WeatherService {
  @Tool(description = "Get weather information by city name")
  public String getWeather(@ToolParam(description = "City name") String cityName) {
    return "Sunny in " + cityName;
  }
}
3. Configure Nacos registration parameters
spring:
  application:
    name: mcp-nacos-registry-example
  ai:
    mcp:
      server:
        name: webmvc-mcp-server   # MCP service name
        version: 1.0.0            # Service version
        type: SYNC                # Call type: SYNC (synchronous) or ASYNC (asynchronous)
        instructions: "This mcp server provides time information tools and resources"
    alibaba:
      mcp:
        nacos:
          server-addr:          # Replace with your Nacos address
          namespace: public    # Nacos namespace ID (default: public)
          access-key:           # your AccessKey ID
          secret-key:           # your AccessKey secret
          register:
            enabled: true   # Specifies whether to enable service registration
4. Start the service
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    @Bean
    public ToolCallbackProvider weatherTools(WeatherService weatherService) {
        return MethodToolCallbackProvider.builder().toolObjects(weatherService).build();
    }
}

Develop an MCP Server with Nacos MCP Wrapper

1. Prepare the environment
pip install nacos-mcp-wrapper-python
2. Configure automatic registration parameters
nacos_settings = NacosSettings()
nacos_settings.SERVER_ADDR = "127.0.0.1:8848" # <nacos_server_addr> e.g. 127.0.0.1:8848
nacos_settings.NAMESPACE= "public" # Nacos namespace ID
nacos_settings.ACCESS_KEY="" # your AccessKey ID
nacos_settings.SECRET_KEY="" # your AccessKey secret
3. Write the code
from nacos_mcp_wrapper.server.nacos_mcp import NacosMCP
from nacos_mcp_wrapper.server.nacos_settings import NacosSettings
# Create an MCP server instance
nacos_settings = NacosSettings()
nacos_settings.SERVER_ADDR = "127.0.0.1:8848"  # <nacos_server_addr> e.g. 127.0.0.1:8848
nacos_settings.ACCESS_KEY = ""
nacos_settings.SECRET_KEY = ""
mcp = NacosMCP("nacos-mcp-python", nacos_settings=nacos_settings, version="1.0.1", port=18001)
# Register an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two integers together"""
    return a + b
# Register a subtraction tool
@mcp.tool()
def minus(a: int, b: int) -> int:
    """Subtract two numbers"""
    return a - b
if __name__ == "__main__":
    try:
        mcp.run(transport="sse")
        # mcp.run(transport="stdio")
        # mcp.run(transport="streamable-http")
    except Exception as e:
        print(f"Runtime error: {e}")

FAQ

  1. The error mcp server info is not compatible or check mcp server compatible false occurs upon startup.

    This error occurs when the data of the MCP Server being registered is incompatible with the data for that version already in Nacos. To resolve this issue, ensure that the automatically registered MCP Server data is compatible with the data of the corresponding version in Nacos, including the following:

    • The MCP Server protocol (stdio, sse, or Streamable HTTP) must be consistent.

    • The service reference must be consistent.

    • The Tools data must be consistent (name, quantity, parameter types, and whether parameters are optional). The descriptions of tools and parameters do not need to be consistent.

Discover and call an MCP Server

We recommend assigning a dedicated RAM user to the application, separate from the RAM user for console access, to prevent permission escalation risks.

  • If RAM authentication is enabled, you must use an AccessKey ID and AccessKey secret for identity verification.

  • If authentication is not enabled, use the open source username and password. The username is nacos. To get the password, go to the Instance List page, click the ID of the instance, and on the Basic Information page, click Reset next to Open Source Console Password. Then, copy the password.

Discover and call with Spring AI Alibaba

1. Add dependencies
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-model-openai</artifactId>
    <version>{1.0.0 or later}</version>
</dependency>
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-autoconfigure-model-chat-client</artifactId>
    <version>{1.0.0 or later}</version>
</dependency>
<dependency>
    <groupId>com.alibaba.cloud.ai</groupId>
    <artifactId>spring-ai-alibaba-starter-mcp-registry</artifactId>
    <version>{1.0.0.3 or later}</version>
</dependency>
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-mcp-client-webflux</artifactId>
    <version>{1.0.0 or later}</version>
</dependency>

2. Create an async or sync MCP client

Declare a list of synchronous MCP clients:

@Autowired
 private List<LoadbalancedMcpSyncClient> loadbalancedMcpSyncClients;

Or, declare a list of asynchronous MCP clients:

 @Autowired
 private List<LoadbalancedMcpAsyncClient> loadbalancedMcpAsyncClients;

Inject synchronous tool callbacks using ToolCallbackProvider:

@Qualifier("loadbalancedSyncMcpToolCallbacks") ToolCallbackProvider tools

Or, inject asynchronous tool callbacks using ToolCallbackProvider:

@Qualifier("loadbalancedMcpAsyncToolCallbacks") ToolCallbackProvider tools

3. Configure application.yml

spring:
  application:
    name: mcp-client-webflux
  ai:
    openai:
      api-key: ${DASHSCOPE_API_KEY}
      base-url: https://dashscope.aliyuncs.com/compatible-mode
      chat:
        options:
          model: qwen-max
    alibaba:
      mcp:
        nacos:
          namespace: 4ad3108b-4d44-43d0-9634-3c1ac4850c8c
          server-addr: 127.0.0.1:8848
          access-key:           # your AccessKey ID
          secret-key:           # your AccessKey secret
          client:
            enabled: true
            sse:
              connections:
                server1:
                  service-name: webflux-mcp-server # The service name of the corresponding MCP Server in Nacos.
                  version: 1.0.0 # The version of the corresponding MCP Server in Nacos.
    mcp:
      client:
        enabled: true
        name: mcp-client-webflux
        version: 0.0.1
        initialized: true
        request-timeout: 600s
        type: sync
        toolcallback:
          enabled: true
        root-change-notification: true

4. Sample code

@SpringBootApplication
public class NacosMcpDiscoveryClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(NacosMcpDiscoveryClientApplication.class, args);
    }
    @Bean
    public CommandLineRunner predefinedQuestionsDemo(ChatClient.Builder chatClientBuilder, @Qualifier("loadbalancedMcpAsyncToolCallbacks") ToolCallbackProvider tools,
                                                 ConfigurableApplicationContext context) {
        return args -> {
            var chatClient = chatClientBuilder
                    .defaultToolCallbacks(tools.getToolCallbacks())
                    .build();
            Scanner scanner = new Scanner(System.in);
            while (true) {
                System.out.print("\n>>> QUESTION: ");
                String userInput = scanner.nextLine();
                if (userInput.equalsIgnoreCase("exit")) {
                    break;
                }
                if (userInput.isEmpty()) {
                    userInput = "What time is it in Beijing?";
                }
                System.out.println("\n>>> ASSISTANT: " + chatClient.prompt(userInput).call().content());
            }
            scanner.close();
            context.close();
        };
    }
}

Discover and call with Nacos MCP Router

The Nacos MCP Router has two working modes:

  • router mode: The default mode. The Nacos MCP Router acts as a standard MCP Server, providing features to recommend, distribute, install, and proxy other MCP Servers.

  • proxy mode: The Nacos MCP Router provides only the proxy feature. You can convert the stdio or sse protocol to the Streamable HTTP protocol without code changes.

Router mode

Stdio protocol

Start Nacos MCP Router:

Start with uvx:

{
  "mcpServers": {
    "nacos-mcp-router": {
      "command": "uvx",
      "args": [
        "nacos-mcp-router@latest"
      ],
      "env": {
        "NACOS_ADDR": "<NACOS-ADDR>, Optional, default: 127.0.0.1:8848",
        "ACCESS_KEY_ID": "<ACCESS_KEY_ID>, your AccessKey ID",
        "ACCESS_KEY_SECRET": "<ACCESS_KEY_SECRET>, your AccessKey secret"
      }
    }
  }
}

Start with Docker:

{
  "mcpServers": {
    "nacos-mcp-router": {
      "command": "docker",
      "args": [
        "run", 
        "-i", 
        "--rm", 
        "--network", 
        "host",  
        "-e", 
        "NACOS_ADDR=<NACOS-ADDR>", 
        "-e",  
        "ACCESS_KEY_ID=<ACCESS_KEY_ID>", 
        "-e", 
        "ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>", 
        "-e", 
        "TRANSPORT_TYPE=stdio", 
        "nacos-mcp-router:latest"
      ]
    }
  }
}

MCP configuration (example for CherryStudio):

{
    "mcpServers": {
        "nacos-mcp-router": {
            "command": "docker",
            "args": [
                "run", 
                "-i", 
                "--rm", 
                "--network", 
                "host",  
                "-e", 
                "NACOS_ADDR=<NACOS-ADDR>", 
                "-e",  
                "ACCESS_KEY_ID=<ACCESS_KEY_ID>", 
                "-e", 
                "ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET>",
                "-e", 
                "TRANSPORT_TYPE=stdio", 
                "nacos-mcp-router:latest"
            ]
        }
    }
}

SSE protocol

Start with uvx:

export NACOS_ADDR=127.0.0.1:8848
export ACCESS_KEY_ID=ACCESS_KEY_ID
export ACCESS_KEY_SECRET=ACCESS_KEY_SECRET
export TRANSPORT_TYPE=sse
uvx nacos-mcp-router@latest

Start with Docker:

docker run -i --rm --network host -e NACOS_ADDR=$NACOS_ADDR -e ACCESS_KEY_ID=$ACCESS_KEY_ID -e ACCESS_KEY_SECRET=$ACCESS_KEY_SECRET -e TRANSPORT_TYPE=sse nacos-mcp-router:latest

MCP configuration (example for CherryStudio):

{
    "mcpServers": {
        "nacos-mcp-router": {
            "url": "http://$router_ip:8000/sse"
        }
    }
}

Streamable HTTP protocol

Start with uvx:

export NACOS_ADDR=127.0.0.1:8848
export ACCESS_KEY_ID=ACCESS_KEY_ID
export ACCESS_KEY_SECRET=ACCESS_KEY_SECRET
export TRANSPORT_TYPE=streamable_http
uvx nacos-mcp-router@latest

Start with Docker:

docker run -i --rm --network host -e NACOS_ADDR=$NACOS_ADDR -e ACCESS_KEY_ID=$ACCESS_KEY_ID -e ACCESS_KEY_SECRET=$ACCESS_KEY_SECRET -e TRANSPORT_TYPE=streamable_http nacos-mcp-router:latest

MCP configuration (example for CherryStudio):

{
    "mcpServers": {
        "nacos-mcp-router": {
            "url": "http://$router_ip:8000/mcp"
        }
    }
}

Proxy mode

In proxy mode, you must set the environment variables MODE=proxy and PROXIED_MCP_NAME.

Use uvx:

export NACOS_ADDR=$NACOS_ADDR
export ACCESS_KEY_ID=$ACCESS_KEY_ID
export ACCESS_KEY_SECRET=$ACCESS_KEY_SECRET
export TRANSPORT_TYPE=streamable_http
export MODE=proxy
export PROXIED_MCP_NAME=$PROXIED_MCP_NAME
uvx nacos-mcp-router@latest

Use Docker:

docker run -i --rm --network host -e NACOS_ADDR=$NACOS_ADDR -e ACCESS_KEY_ID=$ACCESS_KEY_ID -e ACCESS_KEY_SECRET=$ACCESS_KEY_SECRET -e TRANSPORT_TYPE=streamable_http -e MODE=proxy -e PROXIED_MCP_NAME=$PROXIED_MCP_NAME  nacos-mcp-router:latest

Environment variable configuration:

Parameter

Description

Default

Required

Notes

NACOS_ADDR

The Nacos server address.

127.0.0.1:8848

No

Example: 192.168.1.1:8848. You must include the port number.

AccessKey ID

Your AccessKey ID.

-

No

AccessKey secret

Your AccessKey secret.

-

No

NACOS_NAMESPACE

The Nacos namespace.

public

No

Example: public

TRANSPORT_TYPE

The transport protocol type.

stdio

No

Valid values: stdio, sse, and streamable_http.

PROXIED_MCP_NAME

The name of the proxied MCP server.

-

No

In proxy mode, this is the name of the MCP server to be converted. The server must be registered with Nacos first.

MODE

The working mode.

router

No

Valid values: router and proxy.

PORT

The service port.

8000

No

This parameter is used when the protocol type is sse or streamable_http.

Integrate Dify with Nacos MCP Registry

Nacos 3.0 introduces the MCP Registry management feature, which allows for the centralized management of all MCP Servers. For more information, see Integrate Dify with Nacos MCP Registry for centralized MCP Server management.

Edit an MCP service

  1. Log on to the MSE console and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Registry > Instances, and then click the name of the target instance.

  3. In the left-side navigation pane, click MCP Registry, select a Namespace, and click Edit for the target MCP service:

    • For an MCP tool, you can edit the descriptions in Tool Description and Parameter Structure and save the changes without changing the version number.

    • For other changes, you must update the version number before editing the service.

    Important

    Each MCP service supports only one draft. The most recently saved and unpublished version overwrites the previous draft.

Delete an MCP service

  1. Log on to the MSE console and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Registry > Instances, and then click the name of the target instance.

  3. In the left-side navigation pane, click MCP Registry, select a Namespace, and click Delete for the target MCP service.

Create an MCP tool

You can create an MCP tool using UI-based editing or code-based editing. In UI-based editing mode, you can create an MCP tool by importing a Swagger file. The code-based editing mode is fully compatible with the AI Gateway YAML format.

Protocol conversion configuration: This is used by AI Gateway to convert an HTTP service into an MCP service. It is fully compatible with the open-source Higress RestToMcp template format.

Create a tool by importing Swagger

For the preceding steps, see Create an HTTP-to-MCP service. Before you import a Swagger file, make sure that the file format is valid. After the file is successfully imported, the MCP tool appears in the MCP Tools list.

If a tool with the same name exists, the new tool overwrites the original one.

Click + Based on Swagger File. In the dialog box that appears, drag the Swagger file to the upload area or click Browse Local Files to select the file, and then click Confirm.

Example 1: Swagger file

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Path Parameters API",
    "description": "A sample API that demonstrates path parameters"
  },
  "servers": [
    {
      "url": "http://api.example.com/v1"
    }
  ],
  "paths": {
    "/users/{userId}": {
      "get": {
        "summary": "Get user by ID",
        "operationId": "getUserById",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "description": "The ID of the user to retrieve",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "User information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "User ID"
                    },
                    "name": {
                      "type": "string",
                      "description": "User name"
                    },
                    "email": {
                      "type": "string",
                      "description": "User email"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Update user",
        "operationId": "updateUser",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "description": "The ID of the user to update",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "User information to update",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "User name"
                  },
                  "email": {
                    "type": "string",
                    "description": "User email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User updated successfully"
          }
        }
      }
    }
  }
}

Example 2: YAML file for code-based editing

requestTemplate:
  method: GET
  url: http://restapi.amap.com/v3/weather/weatherInfo?key=xxxx
  argsToUrlParam: true

Related documentation

Deploy an MCP service in Function Compute and register it with MSE Nacos