Skip to content

Docling + MCP for AI Agents

In this lab, you'll learn how to expose Docling's document processing capabilities to AI agents using the Model Context Protocol (MCP) with the official docling-mcp package.

Learning Objectives

By the end of this lab, you will:

  • Understand what MCP is and how it enables AI agents to use tools
  • Set up the docling-mcp server with Continue and Granite via Ollama
  • Use Docling tools through natural language in an AI agent
  • Compare MCP-based integration with REST API integration (Lab 5)

Prerequisites

  • Python 3.11 or later
  • VS Code installed
  • Ollama installed
  • docling-serve from Lab 5 running (docling-serve run)
  • Completed Labs 1-5 (recommended)

Why MCP?

In Lab 5, you wrote code to call the Docling REST API. With MCP, the AI agent discovers and calls Docling tools autonomously based on your natural language requests.

Feature REST API (Lab 5) MCP (Lab 7)
Consumer Your application code AI agents/LLMs
Discovery Read API docs manually Tools auto-discovered by LLM
Invocation You write HTTP requests Agent calls tools autonomously
Best For Production pipelines, batch processing AI-assisted workflows, copilots

Running the Lab

Local Environment Required

This lab requires VS Code, Ollama, and the Continue extension. It cannot run on Google Colab.

  1. Ensure you have completed the Pre-work
  2. Start Jupyter and open the notebook:
jupyter notebook notebooks/MCP_Agents.ipynb

Lab

Docling MCP Agents Notebook

To run the notebook from your command line in Jupyter using the active virtual environment from the pre-work, run:

jupyter notebook notebooks/MCP_Agents.ipynb

The path of the notebook file above is relative to the docling-workshop folder from the git clone in the pre-work.

Quick Start

1. Pull the Granite Model

ollama pull granite4.2:8b

2. Configure Continue

Edit ~/.continue/config.yaml:

name: Docling Workshop
version: 0.0.1
schema: v1

models:
  - name: Granite 4.2
    provider: ollama
    model: granite4.2:8b
    apiBase: http://localhost:11434
    roles:
      - chat
      - edit
      - apply
    capabilities:
      - tool_use

mcpServers:
  - name: Docling
    command: uvx
    args:
      - --from=docling-mcp
      - docling-mcp-server
      - --transport=stdio
    env:
      DOCLING_MCP_SERVICE_URL: http://localhost:5001

docling-mcp sends conversions to the Docling service at DOCLING_MCP_SERVICE_URL, here the docling-serve instance from Lab 5. --transport=stdio is required because otherwise the server starts as an HTTP server instead.

3. Use in Agent Mode

Open Continue in VS Code, switch to Agent mode, and try:

Convert https://arxiv.org/pdf/2501.17887 and summarize the key findings

Available MCP Tools

Tool Description
convert_document_into_docling_document Convert a document (URL or local path) and return its document key
create_new_docling_document Create a new empty document
add_title_to_docling_document Add a document title
add_section_heading_to_docling_document Add a section heading
add_paragraph_to_docling_document Add a paragraph
open_list_in_docling_document Open a list structure
add_list_items_to_list_in_docling_document Add items to an open list
close_list_in_docling_document Close the current list
export_docling_document_to_markdown Export a cached document as Markdown

The notebook lists the full set, including the document manipulation tools.

Resources