Phnix Nacos MCP
一个用于 Nacos MCP 服务器注册和管理的 Python 包装器库。
功能特性
- 支持将 MCP 服务器注册到 Nacos 服务发现平台
- 支持多种传输协议:stdio、SSE、StreamableHTTP
- 自动服务发现和注册
- 兼容 Nacos MCP 生态系统
安装
pip install phnix-nacos-mcp
快速开始
基本使用
from phnix_nacos_mcp import PhnixNacosMCP
from nacos_mcp_wrapper.server.nacos_settings import NacosSettings
from typing import Annotated, Any
from pydantic import Field
from mcp.server.fastmcp.utilities.func_metadata import ArgModelBase
# 配置 Nacos 设置
nacos_settings = NacosSettings(
SERVER_ADDR="localhost:8848",
NAMESPACE="public",
USERNAME="nacos",
PASSWORD="nacos"
)
# 创建 MCP 服务器实例
mcp = PhnixNacosMCP(
name="my-mcp-server",
version="1.0.0",
nacos_settings=nacos_settings,
instructions="这是一个示例 MCP 服务器"
)
# 添加工具
@mcp.tool(description="计算两个整数相加的结果")
def add(
a: Annotated[int, Field(description="被加数")],
b: Annotated[int, Field(description="加数")]
) -> int:
return a + b
# ====================== 工具入参出参(必须继承 ArgModelBase)======================
class MyToolInput(ArgModelBase):
a: int = Field(description="第一个数字")
b: int = Field(description="第二个数字")
class MyToolOutput(ArgModelBase):
sum: int = Field(description="两个数字的和")
product: int = Field(description="两个数字的积")
@mcp.tool(description="输入两个数字,返回和与积")
def calculate(input: MyToolInput) -> MyToolOutput:
return MyToolOutput(
sum=input.a + input.b,
product=input.a * input.b
)
# 运行服务器
if __name__ == "__main__":
mcp.run()
使用 stdio 传输
import asyncio
from phnix_nacos_mcp import PhnixNacosMCP
mcp = PhnixNacosMCP(name="my-server", version="1.0.0")
asyncio.run(mcp.run_stdio_async())
使用 SSE 传输
import asyncio
from phnix_nacos_mcp import PhnixNacosMCP
mcp = PhnixNacosMCP(
name="my-server",
version="1.0.0",
host="0.0.0.0",
port=8000
)
asyncio.run(mcp.run_sse_async())
使用 StreamableHTTP 传输
import asyncio
from phnix_nacos_mcp import PhnixNacosMCP
mcp = PhnixNacosMCP(
name="my-server",
version="1.0.0",
host="0.0.0.0",
port=8000
)
asyncio.run(mcp.run_streamable_http_async())
配置说明
NacosSettings 配置项
| 配置项 | 说明 | 默认值 |
|---|---|---|
| SERVER_ADDR | Nacos 服务器地址 | localhost:8848 |
| NAMESPACE | 命名空间 | public |
| USERNAME | 用户名 | - |
| PASSWORD | 密码 | - |
| ACCESS_KEY | 访问密钥 | - |
| SECRET_KEY | 密钥 | - |
| SERVICE_IP | 服务 IP | 自动获取 |
| SERVICE_PORT | 服务端口 | 8000 |
| SERVICE_GROUP | 服务分组 | DEFAULT_GROUP |
| SERVICE_EPHEMERAL | 是否临时实例 | True |
| SERVICE_REGISTER | 是否注册服务 | True |
| SERVICE_META_DATA | 服务元数据 | {} |
依赖项
- Python >= 3.10
- mcp >= 1.0.0
- nacos-mcp-wrapper-python >= 0.1.0
- jsonref >= 1.0.0
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
更新日志
0.1.0 (2026-04-08)
- 初始版本
- 支持基本的 MCP 服务器注册功能
- 支持 stdio、SSE、StreamableHTTP 传输协议
Metadata
Release files for phnix-nacos-mcp 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| phnix_nacos_mcp-1.0.0.tar.gz | 14.4 kB | Without provenance | Details for phnix_nacos_mcp-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| phnix_nacos_mcp-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for phnix_nacos_mcp-1.0.0-py3-none-any.whl |
Total release size: 29.8 kB
Release files / phnix_nacos_mcp-1.0.0.tar.gz
| Download URL | phnix_nacos_mcp-1.0.0.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ff8cd5a8098b4d07cdf094c37fdd4ad5f2746ea52f03750a570e120b911b4ac
|
|
BLAKE2b-256 checksum How to use checksums |
c9af44d710216323a98b8f4e6b132ed4f35e265fddd7cb451c6532428e7e387f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / phnix_nacos_mcp-1.0.0-py3-none-any.whl
| Download URL | phnix_nacos_mcp-1.0.0-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
706542d76222e375de490d9faff34881b82f61571be0527fbcadd57fd66b02bb
|
|
BLAKE2b-256 checksum How to use checksums |
da6f2e3f5f74bf80c0a9db430e1d3cc2319276978faacc44de4a3941c7366b1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for phnix-nacos-mcp 1.0.0
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.