All docs

OpenAI Agents SDK Setup

Connect OpenAI Agents SDK to graph8 via MCP using MCPServerStreamableHttp

Connect the OpenAI Agents SDK to graph8’s MCP server. The Agents SDK ships with native MCP support, so a graph8 connection is a single MCPServerStreamableHttp call away.

OpenAIChatGPT

Prerequisites

  • Python 3.10+
  • openai-agents SDK with the MCP extra
pip install 'openai-agents[mcp]'

Hosted MCP (remote OAuth)

import asyncio
import os

from agents import Agent, Runner
from 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())

The first run prompts for OAuth in a browser. The SDK caches the token.

Self-hosted MCP (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",
        },
    },
)

Worked example: one-shot prospect list

import asyncio

from agents import Agent, Runner
from 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())

The Agents SDK’s Runner handles tool-call loops automatically. graph8’s confirmation rule for credit-charging tools surfaces as natural-language prompts to the user before any save.

Build with graph8