Skip to content

Add search result pagination support #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

sebthom
Copy link
Contributor

@sebthom sebthom commented Aug 9, 2025

To avoid errors like:

Error: MCP tool "find_code" response (194537 tokens) exceeds maximum allowed tokens (25000).
Please use pagination, filtering, or limit parameters to reduce the response size.

I also implemented a very simple caching mechanism to allow effective and consistent pagination, that caches only last ast-grep result on subsequent find_code calls with the same search pattern. New queries with different pattern or same query with offset=0 will result in cache invalidation.

To avoid errors like:
Error: MCP tool "find_code" response (194537 tokens) exceeds maximum
allowed tokens (25000). Please use pagination, filtering, or limit
parameters to reduce the response size.
@HerringtonDarkholme
Copy link
Member

I think an alternative way to implement this is not to return JSON but alternative format, or to selectively return fields.

@sebthom
Copy link
Contributor Author

sebthom commented Aug 9, 2025

I don't think changing the format to something else solves not reaching the token limit of the consuming model (in my case Opus 4).

I am using it like this with claude-code and it works fine.

Even if you selectively return fields this my not prevent you from blowing up the token limit when enough matches are found.

The problem also is the client does not know in advance how long the result is so from my view paging is the only option to handle this gracefully.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Aug 9, 2025

No, I don't want to introduce additional behaviors like pagination, which requires additional maintenance and LLM understanding the tool usage.

I also don't see ripgrep tool has such behavior.

Can you check how ripgrep tool call is handling the output? Also running the command without --json is worth trying.

For example this ripgrep mcp does not have any pagination and the return is not json as well https://github.com/mcollina/mcp-ripgrep/blob/main/src/index.ts#L479-L487

@sebthom
Copy link
Contributor Author

sebthom commented Aug 9, 2025

ripgrep mcp has a maxResults parameter.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Aug 9, 2025

I think we should follow ripgrep's convention. Also ripgrep is not returning JSON.

@sebthom
Copy link
Contributor Author

sebthom commented Aug 10, 2025

Superseeded by #14

@sebthom sebthom closed this Aug 10, 2025
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