×
Community Blog How to Achieve Autonomous Discovery and Use of MCP Services by AI Agents - Nacos MCP Router Deployment Best Practices

How to Achieve Autonomous Discovery and Use of MCP Services by AI Agents - Nacos MCP Router Deployment Best Practices

The article introduces best practices for deploying the Nacos MCP Router so AI agents can autonomously discover, select, and securely use MCP services.

By Zheng Ji

Background

With the rapid development of artificial intelligence, AI Agent is increasingly integrated into people's daily lives and work scenarios. In particular, since the release of the MCP protocol last November, the ability of AI Agent to interact with external data and tools has significantly improved, demonstrating greater autonomy and practicality. However, while enjoying the conveniences brought by MCP tools, users also face a series of practical challenges:

Complex Service Selection and Configuration: Currently, there are thousands of MCP servers on the market, and users need to select suitable servers based on specific tasks and manually configure them to the AI Agent. This process is not only cumbersome, but it may also significantly reduce usage efficiency and affect the overall experience.

Excessive Token Consumption: If too many MCP servers are configured for the AI Agent, it will require sending the complete descriptive information of all tools when interacting with the large model, leading to a surge in token consumption, increasing inference costs and reducing response speed.

Security and Trust Risks: For MCP servers provided by the open-source community that require local deployment, users often face security concerns: does this server have vulnerabilities? Is there a risk of data leakage? The lack of authoritative security assessment mechanisms makes it difficult for users to have sufficient trust while using it.

These issues somewhat restrict the popularization of the MCP ecosystem and the widespread application of AI Agent, necessitating systematic solutions to improve usability, efficiency, and security.

Nacos Community’s Solution: Nacos MCP Router + Nacos MCP Registry

In response to the challenges faced by AI Agent during the use of the MCP protocol, the Nacos community has launched a powerful open-source product—Nacos MCP Router (hereinafter referred to as Router). Router is a standard MCP Server that follows the MCP protocol. Its core capability is to intelligently select the most suitable MCP Server from the MCP registry based on the semantic description and keywords of user tasks, providing these candidate tools to the large model for decision-making.

By introducing Router, users no longer need to manually configure different MCP Servers for different tasks, nor do they need to sift through a plethora of MCP services. The AI Agent only needs to integrate with this one MCP Server (the Router), greatly simplifying integration and management complexity.

More importantly, Router significantly optimizes token usage efficiency. In the initial phase, the AI Agent only needs to transmit Router's lightweight tool description to the large model, avoiding redundant transmission of all tool information. During execution, Router dynamically matches and only returns MCP tool descriptions relevant to the current task, thus greatly reducing context length, effectively alleviating token consumption problems caused by an excess of tool descriptions, lowering inference costs, and improving response speed.

Moreover, the security issues of MCP Servers are also becoming increasingly prominent. Currently, most open-source MCP Servers rely on local deployment and expose functionalities through standard input/output (stdio) protocols, posing potential security risks such as data leakage and process contamination. To address this, Router provides critical proxy and protocol conversion capabilities: supporting one-click conversion of stdio-based MCP Servers to more secure and controllable SSE or streamable HTTP protocols and achieving isolated operation of services through Docker container deployment. With this mechanism, users can deploy originally insecure stdio services in isolated container environments, effectively blocking sensitive data leakage paths, enhancing overall system security and maintainability.

Nacos MCP Router Architecture and Principles

As part of the Nacos MCP solution, the overall architecture diagram of Router is shown below:

1

1.  Router, as a standard MCP Server, communicates with the upper-layer MCP Client via the MCP protocol, supporting Local mode (stdio protocol) and Remote mode (SSE or streamable HTTP protocol).

2.  Router has two main working modes: intelligent routing mode and proxy mode.

  • Intelligent routing is the full-function mode of Router. In this mode, Router provides functions such as automatic discovery of MCP Servers, intelligent filtering, tool proxying, protocol conversion, security authentication, and dynamic debugging of tools and descriptions.
  • The proxy mode is a subset of Router's functionalities, mainly providing protocol conversion, tool proxying, security authentication, and dynamic debugging of tools and descriptions.

3.  Router takes the Nacos MCP Registry as the data source to obtain the list of MCP Servers. Users can consume MCP Servers through Router after configuring them in Nacos or relying on SDKs for automatic registration.

Working Principle of Intelligent Routing Mode

In intelligent routing mode, Router is a standard MCP Server, providing three MCP tools:

● search_mcp_server: intelligently filters MCP Servers based on task descriptions and keywords;

● add_mcp_server: initializes the specified MCP Server; if it is the stdio protocol, it executes installation and initialization logic; if it is the SSE or streamable HTTP protocol, it executes connection establishment and initialization logic;

● use_mcp_tool: uses a particular tool of the target MCP Server; Router will proxy the tool request to the target MCP Server.

The architectural diagram is as follows:

2

