OpenAI Agents SDK (Python)
OpenAI Agents SDK for Python:带 Authorization 请求头的 MCPServerStreamableHttp,通过 mcp_servers 传给智能体。
- API 密钥(Bearer)
智能体代码
推荐import asyncio, os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp
async def main():
async with MCPServerStreamableHttp(
name="aicharged",
params={
"url": "https://aicharged.io/api/v1/mcp",
"headers": {"Authorization": f"Bearer {os.environ['AICHARGED_API_KEY']}"},
"timeout": 30,
},
) as server:
agent = Agent(name="Assistant", instructions="Use the aicharged.io tools.", mcp_servers=[server])
result = await Runner.run(agent, "List my recent aicharged.io runs")
print(result.final_output)
asyncio.run(main())
安装软件包
pip install openai-agents