get_document_by_path
Retrieve Pydantic AI documentation by specifying the file path relative to the documentation root, returning the parsed document content when available.
Instructions
Retrieves a specific document by its path relative to the Pydantic documentation root (e.g., 'usage/models.md'). Returns the ParsedDocument if found, otherwise None.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- pydantic_ai_docs_server/server.py:62-102 (handler)The `get_document_by_path` tool handler, implemented in `server.py` using `FastMCP`. It validates the path, resolves it to a file, and parses it using `parse_markdown_file`.
@app.tool() async def get_document_by_path(path: str) -> Optional[ParsedDocument]: """ Retrieves a specific document by its path relative to the Pydantic documentation root (e.g., 'usage/models.md'). Returns the ParsedDocument if found, otherwise None. """ logger.info(f"Attempting to get document by path: {path}") try: pydantic_docs_root = get_pydantic_docs_path() full_file_path = (pydantic_docs_root / path).resolve() if not str(full_file_path).startswith(str(pydantic_docs_root.resolve())): logger.warning( f"Path traversal attempt or invalid path for get_document_by_path: {path}" ) return None if not full_file_path.is_file(): logger.info( f"Document not found or not a file at path: {path} (resolved: {full_file_path})" ) return None document = parse_markdown_file( file_path=full_file_path, docs_base_dir=pydantic_docs_root ) if document: logger.info(f"Successfully retrieved document: {document.path}") return document else: logger.warning( f"Failed to parse document at path: {path} (resolved: {full_file_path})" ) return None except Exception as e: logger.error( f"Error in get_document_by_path for path '{path}': {e}", exc_info=True ) return None