跳转至

工具管理概览

MCPStore 提供了完整的工具管理功能,支持工具查询、调用、统计分析和框架集成。

🔍 工具查询

核心方法

🛠️ 工具调用

核心方法

📊 工具统计分析

核心方法

🔧 工具转换

核心方法

🔗 框架集成

LangChain 集成

🎯 快速开始

from mcpstore import MCPStore

# 初始化
store = MCPStore.setup_store()

# 添加服务
store.for_store().add_service({
    "mcpServers": {
        "filesystem": {
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
        }
    }
})

# 列出所有工具
tools = store.for_store().list_tools()
print(f"可用工具: {[t.name for t in tools]}")

# 调用工具
result = store.for_store().call_tool("read_file", {"path": "/tmp/example.txt"})
print(f"工具调用结果: {result}")

# 获取工具统计
stats = store.for_store().get_tools_with_stats()
print(f"工具统计: {stats}")

🤖 Agent 透明代理

MCPStore 支持 Agent 透明代理模式,提供智能工具解析:

from mcpstore import MCPStore

# 初始化
store = MCPStore.setup_store()

# Agent 模式操作
agent_context = store.for_agent("my_agent")

# Agent 只看到本地名称的工具
agent_tools = agent_context.list_tools()

# 智能工具调用(支持精确匹配、前缀匹配、模糊匹配)
result = agent_context.call_tool("read_file", {"path": "/tmp/data.txt"})

🏗️ 工具架构特性

  • 智能解析: 支持精确匹配、前缀匹配、模糊匹配三种工具解析策略
  • 透明代理: Agent模式下自动处理工具名称映射
  • 性能监控: 内置工具调用性能统计和监控
  • 框架集成: 无缝集成LangChain等AI框架
  • 安全验证: 支持工具参数验证和安全包装

🔗 相关文档