Labsco
Shawnzheng011019 logo

PyMilvus Code Generate Helper

β˜… 2

from Shawnzheng011019

Retrieves relevant code snippets and documents to assist in generating PyMilvus code, requiring a running Milvus instance.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredNeeds API keys

milvus-sdk-code-helper

A Model Context Protocol server that retrieves relevant code snippets or documents to help generating pymilvus code.

Architecture

Example

Key Features

  • Automatically fetches and indexes the latest Milvus documentation version (可δ»₯θŽ·ε–ζœ€ζ–°ζ–‡ζ‘£η‰ˆζœ¬)
  • Weekly auto-refresh via a lightweight background scheduler

Usage with Cursor

  1. Go to Cursor > Settings > MCP
  2. Click on the + Add New Global MCP Server button
  3. Configure based on your chosen mode:
{
  "mcpServers": {
    "milvus-sdk-code-helper": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

For SSE Transport

{
  "mcpServers": {
    "milvus-sdk-code-helper": {
      "url": "http://localhost:8000"
    }
  }
}

For STDIO Transport

{
  "mcpServers": {
    "milvus-sdk-code-helper": {
      "command": "/PATH/TO/uv",
      "args": [
        "--directory",
        "/path/to/milvus-sdk-code-helper",
        "run",
        "examples/fastmcp_server.py",
        "--transport",
        "stdio",
        "--milvus_uri",
        "http://localhost:19530"
      ],
      "env": {
        "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY"
      }
    }
  }
}

Usage with Claude Desktop

  1. Install Claude Desktop from https://claude.ai/download
  2. Open your Claude Desktop configuration:
    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  3. Add the following configuration:

For HTTP Transport

{
  "mcpServers": {
    "milvus-sdk-code-helper": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

For STDIO Transport

{
  "mcpServers": {
    "milvus-sdk-code-helper": {
      "command": "/PATH/TO/uv",
      "args": [
        "--directory",
        "/path/to/milvus-sdk-code-helper",
        "run",
        "examples/fastmcp_server.py",
        "--transport",
        "stdio",
        "--milvus_uri",
        "http://localhost:19530"
      ],
      "env": {
        "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY"
      }
    }
  }
}
  1. Restart Claude Desktop

⚠️ Note: Remember to set the OPENAI_API_KEY environment variable when using STDIO transport.

Available Tools

The server provides three powerful tools for Milvus code generation and translation:

1. milvus_code_generator

Generate or provide sample PyMilvus/Milvus code based on natural language input.

  • When to use: Code generation, sample code requests, "how to write" queries
  • Parameters:
    • query: Your natural language request for code generation
  • Example: "Generate pymilvus code for hybrid search"

tool1

2. orm_client_code_convertor

Convert between ORM and PyMilvus client code formats.

  • When to use: Converting between ORM and client styles, format adaptation
  • Parameters:
    • query: List of Milvus API names to convert (e.g., ["create_collection", "insert"])
  • Example: "Convert ORM code to PyMilvus client"

tool2

3. milvus_code_translator

Translate Milvus code between different programming languages.

  • When to use: Cross-language code translation
  • Parameters:
    • query: List of Milvus API names in escaped double quotes format (e.g., [\"create_collection\", \"insert\", \"search\"])
    • source_language: Source programming language (python, java, go, csharp, node, restful)
    • target_language: Target programming language (python, java, go, csharp, node, restful)
  • Example: "Translate Python Milvus code to Java"

tool3

⚠️ Important: You don't need to specify tool names or parameters manually. Just describe your requirements naturally, and the MCP system will automatically select the appropriate tool and prepare the necessary parameters.

Legacy Transport Modes

For backward compatibility, the server also supports SSE and STDIO transport modes:

SSE Transport

# Start SSE server
uv run src/mcp_pymilvus_code_generate_helper/sse_server.py --milvus_uri http://localhost:19530

# Cursor configuration for SSE
{
  "mcpServers": {
    "milvus-sdk-code-helper": {
      "url": "http://localhost:23333/milvus-code-helper/sse"
    }
  }
}

STDIO Transport

# Start STDIO server
uv run src/mcp_pymilvus_code_generate_helper/stdio_server.py --milvus_uri http://localhost:19530

# Cursor configuration for STDIO
{
  "mcpServers": {
    "milvus-sdk-code-helper": {
      "command": "/PATH/TO/uv",
      "args": [
        "--directory",
        "/path/to/milvus-sdk-code-helper",
        "run",
        "src/mcp_pymilvus_code_generate_helper/stdio_server.py",
        "--milvus_uri",
        "http://localhost:19530"
      ],
      "env": {
        "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY"
      }
    }
  }
}

Docker Support

You can also run the server using Docker:

Build the Docker Image

docker build -t milvus-code-helper .
# First time run with document update
docker run -p 8000:8000 \
  -e OPENAI_API_KEY=your_openai_key \
  -e MILVUS_URI=http://your-milvus-host:19530 \
  -e MILVUS_TOKEN=your_milvus_token \
  milvus-code-helper

# Lightweight mode for subsequent runs
docker run -p 8000:8000 \
  -e OPENAI_API_KEY=your_openai_key \
  -e MILVUS_URI=http://your-milvus-host:19530 \
  -e MILVUS_TOKEN=your_milvus_token \
  milvus-code-helper examples/fastmcp_server.py