关于 mcp-pymilvus-code-generator
mcp-pymilvus-code-generator 是一款 MCP 服务,可检索 Milvus 代码和文档,辅助生成、转换及翻译 pymilvus 代码。它支持 SSE 和 stdio 传输,并连接 Milvus 实例。
主要功能
- 01检索 pymilvus 代码片段和文档
- 02转换 ORM 与客户端代码
- 03跨语言翻译 Milvus 代码
- 04支持 SSE 和 stdio 传输
- 05连接本地或远程 Milvus
适用场景
- 01根据自然语言请求生成 pymilvus 代码
- 02转换 ORM 与 pymilvus 客户端代码
- 03跨语言翻译 Milvus API 代码
MCP 相关
它向 MCP 客户端提供检索 pymilvus 示例、转换 ORM 与客户端代码以及翻译 Milvus 代码的工具。可通过 SSE 或 stdio 运行。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
mcp-pymilvus-code-generate-helper
一个模型上下文协议服务,可检索相关代码片段或文档,帮助生成 pymilvus 代码。


前提条件
使用此 MCP 服务之前,请确保已具备:
使用方法
推荐的使用方式是直接通过 uv 运行此 MCP 服务,无需安装。以下示例中的 Claude Desktop 和 Cursor 都采用这种配置方式。该服务现在同时支持 sse 和 stdio:
SSE
运行服务
uv run src/mcp_pymilvus_code_generate_helper/sse_server.py
# mcp server will connect to local milvus server(http://localhost:19530) by default if no milvus_uri is provided
# to connect to a remote milvus server, you can specify the milvus_uri like this:
# uv run src/mcp_pymilvus_code_generate_helper/sse_server.py --milvus_uri http://<your-server-ip>:<your-server-port>
在 Cursor 中使用
- 前往
Cursor>Preferences>Cursor Settings>MCP - 点击
+ Add New MCP Server按钮 - 填写表单:
- 名称:
pymilvus-code-generate-helper(或任意名称) - 类型:选择
sse - 服务 URL:
http://localhost:23333/milvus-code-helper/sse(替换为服务的 IP 地址)
- 名称:
- 点击
Save
也可以直接按如下方式编辑 mcp.json:
{
"mcpServers": {
"pymilvus-code-generate-helper": {
"url": "http://localhost:23333/milvus-code-helper/sse"
}
}
}
在 Claude Desktop 中使用
⚠️ Claude desktop 目前连接远程 MCP 服务的能力有限
STDIO
运行服务
uv run src/mcp_pymilvus_code_generate_helper/stdio_server.py
# mcp server will connect to local milvus server(http://localhost:19530) by default if no milvus_uri is provided
# to connect to a remote milvus server, you can specify the milvus_uri like this:
# uv run src/mcp_pymilvus_code_generate_helper/stdio_server.py --milvus_uri http://<your-server-ip>:<your-server-port>
在 Cursor 中使用
- 前往
Cursor>Preferences>Cursor Settings>MCP - 点击
+ Add New MCP Server按钮 - 填写表单:
- 名称:
pymilvus-code-generate-helper(或任意名称) - 类型:选择
stdio - 命令:
/PATH/TO/uv --directory /path/to/mcp-pymilvus-code-generator run src/mcp_pymilvus_code_generate_helper/stdio_server.py
- 名称:
- 点击
Save
也可以直接按如下方式编辑 mcp.json:
{
"mcpServers": {
"pymilvus-code-generate-helper": {
"command": "/PATH/TO/uv",
"args": [
"--directory",
"/path/to/mcp-pymilvus-code-generator",
"run",
"src/mcp_pymilvus_code_generate_helper/stdio_server.py",
"--milvus_uri",
"http://localhost:19530"
],
"env": {
"OPENAI_API_KEY": "YOUR OPENAI API KEY HERE"
}
}
}
}
在 Claude Desktop 中使用
- 从 https://claude.ai/download 安装 Claude Desktop
- 打开 Claude Desktop 配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- macOS:
- 添加以下配置:
{
"mcpServers": {
"pymilvus-code-generate-helper": {
"command": "/PATH/TO/uv",
"args": [
"--directory",
"/path/to/mcp-server-milvus/src/mcp_server_milvus",
"run",
"src/mcp_pymilvus_code_generate_helper/stdio_server.py",
"--milvus_uri",
"http://localhost:19530"
],
"env": {
"OPENAI_API_KEY": "YOUR OPENAI API KEY HERE"
}
}
}
}
- 重启 Claude Desktop
⚠️ 注意:请记得设置 OPENAI_API_KEY 环境变量
用户规则
以下是可添加给用户的额外指令,可提高 Cursor 中工具调用的准确性: 若要提高使用 Cursor 时工具调用的准确性,可以按如下方式设置用户规则:
前往 Cursor > Preferences > Cursor Settings > Rules,并将以下内容添加到用户规则中。以下示例规则已被证明效果良好,供你参考:
Always use tools in milvus code generation, convertion and translation tasks.
1.milvus code generation.
- Can you help me generate a sample pymilvus code to hybrid search?
Call milvus_pypmilvus_code_generate_helper
2.milvus client and orm code convertion.
- Can you help me translate the following orm code to create collection to pymilvus client?
- <code context> translate to orm
Call milvus_orm_client_code_convert_helper
3.milvus code translation between different programming language.
- Can you help me translate the following milvus code to java.
- <code context> translate to nodejs
Call milvus_code_translate_helper
If you meet the milvus code translation between different programming language task or convert between orm and milvus client, you must identify all API calls of the selected codes related to the Milvus SDK. The "query" argument should be a list of API call descriptions.
Here is the examples:
Example 1
Context:
```
from pymilvus import MilvusClient, DataType
CLUSTER_ENDPOINT = "http://localhost:19530"
TOKEN = "root:Milvus"
# 1. Set up a Milvus client
client = MilvusClient(
uri=CLUSTER_ENDPOINT,
token=TOKEN
)
# 2. Create a collection in quick setup mode
client.create_collection(
collection_name="quick_setup",
dimension=5
)
res = client.get_load_state(
collection_name="quick_setup"
)
print(res)
```
Parsed arguments of tool using:
["create_collection", "get_load_state"]
Example 2
Context:
```
from pymilvus import MilvusClient
client = MilvusClient(uri="http://localhost:19530", token="root:Milvus")
if not client.has_collection("my_collection"):
client.create_collection(collection_name="my_collection", dimension=128)
client.insert(
collection_name="my_collection",
data=[{"vector": [0.1, 0.2, 0.3, 0.4, 0.5]}]
)
client.flush(["my_collection"])
```
Parsed arguments of tool using:
["has_collection", "create_collection", "insert", "flush"]
你可以根据工作流自由调整或添加更多规则。
可用工具
服务器提供以下工具:
-
milvus-pypmilvus-code-generate-helper:查找相关的 pymilvus 代码/文档,帮助根据用户的自然语言输入生成代码- 参数:
query:用于生成代码的用户查询
- 参数:
-
milvus-orm-client-code-convert-helper:查找相关的 ORM 和 pymilvus 客户端代码/文档,帮助将 ORM 代码转换为 pymilvus 客户端代码(反之亦然)- 参数:
query:用户查询和代码上下文中的 Milvus API 名称字符串,采用列表格式,用于在 ORM 和 Milvus 客户端之间转换
- 参数:
-
milvus-code-translate-helper:查找不同编程语言中的相关文档和代码片段,用于翻译 Milvus 代码 -
参数:
query:用于将代码从一种编程语言翻译为另一种的 Milvus API 名称字符串,采用列表格式(例如,['create_collection', 'insert', 'search'])source_language:源编程语言(例如,'python'、'java'、'go'、'csharp'、'node'、'restful')target_language:目标编程语言(例如,'python'、'java'、'go'、'csharp'、'node'、'restful')
⚠️ 注意:你无需在查询中指定工具名称或参数。像平常使用 LLM 编写代码时一样提出需求,并选择相关的代码上下文即可。MCP 会根据查询内容自动选择适当的工具,并准备相应的参数。
Docker
你也可以使用 Docker 构建并运行 milvus code helper MCP 服务
构建 Docker 镜像
docker build -t milvus-code-helper .
运行 Docker 容器
docker run -p <YOUR_HOST_IP>:<YOUR_HOST_PORT>:23333 -e OPENAI_API_KEY -e MILVUS_URI=<YOUR_MILVUS_URI> -e MILVUS_TOKEN=<YOUR_MILVUS_TOKEN> milvus-code-helper
贡献
欢迎贡献!如果你对改进检索结果有任何想法,请提交 pull request 或提出 issue。
许可证
本项目采用 MIT License 授权。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。