-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Use HTTP transport for MCP to properly pass authInfo #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Use HTTP transport for MCP to properly pass authInfo #139
Conversation
Replace InMemoryTransport with StreamableHTTPClientTransport to make HTTP requests to /api/mcp endpoint with forwarded auth token. This ensures MCP tool handlers receive proper authInfo through the established withMcpAuth middleware flow. - Add authToken to ChatRequestBody type - Extract auth token from request headers in validateChatRequest - Use HTTP transport to /api/mcp with Authorization header - Update tests to include authToken in request bodies Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Internal flows like email processing don't have an auth token from HTTP headers. Make authToken optional and skip MCP tools when not present. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move getBaseUrl utility to its own file following SRP. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move MCP tools fetching logic to its own file following SRP. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace StreamableHTTPClientTransport with AI SDK's built-in transport
config which provides a simpler API:
transport: {
type: "sse",
url: "...",
headers: { Authorization: "..." }
}
This should fix the "Streamable HTTP error" issue.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The MCP route is at app/mcp/route.ts, not app/api/mcp/route.ts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The mcp-handler server only supports HTTP transport, not SSE. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
| * Sets up and filters tools for a chat request. | ||
| * Aggregates tools from: | ||
| * - MCP server (in-process via in-memory transport, no HTTP overhead) | ||
| * - MCP server (via HTTP transport to /api/mcp for proper auth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * - MCP server (via HTTP transport to /api/mcp for proper auth) | |
| * - MCP server (via HTTP transport to /mcp for proper auth) |
Documentation comment references incorrect MCP endpoint path /api/mcp instead of /mcp
View Details
📝 Patch Details
diff --git a/lib/chat/setupToolsForRequest.ts b/lib/chat/setupToolsForRequest.ts
index 1574630..b15adde 100644
--- a/lib/chat/setupToolsForRequest.ts
+++ b/lib/chat/setupToolsForRequest.ts
@@ -7,7 +7,7 @@ import { getMcpTools } from "@/lib/mcp/getMcpTools";
/**
* Sets up and filters tools for a chat request.
* Aggregates tools from:
- * - MCP server (via HTTP transport to /api/mcp for proper auth)
+ * - MCP server (via HTTP transport to /mcp for proper auth)
* - Google Sheets (via Composio integration)
*
* @param body - The chat request body
Analysis
Bug Explanation:
The comment at line 10 of lib/chat/setupToolsForRequest.ts contains an inaccurate reference to the MCP endpoint. The comment states "via HTTP transport to /api/mcp for proper auth", but the actual endpoint is /mcp, not /api/mcp.
This was confirmed by examining:
- The file structure shows
app/mcp/route.ts(notapp/api/mcp/route.ts), which in Next.js app router maps to the/mcpendpoint - The actual implementation in
lib/mcp/getMcpTools.tsat line 14 constructs the URL as${getBaseUrl()}/mcp, confirming the endpoint is/mcp
While this is a documentation comment and doesn't affect runtime behavior, it creates confusion for developers reading the code who might think the endpoint should be at /api/mcp.
Fix Applied:
Changed line 10 from:
- MCP server (via HTTP transport to /api/mcp for proper auth)
to:
- MCP server (via HTTP transport to /mcp for proper auth)
This ensures the comment accurately reflects the actual endpoint being used throughout the codebase.
Summary
Changes
authTokentoChatRequestBodytypevalidateChatRequestsetupToolsForRequestto use HTTP transport to/api/mcpwith Authorization headerauthTokenin request bodiesTest plan
🤖 Generated with Claude Code