list_items
Retrieve items with pagination and optional name filtering to manage and navigate data collections efficiently.
Instructions
List all items with optional filtering and pagination.
Args: page: Page number (1-indexed) page_size: Number of items per page filter_name: Optional filter by name (case-insensitive contains)
Returns: A dictionary containing: - items: List of item objects - total: Total number of items matching the filter - page: Current page number - page_size: Number of items per page
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | ||
| page_size | No | ||
| filter_name | No |
Input Schema (JSON Schema)
{
"properties": {
"filter_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"page": {
"default": 1,
"type": "integer"
},
"page_size": {
"default": 10,
"type": "integer"
}
},
"type": "object"
}
Implementation Reference
- src/skeleton_mcp/api/example.py:39-78 (handler)The handler function that implements the list_items tool logic, including pagination, filtering, and mock data handling.async def list_items( page: int = 1, page_size: int = 10, filter_name: str | None = None, ) -> dict[str, Any]: """ List all items with optional filtering and pagination. Args: page: Page number (1-indexed) page_size: Number of items per page filter_name: Optional filter by name (case-insensitive contains) Returns: A dictionary containing: - items: List of item objects - total: Total number of items matching the filter - page: Current page number - page_size: Number of items per page """ # In a real implementation: # client = get_client() # return client.get("items", params={"page": page, "page_size": page_size}) items = list(MOCK_ITEMS.values()) if filter_name: items = [i for i in items if filter_name.lower() in i["name"].lower()] total = len(items) start = (page - 1) * page_size end = start + page_size items = items[start:end] return { "items": items, "total": total, "page": page, "page_size": page_size, }
- src/skeleton_mcp/server.py:89-89 (registration)The registration of the list_items tool using FastMCP by applying mcp.tool() to the imported example.list_items function.mcp.tool()(example.list_items)