Skip to content

Fix invalid JSON Schema for query_results_cache_retrieve#263

Merged
data-douser merged 7 commits intomainfrom
copilot/fix-invalid-schema-query-results-cache-retrieve
Apr 24, 2026
Merged

Fix invalid JSON Schema for query_results_cache_retrieve#263
data-douser merged 7 commits intomainfrom
copilot/fix-invalid-schema-query-results-cache-retrieve

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

Closes #262.

Reported Bug

GitHub Copilot Chat rejects the ql-mcp server with HTTP 400 "[...] is not of type 'object', 'boolean'" because query_results_cache_retrieve exposes lineRange and resultIndices as z.tuple([...]), which zod-to-json-schema serializes to an array-style schema (items: [{...}, {...}]) that strict JSON-Schema validators reject.

Update Metadata

  • Breaking Changes: Yes — wire-level shape of lineRange / resultIndices changes from [start, end] to { start, end }. The tool was effectively unusable from Copilot Chat before, so the blast radius is small.
  • API Compatibility: Changed (input shape only; behavior preserved)
  • Performance Impact: Neutral

🎯 Changes Description

Current Behavior

lineRange / resultIndices are declared with z.tuple([...]). The MCP SDK serializes the tool's input schema via zod-to-json-schema, producing per-property values that are JSON arrays. OpenAI/Copilot's strict validator requires every property's schema value to be an object or boolean, and refuses to load the server.

Updated Behavior

Both parameters are declared with z.object({ start, end }) (same min / start <= end refinements) and converted back to [start, end] tuples at the call boundary, so SqliteStore is unchanged. Resulting JSON Schema is a clean type: "object" with start / end integer properties — accepted by Copilot Chat.

Motivation

Restore usability of the entire ql-mcp server in GitHub Copilot Chat, where a single malformed property schema currently fails the whole tools/list validation.

🔄 Before vs. After Comparison

API Changes

// BEFORE
lineRange: z.tuple([z.number().int().min(1), z.number().int().min(1)])
  .refine(([s, e]) => s <= e, { message: 'lineRange start must be <= end' })
  .optional(),

// AFTER
lineRange: z.object({
  start: z.number().int().min(1),
  end:   z.number().int().min(1),
})
  .refine(({ start, end }) => start <= end, { message: 'lineRange.start must be <= lineRange.end' })
  .optional(),

Output Format Changes

Tool output is unchanged. The wire-level input for the affected parameters changes shape:

// BEFORE
{ "cacheKey": "...", "lineRange": [1, 10], "resultIndices": [0, 5] }

// AFTER
{ "cacheKey": "...", "lineRange": { "start": 1, "end": 10 }, "resultIndices": { "start": 0, "end": 5 } }

The serialized JSON Schema for lineRange is now:

{
  "type": "object",
  "properties": {
    "start": { "type": "integer", "minimum": 1 },
    "end":   { "type": "integer", "minimum": 1 }
  },
  "required": ["start", "end"],
  "additionalProperties": false
}

Validation Scenarios

  1. Schema serialization: Asserts every property of every cache tool's inputSchema is an object/boolean (never an array) using the SDK's real toJsonSchemaCompat.
  2. Wire-protocol: New extension e2e test calls client.listTools() against a spawned server and enforces the same invariant for every registered tool, then invokes query_results_cache_retrieve with { start, end }.
  3. Validation: Object form accepted; legacy [start, end] tuple rejected; start > end, negatives, and floats rejected.

Copilot AI self-assigned this Apr 23, 2026
Copilot AI review requested due to automatic review settings April 23, 2026 14:58
Copilot AI review requested due to automatic review settings April 23, 2026 14:58
…t for lineRange/resultIndices)

Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/950558d1-9e5d-4eec-bdd3-0668c904dd1f

Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 23, 2026 15:17
Copilot AI changed the title [WIP] Fix invalid schema for query_results_cache_retrieve tool Fix invalid JSON Schema for query_results_cache_retrieve (Copilot Chat HTTP 400) Apr 23, 2026
Copilot AI requested a review from data-douser April 23, 2026 15:19
Adds tests to generically avoid regressions due to invalid schema
for any MCP tool.
Copilot AI review requested due to automatic review settings April 24, 2026 19:10
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a JSON Schema incompatibility that caused GitHub Copilot Chat to reject the MCP server (HTTP 400 ... is not of type 'object', 'boolean') by changing query_results_cache_retrieve input parameters from tuple-form Zod schemas to object-form schemas that serialize cleanly via zod-to-json-schema.

Changes:

  • Replace lineRange / resultIndices input types from z.tuple([start,end]) to z.object({ start, end }) and adapt the handler by converting back to tuples at the store boundary.
  • Add/expand regression tests to ensure tool input schemas never contain array-valued JSON Schema nodes (unit-level and VS Code e2e).
  • Update the client integration-test fixture inputs and document the breaking input-shape change in CHANGELOG.md.
