Build AI applications with Civic and the Vercel AI SDK. Your agents can access external tools via MCP — GitHub, Slack, Google Workspace, and more.
Framework: This guide is written for Next.js projects. The core MCP client setup works with any JavaScript framework, but the authentication examples below use Next.js-specific APIs.
The fastest way to get started is with the starter template:
AI Chatbot Starter
Clone our Next.js + Vercel AI SDK template with Civic pre-configured. Includes authentication, streaming, and tool calling out of the box.
git clone https://github.com/civicteam/ai-chatbot.gitcd ai-chatbotpnpm installcp .env.example .env.local# Edit .env.local with your CIVIC_AUTH_CLIENT_ID and AI provider keyspnpm dev
pnpm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/react @modelcontextprotocol/sdk @civic/auth
Vercel AI SDK version: experimental_createMCPClient ships in the ai package for AI SDK v5. If you’re on v6+, install @ai-sdk/mcp and import from there instead:
pnpm install @ai-sdk/mcp
// v6+import { experimental_createMCPClient } from '@ai-sdk/mcp';// v5import { experimental_createMCPClient } from 'ai';
Why user auth for tool calls? Civic needs to know which user’s toolkit and permissions to use. For multi-user apps, each user gets their own access token tied to their Civic account.Why Civic Auth? Civic needs to identify which user is accessing tools and authorize their permissions. Civic Auth provides the secure access token. (Support for additional identity providers coming soon.)
1. next.config.ts
2. API Route
3. Middleware
4. Get Token
import { createCivicAuthPlugin } from "@civic/auth/nextjs"import type { NextConfig } from "next";const nextConfig: NextConfig = {};const withCivicAuth = createCivicAuthPlugin({ clientId: "YOUR_CLIENT_ID" });export default withCivicAuth(nextConfig)
File:src/app/api/auth/[...civicauth]/route.ts
import { handler } from "@civic/auth/nextjs"export const GET = handler()export const POST = handler()