-
Notifications
You must be signed in to change notification settings - Fork 143
MCP server API #744
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?
MCP server API #744
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests
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 |
| }; | ||
|
|
||
| const json = (status: number, data: unknown, extra?: HeadersInit) => { | ||
| return new Response(JSON.stringify(data), { |
Check warning
Code scanning / CodeQL
Information exposure through a stack trace Medium
stack trace information
This information exposed to the user depends on
stack trace information
This information exposed to the user depends on
stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 30 days ago
To fix the problem, sensitive error details (such as stack traces, error messages, and internal error structures) should never be sent to the client. Only generic, non-specific error messages should be sent in the HTTP response, while the details (including stack traces) should be logged server-side for debugging.
Best fix approach:
- In each place where a JSON response is sent with an
erroranddetailproperty, remove the inclusion ofdetail: String(e)from the response sent to the client. - Instead, log the error (message, stack, etc.) on the server using
console.errorto preserve the debugging utility. - Only send generic error messages to the client, e.g.
{ error: "Failed to connect MCP server" }and{ error: "MCP tool execution failed" }. - Direct edits should be made to lines 248 and 357 where currently the error detail is returned to the client.
No new imports are required; only the error response objects and the surrounding catch blocks need to be adjusted.
-
Copy modified lines R248-R250 -
Copy modified lines R358-R359
| @@ -245,7 +245,9 @@ | ||
| } | ||
| client = await connectMcp(baseUrl, apiKey, profile || undefined); | ||
| } catch (e) { | ||
| return json(502, { error: "Failed to connect MCP server", detail: String(e) }, headers); | ||
| // eslint-disable-next-line no-console | ||
| console.error("[mcp] connect MCP server failed", e); | ||
| return json(502, { error: "Failed to connect MCP server" }, headers); | ||
| } | ||
|
|
||
| try { | ||
| @@ -353,8 +355,8 @@ | ||
| return json(200, result, headers); | ||
| } catch (e) { | ||
| // eslint-disable-next-line no-console | ||
| console.error("[mcp] execution failed", String(e)); | ||
| return json(500, { error: "MCP tool execution failed", detail: String(e) }, headers); | ||
| console.error("[mcp] execution failed", e); | ||
| return json(500, { error: "MCP tool execution failed" }, headers); | ||
| } finally { | ||
| await Promise.resolve(client?.close?.()); | ||
| } |
| console.log("[mcp] POST /api/mcp", { | ||
| serverUrlEnv: Boolean(smitheryServerUrlEnv), | ||
| hasApiKey: Boolean(smitheryApiKeyEnv), | ||
| profile: smitheryProfileEnv || undefined, | ||
| hasOpenAIKey: Boolean(openaiApiKey), | ||
| }); |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
an access to hasApiKey
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 30 days ago
To fix the logging of sensitive information, remove or redact any output that could reveal (even indirectly) the existence, value, or configuration of secrets like API keys or sensitive profiles. In this specific case:
- Remove all references to
smitheryServerUrlEnv,smitheryApiKeyEnv,smitheryProfileEnv, andopenaiApiKeyfrom the log statement. - If operational status must be logged (e.g., to check system health), make sure it is generic and does not depend on secret values.
- Only log fixed text or non-sensitive values.
- Adjust the code in
app/api/mcp/route.ts, specifically lines 204–209, so that the log statement does not include any information derived from environment variables that are potentially sensitive.
No additional imports or packages are needed. Only edit the logging line(s).
-
Copy modified line R204
| @@ -201,12 +201,7 @@ | ||
| const openaiApiKey = process.env.OPENAI_API_KEY; | ||
|
|
||
| // eslint-disable-next-line no-console | ||
| console.log("[mcp] POST /api/mcp", { | ||
| serverUrlEnv: Boolean(smitheryServerUrlEnv), | ||
| hasApiKey: Boolean(smitheryApiKeyEnv), | ||
| profile: smitheryProfileEnv || undefined, | ||
| hasOpenAIKey: Boolean(openaiApiKey), | ||
| }); | ||
| console.log("[mcp] POST /api/mcp request received"); | ||
|
|
||
| // Parse body | ||
| let body: unknown; |
No description provided.