Give the /api/chat agent the MCP toolset - #11
Merged
Merged
Conversation
`/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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The agent behind
/api/chathad no tools, so a chat turn could only talk. It now builds its toolset from the MCP server at/api/mcpvia@ai-sdk/mcp'screateMCPClient, 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
fetchhands the request toapp.request, so it never leaves the process;appis imported lazily becauseapp.tsalready imports the agent, and the client is closed from the stream'sonEndrather than afinally, which would cut it off mid-turn.The chat route renders tool parts with AI Elements'
Toolpanel (added along with thecode-blockit depends on, henceshiki), showing each call's input and output as a collapsible panel.🤖 Generated with Claude Code