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

# Vercel AI SDK

> Route a Vercel AI SDK agent's tool calls through Invoke over MCP: each call checked, recorded as your agent, and receipted.

Your TypeScript agent keeps its model and its `generateText` loop. It gets its tools from your Invoke workspace over MCP, so every tool call goes through Invoke.

## Before you start

In the [console](https://console.invokehq.run/sign-in), open **API** and copy two things: the **MCP endpoint** and an **Agent key**. The key belongs to one agent, so every call your agent makes is recorded as that agent's, and it can't act as another.

```bash theme={null}
export INVOKE_MCP_URL=https://api.invokehq.run/v1/workspaces/ws_…/mcp
export INVOKE_API_KEY=inv_live_…
```

**1. Install**

```bash theme={null}
npm init -y && npm pkg set type=module
npm install ai @ai-sdk/mcp @ai-sdk/openai
export OPENAI_API_KEY=sk-…
```

**2. Write the agent**

Save this as `agent.ts`:

```typescript agent.ts theme={null}
// A Vercel AI SDK agent whose tool calls go through Invoke.
//
// npm install ai @ai-sdk/mcp @ai-sdk/openai
// export INVOKE_API_KEY=inv_live_...      # your agent's own key
// export INVOKE_MCP_URL=https://...       # from `invoke gateway url`
// export OPENAI_API_KEY=sk-...
// node agent.ts
import { createMCPClient } from "@ai-sdk/mcp"
import { openai } from "@ai-sdk/openai"
import { generateText, stepCountIs } from "ai"

const prompt =
  process.argv.slice(2).join(" ") ||
  "Remember that the staging deploy is frozen until Friday. Then recall your notes and tell me what you know."

const invoke = await createMCPClient({
  transport: {
    type: "http",
    url: process.env.INVOKE_MCP_URL!,
    headers: { Authorization: `Bearer ${process.env.INVOKE_API_KEY}` },
  },
})

try {
  const { text, steps } = await generateText({
    model: openai(process.env.MODEL ?? "gpt-5.4-mini"),
    tools: await invoke.tools(),
    stopWhen: stepCountIs(10),
    prompt,
  })
  for (const step of steps) {
    for (const call of step.toolCalls) console.log("→", call.toolName, JSON.stringify(call.input))
  }
  console.log(text)
} finally {
  await invoke.close()
}
```

Node 24 runs `agent.ts` as is. On an older Node, run it with `npx tsx agent.ts`. Close the MCP client when you're done, as the `finally` does.

**3. Run it**

```bash theme={null}
node agent.ts
```

The agent uses Invoke's own memory tools, so it works on a new workspace with nothing connected. You'll see something like:

```text theme={null}
→ invoke_remember {"text":"The staging deploy is frozen until Friday."}
→ invoke_recall {}
Based on my notes, the staging deploy is frozen until Friday.
```

## Give it a real tool

In the console, open **Connectors** and connect a tool: GitHub, Slack, Linear, Notion or any MCP server. Its tools appear to your agent on the next run, with names a model API accepts (a GitHub connector's `create_issue` is listed as `github_create_issue`). Then ask for something that changes the world:

```bash theme={null}
node agent.ts "Open an issue in acme/api titled 'Staging deploy frozen until Friday'"
```

Read back what happened with the [CLI](https://docs.invokehq.run/sdk/cli.md):

```bash theme={null}
invoke login --api-key "$INVOKE_API_KEY"
invoke gateway use ws_…        # the id in your MCP endpoint
invoke gateway receipts
```

Each write has a receipt that names your agent. If the agent claims a task first (`invoke_claim_task`), a retried write for that task is answered with its first receipt instead of running twice.

## What happened

* **Your agent acted as itself.** The key is its identity: Invoke records every call as that agent's.
* **Every call was checked before it ran:** the agent's permissions, your workspace's policies and its budget.
* **`invoke_remember` and `invoke_recall` are Invoke's own memory.** Notes an agent keeps across runs. Claiming a task again brings back its history and notes, and the workspace's other agents can read them.

## Other models

For Claude, `npm install @ai-sdk/anthropic`, import `anthropic` from it, and pass `anthropic(process.env.MODEL ?? "claude-opus-5-5")` as the model.

## Next steps

* [CLI](https://docs.invokehq.run/sdk/cli.md): connect tools, then read receipts and the event log
* [Authentication](https://docs.invokehq.run/configuration/authentication.md): agent keys and account keys
* [Traces](https://docs.invokehq.run/concepts/traces.md): read a run back stage by stage


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.