> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackone.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK

> Connect StackOne MCP to OpenAI Agents SDK with built-in MCP server support.

## Overview

OpenAI Agents SDK includes native MCP support with `MCPServerStreamableHttp`, enabling direct integration with StackOne's MCP server.

[Official Docs](https://openai.github.io/openai-agents-python/mcp/)

## Installation

```bash theme={null}
pip install openai-agents
```

Or with uv:

```bash theme={null}
uv add openai-agents
```

## Quick Start

Connect to StackOne MCP and use tools with OpenAI agents:

```python theme={null}
import os
import asyncio
import base64
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp, MCPServerStreamableHttpParams

# Configure StackOne account
STACKONE_ACCOUNT_ID = "<account_id>"  # Your StackOne account ID

# Encode API key for Basic auth
auth_token = base64.b64encode(
    f"{os.getenv('STACKONE_API_KEY')}:".encode()
).decode()

async def main():
    # Create MCP server connection
    stackone_mcp = MCPServerStreamableHttp(
        params=MCPServerStreamableHttpParams(
            url="https://api.stackone.com/mcp",
            headers={
                "Authorization": f"Basic {auth_token}",
                "x-account-id": STACKONE_ACCOUNT_ID
            }
        )
    )

    # Use async context manager to connect/disconnect automatically
    async with stackone_mcp:
        # Create agent with StackOne tools
        agent = Agent(
            name="stackone-assistant",
            model="gpt-5",
            mcp_servers=[stackone_mcp]
        )

        # Run agent
        result = await Runner.run(agent, "List Salesforce accounts")
        print(result.final_output)

asyncio.run(main())
```

## Environment Variables

```bash theme={null}
STACKONE_API_KEY=<stackone_api_key>
OPENAI_API_KEY=your_openai_key
```

## Multi-Turn Conversation

Pass previous messages as context for follow-up questions:

```python theme={null}
import os
import asyncio
import base64
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp, MCPServerStreamableHttpParams

STACKONE_ACCOUNT_ID = "<account_id>"
auth_token = base64.b64encode(
    f"{os.getenv('STACKONE_API_KEY')}:".encode()
).decode()

async def main():
    stackone_mcp = MCPServerStreamableHttp(
        params=MCPServerStreamableHttpParams(
            url="https://api.stackone.com/mcp",
            headers={
                "Authorization": f"Basic {auth_token}",
                "x-account-id": STACKONE_ACCOUNT_ID
            }
        )
    )

    async with stackone_mcp:
        agent = Agent(
            name="stackone-assistant",
            model="gpt-5",
            mcp_servers=[stackone_mcp]
        )

        # First turn
        result = await Runner.run(agent, "List Salesforce accounts")
        print(result.final_output)

        # Continue conversation — pass previous output as context
        result = await Runner.run(
            agent,
            "Show me the most recent account activities",
            context=result.context
        )
        print(result.final_output)

asyncio.run(main())
```

## Resources

* [OpenAI Agents SDK MCP Guide](https://openai.github.io/openai-agents-python/mcp/)
* [OpenAI Agents SDK Documentation](https://openai.github.io/openai-agents-python/)
* [StackOne Authentication](/mcp/auth-security)

## Next Steps

<CardGroup cols={2}>
  <Card title="Pydantic AI" icon="robot" href="/mcp/framework-guides/pydantic-ai">
    Try Pydantic AI with built-in MCP support
  </Card>

  <Card title="LangChain" icon="link" href="/mcp/framework-guides/langchain">
    Build agents with LangChain MCP adapters
  </Card>
</CardGroup>
