> **Building with AI coding agents?** Install the authstack plugin with one command. This equips your agent with accurate Scalekit implementation patterns.
>
> **Recommended**:
> ```bash
> npx @scalekit-inc/cli setup
> ```
>
> Global:
> ```bash
> npm install -g @scalekit-inc/cli
> scalekit setup
> ```
>
> Supports Claude Code, Cursor, GitHub Copilot, Codex + skills for 40+ agents.
> Features: full-stack-auth, agent-auth, mcp-auth, modular-sso, modular-scim.
> [Full setup guide](https://docs.scalekit.com/dev-kit/build-with-ai/)

---

# Vercel AI SDK

Build a Vercel AI SDK agent with Scalekit-authenticated tools using the tool() helper and jsonSchema() adapter.
Build an agent using the Vercel AI SDK that reads a user's Gmail inbox. Use `tool()` and `jsonSchema()` from the `ai` package to wrap Scalekit tools. No manual schema conversion needed.

## Install

```sh
npm install @scalekit-sdk/node ai @ai-sdk/openai
```

## Initialize

```typescript

const scalekit = new ScalekitClient(
  process.env.SCALEKIT_ENV_URL!,
  process.env.SCALEKIT_CLIENT_ID!,
  process.env.SCALEKIT_CLIENT_SECRET!,
);
```

## Connect the user to Gmail

```typescript
const { connectedAccount } = await scalekit.actions.getOrCreateConnectedAccount({
  connectionName: 'gmail',
  identifier: 'user_123',
});
if (connectedAccount?.status !== ConnectorStatus.ACTIVE) {
  const { link } = await scalekit.actions.getAuthorizationLink({ connectionName: 'gmail', identifier: 'user_123' });
  console.log('Authorize Gmail:', link);
}
```

See [Authorize a user](/agentkit/tools/authorize/) for production auth handling.

## Run the agent

```typescript

const { tools: scopedTools } = await scalekit.tools.listScopedTools('user_123', {
  filter: { connectionNames: ['gmail'] },
  pageSize: 100, // fetch beyond the default page so no connector tools are missed
});

const tools = Object.fromEntries(
  scopedTools.map(t => [
    t.tool.definition.name,
    tool({
      description: t.tool.definition.description,
      parameters: jsonSchema(t.tool.definition.input_schema ?? { type: 'object', properties: {} }),
      execute: async (args) => {
        const result = await scalekit.actions.executeTool({
          toolName: t.tool.definition.name,
          identifier: 'user_123',
          toolInput: args,
        });
        return result.data;
      },
    }),
  ]),
);

const { text } = await generateText({
  model: openai('gpt-4o'),
  tools,
  stopWhen: stepCountIs(5),
  prompt: 'Fetch my last 5 unread emails and summarize them',
});
console.log(text);
```

## Use MCP instead

The Vercel AI SDK supports MCP via `experimental_createMCPClient`. Pass the Virtual MCP Server URL and a session token to connect without any tool schema setup:

```typescript

const mcpClient = await experimental_createMCPClient({
  transport: {
    type: 'streamable-http',
    url: mcpUrl,     // mcp_server_url from Virtual MCP Server config
    headers: { Authorization: `Bearer ${mcpToken}` },
  },
});

const tools = await mcpClient.tools();

const { text } = await generateText({
  model: openai('gpt-4o'),
  tools,
  stopWhen: stepCountIs(5),
  prompt: 'Fetch my last 5 unread emails and summarize them',
});
await mcpClient.close();
console.log(text);
```

See [Virtual MCP Servers](/agentkit/mcp/overview/) for setup details and how to get `mcpUrl` and `mcpToken`.


---

## More Scalekit documentation

| Resource | What it contains | When to use it |
|----------|-----------------|----------------|
| [/llms.txt](/llms.txt) | Structured index with routing hints per product area | Start here — find which documentation set covers your topic before loading full content |
| [/llms-full.txt](/llms-full.txt) | Complete documentation for all Scalekit products in one file | Use when you need exhaustive context across multiple products or when the topic spans several areas |
| [sitemap-0.xml](https://docs.scalekit.com/sitemap-0.xml) | Full URL list of every documentation page | Use to discover specific page URLs you can fetch for targeted, page-level answers |
