added offset to MCP tools
This commit is contained in:
parent
3c3d15fcb2
commit
7342def2ce
|
|
@ -153,19 +153,22 @@ The MCP server provides these tools to AI assistants:
|
||||||
|
|
||||||
## Tool Details
|
## 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 |
|
| Tool | Parameters | Description |
|
||||||
|------|-----------|-------------|
|
|------|------------|-------------|
|
||||||
| `search_notes` | `max_results` | Limit number of search results |
|
| `search_notes` | `max_results`, `offset` | Paginate search results |
|
||||||
| `list_notes` | `max_results` | Limit number of notes returned |
|
| `list_notes` | `max_results`, `offset` | Paginate notes list |
|
||||||
| `get_notes_by_tag` | `max_results` | Limit number of notes returned |
|
| `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)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -208,12 +208,13 @@ class MCPServer:
|
||||||
"""Search notes by query."""
|
"""Search notes by query."""
|
||||||
query = args.get("query", "").strip()
|
query = args.get("query", "").strip()
|
||||||
max_results = args.get("max_results")
|
max_results = args.get("max_results")
|
||||||
|
offset = args.get("offset", 0)
|
||||||
|
|
||||||
if not query:
|
if not query:
|
||||||
return "No search term provided. Please specify a query."
|
return "No search term provided. Please specify a query."
|
||||||
|
|
||||||
# Use server-side pagination if max_results is specified
|
# 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:
|
if not response.success:
|
||||||
return f"Search failed: {response.error}"
|
return f"Search failed: {response.error}"
|
||||||
|
|
@ -250,9 +251,10 @@ class MCPServer:
|
||||||
def _tool_list_notes(self, args: dict) -> str:
|
def _tool_list_notes(self, args: dict) -> str:
|
||||||
"""List all notes."""
|
"""List all notes."""
|
||||||
max_results = args.get("max_results")
|
max_results = args.get("max_results")
|
||||||
|
offset = args.get("offset", 0)
|
||||||
|
|
||||||
# Use server-side pagination if max_results is specified
|
# 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:
|
if not response.success:
|
||||||
return f"Failed to list notes: {response.error}"
|
return f"Failed to list notes: {response.error}"
|
||||||
|
|
@ -341,12 +343,13 @@ class MCPServer:
|
||||||
"""Get notes with a specific tag."""
|
"""Get notes with a specific tag."""
|
||||||
tag = args.get("tag", "")
|
tag = args.get("tag", "")
|
||||||
max_results = args.get("max_results")
|
max_results = args.get("max_results")
|
||||||
|
offset = args.get("offset", 0)
|
||||||
|
|
||||||
if not tag:
|
if not tag:
|
||||||
return "Error: tag is required"
|
return "Error: tag is required"
|
||||||
|
|
||||||
# Use server-side pagination if max_results is specified
|
# 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:
|
if not response.success:
|
||||||
return f"Failed to get notes by tag: {response.error}"
|
return f"Failed to get notes by tag: {response.error}"
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ TOOLS: list[dict[str, Any]] = [
|
||||||
"max_results": {
|
"max_results": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Maximum number of results to return. Useful for large vaults. If not specified, returns all matches."
|
"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"]
|
"required": ["query"]
|
||||||
|
|
@ -39,6 +43,10 @@ TOOLS: list[dict[str, Any]] = [
|
||||||
"max_results": {
|
"max_results": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Maximum number of notes to return. Useful for large vaults. If not specified, returns all notes."
|
"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": []
|
"required": []
|
||||||
|
|
@ -84,6 +92,10 @@ TOOLS: list[dict[str, Any]] = [
|
||||||
"max_results": {
|
"max_results": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Maximum number of notes to return. Useful for large vaults. If not specified, returns all matches."
|
"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"]
|
"required": ["tag"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue