list_documents
Retrieve paginated lists of documents from your PocketMCP database to browse indexed files and navigate large collections.
Instructions
List all documents with pagination
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_documents"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Pagination options |
Implementation Reference
- src/server.ts:403-427 (handler)Main handler function that executes the list_documents tool logic. Extracts pagination parameters from args, calls the database to retrieve documents, and returns formatted JSON response with document list and cursor information.
async function handleListDocuments(args: any, db: DatabaseManager): Promise<any> { const { page } = args || {}; const { limit = 50, cursor } = page || {}; // Simple pagination for now - cursor not implemented const documents = db.listDocuments(limit, 0); return { content: [ { type: 'text', text: JSON.stringify({ documents: documents.map(doc => ({ doc_id: doc.doc_id, external_id: doc.external_id, title: doc.title, source: doc.source, updated_at: doc.updated_at, })), next_cursor: documents.length === limit ? 'next' : undefined, // Simplified }, null, 2), }, ], }; } - src/server.ts:214-237 (registration)Tool registration where list_documents is registered with the MCP server. Includes the tool name, description, and input schema definition.
{ name: 'list_documents', description: 'List all documents with pagination', inputSchema: { type: 'object', properties: { page: { type: 'object', properties: { limit: { type: 'number', description: 'Number of documents per page (default: 50)', default: 50, }, cursor: { type: 'string', description: 'Cursor for pagination (not implemented yet)', }, }, description: 'Pagination options', }, }, }, }, - src/db.ts:294-301 (helper)Database helper method that queries SQLite for documents with pagination support (limit/offset). Returns Document array ordered by updated_at DESC.
listDocuments(limit: number = 50, offset: number = 0): Document[] { const stmt = this.db.prepare(` SELECT * FROM documents ORDER BY updated_at DESC LIMIT ? OFFSET ? `); return stmt.all(limit, offset) as Document[]; } - src/server.ts:253-254 (registration)Tool dispatch case in the switch statement that routes list_documents calls to the handler function.
case 'list_documents': return await handleListDocuments(args, db);