The workflow in intelligent routing mode is as follows:

  1. Router starts and retrieves the MCP Server list from the Nacos MCP Registry, storing relevant descriptions in the vector database;
  2. When the Agent initializes and establishes a session with the large model, it informs the large model of Router's tool list (the three mentioned above);
  3. The user initiates a task through the Agent, and the large model selects to use search_mcp_server based on the user's task description, constructs parameters to initiate tool calls, searching for available MCP Servers;
  4. Router, based on the tool call parameters, queries the available MCP Server list and returns the top 5 relevant ones;
  5. The large model selects the appropriate MCP Server and calls add_mcp_server tool to initialize the target MCP Server;
  6. Router initializes the target MCP Server and returns the tool list of the target MCP Server;
  7. The large model selects the tools of the target MCP Server, constructs parameters, calls Router's use_mcp_tool tool to initiate the tool call;
  8. Router proxies the MCP tool request to the target MCP Server and returns the results to the Agent;
  9. The large model receives the query data and organizes the final results.

Working Principle of Proxy Mode

The proxy mode is relatively simpler. The initial intention of proxy mode is to convert stdio protocol MCP Servers to SSE or streamable HTTP protocol MCP Servers at the click of a button, while also providing users with an isolated MCP operating environment via container technology.

3

Nacos MCP Router Deployment Practices

Overall Principles

4

● Both Nacos and Router are containerized deployments, isolating computing resources

● Nacos and Router are deployed in multiple copies to enhance stability

● Router uses SLB to provide load balancing capabilities and expose services externally

● It is recommended to use streamable HTTP protocol to provide stateless MCP Server

Architecture Topology

5

To reduce complexity, this deployment is based on Alibaba Cloud's container platform ACS, as the Serverless delivery model of ACS helps users avoid the complexity of managing underlying K8s resources.

Creating Nacos and Nacos MCP Router Clusters

The Nacos MCP Router now supports one-click deployment via Helm, including the Nacos cluster that Router depends on, and can automatically create SLB to expose services. First, ensure that Helm and kubectl are correctly installed and configured. For convenience, we deploy Nacos and Router on Alibaba Cloud ACS, and the deployment script is as follows:

git clone https://github.com/nacos-group/nacos-mcp-router.git
cd nacos-mcp-router/helm
bash randomize_values.sh
helm install nacos-mcp-router . -n nacos-mcp --create-namespace

After executing the command successfully, wait for the cluster initialization to complete. After deployment, it appears as shown below, including 3 nodes of Nacos, MySQL, and Router.

6
7

Registering MCP Server to Nacos

1.  Log in to the Nacos console: After the cluster deployment is complete, we need to register the relevant MCP Servers in Nacos. Find the external SLB of Nacos in the ACS console to access the Nacos console and register the MCP Server.

8

2.  Initialize the console password: The first time logging into the Nacos console requires initializing the password, here, the password should be initialized to the value of NACOS_PASSWORD in the values.yaml file

9

3.  Register Local MCP Server

10
11

Using Router's Proxy Mode to Convert stdio Protocol MCP Server to Streamable HTTP Protocol

As mentioned earlier, Router supports MCP protocol conversion. This section describes deploying Router in proxy mode and proxying stdio protocol MCP Servers while exposing streamable HTTP protocol, taking MCP Server fetch as an example:

● Deploy fetch

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fetch-mcp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fetch-mcp
  template:
    metadata:
      labels:
        app: fetch-mcp
    spec:
      containers:
        - name: fetch-mcp
          image: "nacos/nacos-mcp-router:latest"
          env:
            - name: TRANSPORT_TYPE
              value: streamable_http
            - name: MODE
              value: "proxy"
            - name: PROXIED_MCP_NAME
              value: "fetch"
            - name: PROXIED_MCP_SERVER_CONFIG
              value: '{"mcpServers":{"fetch":{"command":"uvx","args":["mcp-server-fetch"]}}}'
            - name: AUTO_REGISTER_TOOLS
              value: "false"

---
apiVersion: v1
kind: Service
metadata:
  name: fetch-mcp
spec:
  type: ClusterIP
  selector:
    app: fetch-mcp
  ports:
    - name: http
      port: 8000
      targetPort: 8000

Deploy using kubectl:

kubectl apply -f nacos-mcp-router-proxy-deployment.yaml -n nacos-mcp

● After deployment, you can see the access information of fetch-mcp:

12

● In the Nacos console, simply register fetch as a streamable protocol MCP Server.

13

Using Router through Cherry Studio

● Configure the cherry studio MCP server, select streamable protocol, the address is the public address of the Router

14
15

● Use Router to automatically discover MCP

16

Future Plans

There are many things the Nacos MCP Router aims to achieve in the future, with recent focuses on security, stability, and intelligence:

Security: Unified authentication management for MCP

Stability: Rate limiting for tool calls, observability

Intelligence: Virtual MCP construction, MCP tool filtering, optimization of retrieval accuracy

Everyone is welcome to participate in co-building, starred at: https://github.com/nacos-group/nacos-mcp-router

0 1 0
Share on

You may also like

Comments

Related Products