Skip to content

Fix document/organization name filtering (client-side substring match) - #5

Open
jason-sager wants to merge 1 commit into
Junto-Platforms:mainfrom
jason-sager:fix/document-name-search
Open

Fix document/organization name filtering (client-side substring match)#5
jason-sager wants to merge 1 commit into
Junto-Platforms:mainfrom
jason-sager:fix/document-name-search

Conversation

@jason-sager

Copy link
Copy Markdown

Problem

itglue_list_documents (and itglue_list_organizations) advertise filter_name as a "partial match", but it doesn't filter at all — a name-filtered query returns the organization's entire document library.

Root cause: the IT Glue API's documents relationship endpoint does not support filter[name] (its only documented filter is filter[document_folder_id]), and where filter[name] exists on other resources it is exact whole-string match, never substring. The server sends filter[name]=<term> faithfully, but the API silently ignores the unrecognized param, so the two-call root + folder merge returns everything. This also contradicts the server's own instructions block, which says filters are exact-match.

There's also a secondary bug: list_documents reports the total as rootResult.total_count + folderResult.total_count, which double-counts.

Fix

Move name matching client-side, where substring matching is actually possible:

  • Add ITGlueClient.getAll() — fully paginates an endpoint at page[size]=1000, with termination guards (hard page cap, empty-page break, non-advancing next_page break).
  • itglue_list_documents: when filter_name is set, fetch all documents (root + folder), dedupe by id, match by case-insensitive substring, then paginate the filtered list client-side. filter_id (a genuine server-side exact match) stays on the wire.
  • itglue_list_organizations: same treatment via a single getAll over /organizations; id/type/status filters stay server-side.
  • Browse mode (no filter_name) is unchanged except the total is now the deduped row count instead of the double-counted sum.
  • Corrected the misleading "partial match" / "exact match" wording in both schemas, both tool descriptions, the server instructions block, and the README so they match actual behavior.

Notes / trade-offs

  • A name-filtered query now fetches the full list for the scope before matching (bounded: ~2 × ceil(docCount/1000) requests for documents; well within the 3000-req/5-min limit). Prefer filter_id when the exact ID is known.
  • No new dependencies; no public tool signatures changed.

Tests

  • New getAll unit tests (multi-page accumulation, all three guards, page[size]=1000).
  • New search-mode tests for both tools (substring, case-insensitivity, dedup, client-side pagination).
  • Updated the assertions that encoded the old on-the-wire filter[name] behavior and the double-counted total.
  • npm test194 passing; tsc --noEmit clean.

🤖 Generated with Claude Code

The IT Glue API does not support filter[name] on the documents endpoint
(its only documented filter is filter[document_folder_id]), and where
filter[name] exists on other resources it is exact whole-string match. The
server sent filter[name]=<term> anyway; the API silently ignored it and the
two-call root+folder merge returned the organization's entire library — even
though the tool advertised "partial match."

- Add ITGlueClient.getAll() to fully paginate an endpoint, with termination
  guards (hard page cap, empty-page break, non-advancing next_page break).
- itglue_list_documents / itglue_list_organizations: match filter_name as a
  case-insensitive substring client-side over the full list, then paginate.
  Exact filters (id, type, status) stay server-side.
- Fix the double-counted total in list_documents browse mode (was
  rootResult.total_count + folderResult.total_count).
- Make wording truthful in both schemas, both tool descriptions, the server
  instructions block, and the README.

Tests: add getAll pagination/guard tests and search-mode tests; update the
assertions that encoded the old on-the-wire filter[name] behavior. 194 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant