> ## Documentation Index
> Fetch the complete documentation index at: https://corsair-feat-reconnect-error.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI

> Connect Corsair to OpenAI via the Agents SDK or the Responses API over HTTP.

There are two ways to give an OpenAI model Corsair's tools. Use the **Agents SDK** if you're building with `@openai/agents`; use the **Responses API** if you're calling the model directly over HTTP.

<Tabs>
  <Tab title="Agents SDK">
    Use `OpenAIAgentsProvider` to connect Corsair to the [OpenAI Agents SDK](https://github.com/openai/openai-agents-js).

    ## Install

    ```bash theme={null}
    npm install @openai/agents
    ```

    ## Usage

    ```ts agent.ts theme={null}
    import { OpenAIAgentsProvider } from '@corsair-dev/mcp';
    import { Agent, run, tool } from '@openai/agents';
    import { corsair } from './corsair';

    const provider = new OpenAIAgentsProvider();
    const tools = provider.build({ corsair, tool });

    const agent = new Agent({
        name: 'corsair-agent',
        model: 'gpt-4.1',
        instructions:
            'You have access to Corsair tools. Use list_operations to discover available APIs, get_schema to understand required arguments, and run_script to execute them. When referencing resources (like channels), always use their ID, not their name.',
        tools,
    });

    const result = await run(agent, 'Setup corsair, then list all Slack channels.');
    console.log(result.finalOutput);
    ```

    `OpenAIAgentsProvider.build()` is async. It dynamically imports `@openai/agents` as an optional peer dependency. Pass the `tool` function from `@openai/agents` so the provider can wrap each Corsair tool in the correct format.
  </Tab>

  <Tab title="Responses API">
    Use `getOpenAIMcpConfig` to connect Corsair to the [OpenAI API](https://platform.openai.com/docs) over HTTP. You expose Corsair as an MCP server endpoint and pass the config to the OpenAI client.

    ## Install

    ```bash theme={null}
    npm install openai
    ```

    ## Server

    Expose Corsair as an MCP HTTP endpoint using `createBaseMcpServer` and `createMcpRouter`.

    ```ts server.ts theme={null}
    import express from 'express';
    import { createBaseMcpServer, createMcpRouter } from '@corsair-dev/mcp';
    import { corsair } from './corsair';

    const app = express();
    app.use(express.json());

    app.use('/mcp', createMcpRouter(() => createBaseMcpServer({ corsair })));

    app.listen(3000, () => console.log('MCP server running on :3000'));
    ```

    ## Client

    ```ts agent.ts theme={null}
    import OpenAI from 'openai';
    import { getOpenAIMcpConfig } from '@corsair-dev/mcp';

    const client = new OpenAI();

    const response = await client.responses.create({
        model: 'gpt-4.1',
        tools: [
            {
                type: 'mcp',
                ...getOpenAIMcpConfig('http://localhost:3000/mcp'),
            },
        ],
        input: 'Setup corsair, then list all Slack channels.',
    });

    console.log(response.output_text);
    ```

    `getOpenAIMcpConfig` returns the `serverLabel` and `serverUrl` fields expected by OpenAI's `mcp` tool type.
  </Tab>
</Tabs>