Show a summary per file
File Description
server/src/tools/cache-tools.ts Changes query_results_cache_retrieve schema for lineRange/resultIndices to object form; converts to tuple internally for existing store APIs.
server/test/src/tools/cache-tools.test.ts Updates schema validation tests for new object shape and adds JSON-schema serialization regression coverage for cache tools.
server/test/src/tools/tool-schema-validation.test.ts Adds a new cross-tool regression test ensuring strict JSON Schema compatibility across all tool input schemas.
extensions/vscode/test/suite/mcp-tool-e2e.integration.test.ts Adds wire-protocol regression coverage ensuring listed tool schemas are strict-validator compatible and exercises new argument shape.
client/integration-tests/.../test-config.json Updates fixture to pass lineRange as {start,end}.
client/integration-tests/.../before/monitoring-state.json Updates stored parameters snapshot to the new {start,end} shape.
client/integration-tests/.../after/monitoring-state.json Updates expected parameters snapshot to the new {start,end} shape.
CHANGELOG.md Documents the Copilot Chat HTTP 400 schema issue and the breaking input-shape change under [Unreleased].
server/dist/codeql-development-mcp-server.js Rebuilt bundled artifact reflecting the schema and handler changes.

Copilot's findings

  • Files reviewed: 8/10 changed files
  • Comments generated: 2

Comment thread server/test/src/tools/tool-schema-validation.test.ts
Comment thread CHANGELOG.md Outdated
@data-douser data-douser changed the title Fix invalid JSON Schema for query_results_cache_retrieve (Copilot Chat HTTP 400) Fix invalid JSON Schema for query_results_cache_retrieve Apr 24, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Nathan Randall <70299490+data-douser@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 19:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Copilot Chat compatibility by changing query_results_cache_retrieve’s lineRange / resultIndices input shape from Zod tuples (which serialize to array-valued schemas) to { start, end } objects, and adds regression tests to ensure all tool schemas remain strict-JSON-Schema-compatible.

Changes:

  • Update query_results_cache_retrieve inputs to object ranges and adapt handler to pass tuples to the underlying store.
  • Add unit/e2e regression tests to ensure tool input schemas never contain array-valued schema nodes (Copilot/OpenAI strict validation).
  • Document the change in the root changelog and update client integration test fixtures to use the new input shape.
Show a summary per file
File Description
server/src/tools/cache-tools.ts Switch lineRange / resultIndices from z.tuple to z.object({ start, end }) and convert back to tuple at the store boundary.
server/test/src/tools/cache-tools.test.ts Update schema validation tests for new object-form inputs and add JSON Schema serialization regression tests for cache tools.
server/test/src/tools/tool-schema-validation.test.ts New global tool-schema regression test validating that tool schemas don’t contain array-valued schema nodes.
extensions/vscode/test/suite/mcp-tool-e2e.integration.test.ts Add wire-level regression test that listTools() returns strict-JSON-Schema-compatible inputSchema for every tool, and exercise new object-form args.
client/integration-tests/primitives/tools/query_results_cache_retrieve/retrieve_with_subset/test-config.json Update integration test tool arguments to include object-form lineRange.
client/integration-tests/primitives/tools/query_results_cache_retrieve/retrieve_with_subset/before/monitoring-state.json Update recorded parameters to include object-form lineRange.
client/integration-tests/primitives/tools/query_results_cache_retrieve/retrieve_with_subset/after/monitoring-state.json Update recorded parameters to include object-form lineRange.
CHANGELOG.md Add an Unreleased entry describing the schema fix and input shape change.
server/dist/codeql-development-mcp-server.js Bundled output reflecting the TypeScript changes.

Copilot's findings

  • Files reviewed: 8/10 changed files
  • Comments generated: 2

Comment thread server/test/src/tools/tool-schema-validation.test.ts
Comment thread CHANGELOG.md Outdated
Copilot AI review requested due to automatic review settings April 24, 2026 19:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Copilot Chat compatibility issue by changing query_results_cache_retrieve input parameters from tuple form ([start, end]) to object form ({ start, end }), avoiding invalid JSON Schema serialization that caused tools/list to be rejected.

Changes:

  • Update query_results_cache_retrieve input schema for lineRange and resultIndices from z.tuple(...) to z.object({ start, end }), converting back to tuples at the store boundary.
  • Add regression tests to ensure tool input schemas never serialize to array-valued JSON Schema fragments (unit + VS Code e2e).
  • Update client integration test fixtures and changelog to reflect the new wire-level input shape.
Show a summary per file
File Description
server/src/tools/cache-tools.ts Switch lineRange/resultIndices to object inputs and convert back to tuple internally to keep store APIs unchanged.
server/test/src/tools/cache-tools.test.ts Update schema validation expectations and add cache-tool JSON Schema serialization regression tests.
server/test/src/tools/tool-schema-validation.test.ts New test validating JSON Schema serialization invariants across all registered tools.
extensions/vscode/test/suite/mcp-tool-e2e.integration.test.ts Add wire-level e2e regression asserting all tool schemas are strict-JSON-Schema-valid and validate the new {start,end} inputs.
client/integration-tests/**/test-config.json Update tool invocation arguments to use the new lineRange object form.
client/integration-tests/**/monitoring-state.json Update stored parameters snapshots to match the new input shape.
CHANGELOG.md Document the fix and breaking input-shape change under [Unreleased].
server/dist/codeql-development-mcp-server.js Regenerated bundle reflecting the schema and handler updates.

Copilot's findings

  • Files reviewed: 8/10 changed files
  • Comments generated: 0

@data-douser data-douser marked this pull request as ready for review April 24, 2026 20:06
@data-douser data-douser requested review from a team and enyil as code owners April 24, 2026 20:06
@data-douser data-douser added bug Something isn't working testing labels Apr 24, 2026
@data-douser data-douser merged commit db62263 into main Apr 24, 2026
20 checks passed
@data-douser data-douser deleted the copilot/fix-invalid-schema-query-results-cache-retrieve branch April 24, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix invalid schema for query_results_cache_retrieve tool use in VS Code Copilot Chat

3 participants