使用说明
项目简介
AgentR 是一个 Python 框架,用于快速构建基于 Model Context Protocol (MCP) 的服务器。它提供了一套简洁的抽象,方便开发者将各种 API 服务集成到 agent 工作流中,作为 LLM 客户端的上下文信息和功能提供者。AgentR 简化了 MCP 服务器的搭建过程,并内置了多种常用 API 的集成方案,如 GitHub, Google Calendar, Gmail, Reddit, Tavily 等。
主要功能点
- MCP 协议集成: 完全兼容 Model Context Protocol 架构,能够作为 MCP 服务器与 LLM 客户端进行通信。
- 简化 API 集成: 内置多种常用 API 应用 (Applications),如 GitHub, Google Calendar, Gmail 等,可以通过简单的配置快速集成。
- 认证管理: 支持 API 密钥和 OAuth 两种认证方式,并提供灵活的凭据管理方案。
- 可扩展架构: 易于扩展新的应用集成,开发者可以方便地添加自定义的应用和服务。
- 命令式工具: 将API功能封装为工具 (Tools),供 LLM 客户端调用,扩展 LLM 的能力边界。
安装步骤
- 安装 AgentR: 使用 pip 命令即可安装 AgentR 框架。
pip install agentr - 获取 AgentR API Key: 某些应用集成需要 AgentR API Key,请访问 https://agentr.dev 创建账户并生成 API Key。
- 设置 API Key 环境变量: 将获取到的 AgentR API Key 设置为环境变量 'AGENTR_API_KEY'。
export AGENTR_API_KEY="your_api_key_here"
服务器配置
AgentR 服务器可以通过 Python 代码进行配置和启动。以下是一个 MCP 客户端配置 AgentR 服务器的 JSON 示例,客户端需要配置 'command' 和 'args' 来启动 AgentR 服务器:
{ "servers": [ { "name": "agentr-server", "command": "agentr", "args": ["run"] } ] }
配置参数说明:
- 'name': 服务器名称,可以自定义,例如 "agentr-server"。
- 'command': 启动服务器的命令,这里使用 'agentr',需要确保 agentr CLI 工具已安装并且在 PATH 环境变量中。
- 'args': 传递给启动命令的参数,这里使用 'run' 参数来运行 AgentR 测试服务器。
注意: AgentR 客户端无需配置额外的服务器地址或端口,因为它默认使用 Stdio (标准输入输出) 作为传输协议,通过命令行直接与 MCP 客户端进行通信。
基本使用方法
- 创建服务器实例: 在 Python 代码中,通过 'agentr.server.TestServer' 类创建服务器实例,并配置需要集成的应用列表。
from agentr.server import TestServer apps_list = [ { "name": "tavily", "integration": { "name": "tavily_api_key", "type": "api_key", "store": { "type": "environment", } }, }, { "name": "zenquotes", "integration": None }, { "name": "github", "integration": { "name": "github", "type": "agentr", } } ] server = TestServer(name="My Agent Server", description="A server for my agent apps", apps_list=apps_list) if __name__ == "__main__": server.run() - 运行服务器: 执行 Python 脚本即可启动 AgentR 服务器。服务器将加载配置的应用,并将其提供的工具注册到 MCP 服务器中。
python your_server_script.py - 客户端连接和调用工具: MCP 客户端配置好 AgentR 服务器后,即可连接到服务器并发现和调用服务器提供的工具,例如搜索网页、获取 GitHub 信息、发送邮件等。 具体工具的使用方法请参考 AgentR 框架中各个应用的文档和工具描述。
提示: AgentR 仓库中包含 'src/agentr/test.py' 文件,可以直接运行该文件来启动一个包含预配置应用的测试服务器。
python src/agentr/test.py
信息
分类
开发者工具