Skip to content

Fix context window overflow and patch all npm security vulnerabilities#17

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-claude-maximum-length-issue
Draft

Fix context window overflow and patch all npm security vulnerabilities#17
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-claude-maximum-length-issue

Conversation

Copilot AI commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Claude exhausts its context window after the first tool call because every API response was returned verbatim — a single getCollections call on a self-hosted instance produces 100 KB+ of schema JSON, leaving almost no room for subsequent exchanges.

Response size fixes

  • truncateResponse helper — serialises to pretty JSON and caps output at 50 000 chars (~12 500 tokens), appending a guidance note when truncated so the LLM knows to use limit/offset
  • getCollections — strips the verbose per-column schema field from every collection entry before serialising; collection and meta are preserved
  • Default limit: 50 on all unbounded list endpoints (getItems, getActivity, getFiles, getUsers, getRoles, getPermissions) — caller-supplied value wins via spread
const query = { limit: 50, ...(toolArgs.query as Record<string, unknown> | undefined) };
  • All 15 tool response paths now route through truncateResponse instead of raw JSON.stringify

Security patches

Package Before After Severity
@modelcontextprotocol/inspector ^0.10.2 ^0.16.6 XSS → RCE via untrusted server; missing client↔proxy auth
axios ^1.6.7 ^1.15.0 High — DoS, SSRF, metadata exfiltration (4 CVEs)
form-data ^4.0.0 ^4.0.4 Critical — unsafe boundary RNG
path-to-regexp (transitive) 8.2.0 ^8.4.0 High — two ReDoS vectors

Copilot AI and others added 3 commits April 20, 2026 13:58
- Add MAX_RESPONSE_SIZE (50 000 chars) constant and truncateResponse helper
  that serialises data to JSON and appends a guidance note when the result
  would exceed the limit.
- Strip the verbose per-column `schema` field from getCollections responses;
  system collections alone can produce 100 KB+ of schema detail that is
  rarely needed.
- Apply a default limit:50 to all list endpoints (getItems, getActivity,
  getFiles, getUsers, getRoles, getPermissions) so that callers get a
  manageable page of results unless they explicitly request more.
- Route every tool response through truncateResponse instead of a raw
  JSON.stringify call.

Agent-Logs-Url: https://github.com/pixelsock/directus-mcp/sessions/87c79510-f24b-4b00-86aa-20dd65d67504

Co-authored-by: pixelsock <4932231+pixelsock@users.noreply.github.com>
- Expand MAX_RESPONSE_SIZE comment to explain the 50 000 char threshold
  (Claude context window, ~12 500 tokens, room for history)
- Add NOTE to truncation message warning callers that the JSON may be
  incomplete at the cut point and guiding them to use limit/offset

Agent-Logs-Url: https://github.com/pixelsock/directus-mcp/sessions/87c79510-f24b-4b00-86aa-20dd65d67504

Co-authored-by: pixelsock <4932231+pixelsock@users.noreply.github.com>
@modelcontextprotocol/inspector: 0.10.2 -> ^0.16.6
  - Fixes XSS / command execution via untrusted MCP server (< 0.16.6)
  - Fixes missing auth between Inspector client and proxy (< 0.14.1)

axios: ^1.6.7 -> ^1.15.0
  - Fixes DoS via missing data-size check (GHSA-4hjh-wcwx-xvwj)
  - Fixes DoS via __proto__ key in mergeConfig (GHSA-43fc-jf86-j433)
  - Fixes NO_PROXY hostname normalisation bypass / SSRF (GHSA-3p68-rc4w-qgx5)
  - Fixes unrestricted cloud metadata exfiltration (GHSA-fvcv-3m26-pcqx)

form-data: ^4.0.0 -> ^4.0.4
  - Fixes unsafe random boundary generation (GHSA-fjxv-7rqg-78g4, critical)

path-to-regexp (transitive, via @modelcontextprotocol/sdk -> express -> router):
  - Bumped to ^8.4.0 via npm audit fix
  - Fixes two ReDoS vulnerabilities (GHSA-j3q9-mxjg-w52f, GHSA-27v5-c462-wpq7)

Agent-Logs-Url: https://github.com/pixelsock/directus-mcp/sessions/87c79510-f24b-4b00-86aa-20dd65d67504

Co-authored-by: pixelsock <4932231+pixelsock@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Claude hitting the maximum length on every other question Fix context window overflow and patch all npm security vulnerabilities Apr 20, 2026
Copilot AI requested a review from pixelsock April 20, 2026 14:06
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.

Claude hitting the maximum length on every other question

2 participants