Cover image
Try Now
2025-04-14

探索创建DeepHaven Core MCP服务器

3 years

Works with Finder

0

Github Watches

0

Github Forks

0

Github Stars

test-dh-mcp

This project demonstrates how to define and run an MCP (Multi-Channel Protocol) server using the FastMCP implementation. It includes examples for tool registration, server/client usage, and integration with Claude Desktop and MCP Inspector.

Project Structure

  • src/mcp_server.py — Main entrypoint to run the MCP server (configurable for SSE or stdio transport).
  • src/dhmcp/__init__.py — All tools are registered here using the @mcp_server.tool() decorator.
  • src/mcp_client.py — Example async client for testing tools.
  • requirements.txt — Python dependencies (including mcp[cli] and autogen-ext).

Using uv for Dependency Management

uv is a modern, ultra-fast Python package manager and runner. It can be used as a drop-in replacement for pip and venv, providing faster installs and improved dependency management.

Key Concepts

  • pyproject.toml: The modern, recommended way to specify your project's dependencies and metadata. uv uses this as the source of truth.
  • requirements.txt: Supported for compatibility with traditional Python tools and workflows. Optional if you use pyproject.toml.
  • uv.lock: Lockfile for reproducible installs (auto-managed by uv).

Modern Workflow (Recommended)

  1. Add dependencies directly to your project:
    uv pip install <package>
    # Example:
    uv pip install autogen-ext mcp[cli]
    
    This updates pyproject.toml and uv.lock.
  2. Sync environment:
    uv pip install  # Installs all dependencies from pyproject.toml
    
  3. Run scripts:
    uv run src/mcp_server.py
    uv run src/mcp_client.py
    

Compatibility Workflow (requirements.txt)

  • If you have an existing requirements.txt, you can use:
    uv pip install -r requirements.txt
    # or
    uv add --requirements requirements.txt
    
  • This will sync dependencies and update your lockfile. You can keep both files in sync for maximum compatibility.

Notes

  • requirements.txt is optional with uv. For new projects, you can rely entirely on pyproject.toml and uv.lock.
  • For legacy projects or sharing with users of pip, keep requirements.txt up to date.
  • uv works with or without a virtual environment. Use uv venv .venv to create one if desired.
  • If you have multiple environments, use --active to target the currently activated one.

Quick Start: Server

1. Install dependencies

It is recommended to use a virtual environment:

  • Using venv:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  • Using uv:
uv pip install -r requirements.txt

2. Run the MCP Server

From the project root, run (choose the transport that fits your use case):

  • SSE transport (default, for browser/web clients):

    python src/mcp_server.py
    # or, explicitly:
    python src/mcp_server.py --transport sse
    # or, using uv:
    uv run src/mcp_server.py
    

    The server will listen on http://localhost:8000/sse

  • Stdio transport (recommended for Claude Desktop/Inspector):

    python src/mcp_server.py --transport stdio
    # or, using uv:
    uv run src/mcp_server.py --transport stdio
    

    The server will communicate via stdio (no HTTP port needed).

You should see log output indicating the server is running with the selected transport.

Quick Start: Client

Note: The Python client (mcp_client.py) requires the MCP server to be running in SSE mode (the default). It will not work if the server is running in stdio mode.

1. Install dependencies

It is recommended to use a virtual environment:

  • Using venv:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  • Using uv:
uv pip install -r requirements.txt

2. Run the MCP Client

From the project root, run:

  • Using venv:
cd src
python -m mcp_client
  • Using uv:
cd src
uv run mcp_client.py

You should see log output indicating the client is running and listing available tools.

Claude Desktop

You can connect Claude Desktop to your local stdio MCP server to use custom tools.

  1. Edit ~/Library/Application\ Support/Claude/claude_desktop_config.json:

    • Using venv:
    {
        "mcpServers": {
            "test-dh-mcp": {
                "command": "/Users/chip/dev/test-dh-mcp/.venv/bin/python3",
                "args": ["/Users/chip/dev/test-dh-mcp/src/mcp_server.py", "--transport", "stdio"]
            }
        }
    }
    
    • Using uv:
    {
        "mcpServers": {
            "test-dh-mcp": {
                "command": "uv",
                "args": [
                    "--directory",
                    "/Users/chip/dev/test-dh-mcp/src",
                    "run", 
                    "mcp_server.py", 
                    "--transport", 
                    "stdio"
                ]
            }
        }
    }
    
  2. Restart Claude Desktop.

  3. Debugging logs can be found in ~/Library/Logs/Claude/

