Skip to content

fix(mcp): cap ChatGPT list_posts limit at 50 instead of rejecting it - #136

Merged
Ooscaar merged 1 commit into
developfrom
mcp-watch/list-posts-limit
Nov 27, 2026
Merged

Ooscaar merged 1 commit into
developfrom
mcp-watch/list-posts-limit

Conversation

@Ooscaar

@Ooscaar Ooscaar commented Nov 27, 2026

Copy link
Copy Markdown
Member

Problem

ChatGPT regularly calls list_posts with limit above 50. The tool declares limit: int = Field(ge=1, le=50), so pydantic rejects the whole call before it reaches the API (InvalidArguments, limit: less_than_equal).

Axiom (zernio-mcp, last 7 days): 360 failed calls from 99 users, all from the ChatGPT app server (client openai-mcp, surface chatgpt). The error text already names the maximum ("Input should be less than or equal to 50"), but the calls keep failing.

Fix

src/late/mcp/chatgpt_server.py, list_posts:

  • A BeforeValidator (_cap_posts_limit) clamps any number above 50 to 50 before the le=50 check, so an oversized limit returns the newest 50 posts instead of an error. ge=1 still rejects 0 and negatives.
  • The advertised input schema is unchanged: still maximum: 50, same description. The 13 hand-written ChatGPT tools are pinned to the definitions OpenAI approved (tests/fixtures/chatgpt_live_tools.json), and that test still passes.
  • When limit is 50 and more posts exist, the text result adds: "50 is the most one call returns (larger limits are capped); these are the newest. Narrow with status or account_id to see others." The structured output is unchanged.

Why clamp instead of reject

  • Same approach elsewhere. GitHub REST ("the value is automatically reduced to the maximum"), Google AIP-158 ("should coerce down to the maximum permitted page size") and Slack ("Invalid limit values are … adjusted") all clamp. T3 Code's clampedPositiveInt (packages/contracts/src/orchestratorMcp.ts) clamps above the maximum while still advertising it, because some model clients hide or ignore maximum, which is the situation here.
  • Unlike GitHub's silent clamp, the result tells the model it was capped and how to narrow. That's in line with Anthropic's guidance to steer agents when a result is truncated.
  • OpenAI review. The approved definition is unchanged, and every call within the schema behaves exactly as before. Only calls outside the schema now get useful data plus a note instead of an error.
  • Trade-off. Many MCP servers (GitHub MCP, Sentry, Cloudflare, Executor) let the SDK reject out-of-range values as isError results. For ChatGPT, that costs a failed call and a retry every time it overshoots, which is what the numbers above show.

Tests

  • test_list_posts_clamps_an_oversized_limit_instead_of_rejecting_it: calls limit=100. It checks the call succeeds, the API receives limit=50, and the text mentions the cap. It fails on the old code with less_than_equal.
  • test_list_posts_does_not_mention_clamping_for_a_normal_limit: limit=10 passes through unchanged, with no cap note.
  • Full suite after the rebase onto develop: 3844 passed. ruff check src tests and mypy src --ignore-missing-imports are clean.

🤖 Generated with Claude Code

…g it

ChatGPT regularly calls list_posts with limit > 50; pydantic's le=50
rejected the whole call with "limit: less_than_equal" (80 failures from
25 users in a day). A BeforeValidator now caps the value at 50 before the
le check runs, and the text result says 50 is the most one call returns
when more posts exist.

The advertised input schema is unchanged (still maximum: 50 and the same
description) because the 13 hand-written ChatGPT tools are pinned to the
definitions OpenAI approved (tests/fixtures/chatgpt_live_tools.json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ooscaar
Ooscaar merged commit b1c5565 into develop Nov 27, 2026
4 checks passed
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