all2md.mcp.tools
Tool implementations for MCP server.
This module implements the simplified tool functions for reading documents as markdown and saving markdown to other formats.
Functions
read_document_as_markdown_impl: Implementation of read_document_as_markdown tool
save_document_from_markdown_impl: Implementation of save_document_from_markdown tool
- all2md.mcp.tools.read_document_as_markdown_impl(input_data: ReadDocumentAsMarkdownInput, config: MCPConfig) list[Any]
Implement read_document_as_markdown tool with simplified API.
This implementation uses automatic source detection and AST-based processing to extract images as FastMCP Image objects, allowing vLLMs to “see” the images alongside markdown text.
- Parameters:
input_data (ReadDocumentAsMarkdownInput) – Tool input parameters
config (MCPConfig) – Server configuration (for allowlists, attachment mode, etc.)
- Returns:
List with markdown string as first element, followed by FastMCP Image objects for any images found in the document. FastMCP automatically converts this to appropriate MCP content blocks.
- Return type:
list
- Raises:
MCPSecurityError – If security validation fails
All2MdError – If conversion fails
- all2md.mcp.tools.save_document_from_markdown_impl(input_data: SaveDocumentFromMarkdownInput, config: MCPConfig) SaveDocumentFromMarkdownOutput
Implement save_document_from_markdown tool with simplified API.
This tool always writes to disk (no content return). The filename parameter is required and must pass write allowlist validation.
- Parameters:
input_data (SaveDocumentFromMarkdownInput) – Tool input parameters
config (MCPConfig) – Server configuration (for allowlists, etc.)
- Returns:
Result with output path and warnings
- Return type:
- Raises:
MCPSecurityError – If security validation fails
All2MdError – If rendering fails
Notes
This function uses secure file opening with TOCTOU protection to prevent symlink attacks. The file is opened immediately after validation using OS-level flags (O_NOFOLLOW) to ensure the validated path is actually being written to, not a symlink that was swapped in between validation and write operations.