> **Building with AI coding agents?** If you're using an AI coding agent, install the official Scalekit plugin. It gives your agent full awareness of the Scalekit API — reducing hallucinations and enabling faster, more accurate code generation.
>
> - **Claude Code**: `/plugin marketplace add scalekit-inc/claude-code-authstack` then `/plugin install <auth-type>@scalekit-auth-stack`
> - **GitHub Copilot CLI**: `copilot plugin marketplace add scalekit-inc/github-copilot-authstack` then `copilot plugin install <auth-type>@scalekit-auth-stack`
> - **Codex**: run the bash installer, restart, then open Plugin Directory and enable `<auth-type>`
> - **Skills CLI** (Windsurf, Cline, 40+ agents): `npx skills add scalekit-inc/skills --list` then `--skill <skill-name>`
>
> `<auth-type>` / `<skill-name>`: `agentkit`, `full-stack-auth`, `mcp-auth`, `modular-sso`, `modular-scim` — [Full setup guide](https://docs.scalekit.com/dev-kit/build-with-ai/)

---

# Vercel AI SDK

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
import { ScalekitClient } from '@scalekit-sdk/node';
import { ConnectorStatus } from '@scalekit-sdk/node/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb';

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
import { generateText, jsonSchema, stepCountIs, tool } from 'ai';
import { openai } from '@ai-sdk/openai';

const { tools: scopedTools } = await scalekit.tools.listScopedTools('user_123', {
  filter: { connectionNames: ['gmail'] },
});

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 a Scalekit-generated MCP URL to connect without any tool schema setup:

```typescript
import { experimental_createMCPClient, generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const mcpClient = await experimental_createMCPClient({
  transport: {
    type: 'sse',
    url: mcpUrl,  // from actions.mcp.ensure_instance()
  },
});

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 [Generate user MCP URLs](/agentkit/mcp/generate-user-urls/) to get `mcpUrl`.

---

## 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 |
