Skip to content

fix: handle missing/empty task param gracefully in codegraph_context#591

Open
wwhsaber wants to merge 1 commit into
colbymchenry:mainfrom
wwhsaber:fix/empty-task-validation
Open

fix: handle missing/empty task param gracefully in codegraph_context#591
wwhsaber wants to merge 1 commit into
colbymchenry:mainfrom
wwhsaber:fix/empty-task-validation

Conversation

@wwhsaber

Copy link
Copy Markdown

Problem

When MCP clients (notably Cursor Agent) call codegraph_context but pass the search text under query instead of task, or pass it in a malformed way, the tool returns:

task must be a non-empty string

This is confusing and doesn't help the client understand what went wrong.

Changes

1. Parameter fallback in handleContext

// Before
const task = this.validateString(args.task, 'task');
// After
const task = this.validateString(args.task ?? args.query, 'task');

MCP clients that pass query instead of task now work transparently.

2. Improved validateString diagnostics

  • Shows the actual type/value received (e.g. got undefined vs got object)
  • Adds a hint about passing the parameter directly (not wrapped in an object)
  • Trims whitespace before checking length
  • Distinguishes between non-string vs whitespace-only inputs

All error messages still contain non-empty string so existing test assertions pass.

Fixes #577

@wwhsaber wwhsaber force-pushed the fix/empty-task-validation branch from 167a52c to 05d756d Compare June 8, 2026 10:04
Two changes to address colbymchenry#577:

1. Add codegraph_context tool with task/query fallback so MCP clients
   that pass  instead of  still work.

2. Improve validateString error messages:
   - Show the actual type/value received instead of generic message
   - Add hint about passing the parameter directly (not wrapped)
   - Trim whitespace before checking length
   - Distinguish between undefined/non-string vs whitespace-only

Also adds markSessionConsulted helper with CWE-59 symlink protection.

Fixes colbymchenry#577

Rebased on latest upstream/main — old branch had 119 files of conflicts.
@wwhsaber wwhsaber force-pushed the fix/empty-task-validation branch from 05d756d to 3ae85c6 Compare June 9, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Cursor Agent] "task must be a non-empty string" error when query contains spaces or certain phrases

2 participants