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

Conversation

sestinj
Copy link
Contributor

@sestinj sestinj commented Jun 20, 2025

Empty query was causing "resource not found" even though the user should be allowed to enter nothing in the input box. There was no way of handling the empty string with current MCP server frameworks

@sestinj sestinj requested a review from a team as a code owner June 20, 2025 18:26
@sestinj sestinj requested review from Patrick-Erichsen and removed request for a team June 20, 2025 18:26
Copy link

netlify bot commented Jun 20, 2025

Deploy Preview for continuedev canceled.

Name Link
🔨 Latest commit 8b6d1ff
🔍 Latest deploy log https://app.netlify.com/projects/continuedev/deploys/6855a7d821410200081832b3

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 20, 2025
@@ -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)

Copy link

recurseml bot commented Jun 20, 2025

😱 Found 1 issue. Time to roll up your sleeves! 😱

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Jun 23, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 23, 2025
@Patrick-Erichsen Patrick-Erichsen merged commit deda3f0 into main Jun 23, 2025
67 of 70 checks passed
@Patrick-Erichsen Patrick-Erichsen deleted the nate/query-empty-null branch June 23, 2025 22:36
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Jun 23, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants