# Building with Sequel

Use the Sequel MCP server inside your own agents — examples for the Vercel AI SDK, the Claude Agent SDK, and the OpenAI Agents SDK.

Sequel isn't only for off-the-shelf tools like Claude or Cursor — you can point your own agents at the same hosted MCP server and give them secure, schema-aware access to your data. Every framework that speaks [Model Context Protocol](https://modelcontextprotocol.io) connects the same way: the streamable HTTP endpoint `https://api.sequel.sh/mcp`, authenticated with a Bearer API key.

<Callout type="tip" title="Grab an API key first">
Create a key under **Settings → API Keys** in the dashboard and pass it as `Authorization: Bearer sql_…`. See [API keys & authentication](/docs/api-keys-and-auth) for details.
</Callout>

## Vercel AI SDK

Create an MCP client over the streamable HTTP transport, then hand its tools to `generateText`.

```ts
import { experimental_createMCPClient, generateText, stepCountIs } from "ai";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { anthropic } from "@ai-sdk/anthropic";

const mcp = await experimental_createMCPClient({
  transport: new StreamableHTTPClientTransport(new URL("https://api.sequel.sh/mcp"), {
    requestInit: {
      headers: { Authorization: "Bearer " + process.env.SEQUEL_API_KEY },
    },
  }),
});

const { text } = await generateText({
  model: anthropic("claude-opus-4-8"),
  tools: await mcp.tools(),
  stopWhen: stepCountIs(10),
  prompt: "How many users signed up last week?",
});

console.log(text);
```

## Claude Agent SDK

Register Sequel as an `http` MCP server in the `query` options — the agent discovers and calls the tools on its own.

```ts
import { query } from "@anthropic-ai/claude-agent-sdk";

const response = query({
  prompt: "How many users signed up last week?",
  options: {
    mcpServers: {
      sequel: {
        type: "http",
        url: "https://api.sequel.sh/mcp",
        headers: { Authorization: "Bearer " + process.env.SEQUEL_API_KEY },
      },
    },
  },
});

for await (const message of response) {
  if (message.type === "result") console.log(message.result);
}
```

## OpenAI Agents SDK

Wrap the endpoint in an `MCPServerStreamableHttp` and attach it to your agent's `mcpServers`.

```ts
import { Agent, run, MCPServerStreamableHttp } from "@openai/agents";

const sequel = new MCPServerStreamableHttp({
  name: "Sequel",
  url: "https://api.sequel.sh/mcp",
  requestInit: {
    headers: { Authorization: "Bearer " + process.env.SEQUEL_API_KEY },
  },
});

const agent = new Agent({
  name: "Data analyst",
  instructions: "Answer questions using the connected data sources.",
  mcpServers: [sequel],
});

await sequel.connect();
const result = await run(agent, "How many users signed up last week?");
console.log(result.finalOutput);
await sequel.close();
```

## Next steps

- [Install Sequel MCP in your tool](/docs/install)
- [API keys & authentication](/docs/api-keys-and-auth)
- [Browse all integrations](/docs/integrations)
