MCP服务器Python模块化工具

将任何MCP服务器转换为Python模块,支持工具转换、自动完成和类型安全,适用于快速集成和开发。

  • by remodlai
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 remodlai/functional-mcp

使用说明

功能性mcp

使用FastMCP将任何MCP服务器转换为Python模块。

与mcp2py类似,但基于FastMCP构建,支持工具转换。

快速开始

from functional_mcp import load

# Load MCP server
server = load("npx -y @modelcontextprotocol/server-filesystem /tmp")

# Tools become Python methods
files = server.list_directory(path="/tmp")
content = server.read_file(path="/tmp/test.txt")

主要特点

  • 工具转换:使用FastMCP的ArgTransform重命名、重新映射和自定义工具
  • 自动完成:所有工具的IDE自动补全
  • 类型安全:从架构生成的完整类型提示
  • FastMCP供电:基于FastMCP构建,以实现更好的文档和生态系统一致性

安装

pip install functional-mcp

工具转换

from functional_mcp import load, transform_tool
from functional_mcp import ArgTransform

server = load("weather-server")

# Transform a generic tool to be Miami-specific
miami_weather = transform_tool(
    server.get_forecast,
    name="get_miami_weather",
    transform_args={
        "lat": ArgTransform(hide=True, default=25.7617),
        "lon": ArgTransform(hide=True, default=-80.1918),
    }
)

# Now simpler to use
weather = miami_weather(time="tomorrow")

与Remodl SDK集成

from functional_mcp import load
import remodl

# Load MCP tools
server = load("npx filesystem-server /tmp")

# Use with Remodl agents
from remodl.agents import create_agent

agent = create_agent(
    name="File Assistant",
    tools=server.tools  # Auto-compatible!
)

与mcp2py相比的优势

  1. 更好的文档 -FastMCP拥有全面的文档
  2. 工具转换 -无需分叉即可定制工具
  3. 生态系统一致性 -与FastAPI/Pydantic相同的模式
  4. Remodl集成 -从头开始为Remodl SDK构建