跳转到主要内容
于 2026 年 11 月 20 日针对 openai-agents 0.25.0(Python)和 @openai/agents 0.22.0(TypeScript)验证。
有两种连接方式:

安装

Hosted MCP 工具

模型从 OpenAI 一侧调用 TronRental。在调用任何会改变数据的工具之前请求批准:只读工具自动运行,其余工具经过你的回调。
hosted.py
authorization 以 Authorization: Bearer <value> 发送给 TronRental:API 密钥,或用户的 OAuth 访问令牌。若要缩小模型能看到的范围,请添加 "allowed_tools": ["quote_energy", "buy_energy", "get_order"]。

本地 MCP 客户端

你的进程连接 TronRental 并把工具交给智能体;密钥永远不会离开你的服务器。
local.py

TypeScript

当 requireApproval 不是 "never" 时,运行会在需要批准的工具处停止,并在 result.interruptions 中返回它们;用 result.state.approve(...) 批准,然后用 result.state 再次运行。 在 TypeScript 中使用本地客户端时,请使用 @openai/agents 中的 new MCPServerStreamableHttp({ url, requestInit: { headers } }),并把它传入 mcpServers。

不使用 SDK 调用 Responses API

Hosted 工具就是 Responses API 的 mcp 工具: