all2md.mcp.server
FastMCP server for all2md document conversion.
This module implements the main MCP server using FastMCP with stdio transport. It exposes read_document_as_markdown, save_document_from_markdown, and edit_document tools to LLMs with comprehensive security controls.
Functions
main: Server entry point (for CLI)
- all2md.mcp.server.protect_stdout() Iterator[None]
Redirect OS-level stdout (fd 1) to stderr for the duration.
The MCP stdio transport uses stdout for its JSON-RPC messages. Some libraries in the conversion pipeline (notably PyMuPDF) print advisories straight to stdout, which corrupts that channel and breaks the client connection. We point fd 1 at stderr while running conversion code, then restore it before FastMCP serializes the response. This catches both Python-level
printand C-level writes.
- all2md.mcp.server.create_server(config: MCPConfig, read_impl: Callable[[ReadDocumentAsMarkdownInput, MCPConfig], list[Any]], save_impl: Callable[[SaveDocumentFromMarkdownInput, MCPConfig], SaveDocumentFromMarkdownOutput], edit_doc_impl: Callable[[EditDocumentInput, MCPConfig], EditDocumentOutput], search_impl: Callable[[SearchDocumentsInput, MCPConfig], SearchDocumentsOutput], diff_impl: Callable[[DiffDocumentsInput, MCPConfig], DiffDocumentsOutput], outline_impl: Callable[[GetDocumentOutlineInput, MCPConfig], GetDocumentOutlineOutput], list_files_impl: Callable[[ListWorkspaceFilesInput, MCPConfig], ListWorkspaceFilesOutput]) FastMCP
Create and configure FastMCP server with tools.
- Parameters:
config (MCPConfig) – Server configuration
read_impl (callable) – Implementation function for read_document_as_markdown tool
save_impl (callable) – Implementation function for save_document_from_markdown tool
edit_doc_impl (callable) – Implementation function for edit_document tool
search_impl (callable) – Implementation function for search_documents tool
diff_impl (callable) – Implementation function for diff_documents tool
outline_impl (callable) – Implementation function for get_document_outline tool
list_files_impl (callable) – Implementation function for list_workspace_files tool
- Returns:
Configured MCP server instance
- Return type:
FastMCP
- all2md.mcp.server.configure_logging(level: str) None
Configure logging for the MCP server.
- all2md.mcp.server.main() int
Run all2md-mcp server.