Docling MCP

repository·main·Indexed 20 days ago

https://github.com/docling-project/docling-mcp

A Model Context Protocol (MCP) server that provides tools for document conversion, processing, and generation using the Docling library. It enables agentic AI workflows by transforming complex documents like PDFs into structured formats. It supports integrations with Claude for Desktop, LM Studio, LlamaIndex RAG, Pydantic AI, and Llama Stack, offering flexible installation modes including Remote, Local, and Hybrid.

Tokens
15K
Snippets
41
Records
51
Agent score
71%

What's inside docling-mcp

  1. Configure docling-mcp v2 architecture modes

    main

    docling-mcp v2 uses a hybrid architecture allowing for lightweight remote conversion or full offline local conversion.

    Remote Mode (Default)

    Uses Docling Serve for cloud-based conversion. This is the lightweight option (~50 MB) and requires no model downloads.

    • Setup: pip install docling-mcp
    • Config: Set DOCLING_SERVICE_URL and optionally DOCLING_SERVICE_API_KEY.

    Local Mode (Full/Offline)

    Performs conversion locally on your machine.

    • Setup: pip install "docling-mcp[local]"
    • Config: Set DOCLING_CONVERSION_MODE=local.

    Hybrid Mode

    Falls back to local conversion if the remote service is unavailable.

    • Setup: pip install "docling-mcp[local]"
    • Config: Set DOCLING_CONVERSION_MODE=remote (or leave default) and DOCLING_FALLBACK_TO_LOCAL=true.
    # Remote mode (lightweight, default)
    pip install docling-mcp
    export DOCLING_SERVICE_URL=https://your-docling-service.example.com
    
    # Local mode (full, offline)
    pip install "docling-mcp[local]"
    export DOCLING_CONVERSION_MODE=local
  2. Configure Docling MCP in an MCP client

    main

    To integrate Docling MCP into an MCP-compatible client (like Claude for Desktop), add a configuration entry to your client's config file (e.g., claude_desktop_config.json). You can pass environment variables directly in the env block.

    {
      "mcpServers": {
        "docling": {
          "command": "uvx",
          "args": [
            "--from=docling-mcp",
            "docling-mcp-server"
          ],
          "env": {
            "DOCLING_MCP_CONVERSION_MODE": "remote",
            "DOCLING_MCP_SERVICE_URL": "https://your-docling-service.example.com",
            "DOCLING_MCP_SERVICE_API_KEY": "your-api-key-here"
          }
        }
      }
    }
  3. Integrate Docling MCP with Claude for Desktop

    main

    To use Docling MCP with Claude for Desktop, you must add the Docling MCP configuration to your claude_desktop_config.json file.

    File Location:

    • MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json

    After configuring the MCP endpoint, you may need to extend Claude's capabilities to read from your local file system by following the official Model Context Protocol (MCP) quickstart guide for Claude Desktop users.

  4. Upgrade docling-mcp to v3 (MCP Python SDK v2)

    main

    docling-mcp v3 migrates from MCP Python SDK v1 to v2.

    Who is affected

    • Standalone users (running via uvx or containers) are not affected. Server behavior, CLI flags, and tool names remain identical.
    • Library users who embed docling-mcp and import from the mcp SDK directly are affected because the shared mcp dependency will upgrade to v2.
    • Custom MCP client developers using mcp<2.0.0 may experience wire protocol issues when connecting to a v3 server.

    How to upgrade

    Install the latest release:

    pip install --upgrade docling-mcp

    If your project imports from the MCP SDK directly, you must also migrate your code to the MCP SDK v2 patterns (e.g., changing FastMCP to MCPServer and updating error/result attribute naming).

  5. Set up Docling MCP with LlamaIndex functionalities

    main

    To use Docling MCP tools that leverage LlamaIndex RAG (Retrieval-Augmented Generation) capabilities, you must configure a Llama Stack backend and install specific dependencies.

    Requirements

    • A Llama Stack backend providing the Responses API.
    • The openai-agents library.

    Installation

    Use uv to create a virtual environment and install the docling-mcp package with the llama-index-rag extra, along with the necessary agent and notebook tools:

    uv venv
    uv pip install "docling-mcp[llama-index-rag]" openai-agents ipykernel notebook rich

    Starting the Server

    Run the docling-mcp-server using streamable-http transport. You must explicitly enable the conversion and llama-index-rag tool groups to access these functionalities:

    docling-mcp-server --transport streamable-http --port 8000 --host 0.0.0.0 conversion llama-index-rag
    uv venv
    uv pip install "docling-mcp[llama-index-rag]" openai-agents ipykernel notebook rich
    
    docling-mcp-server --transport streamable-http --port 8000 --host 0.0.0.0 conversion llama-index-rag
  6. Install Docling MCP in Remote, Local, or Hybrid modes

    main

    Docling MCP can be installed in three different modes depending on your infrastructure needs:

    1. Remote Mode (Recommended): Lightweight client that connects to a docling-serve instance. Requires DOCLING_MCP_SERVICE_URL and DOCLING_MCP_SERVICE_API_KEY.
    2. Local Mode: Full features including local document conversion. Requires the [local] extra.
    3. Hybrid Mode: Installs local support but defaults to remote, with an automatic fallback to local if the remote service is unreachable.

    All configuration is handled via environment variables with the DOCLING_MCP_ prefix.

    # Remote Mode
    pip install docling-mcp
    export DOCLING_MCP_SERVICE_URL=https://your-docling-service.example.com
    export DOCLING_MCP_SERVICE_API_KEY=your-api-key-here
    export DOCLING_MCP_CONVERSION_MODE=remote
    
    # Local Mode
    pip install "docling-mcp[local]"
    export DOCLING_MCP_CONVERSION_MODE=local
    
    # Hybrid Mode
    pip install "docling-mcp[local]"
    export DOCLING_MCP_SERVICE_URL=https://your-docling-service.example.com
    export DOCLING_MCP_CONVERSION_MODE=remote
    export DOCLING_MCP_FALLBACK_TO_LOCAL=true
  7. Use watsonx.ai for Llama Stack inference via LiteLLM

    main

    To connect Llama Stack to watsonx.ai, use LiteLLM as a proxy to serve the watsonx.ai inference endpoint as an OpenAI-compatible API.

    1. Create an env.secrets file containing your WATSONX_URL, WATSONX_APIKEY, and WATSONX_PROJECT_ID.
    2. Create a litellm_config.yaml to map model names to their watsonx paths.
    3. Run LiteLLM in a container.
    4. Run the Llama Stack starter distribution, setting VLLM_URL to point to the LiteLLM proxy (default port 4000).
    5. Register models and test via llama-stack-client.
    # litellm_config.yaml example
    model_list:
      - model_name: "granite-3-3-8b-instruct"
        litellm_params:
          model: "watsonx/ibm-granite/granite-3-3-8b-instruct"
      - model_name: "llama-3-3-70b"
        litellm_params:
          model: "watsonx/meta-llama/llama-3-3-70b-instruct"
    # 1. Run LiteLLM proxy
    podman run \
      -v $(pwd)/litellm_config.yaml:/app/config.yaml \
      --rm \
      -p 4000:4000 \
      --env-file env.secrets \
      ghcr.io/berriai/litellm:v1.74.9-stable \
      --config /app/config.yaml
    
    # 2. Run Llama Stack pointing to LiteLLM
    export LLAMA_STACK_PORT=8321
    
    podman run \
        -it \
        --pull always \
        -p $LLAMA_STACK_PORT:$LLAMA_STACK_PORT \
        -v ~/.llama:/root/.llama \
        llamastack/distribution-starter:0.2.18 \
        --port $LLAMA_STACK_PORT \
        --env VLLM_URL=http://host.containers.internal:4000
    
    # 3. Register and Test
    uvx --from llama-stack-client llama-stack-client models register wx/llama-3-3-70b --provider-id vllm --provider-model-id llama-3-3-70b
    
    uvx --from llama-stack-client llama-stack-client --endpoint http://localhost:8321 \
        inference chat-completion \
        --model-id wx/llama-3-3-70b \
        --message "Write a short story about a robot."
  8. Set up Llama Stack with Docling MCP tools

    main

    This guide demonstrates how to integrate Docling MCP into the Llama Stack framework to create agentic workflows. This requires running an inference model via Ollama, a Llama Stack server (via Podman/Docker), and the Docling MCP server locally.

    Prerequisites

    1. Prepare the Inference Model

    Load a model (e.g., Meta Llama 3.2) using Ollama:

    export OLLAMA_INFERENCE_MODEL="llama3.2:3b-instruct-fp16"
    ollama run $OLLAMA_INFERENCE_MODEL --keepalive 60m

    2. Run Llama Stack Server

    Create a local directory for persistence and start the Llama Stack starter distribution using Podman:

    mkdir -p ~/.llama
    
    export LLAMA_STACK_PORT=8321
    
    podman run \
      -it \
      --pull always \
      -p $LLAMA_STACK_PORT:$LLAMA_STACK_PORT \
      -v ~/.llama:/root/.llama \
      llamastack/distribution-starter \
      --port $LLAMA_STACK_PORT \
      --env OLLAMA_URL=http://host.containers.internal:11434

    3. Run Docling MCP Server

    Clone the docling-mcp repository, sync dependencies with uv, and start the server using the streamable-http transport:

    git clone git@github.com:docling-project/docling-mcp.git
    cd docling-mcp
    uv sync
    
    uv run docling-mcp-server --transport streamable-http --port 8000 --host 0.0.0.0

    4. Register Docling Tools in Llama Stack

    Use the llama-stack-client CLI to register the Docling MCP server as a tool group:

    uvx --with llama-stack-client llama-stack-client toolgroups register "mcp::docling" \
      --provider-id="model-context-protocol" \
      --mcp-endpoint="http://host.containers.internal:8000/mcp"

    To verify registration, list the toolgroups:

    uvx --with llama-stack --from llama-stack-client llama-stack-client toolgroups list
    # Registering the toolgroup
    uvx --with llama-stack-client llama-stack-client toolgroups register "mcp::docling" \
      --provider-id="model-context-protocol" \
      --mcp-endpoint="http://host.containers.internal:8000/mcp"
  9. Set up the Docling MCP server for Pydantic AI agents

    main

    To use Docling MCP tools with agents (such as those built with the Pydantic AI SDK), you must first start the docling-mcp-server. You need to enable both the conversion and generation tool groups. For compatibility with many agentic frameworks, it is recommended to use the streamable-http transport.

    Requirements:

    • Pydantic AI
    • An LLM provider (e.g., LM Studio or a Llama Stack server for OpenAI-compatible Responses APIs).

    Note on Llama Stack: If your agent uses an OpenAI-compatible Responses API, you must also follow the Llama Stack setup procedures to start its server.

    docling-mcp-server --transport streamable-http --port 8000 --host 0.0.0.0 conversion generation
  10. Launch Docling MCP server via uvx

    main

    The easiest way to run the Docling MCP server is using uvx. You must specify the --transport argument based on your client's requirements:

    • stdio: For clients like Claude for Desktop or LM Studio.
    • sse: For clients like Llama Stack.
    • streamable-http: For containerized setups.
    # stdio transport
    uvx --from docling-mcp docling-mcp-server --transport stdio
    
    # sse transport
    uvx --from docling-mcp docling-mcp-server --transport sse
    
    # streamable-http transport
    uvx --from docling-mcp docling-mcp-server --transport streamable-http