list_documents
Retrieve a complete list of indexed documents with their word counts.
Instructions
List every document currently in the index, along with its word count.
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 |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server/main.py:68-85 (handler)The main MCP tool handler for list_documents. Decorated with @mcp.tool(), it calls _index.list_documents() and formats the output as a human-readable string listing each document's filename and word count.
@mcp.tool() def list_documents() -> str: """ List every document currently in the index, along with its word count. """ docs = _index.list_documents() if not docs: return ( "No documents found. Add .txt or .md files to the documents/ directory " "and restart the server." ) lines = [f"Indexed {len(docs)} document(s) from {DOCUMENTS_DIR}:\n"] for d in docs: lines.append(f" - {d['filename']} ({d['word_count']} words)") return "\n".join(lines) - server/search.py:120-124 (helper)The DocumentIndex.list_documents() helper method that returns a list of dicts with 'filename' and 'word_count' for each indexed document, sorted alphabetically by filename.
def list_documents(self) -> list[dict[str, Any]]: return [ {"filename": name, "word_count": len(text.split())} for name, text in sorted(self.documents.items()) ] - server/main.py:68-68 (registration)The tool is registered via the @mcp.tool() decorator on the list_documents function in server/main.py. FastMCP automatically registers it as an available MCP tool.
@mcp.tool() - server/search.py:120-124 (schema)The return type of list_documents is list[dict[str, Any]], where each dict has keys 'filename' (str) and 'word_count' (int). No input parameters are needed.
def list_documents(self) -> list[dict[str, Any]]: return [ {"filename": name, "word_count": len(text.split())} for name, text in sorted(self.documents.items()) ]