15.9 C
New York
Thursday, May 15, 2025

MarkItDown MCP Can Convert Any Doc into Markdowns!


Dealing with paperwork is now not nearly opening information in your AI initiatives, it’s about reworking chaos into readability. Docs similar to PDFs, PowerPoints, and Phrase flood our workflows in each form and dimension. Retrieving structured content material from these paperwork has change into a giant process in the present day. Markitdown MCP (Markdown Conversion Protocol) from Microsoft simplifies this. It converts numerous information into structured Markdown format. This helps builders and technical writers enhance documentation workflows. This text explains Markitdown MCP and exhibits its utilization. We’ll cowl organising the Markitdown MCP server and also will talk about MarkItDown within the context of this protocol. Utilizing the Markitdown mcp server for testing can be coated beneath.

What’s MarkItDown MCP?

Markitdown MCP presents a regular methodology for doc conversion. It acts as a server-side protocol. It makes use of Microsoft’s MarkItdown library within the backend. The server hosts a RESTful API. Customers ship paperwork like PDFs or Phrase information to this server. The server then processes these information. It makes use of superior parsing and particular formatting guidelines. The output is Markdown textual content that retains the unique doc construction.

Key Options of Markitdown MCP

The Markitdown MCP server consists of a number of helpful options:

  • Extensive Format Help: It converts widespread information like PDF, DOCX, and PPTX to Markdown.
  • Construction Preservation: It makes use of strategies to grasp and preserve doc layouts like headings and lists.
  • Configurable Output: Customers can regulate settings to regulate the ultimate Markdown type.
  • Server Operation: It runs as a server course of. This permits integration into automated techniques and cloud setups.

The Function of Markdown in Workflows

Markdown is a well-liked format for documentation. Its easy syntax makes it straightforward to learn and write. Many platforms like GitHub help it properly. Static web site mills usually use it. Changing different codecs to Markdown manually takes time. Markitdown MCP automates this conversion. This offers clear advantages:

  • Environment friendly Content material Dealing with: Remodel supply paperwork into usable Markdown.
  • Constant Collaboration: Normal format helps groups work collectively on paperwork.
  • Course of Automation: Embrace doc conversion inside bigger automated workflows.

Setting Up the Markitdown MCP Server for Integration

We are able to arrange the Markitdown MCP server with totally different shoppers like Claude, Windsurf, Cursor utilizing Docker Picture as talked about within the Github Repo. However right here we will likely be creating an area MCP consumer utilizing LangChain’s MCP Adaptors. We want a operating the server to make use of it with LangChain. The server helps totally different operating modes.

Set up

First, set up the required Python packages.

pip set up markitdown-mcp langchain langchain_mcp_adapters langgraph langchain_groq

Server Configuration

Run the Markitdown MCP server utilizing STDIO mode. This mode connects normal enter and output streams. It really works properly for script-based integration. Straight run the next within the terminal.

markitdown-mcp

The server will begin operating with some warnings.

MarkItDown MCP Can Convert Any Doc into Markdowns!

We are able to additionally use SSE (Server-Despatched Occasions) mode. This mode fits net purposes or long-running connections. It is usually helpful when organising a Markitdown MCP server for testing particular eventualities.

markitdown-mcp --sse --host 127.0.0.1 --port 3001

Choose the mode that matches your integration plan. Utilizing the the server for testing domestically through STDIO is usually a superb begin. We suggest utilizing STDIO mode for this text.

Markdown Conversion with Markitdown MCP

We have now already coated easy methods to construct an MCP server and consumer setup domestically utilizing LangChain in our earlier weblog MCP Consumer Server Utilizing LangChain.

Now, this part exhibits easy methods to use LangChain with the Markitdown MCP server. It automates the conversion of a PDF file to Markdown. The instance employs Groq’s LLaMA mannequin by ChatGroq. Be sure to arrange the Groq API key as an surroundings variable or cross it on to ChatGroq.

Step 1: Import the mandatory libraries first.

from mcp import ClientSession, StdioServerParameters
from mcp.consumer.stdio import stdio_client
from langchain_mcp_adapters.instruments import load_mcp_tools
from langgraph.prebuilt import create_react_agent
import asyncio
from langchain_groq import ChatGroq

Step 2: Initialize the Groq LLM, it’s freed from price. You will discover the API key right here

Right here’s the Groq API Key: Groq API Key

# Initialize Groq mannequin
mannequin = ChatGroq(mannequin="meta-llama/llama-4-scout-17b-16e-instruct", api_key="YOUR_API_KEY")

Step 3: Configure the MCP server

We’re utilizing StdioServerParameters, and instantly utilizing the put in Markitdown MCP package deal right here

server_params = StdioServerParameters(
   command="markitdown-mcp",
   args=[]  # No further arguments wanted for STDIO mode
)

Step 4: Now, outline the Asynchronous perform

This may take the PDF path because the enter, ClientSession begins communication. load_mcp_tools offers capabilities for LangChain interplay with Markitdown MCP. Then a ReAct agent is created, It makes use of the mannequin and the MCP instruments. The code creates a file_uri for the PDF and sends a immediate asking the agent to transform the file utilizing MCP.

