Skip to content

Handle empty query by sending "null" instead of empty string in MCP context provider #6225

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

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/context/providers/MCPContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class MCPContextProvider extends BaseContextProvider {
private insertInputToUriTemplate(uri: string, query: string): string {
const TEMPLATE_VAR = "query";
if (uri.includes(`{${TEMPLATE_VAR}}`)) {
return uri.replace(`{${TEMPLATE_VAR}}`, encodeURIComponent(query));
// Sending an empty string will result in an error, so we instead send "null"
const queryOrNull = query.trim() === "" ? "null" : query;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line assumes query is a non-null string and calls trim() without any type checking. Since this method is called with extras.fullInput which could be undefined, this could cause a runtime error. The code should add a null check before using trim(), e.g., const queryOrNull = (query?.trim() ?? "") === "" ? "null" : query;


React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)

return uri.replace(`{${TEMPLATE_VAR}}`, encodeURIComponent(queryOrNull));
}
return uri;
}
Expand Down
Loading