Registering Tools

Define new tools in dhmcp/__init__.py using the @mcp_server.tool() decorator. Example:

@mcp_server.tool()
def echo_tool(message: str) -> str:
    """
    Echo tool that returns the input message prefixed with 'Echo:'.
    """
    return f"Echo: {message}"

Troubleshooting

  • Ensure you are running commands from the correct directory (src for direct script execution).
  • If you change tool definitions, restart the server.
  • For connection issues, check that the server is running and listening on the expected address/port (for SSE), or correctly attached via stdio (for Claude/Inspector).

Is the server running?

  • SSE mode:
    curl http://localhost:8000/sse
    
  • Stdio mode:
    • Check your Claude/Inspector logs for successful connection and tool listing.

MCP Inspector

The MCP Inspector is a tool that allows you to inspect the state of an MCP server.

  1. Install the MCP Inspector:

    npm install -g @modelcontextprotocol/inspector
    
  2. Run the MCP Inspector:

    • ** SSE mode: **

      • Using venv:
      cd /Users/chip/dev/test-dh-mcp/src
      npx @modelcontextprotocol/inspector \
      /Users/chip/dev/test-dh-mcp/venv/bin/python3 mcp_server.py --transport sse
      
      • Using uv:
      cd /Users/chip/dev/test-dh-mcp/src
      npx @modelcontextprotocol/inspector \
      uv run mcp_server.py --transport sse
      
    • ** Stdio mode: **

      • Using venv:
      cd /Users/chip/dev/test-dh-mcp/src
      npx @modelcontextprotocol/inspector \
      /Users/chip/dev/test-dh-mcp/venv/bin/python3 mcp_server.py --transport stdio
      
      • Using uv:
      cd /Users/chip/dev/test-dh-mcp/src
      npx @modelcontextprotocol/inspector \
      uv run mcp_server.py --transport stdio
      

相关推荐

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • rulego
  • ⛓️Rulego是一种轻巧,高性能,嵌入式,下一代组件编排规则引擎框架。

  • Byaidu
  • PDF科学纸翻译带有保留格式的pdf -基于ai完整保留排版的pdf文档全文双语翻译

  • sigoden
  • 使用普通的bash/javascript/python函数轻松创建LLM工具和代理。

  • hkr04
  • 轻巧的C ++ MCP(模型上下文协议)SDK

  • RockChinQ
  • 😎简单易用、🧩丰富生态 -大模型原生即时通信机器人平台| 适配QQ / 微信(企业微信、个人微信) /飞书 /钉钉 / discord / telegram / slack等平台| 支持chatgpt,deepseek,dify,claude,基于LLM的即时消息机器人平台,支持Discord,Telegram,微信,Lark,Dingtalk,QQ,Slack

  • dmayboroda
  • 带有可配置容器的本地对话抹布

  • modelscope
  • 开始以更轻松的方式开始构建具有LLM授权的多代理应用程序。

    Reviews

    2.8 (5)
    Avatar
    user_ea88unDA
    2025-04-24

    As a dedicated user of test-dh-mcp, I am thoroughly impressed with its seamless integration and user-friendly interface. Created by the talented chipkent, this application has significantly streamlined my workflow. Although there are no specific product details available in the description, I highly recommend giving it a try based on my positive experience.

    Avatar
    user_N2wYM7Wx
    2025-04-24

    As a loyal user of the test-dh-mcp application, I am highly impressed with its performance and user-friendly interface. Developed by chipkent, this tool stands out for its reliability and efficiency. It significantly enhances my workflow, and I would highly recommend it to anyone looking for a robust MCP application.

    Avatar
    user_8hHk4GtB
    2025-04-24

    As a loyal user of test-dh-mcp, I must commend chipkent for creating such a fantastic application. It is incredibly user-friendly and efficient, meeting all my needs seamlessly. This product stands out in its category and has made my workflow much more streamlined. Highly recommend it!

    Avatar
    user_bSzJMv0G
    2025-04-24

    As an avid user of test-dh-mcp, I have been thoroughly impressed by its performance and reliability. Developed by the talented chipkent, this application has significantly streamlined my workflow. Highly recommended for anyone seeking efficiency and precision.

    Avatar
    user_oj24SenY
    2025-04-24

    I've been using test-dh-mcp by chipkent for a while now, and it's truly a game-changer. The seamless integration and intuitive design make it stand out. Highly recommended for anyone looking to improve their workflow!