Repository navigation
fix(mcp): cap ChatGPT list_posts limit at 50 instead of rejecting it - #136
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ChatGPT regularly calls
list_postswithlimitabove 50. The tool declareslimit: 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 (clientopenai-mcp, surfacechatgpt). 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:BeforeValidator(_cap_posts_limit) clamps any number above 50 to 50 before thele=50check, so an oversized limit returns the newest 50 posts instead of an error.ge=1still rejects 0 and negatives.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.limitis 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
limitvalues are … adjusted") all clamp. T3 Code'sclampedPositiveInt(packages/contracts/src/orchestratorMcp.ts) clamps above the maximum while still advertising it, because some model clients hide or ignoremaximum, which is the situation here.isErrorresults. 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: callslimit=100. It checks the call succeeds, the API receiveslimit=50, and the text mentions the cap. It fails on the old code withless_than_equal.test_list_posts_does_not_mention_clamping_for_a_normal_limit:limit=10passes through unchanged, with no cap note.develop: 3844 passed.ruff check src testsandmypy src --ignore-missing-importsare clean.🤖 Generated with Claude Code