Skip to main content

Nacos MCP 使用指南

一个基于 FastMCP 的 Model Context Protocol (MCP) 工具,用于读取 Nacos 配置、查看历史版本、对比变更以及检查服务注册状态,兼容 Nacos 2.4.x。


📋 目录

  1. 功能特点
  2. 快速开始
  3. 在 Cursor 中集成
  4. 工具功能
  5. 使用示例
  6. 常见问题

功能特点

核心能力

  • 📄 配置读取:按 Data ID 获取单个配置或批量读取多个配置
  • 🧭 历史追溯:列出配置历史、获取详情、自动对比最近两版
  • ✅ 服务状态检查:查看服务实例、健康状态、注册情况
  • 🧩 上下文汇总:一次性聚合配置、历史与服务状态信息
  • 🔐 鉴权支持:支持用户名密码登录,自动管理 token
  • 🧰 兼容 Nacos 2.4.x:对接口版本差异做兜底处理

配置灵活性

工具支持多种配置方式,按优先级自动选择:

  1. 方法参数(调用时直接传入)
  2. 环境变量(Cursor MCP 配置或系统环境变量)
  3. 默认值(工具内置)

快速开始

环境准备

Python 版本要求

  • Python 3.8 或更高版本(推荐 Python 3.9+)
  • 支持 Windows、Linux、Mac 操作系统

检查 Python 环境

# 检查 Python 版本
python --version
# 或
py --version

检查 pip 是否可用

# 检查 pip 版本
pip --version
# 或
py -m pip --version

安装

从 PyPI 安装(默认)

pip install mcp-nacos-helper

使用国内镜像源(可选)

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple mcp-nacos-helper

在 Cursor 中集成

示例配置见:configs/cursor-mcp-config-example.json

推荐在 env 中补充:

  • PYTHONUTF8=1
  • PYTHONIOENCODING=utf-8

PyPI 安装模式示例:

{
  "mcpServers": {
    "nacos-helper-pypi": {
      "command": "py",
      "args": [
        "-m",
        "mcp_services.nacos.tool"
      ],
      "cwd": "${workspaceFolder}",
      "env": {
        "PYTHONUTF8": "1",
        "PYTHONIOENCODING": "utf-8",
        "NACOS_SERVER_ADDR": "http://127.0.0.1:8848",
        "NACOS_NAMESPACE": "sae-dev",
        "NACOS_GROUP": "DEFAULT_GROUP",
        "NACOS_USERNAME": "nacos",
        "NACOS_PASSWORD": "nacos",
        "NACOS_TIMEOUT": "5",
        "NACOS_DATA_IDS": "application.yml,bootstrap.yml",
        "NACOS_REGISTRY_NAMESPACE": "sae-registry"
      }
    }
  }
}

说明:

  • NACOS_NAMESPACE:配置读取命名空间
  • NACOS_REGISTRY_NAMESPACE:服务注册查询命名空间(可选)
  • PYTHONUTF8/PYTHONIOENCODING:避免中文乱码

工具功能

工具提供以下能力(文字说明):

  • 配置读取:读取单个或多个配置
  • 历史追溯:列出历史、获取详情、对比最近两版
  • 服务状态检查:查看实例与健康状态
  • 上下文汇总:聚合配置、历史、服务状态

使用示例

示例均为“自然语言调用”,适合在 Cursor 中直接提问:

读取 cdc-major-disease-service.yml 的配置
对比 cdc-major-disease-service.yml 最近两版历史
检查 CDC-MAJOR-DISEASE-SERVICE 是否已注册

常见问题

1) 历史接口提示需要 nid

工具已自动处理,直接使用“获取最新历史”或“对比最近两版”的能力即可。

2) 历史返回 0,但控制台有数据

多为 namespace 参数或接口版本差异导致,请检查:

  • NACOS_NAMESPACE
  • NACOS_REGISTRY_NAMESPACE

3) 中文输出乱码

在环境变量中添加:

  • PYTHONUTF8=1
  • PYTHONIOENCODING=utf-8

Metadata

Release files for mcp-nacos-helper 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-nacos-helper 1.0.3
File Size Uploaded Provenance
mcp_nacos_helper-1.0.3.tar.gz 9.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-nacos-helper 1.0.3
File Interpreter ABI Platform
mcp_nacos_helper-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 19.0 kB

Release files / mcp_nacos_helper-1.0.3.tar.gz

Download URL mcp_nacos_helper-1.0.3.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
90d161532d86a9b7b18eb392c3b8ca4e6e8f293cb1640c9ac1041cf439e8e689
BLAKE2b-256 checksum
How to use checksums
756961b3b0899302d56b5e73456b8cd40841a206b01b797dbb45f86c84611432
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / mcp_nacos_helper-1.0.3-py3-none-any.whl

Download URL mcp_nacos_helper-1.0.3-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02d63b40828937df962f04cefbd5f20e5edee01e998d2eff87dc73bfbda7f510
BLAKE2b-256 checksum
How to use checksums
7e4d1d92e842788f95aaf9d60e436b0f602f8ff58cc1d8e16fb5530265e13ac8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for mcp-nacos-helper 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page