Docling Server MCP
MCP Docling is an MCP server that processes documents using the Docling library, enabling conversion, extraction, and Q&A generation for improved document handling.
How to Install and Use Docling Server MCP
If you want to work with documents and make your text tasks easier, the Docling Server MCP is a great tool to try. It lets you "play with your documents" in a smart way using the Docling library. Here’s an easy, step-by-step guide on how to install and use it.
Step 1: Installing Docling Server MCP
Before you can start, you need to install the Docling Server MCP package. The easiest way is to use pip, a tool for installing Python packages. To do this, open your terminal or command prompt and run this command:
pip install -e .
This will install the package on your computer so you can run the server.
Step 2: Starting the Server
Once installed, you can start the Docling Server MCP in two main ways. By default, it runs using stdio transport, which works in the terminal. You just need to type:
mcp-server-lls
If you want, you can also use the server with SSE (Server-Sent Events) transport, which is good for custom setups or network use. You just add options for transport and port like this:
mcp-server-lls --transport sse --port 8000
This starts the server using SSE on port 8000.
If you want to try without installing, you can run it directly using the uv tool like this:
# Using stdio transport (default)
uv run mcp-server-lls
Or with SSE transport:
uv run mcp-server-lls --transport sse --port 8000
Step 3: What Can You Do with Docling Server MCP?
Docling Server MCP gives you several tools to work with documents. Here are some examples:
- convert_document: Change documents from a URL or local file into markdown format. You can also turn on OCR for scanned text.
{
"source": "path_or_url_to_document",
"enable_ocr": False,
"ocr_language": ["en"]
}
-
extract_tables: Pull tables out of a document into structured data.
-
convert_batch: Process many documents at once by listing their URLs or file paths.
-
qna_from_document: Make a Q&A file in YAML format from a document. This needs you to set IBM Watson X credentials as environment variables:
WATSONX_PROJECT_IDWATSONX_APIKEYWATSONX_URL(default is https://us-south.ml.cloud.ibm.com)
Step 4: Using Docling Server MCP with Llama Stack
To make Docling Server MCP work with Llama Stack, which supports smart apps, you can use this example code snippet in Python:
from llama_stack_client.lib.agents.agent import Agent
from llama_stack_client.lib.agents.event_logger import EventLogger
from llama_stack_client.types.agent_create_params import AgentConfig
from llama_stack_client.types.shared_params.url import URL
from llama_stack_client import LlamaStackClient
import os
model_id = os.environ["INFERENCE_MODEL"]
client = LlamaStackClient(base_url=f"http://localhost:{os.environ.get('LLAMA_STACK_PORT', '8080')}")
client.toolgroups.register(
toolgroup_id="mcp::docling",
provider_id="model-context-protocol",
mcp_endpoint=URL(uri="http://0.0.0.0:8000/sse")
)
agent_config = AgentConfig(
model=model_id,
instructions="""You are a helpful assistant with access to tools to manipulate documents.
Always use the appropriate tool when asked to process documents.""",
toolgroups=["mcp::docling"],
tool_choice="auto",
max_tool_calls=3,
)
agent = Agent(client, agent_config)
session_id = agent.create_session("test-session")
def _summary_and_qna(source: str):
run_turn(f"Please convert the document at {source} to markdown and summarize its content.")
run_turn(f"Please generate a Q&A document with 3 items for source at {source} and display it in YAML format.")
This example shows how to register the Docling tools and create an agent that can process documents easily.
Step 5: Caching for Better Performance
Docling Server MCP saves processed documents in a cache folder at ~/.cache/mcp-docling/. This makes it faster when you work with the same documents again.
By following these steps, you can install and use the Docling Server MCP smoothly. It helps you convert, extract, and process documents with simple commands and code, making document work much easier!