Skip to content

Reduce token usage in MCP tools by avoiding unnecessary data fetching#229

Open
RomKadria wants to merge 2 commits intomasterfrom
feature/romka/refactor-tools
Open

Reduce token usage in MCP tools by avoiding unnecessary data fetching#229
RomKadria wants to merge 2 commits intomasterfrom
feature/romka/refactor-tools

Conversation

@RomKadria
Copy link
Collaborator

Summary

Three targeted optimizations to reduce response payload sizes in platform API tools, cutting unnecessary token consumption:

1. get_updates — Conditional fetching + dropped HTML body

Problem: The GraphQL queries always fetched replies and assets from the monday.com API, even when includeReplies and includeAssets were false. The tool discarded them in JavaScript after they'd already been transferred. Additionally, every update returned both body (HTML markup) and text_body (plain text) — the HTML is unnecessary for LLM consumption and roughly doubles each update's content size.

Fix:

  • Added @include(if: $includeReplies) and @include(if: $includeAssets) directives to both GetItemUpdates and GetBoardUpdates GraphQL queries, so the API itself skips these fields when not requested.
  • Removed the body (HTML) field from queries and response mapping — text_body is sufficient for LLM tools.

2. get_board_activity — New includeData option (default false)

Problem: Each activity log entry has a data field containing the full raw JSON of before/after column state for every change. With the default limit of 1000 entries, this produces massive payloads — often 100k+ tokens of raw JSON that the LLM rarely needs.

Fix:

  • Added an includeData input parameter (boolean, default false) with a descriptive schema.
  • Added @include(if: $includeData) directive to the data field in the GraphQL query so it's not even fetched when not needed.

3. list_users_and_teams — Fixed listUsersOnly query

Problem: The listUsersOnly GraphQL query was identical to listUsersWithTeams — both fetched teams { ...UserTeamMembership } for every user. With DEFAULT_USER_LIMIT = 1000, this meant team membership data for up to 1000 users was being fetched and serialized for no reason on the "users only" code path.

Fix: Removed the teams fragment from listUsersOnly so it actually matches its semantic intent.

Test plan

  • All 13 get-updates-tool tests pass (including updated assertions for new includeReplies/includeAssets variables)
  • All 14 list-users-and-teams-tool tests pass
  • GraphQL codegen succeeds with updated queries
  • Zero linter errors on all changed files

Made with Cursor

RomKadria and others added 2 commits March 12, 2026 01:50
- get_updates: Use @include directives so replies and assets are only
  fetched from the API when requested (previously always fetched and
  discarded in JS). Drop redundant HTML body field — text_body is
  sufficient for LLM consumption and roughly halves update content size.

- get_board_activity: Add opt-in includeData parameter (default false)
  with @include directive. The raw data field contains full before/after
  JSON state of every change and was unconditionally fetched for up to
  1000 entries, producing massive payloads.

- list_users_and_teams: Fix listUsersOnly query which was identical to
  listUsersWithTeams — it fetched team membership data for every user
  (up to 1000) despite being the "users only" code path.

Made-with: Cursor
Copy link
Collaborator

@damian-rakus damian-rakus left a comment

Choose a reason for hiding this comment

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

Before merging let's make sure all relevant subgraphs support the @include

@RomKadria
Copy link
Collaborator Author

Before merging let's make sure all relevant subgraphs support the @include

Yeah I sent them a message, I think you are in that channel as well

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.

2 participants