MCP代理编排系统
使用模型上下文协议 (MCP) 的基于状态的代理编排系统的 Python 实现。
什么是 MCP?
模型上下文协议 (MCP) 允许应用程序以标准化的方式为 LLM 提供上下文,从而将提供上下文的关注点与实际的 LLM 交互分离开来。使用 MCP,您可以构建服务器来公开:
- 资源:为法学硕士提供信息的数据源
- 工具:允许 LLM 执行操作的功能
- 提示:可重复使用的 LLM 交互模板
安装
先决条件
- Python 3.10 或更高版本
- MCP Python SDK 1.2.0 或更高版本
设置您的环境
使用 uv(推荐)
使用 pip
克隆或下载项目文件
将项目文件放在您的目录中:
orchestrator.py
- 实现状态机的主 MCP 服务器orchestrator_client.py
- 演示编排流程的客户端requirements.txt
- 项目依赖项.gitignore
- Git 忽略文件
项目结构
orchestrator.py
- 实现状态机的主 MCP 服务器orchestrator_client.py
- 演示编排流程的客户端requirements.txt
- 项目依赖项
运行编排系统
- 直接启动编排服务器进行测试:
- 在单独的终端中,运行客户端以查看实际的编排过程:
与 Claude 桌面版集成
1. 安装 Claude 桌面版
确保已安装 Claude 桌面版。您可以从Anthropic 网站下载最新版本。
2. 配置 Claude 桌面版
- 打开您的 Claude for Desktop 配置文件:macOS/Linux:视窗:
- 添加 Orchestrator 服务器配置:将该路径替换为 Orchestrator.py 文件的绝对路径。
- 保存配置文件并重新启动 Claude for Desktop。
3. 在 Claude 中使用 Orchestrator
配置完成后,您可以:
- 打开 Claude 桌面版
- 点击侧边栏中的 MCP 服务器图标
- 从可用服务器列表中选择“agent-orchestrator”
- 开始与编排系统交互
克劳德将能够:
- 不同代理状态之间的转换
- 从知识库存储和检索信息
- 在状态转换过程中保持对话上下文
- 访问特定于状态的提示
代理状态
编排系统实现了一个具有以下状态的状态机:
- IDLE :等待指令
- 规划:为任务创建结构化计划
- 研究:收集任务所需的信息
- 执行:执行计划的行动
- 审查:评估结果并确定下一步行动
- ERROR :处理错误或意外情况
定制系统
添加新州
- 将状态添加到
orchestrator.py
中的AgentState
枚举中 - 为新状态创建提示函数
- 更新
_get_available_transitions()
中的转换逻辑 - 在资源访问函数中添加新状态的处理程序
创建自定义工具
通过创建用@mcp.tool()
装饰的函数来添加新工具:
开发和测试
使用 MCP CLI
MCP CLI 提供开发和测试工具:
使用 Python 进行手动测试
资源
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
基于状态的代理编排系统,允许在不同状态(IDLE、PLANNING、REVIEWING、EXECUTING、REVIEWING、ERROR)之间转换,同时保持对话上下文并提供特定于状态的提示。
Related MCP Servers
- -securityAlicense-qualityA server for task orchestration and coordination, facilitating task management with dependencies, multi-instance collaboration, and persistent task tracking.Last updated -717JavaScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables AI agents to interact with ClickUp workspaces, allowing task creation, management, and workspace organization through natural language commands.Last updated -605MIT License
- -securityFlicense-qualityA Model Context Protocol server that enables role-based context management for AI agents, allowing users to establish specific instructions, maintain partitioned memory, and adapt tone for different agent roles in their system.Last updated -TypeScript
- -securityAlicense-qualityAn MCP server that extends AI agents' context window by providing tools to store, retrieve, and search memories, allowing agents to maintain history and context across long interactions.Last updated -5TypeScriptMIT License