Skip to content

Give the /api/chat agent the MCP toolset - #11

Merged
kamath merged 1 commit into
mainfrom
ai-sdk-mcp-agent
Jul 26, 2026
Merged

Give the /api/chat agent the MCP toolset#11
kamath merged 1 commit into
mainfrom
ai-sdk-mcp-agent

Conversation

@kamath

@kamath kamath commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

The agent behind /api/chat had no tools, so a chat turn could only talk. It now builds its toolset from the MCP server at /api/mcp via @ai-sdk/mcp's createMCPClient, so the agent sees exactly the tools every other MCP client does — one per OpenAPI operation, with no parallel hand-written list to drift.

The transport's fetch hands the request to app.request, so it never leaves the process; app is imported lazily because app.ts already imports the agent, and the client is closed from the stream's onEnd rather than a finally, which would cut it off mid-turn.

The chat route renders tool parts with AI Elements' Tool panel (added along with the code-block it depends on, hence shiki), showing each call's input and output as a collapsible panel.

🤖 Generated with Claude Code

`/api/chat` built its agent with no tools; the MCP server at `/api/mcp`
already derives one tool per OpenAPI operation, so the agent now consumes
that server through `@ai-sdk/mcp`'s `createMCPClient` rather than carrying a
parallel hand-written list. The transport's `fetch` calls `app.request` so
the request never leaves the process, `app` is imported lazily to avoid the
cycle, and the client closes on the stream's `onEnd` — a `finally` around the
handler would cut it off mid-turn.

The chat route renders tool parts with AI Elements' `Tool` panel, which pulls
in `code-block` and therefore `shiki`.

Co-Authored-By: Claude <noreply@anthropic.com>
@kamath
kamath merged commit b5573d9 into main Jul 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant