From d351a9fd2e294f4673dd98de27ac754f4ef591d6 Mon Sep 17 00:00:00 2001 From: Adam Fourney Date: Tue, 25 Mar 2025 07:33:02 -0700 Subject: [PATCH] Added STDIO default option. --- packages/markitdown-mcp/README.md | 22 ++++++++++++---- .../src/markitdown_mcp/__main__.py | 26 ++++++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/markitdown-mcp/README.md b/packages/markitdown-mcp/README.md index 65b6409..a09c800 100644 --- a/packages/markitdown-mcp/README.md +++ b/packages/markitdown-mcp/README.md @@ -4,7 +4,7 @@ ![PyPI - Downloads](https://img.shields.io/pypi/dd/markitdown) [![Built by AutoGen Team](https://img.shields.io/badge/Built%20by-AutoGen%20Team-blue)](https://github.com/microsoft/autogen) -The `markitdown-mcp` package provides a lightweight SSE MCP server for calling MarkItDown. +The `markitdown-mcp` package provides a lightweight STDIO and SSE MCP server for calling MarkItDown. It exposes one tool: `convert_to_markdown(uri)`, where uri can be any `http:`, `https:`, `file:`, or `data:` URI. @@ -18,10 +18,17 @@ pip install markitdown-mcp ## Usage -To run the MCP server, use the following command: +To run the MCP server, ussing STDIO (default) use the following command: + ```bash -markitdown-mcp --host 127.0.0.1 --port 3001 +markitdown-mcp +``` + +To run the MCP server, ussing SSE use the following command: + +```bash +markitdown-mcp --sse --host 127.0.0.1 --port 3001 ``` ## Accessing from Claude Desktop @@ -38,7 +45,12 @@ npx @modelcontextprotocol/inspector You can then connect to the insepctor through the specified host and port (e.g., `http://localhost:5173/`). -Then: +If using STDIO: +* select `STDIO` as the transport type, +* input `markitdown-mcp` as the command, and +* click `Connect` + +If using SSE: * select `SSE` as the transport type, * input `http://127.0.0.1:3001/sse` as the URL, and * click `Connect` @@ -51,7 +63,7 @@ Finally: ## Security Considerations -The server does not support authentication, and runs with the privileges of the user running it. It is recommended to run the server bound to `localhost` (default). +The server does not support authentication, and runs with the privileges if the user running it. For this reason, when running in SSE mode, it is recommended to run the server bound to `localhost` (default). ## Trademarks diff --git a/packages/markitdown-mcp/src/markitdown_mcp/__main__.py b/packages/markitdown-mcp/src/markitdown_mcp/__main__.py index 99f6f97..32b7527 100644 --- a/packages/markitdown-mcp/src/markitdown_mcp/__main__.py +++ b/packages/markitdown-mcp/src/markitdown_mcp/__main__.py @@ -1,3 +1,4 @@ +import sys from typing import Any from mcp.server.fastmcp import FastMCP from starlette.applications import Starlette @@ -49,16 +50,33 @@ def main(): mcp_server = mcp._mcp_server parser = argparse.ArgumentParser(description="Run MCP SSE-based MarkItDown server") + parser.add_argument( - "--host", default="127.0.0.1", help="Host to bind to (default: 127.0.0.1)" + "--sse", + action="store_true", + help="Run the server with SSE transport rather than STDIO (default: False)", ) parser.add_argument( - "--port", type=int, default=3001, help="Port to listen on (default: 3001)" + "--host", default=None, help="Host to bind to (default: 127.0.0.1)" + ) + parser.add_argument( + "--port", type=int, default=None, help="Port to listen on (default: 3001)" ) args = parser.parse_args() - starlette_app = create_starlette_app(mcp_server, debug=True) - uvicorn.run(starlette_app, host=args.host, port=args.port) + if not args.sse and (args.host or args.port): + parser.error("Host and port arguments are only valid when using SSE transport.") + sys.exit(1) + + if args.sse: + starlette_app = create_starlette_app(mcp_server, debug=True) + uvicorn.run( + starlette_app, + host=args.host if args.host else "127.0.0.1", + port=args.port if args.port else 3001, + ) + else: + mcp.run() if __name__ == "__main__":