Configuración del SDK de Agentes de OpenAI
Conecte el OpenAI Agents SDK al servidor MCP de graph8. El Agents SDK incluye soporte nativo para MCP, por lo que la conexión con graph8 solo requiere una llamada a MCPServerStreamableHttp.
Requisitos previos
- Python 3.10+
- SDK
openai-agentscon el extra de MCP
pip install 'openai-agents[mcp]'MCP alojado en la nube (OAuth remoto)
import asyncioimport os
from agents import Agent, Runnerfrom agents.mcp import MCPServerStreamableHttp
async def main() -> None: async with MCPServerStreamableHttp( name="graph8", params={"url": "https://be.graph8.com/mcp/"}, ) as server: agent = Agent( name="ProspectFinder", instructions=( "You find prospects for SaaS GTM teams. Use g8_find_contacts to " "preview. Never call g8_build_contact_list, g8_enrich_contacts, " "or g8_add_to_sequence without explicit user confirmation." ), mcp_servers=[server], model="gpt-4o", )
result = await Runner.run( agent, "Find 10 VP Engineering at Series B SaaS in the US. " "Return name, company, title, and linkedin URL.", ) print(result.final_output)
if __name__ == "__main__": asyncio.run(main())La primera ejecución solicita autenticación OAuth en el navegador. El SDK guarda el token en caché.
MCP autoalojado (stdio)
import os
from agents.mcp import MCPServerStdio
server = MCPServerStdio( name="graph8", params={ "command": "uvx", "args": ["g8-mcp-server"], "env": { "G8_API_KEY": os.environ["G8_API_KEY"], "G8_MCP_MODE": "gtm", }, },)Ejemplo práctico: lista de prospectos en una sola consulta
import asyncio
from agents import Agent, Runnerfrom agents.mcp import MCPServerStreamableHttp
async def build_prospect_list() -> None: async with MCPServerStreamableHttp( name="graph8", params={"url": "https://be.graph8.com/mcp/"}, ) as server: agent = Agent( name="GTMAgent", instructions=( "Step 1: g8_find_contacts to preview 50 VP Eng at Series B SaaS.\n" "Step 2: Pick the top 25 by signal score. Ask the user to confirm.\n" "Step 3: g8_build_contact_list named 'Series B SaaS VP Eng'.\n" "Step 4: g8_list_sequences to find 'New SaaS Outreach'.\n" "Step 5: g8_add_to_sequence after confirmation.\n" ), mcp_servers=[server], model="gpt-4o", ) result = await Runner.run(agent, "Run the full prospect-to-sequence flow.") print(result.final_output)
asyncio.run(build_prospect_list())El componente Runner del Agents SDK gestiona los ciclos de llamadas a herramientas de forma automática. La regla de confirmación de graph8 para herramientas que consumen créditos se presenta al usuario como mensajes en lenguaje natural antes de cualquier guardado.