async def run_conversion(pdf_path: str):
   async with stdio_client(server_params) as (learn, write):
       async with ClientSession(learn, write) as session:

           await session.initialize()
           print("MCP Session Initialized.")

           # Load out there instruments
           instruments = await load_mcp_tools(session)
           print(f"Loaded Instruments: {[tool.name for tool in tools]}")

           # Create ReAct agent
           agent = create_react_agent(mannequin, instruments)
           print("ReAct Agent Created.")

           # Put together file URI (convert native path to file:// URI)
           file_uri = f"file://{pdf_path}"
           # Invoke agent with conversion request
           response = await agent.ainvoke({

               "messages": [("user", f"Convert {file_uri} to markdown using Markitdown MCP just return the output from MCP server")]

           })

           # Return the final message content material
           return response["messages"][-1].content material

Step 5: This code calls the run_conversion perform

We’re calling and extracting Markdown from the response. It saves the content material to pdf.md, and eventually prints the output within the terminal.

if __name__ == "__main__":

   pdf_path = "/house/harsh/Downloads/LLM Analysis.pptx.pdf"  # Use absolute path
   outcome = asyncio.run(run_conversion(pdf_path))

   with open("pdf.md", 'w') as f:
      f.write(outcome)

   print("nMarkdown Conversion Outcome:")
   print(outcome)

Output

Output

Full Code

from mcp import ClientSession, StdioServerParameters
from mcp.consumer.stdio import stdio_client

from langchain_mcp_adapters.instruments import load_mcp_tools
from langgraph.prebuilt import create_react_agent

import asyncio
from langchain_groq import ChatGroq
# Initialize Groq mannequin
mannequin = ChatGroq(mannequin="meta-llama/llama-4-scout-17b-16e-instruct", api_key="")
# Configure MCP server
server_params = StdioServerParameters(

   command="markitdown-mcp", 
   args=[]  # No further arguments wanted for STDIO mode

)

async def run_conversion(pdf_path: str):
   async with stdio_client(server_params) as (learn, write):

       async with ClientSession(learn, write) as session:
           await session.initialize()

           print("MCP Session Initialized.")
           # Load out there instruments
           instruments = await load_mcp_tools(session)

           print(f"Loaded Instruments: {[tool.name for tool in tools]}")
           # Create ReAct agent

           agent = create_react_agent(mannequin, instruments)
           print("ReAct Agent Created.")

           # Put together file URI (convert native path to file:// URI)

           file_uri = f"file://{pdf_path}"
           # Invoke agent with conversion request
           response = await agent.ainvoke({

               "messages": [("user", f"Convert {file_uri} to markdown using Markitdown MCP just retrun the output from MCP server")]

           })

           # Return the final message content material
           return response["messages"][-1].content material

if __name__ == "__main__":
   pdf_path = "/house/harsh/Downloads/LLM Analysis.pdf"  # Use absolute path

   outcome = asyncio.run(run_conversion(pdf_path))
   with open("pdf.md", 'w') as f:

       f.write(outcome)
   print("nMarkdown Conversion Outcome:")
   print(outcome)

Analyzing the Output

The script generates a pdf.md file. This file holds the Markdown model of the enter PDF. The conversion high quality is determined by the unique doc’s construction. Markitdown MCP normally preserves components like:

  • Headings (numerous ranges)
  • Paragraph textual content
  • Lists (bulleted and numbered)
  • Tables (transformed to Markdown syntax)
  • Code blocks

Output

Output

Right here within the output, we are able to see that it efficiently retrieved the headings, contents, in addition to regular textual content in markdown format.

Therefore, operating an area server for testing helps consider totally different doc varieties.

Additionally watch:

Sensible Use Instances in LLM Pipelines

Integrating Markitdown MCP can enhance a number of AI workflows:

  • Information Base Constructing: Convert paperwork into Markdown. Ingest this content material into data bases or RAG techniques.
  • LLM Content material Preparation: Remodel supply information into Markdown. Put together constant enter for LLM summarization or evaluation duties.
  • Doc Information Extraction: Convert paperwork with tables into Markdown. This simplifies parsing structured knowledge.
  • Documentation Automation: Generate technical manuals. Convert supply information like Phrase paperwork into Markdown for static web site mills.

Conclusion

Markitdown MCP offers a succesful, server-based methodology for doc conversion. It handles a number of codecs. It produces structured Markdown output. Integrating it with LLMs allows automation of doc processing duties. This method helps scalable documentation practices. Utilizing the the server for testing makes analysis easy. MarkItDown’s MCP is finest understood by its sensible software in these workflows.

Discover the Markitdown MCP GitHub repository for extra data.

Continuously Requested Questions

Q1. What’s the foremost perform of Markitdown MCP?

Ans. Markitdown MCP converts paperwork like PDFs and Phrase information into structured Markdown. It makes use of a server-based protocol for this process.

Q2. Which file codecs can the Markitdown MCP server course of?

Ans. The server handles PDF, DOCX, PPTX, and HTML information. Different codecs could also be supported relying on the core library.

Q3. How does LangChain use Markitdown MCP?

Ans. LangChain makes use of particular instruments to speak with the server. Brokers can then request doc conversions by this server.

This autumn. Is Markitdown MCP open supply?

Ans. Sure, it’s open-source software program from Microsoft. Customers are accountable for any server internet hosting prices.

Q5. Can I run the Markitdown MCP server for testing functions?

Ans. Sure, the server for testing can run domestically. Use both STDIO or SSE mode for improvement and analysis.

Hello, I’m Pankaj Singh Negi – Senior Content material Editor | Obsessed with storytelling and crafting compelling narratives that remodel concepts into impactful content material. I like studying about know-how revolutionizing our way of life.

Login to proceed studying and luxuriate in expert-curated content material.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles