epam / epam/statgpt-backend

MCP app: Keep MCP tool results within Claude payload limits via scoping and pagination

Open
#601 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
26
Forks
1
Avg merge
1d 17h
Merged PRs (30d)
25

Description

### StatGPT Backend version
latest

### What is the problem this feature will solve?

Anthropic caps tool results at roughly 150,000 characters on Claude.ai and Claude Desktop and 25,000 tokens in Claude Code. Statistical queries routinely produce result sets far larger than that: a broad dataflow query can return thousands of observations plus metadata.

Without an explicit budget, oversized results are truncated or rejected by the host, which the user experiences as a broken tool rather than as a query that needs narrowing.

Required by: [Anthropic: Building connectors](https://claude.com/docs/connectors/building).

### What is the proposed feature or solution?

**Measure before returning.** Compute the serialized size of every tool result and enforce a configurable budget below the host limits.

**Paginate.** Add cursor-based pagination to list- and observation-returning tools, with a documented default page size and a stable cursor that survives follow-up calls.

**Scope by default.** Apply sensible default limits (time range, dimensions, number of series) and require the caller to widen them explicitly.

**Degrade usefully.** When a result would exceed the budget, return a summary plus the counts and the exact parameters needed to narrow the query, rather than a truncated blob.

**Split model-facing and human-facing payloads.** Keep `structuredContent` scoped to what the model needs; large tabular output should be summarised or offered as a downloadable artifact.

**Definition of done.** A test suite asserts that every tool stays within the budget for a worst-case query, and pagination is documented in the tool schemas.

### What alternatives have you considered?

- **Let the client truncate** — inadequate because truncation happens mid-payload, corrupting structured output and hiding the fact that data is missing.
- **A single global row cap** — insufficient since payload size depends on dimension count and metadata, not row count alone.
- **Always return a download link** — rejected as the default: it breaks the conversational flow for small results the model should reason over directly.

Contributor guide

Open the contributing guide

Research direction

Start by locating the MCP tools and their tool schemas, then inspect how results are serialized into structuredContent. Define the payload budget, pagination behavior, default scoping, and useful degradation rules from the issue. Done means worst-case tool queries stay within budget and pagination is documented in the tool schemas.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.