Skip to main content

SSE-based MCP Server and Client

Project description

Teamwork Model Context Protocol

不能远程调用的MCP 和 不能支撑团队协作的MCP,都是不完整的。

本项目封装极简MCP的SSE远程调用接口,并集成多个团队的工具集合以供参考。Features:

  • 本项目用于快速迭代内部工具和训练内部算法模型。
  • 适合快速技术验证。
  • 项目中所有工具单元都添加了测试,可一键运行。
  • 作为MCP工具推理模型训练基础库开发。

I. 安装

  • 使用uv或者直接使用pip都可以
    uv venv
    uv pip install -e .
    

II. 如何测试

1【本地】简单测试一个回声 server-client

  • 服务端
    # server
    from teamwork_mcp import FastMCP, launch_mcp_server_forever
    fastmcp = FastMCP("echo")
    @fastmcp.tool()
    async def echo(state: str) -> str:
        return state
    launch_mcp_server_forever(fastmcp=fastmcp, host="0.0.0.0", port=8080)
    
  • 客户端
    # client
    from teamwork_mcp import SyncedMcpClient
    client = SyncedMcpClient(server_url="http://0.0.0.0:8080/sse")
    result = client.list_tools(); print(result)
    result = client.call_tool("echo", {"state": "ABC"}); print(result)
    

2【本地】为当前库中所有工具建立mcp server

  • 服务端
    # server
    from teamwork_mcp import launch_manifest_mcp_server_forever
    launch_manifest_mcp_server_forever()
    

3【多机 IP + 端口】远程一个阿里云上的 mcp server

  • 云服务端

    # server: 47.243.19.78 记得设置安全组
    from teamwork_mcp import launch_manifest_mcp_server_forever
    launch_manifest_mcp_server_forever(port=33333)
    
  • 客户端

    # 客户端
    from teamwork_mcp import SyncedMcpClient
    client = SyncedMcpClient(server_url="http://xxxxxx:33333/sse")
    result = client.list_tools(); print(result)
    result = client.call_tool("echo", {"state": "ABC"}); print(result)
    

III. 如何添加工具

目前有两种工具封装格式: 一种是pydantic封装,再由qingxu的接口自动转化为mcp的工具,例如 teamwork_mcp/rfft_tools/firecraw_search.py(推荐)。 另外一种是原生的mcp封装,见 teamwork_mcp/dummy_tools/echo.py。 任选一种采纳。

  1. 把工具放在 ${project_dir}/teamwork_mcp/${contributor}_tools 下。
  2. 请写单元测试,命名为 工具名 + _test.py,例如:
    teamwork_mcp/rfft_tools/code_execution_test.py
    teamwork_mcp/rfft_tools/code_execution.py
    teamwork_mcp/rfft_tools/firecraw_search_test.py
    teamwork_mcp/rfft_tools/firecraw_search.py
    teamwork_mcp/rfft_tools/search_api_qwen_test.py
    teamwork_mcp/rfft_tools/search_api_qwen.py
    teamwork_mcp/rfft_tools/web_scrape_test.py
    teamwork_mcp/rfft_tools/web_scrape.py
    
    提交前请对测试文件进行调试,请确保 xxxx_test.py 测试文件能够一键运行,环境变量建议内嵌到_test.py测试代码中。
  3. 修改 ${project_dir}/teamwork_mcp/manifest_tool.pyraw_mcp_tool_manifest_collection 数组。
  4. 运行launch_server_all_tool_test.pylaunch_client_test.py测试。

Todo

  • [] 实现同时接入多个server的高层client

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teamwork_mcp-0.2.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teamwork_mcp-0.2.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file teamwork_mcp-0.2.1.tar.gz.

File metadata

  • Download URL: teamwork_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for teamwork_mcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 277e01c81e81d11968cb796826bc7bbb97118080e387130ad45187442ca2342d
MD5 e51f7557e2732cc8b6f9d9aff69fb122
BLAKE2b-256 a386c4fe58abf41404282453d54b3b5031c1ad1357d6a466906dbc85290cfa1f

See more details on using hashes here.

File details

Details for the file teamwork_mcp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: teamwork_mcp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for teamwork_mcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 140d9426e7abcc8cee9237613d556afb84c7d19e7529f422df07500cdf89a77e
MD5 afe7a6a4c8ae0d03f66bec1baa3b1344
BLAKE2b-256 01a99dbdd48df652c52a81299a39e0ae9115e608035150c5ecf99771b257daa9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page