Skip to content

Add optional page and limit parameters to list_tools for server‑side pagination #211

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

Open
samrat12x opened this issue Apr 19, 2025 · 0 comments

Comments

@samrat12x
Copy link

Body:
Describe the feature
Right now FastMCP’s list_tools always returns the full set of registered tools. For users embedding very large tool‐catalogs into LLM contexts, this can bloat payloads and exhaust context length. It would be great to support optional page and limit query parameters so clients can pull tools page‑by‑page.

Motivation and use cases

Context‑size management: LLM clients often need to send only a subset of tools at a time.

Performance: Large tool lists can increase parsing time; paginating on the server avoids sending unnecessary entries.

Consistency with other endpoints: Many GitBook APIs (and our own tools like list_spaces) already accept page/limit.

Proposed implementation

Update the core ListTools handler in fastmcp/server/fastmcp.py to accept two optional query params:

python
Copy
Edit
async def list_tools(self, page: int = 0, limit: int = 100):
all_tools = list(self._tools.values())
start = page * limit
return {
"data": all_tools[start:start+limit],
"page": page,
"limit": limit,
"total": len(all_tools)
}
Ensure backwards compatibility: if page/limit are omitted, return the full list as today.

Add unit tests covering default behavior and several pagination combinations.

Update README and OpenAPI schema to document the new parameters and response shape.

Alternatives considered

Keeping client‑side slicing only—but server‑side pagination is more efficient for very large catalogs.

Additional context
This mirrors how other FastMCP tools (e.g., list_spaces, list_collection_spaces) already handle paging. Happy to open a PR implementing this!

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

No branches or pull requests

1 participant