Fix #1424: add convert_file and convert_directory MCP tools#1834
Open
kdjkdjkdj wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix #1424: add convert_file and convert_directory MCP tools#1834kdjkdjkdj wants to merge 1 commit intomicrosoft:mainfrom
kdjkdjkdj wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The markitdown-mcp server currently exposes a single tool, convert_to_markdown(uri), which covers http/https/file/data URIs. In practice MCP clients often have plain filesystem paths on hand rather than URIs, which leads to agents spending extra turns on the URI construction (or skipping the tool entirely, see microsoft#1424). This change adds two thin wrapper tools that delegate to the existing MarkItDown.convert_local() API, so no library-side changes are needed: - convert_file(file_path): convert a single local file to markdown. Paths are resolved relative to the current working directory and non-existent paths surface as FileNotFoundError. - convert_directory(dir_path, recursive=True): convert every file in a directory and return a {relative_path: markdown} mapping. Files that fail individually are skipped so a single bad file doesn't abort the batch. Tool-schema generation is handled by FastMCP via Python type hints, so no manual JSON-schema surface is introduced. Closes microsoft#1424. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two thin wrapper MCP tools —
convert_file(file_path)andconvert_directory(dir_path, recursive=True)— alongside the existingconvert_to_markdown(uri). Directly addresses #1424: AI agents tend to skip the current URI-only tool when they already have a plain filesystem path in hand, and end up writing Python glue instead of calling MarkItDown.Changes
One file:
packages/markitdown-mcp/src/markitdown_mcp/__main__.py.convert_file(file_path: str) -> strThin wrapper around
MarkItDown.convert_local(). Resolves~and relative paths against CWD, raisesFileNotFoundErrorfor missing paths viaPath.resolve(strict=True). No library-side change needed.convert_directory(dir_path: str, recursive: bool = True) -> dict[str, str]Walks a directory (recursively by default via
Path.rglob, otherwisePath.iterdir) and converts every file it finds, returning a{relative_path: markdown}mapping. Files that fail individually are skipped with atry/except Exception: continueso a single bad file doesn't abort the batch — mirroring how bulk converters typically behave.Tool schemas are auto-generated by FastMCP from the Python type hints, so no manual JSON-schema surface is introduced.
Backwards compatibility
convert_to_markdown(uri)is untouched.pathlib.Pathfrom the stdlib and the already-importedMarkItDownclass.Test plan
Built and installed locally (editable) on Windows with Python 3.13, then ran the new tools via an MCP client (Claude Code):
convert_fileon a real.docxfrom a deeply-nested OneDrive/SharePoint path with German umlauts (`D:\OneDrive\OneDrive - KEGON AG\KEGON\Intern...\Erfassung-KI-Anwendungsfall-01-Intern-Verzeichnisse.docx`) — converted cleanly.convert_directoryon the repo's own `packages/markitdown-mcp/` (non-recursive) — returned{'Dockerfile', 'pyproject.toml', 'README.md'}.convert_fileautonomously given a plain Windows path (the original `convert_to_markdown` would require the agent to URL-escape and prefixfile://itself — markitdown-mcp: Enhance tool to improve AI agent discoverability for file conversion tasks #1424's core complaint).No unit tests added — the
tests/directory is present but currently empty; happy to addpytestcoverage for both new tools if that's desired before merge.Notes
Closes #1424.