added offset to MCP tools

This commit is contained in:
Gamosoft 2026-03-23 17:57:57 +01:00
parent 3c3d15fcb2
commit 7342def2ce
3 changed files with 30 additions and 12 deletions

View File

@ -153,19 +153,22 @@ The MCP server provides these tools to AI assistants:
## Tool Details
### Pagination with `max_results`
### Pagination with `max_results` and `offset`
Some tools support an optional `max_results` parameter to limit results for large vaults:
Some tools support optional pagination parameters for large vaults:
| Tool | Parameter | Description |
|------|-----------|-------------|
| `search_notes` | `max_results` | Limit number of search results |
| `list_notes` | `max_results` | Limit number of notes returned |
| `get_notes_by_tag` | `max_results` | Limit number of notes returned |
| Tool | Parameters | Description |
|------|------------|-------------|
| `search_notes` | `max_results`, `offset` | Paginate search results |
| `list_notes` | `max_results`, `offset` | Paginate notes list |
| `get_notes_by_tag` | `max_results`, `offset` | Paginate notes by tag |
When omitted, all results are returned. This is useful for large note collections where you only need a subset.
- `max_results` - Maximum items to return (omit for all)
- `offset` - Number of items to skip (for pagination)
**Example prompt:** "Search for notes about Python, but just show me the first 5 results"
**Example prompts:**
- "Search for notes about Python, but just show me the first 5 results"
- "Show me the next 5 Python notes" (uses offset)
---

View File

@ -208,12 +208,13 @@ class MCPServer:
"""Search notes by query."""
query = args.get("query", "").strip()
max_results = args.get("max_results")
offset = args.get("offset", 0)
if not query:
return "No search term provided. Please specify a query."
# Use server-side pagination if max_results is specified
response = self.client.search(query, limit=max_results)
response = self.client.search(query, limit=max_results, offset=offset)
if not response.success:
return f"Search failed: {response.error}"
@ -250,9 +251,10 @@ class MCPServer:
def _tool_list_notes(self, args: dict) -> str:
"""List all notes."""
max_results = args.get("max_results")
offset = args.get("offset", 0)
# Use server-side pagination if max_results is specified
response = self.client.list_notes(limit=max_results)
response = self.client.list_notes(limit=max_results, offset=offset)
if not response.success:
return f"Failed to list notes: {response.error}"
@ -341,12 +343,13 @@ class MCPServer:
"""Get notes with a specific tag."""
tag = args.get("tag", "")
max_results = args.get("max_results")
offset = args.get("offset", 0)
if not tag:
return "Error: tag is required"
# Use server-side pagination if max_results is specified
response = self.client.get_notes_by_tag(tag, limit=max_results)
response = self.client.get_notes_by_tag(tag, limit=max_results, offset=offset)
if not response.success:
return f"Failed to get notes by tag: {response.error}"

View File

@ -25,6 +25,10 @@ TOOLS: list[dict[str, Any]] = [
"max_results": {
"type": "integer",
"description": "Maximum number of results to return. Useful for large vaults. If not specified, returns all matches."
},
"offset": {
"type": "integer",
"description": "Number of results to skip. Use with max_results for pagination."
}
},
"required": ["query"]
@ -39,6 +43,10 @@ TOOLS: list[dict[str, Any]] = [
"max_results": {
"type": "integer",
"description": "Maximum number of notes to return. Useful for large vaults. If not specified, returns all notes."
},
"offset": {
"type": "integer",
"description": "Number of notes to skip. Use with max_results for pagination."
}
},
"required": []
@ -84,6 +92,10 @@ TOOLS: list[dict[str, Any]] = [
"max_results": {
"type": "integer",
"description": "Maximum number of notes to return. Useful for large vaults. If not specified, returns all matches."
},
"offset": {
"type": "integer",
"description": "Number of notes to skip. Use with max_results for pagination."
}
},
"required": ["tag"]