Govern a Vercel AI SDK App
You’re building with the Vercel AI SDK, and your app calls tools such as search, database queries and API actions. You want to know which user made each call, limit what they can do, and keep a log.
ACP works with the AI SDK as an MCP server. You point tool discovery at your ACP endpoint, and each tool call is checked and logged. The rest of your app stays the same.
What you need
- A Vercel AI SDK application (Next.js, SvelteKit, or standalone)
- An ACP Cloud workspace (sign up)
- An identity provider configured in ACP (Auth0, Okta, or Entra ID)
Step 1: Install the MCP client
npm install @modelcontextprotocol/sdk
The AI SDK supports MCP tool providers. ACP is a standard MCP server, so you don’t need a custom SDK.
Step 2: Connect to ACP
In your server-side route handler (e.g., app/api/chat/route.ts):
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";
import { experimental_createMCPClient } from "ai";
export async function POST(req: Request) {
const { messages } = await req.json();
const userJwt = req.headers.get("authorization")?.split(" ")[1];
// Connect to ACP as an MCP server
const mcpClient = await experimental_createMCPClient({
transport: {
type: "sse",
url: "https://api.agenticcontrolplane.com/your-slug",
headers: {
Authorization: `Bearer ${userJwt}`,
},
},
});
const tools = await mcpClient.tools();
const result = streamText({
model: openai("gpt-4o"),
messages,
tools,
});
return result.toDataStreamResponse();
}
The tool list is the set of tools enabled for your workspace, and it’s the same for every user. Permissions are checked when a tool is called. A user with salesforce:read can run query tools. A call to a create or update tool without salesforce:write is rejected.
Step 3: Pass user identity from the frontend
On the client side, include the user’s JWT in requests to your API route:
import { useChat } from "ai/react";
export default function Chat() {
const { messages, input, handleInputChange, handleSubmit } = useChat({
api: "/api/chat",
headers: {
Authorization: `Bearer ${session.accessToken}`,
},
});
return (
<form onSubmit={handleSubmit}>
{messages.map((m) => (
<div key={m.id}>{m.content}</div>
))}
<input value={input} onChange={handleInputChange} />
</form>
);
}
The JWT goes from your frontend to your API route to ACP. ACP verifies it on every tool call.
Step 4: Configure tool scopes in ACP
In your ACP dashboard under Policies → Tool Scopes:
{
"salesforce.query": ["salesforce:read"],
"salesforce.createRecord": ["salesforce:write"],
"github.listRepos": ["github:read"],
"slack.postMessage": ["slack:write"]
}
When the model calls a tool the user lacks scopes for, ACP rejects the call with a JSON-RPC error, code -32004 Insufficient scope. The error data lists the required, have and missing scopes.
What happens on every tool call
User message → Your API route → LLM → Tool call → ACP → Backend
↓
Identity verified
Scopes checked
PII scanned
Action logged
- JWT verification: the signature is checked against your IdP’s JWKS endpoint.
- Scope check: the user’s scopes are compared with what the tool requires.
- Built-in rules: SSN and credit card patterns are blocked, and so are SSRF patterns. Private-range blocking (localhost, 10.x, 192.168.x and so on) applies to tools the ACP gateway executes. For tool calls governed at the model proxy, only cloud-metadata endpoints (169.254.x.x,
metadata.google.internal) are blocked, because localhost is the developer’s own machine. Calls reported by harness hooks are not covered by this rule. - Content scanning: configurable PII detection on inputs and outputs.
- Rate limiting: per-user limits.
- Execution: the tool runs through the connector you configured in ACP.
- Audit logging: who, which tool, when, and what was decided.
Edge runtime compatibility
ACP uses standard HTTP (Streamable HTTP or SSE transport), so it works on Vercel’s Edge runtime without Node.js-specific dependencies.
export const runtime = "edge";
export async function POST(req: Request) {
// Same code as above — works on Edge
}
Multiple users, isolated sessions
Each user’s JWT identifies that user. User A’s calls are checked against A’s scopes, and user B’s against B’s. Every audit row carries the user who made the call.
You don’t need to write permission checks in your own code.
Back to guides · Add governance to LangChain → · PII detection →