-
Notifications
You must be signed in to change notification settings - Fork 0
feat: configure MCP servers in settings page #3
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
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # lib/db/queries.ts # pnpm-lock.yaml
@tobiasbueschel is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
lets gooo! |
This is sick, we need this! |
While I do hope this PR gets accepted, I believe it may be difficult due to some practical limitations. Why it might not be a good fit for the template: ⸻ That’s why I decided to build a dedicated MCP client project based on what I learned here. 👉 MCP Client Chatbot Hope it’s helpful—and if you have feedback or ideas, I’d love to hear them. Thanks! |
/codehelper please review this pr |
result.mergeIntoDataStream(dataStream, { | ||
sendReasoning: true, | ||
}); | ||
} catch (dbError) { |
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.
Error Handling: The mcpClientsToClose
array is only cleared in the onFinish
handler but not in the error cases. This could lead to memory leaks if errors occur frequently. Consider adding a finally
block to ensure clients are always properly closed.
try { | ||
// Create MCP client based on server config | ||
const config = server.config as any; | ||
let clientOptions: { transport: any; name: string }; |
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.
Type Safety: The config
object is cast as any
which bypasses TypeScript's type checking. Consider defining a proper interface for the config object to improve type safety and code maintainability.
console.error("Invalid SSE config for server", server.id, config); | ||
throw new Error("Invalid SSE configuration: URL is missing or not a string."); | ||
} | ||
clientOptions = { |
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.
UX Improvement: When a server fails to load its schema, the error message is only logged to the console and a generic message is displayed to the user. Consider displaying a more specific error message to help users troubleshoot connection issues.
setError(null); | ||
try { | ||
const fetchedServers = await fetchMcpServers(); | ||
setServers(fetchedServers); |
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.
Performance Concern: The fetchServerSchema
function is called for all enabled servers on initial load, which could lead to performance issues if there are many servers. Consider implementing pagination or lazy loading of schemas.
config.url = newUrl; | ||
// Add headers to config if implemented | ||
} else { // stdio | ||
if (!newCommand) { |
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.
Security Improvement: When handling user input for stdio transport commands, consider implementing additional validation beyond just checking if the command is non-empty. For example, you might want to validate against a whitelist of allowed commands.
|
||
export async function fetchMcpServers() { | ||
const session = await auth(); | ||
if (!session?.user?.id) { |
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.
Code Duplication: There's repeated error handling logic for unauthorized users across multiple functions. Consider extracting this into a reusable middleware or helper function to reduce duplication.
} | ||
} | ||
|
||
export async function addMcpServerAction({ |
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.
Error Handling Inconsistency: Some functions throw errors directly while others return error objects with a success: false
property. Consider standardizing the error handling approach across all functions for better maintainability.
<p className="text-sm text-muted-foreground italic"> | ||
{server.isEnabled | ||
? "No tools available or unable to connect to server" | ||
: "Enable the server to view available tools"} |
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.
Accessibility Improvement: The switch component for toggling server status lacks proper ARIA attributes. Consider enhancing it with appropriate ARIA roles and states to improve accessibility.
type: 'stdio'; | ||
command: string; | ||
args?: string[]; | ||
}; |
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.
Potential Memory Leak: The MCP clients are stored in a state variable but there's no cleanup in the useEffect
return function. Consider adding a cleanup function that closes all active MCP clients when components unmount.
throw new Error('Missing required fields: name and config.'); | ||
} | ||
|
||
try { |
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.
Error Handling: The addMcpServerAction
function returns a success object with an error message on failure, but doesn't include the original error details which could be useful for debugging. Consider adding more detailed error information.
hello |
hello again |
This is a super early (+ very rough) implementation of MCPs for the
ai-chatbot
template. I've only had 30 minutes and tried to see how far I could get using the new Gemini 2.5 and Sonnet 3.7 models, hence, here is the result. This resolves the following issue: vercel#575The PR adds the following:
stdio
if running locally orsse
(we might want to disablestdio
altogether for a deployed version)Here are some screenshots of how it looks like at the moment:
Chat page

Server logs showing output of MPC call

Settings page

Adding new MCPs

Remaining tasks
Hoping to find some time to hand-craft this properly over the weekend, but raising this PR for early feedback and for anyone who would like to help contribute to this!
Cheers
References