Model Context Protocol (MCP) Hands-On Walkthrough for the Unstructured Partition Endpoint
Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to LLMs. From the MCP documentation:
Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.
This article provides a hands-on, step-by-step walkthrough to build a simple example on your local development machine that integrates the Unstructured API with MCP. Specifically, this walkthrough demonstrates how to run an MCP server (a lightweight program that exposes specific capabilities through MCP); this MCP server uses the Unstructured Partition Endpoint to partition a single file, with limited support for chunking as well, processing local files one file at a time.
For a hands-on walkthrough of the Unstructured Workflow Endpoint instead, see the MCP Hands-On Walkthrough for the Unstructured Workflow Endpoint, which offers a full range of partitioning, chunking, embedding, and enrichment options for your files and data.
You call this MCP server from an MCP client (an application that maintains a one-to-one connection with an MCP server), which in this walkthrough is Claude for Desktop, a chat-based interface, by asking it plain language questions. Other MCP clients are also available. Learn more.
Requirements
To complete this walkthrough, you must first have an Unstructured account, an Unstructured API key for that account, the necessary Python toolchain and project setups, Claude for Desktop, and an input file for Unstructured to process, as follows.
Unstructured account and API key
Before you begin, you must have an Unstructured account and an Unstructured API key, as follows:
If you signed up for Unstructured through the For Enterprise page, or if you are using a self-hosted deployment of Unstructured, the following information about signing up, signing in, and getting your Unstructured API key might apply differently to you. For details, contact Unstructured Sales at sales@unstructured.io.
-
Go to https://platform.unstructured.io and use your email address, Google account, or GitHub account to sign up for an Unstructured account (if you do not already have one) and sign into the account at the same time. The Unstructured user interface (UI) appears.
-
Get your Unstructured API key:
a. In the Unstructured UI, click API Keys on the sidebar.
b. Click Generate API Key.
c. Follow the on-screen instructions to finish generating the key.
d. Click the Copy icon next to your new key to add the key to your system’s clipboard. If you lose this key, simply return and click the Copy icon again.
By following the preceding instructions, you are signed up for a Developer pay per page account by default.
To save money, consider switching to a Subscribe & Save account instead. To save even more money, consider switching to an Enterprise account instead.
Python toolchain and Claude for Desktop setup
Before you can start coding on your local machine, you must install the Python package and project manager uv
, and install Claude for Desktop, as follows.
Install uv
, as follows.
By using pip
:
Or, by using the following script (be sure to restart your terminal or Command Prompt after running the script):
(To learn more about uv
, see the uv documentation.)
Input file
You must have an input file for Unstructured to process. This file can be any file type that Unstructured supports, such as a .pdf
file.
See the list of supported file types. If you do not have any files available, you can download some from the example-docs folder in the Unstructured repo on GitHub.
To minimize the risk of Claude for Desktop’s hard timeout limit of 60 seconds for MCP server responses, we recommend that you use small files (less than 400 KB) for this walkthrough.
You are now ready to start coding.
Step 1: Create the MCP server
From your current working directory, create a project directory and then initialize it. This example creates a
project directory named mcp-unstructured-parition-demo
. Then go to the project directory:
Create a virtual environment in the root of the project directory. Then activate the virtual environment:
To deactivate and exit the virtual environment at any time, simply run the deactivate
command:
With the virtual environment activated, install the Python SDK for Model Context Protocol and additional code dependencies:
In the root of the project directory, create a new Python file. This example names the file doc_processor.py
.
Then add the following code to this new doc_processor.py
file.
In the following code, replace <absolute-path-to-local-directory>
with the absolute path to the local directory where you want
Unstructured to store the processed files’ content. Be sure that this local directory exists before you run the code.
In the root of the project directory, create a new file named .env
.
Then add the following code to this new .env
file, replacing <your-unstructured-api-key>
with your Unstructured API key:
Step 2: Configure Claude for Desktop to use the MCP server
Open the Claude for Desktop App configuration file from the following location, for example by using Visual Studio Code:
Add the following code to the claude_desktop_config.json
file, and then save the file.
In this file:
"unstructured-partition-mcp"
must match the value that you set inmcp = FastMCP("unstructured-partition-mcp" ...
in thedoc_processor.py
file.- “Absolute path to”
uv
must be the absolute path to theuv
executable on your local machine. - “Absolute path to project directory” must be the absolute path to the project directory.
mcp-unstructured-partition-demo
must match the name of the project directory that you created."doc_processor.py"
must match the name of the Python file that you created for the MCP server.
For macOS or Linux:
For Windows:
Step 3: Run the MCP server and call it from Claude for Desktop
Start Claude for Desktop. If it is already running, restart it.
Ask the following question in the chat window, replacing <absolute-path-to-local-file>
with the absolute path to the local file that you
want Unstructured to process.
This walkthrough has been tested with small files (less than 400 KB), due to Claude for Desktop’s hard timeout limit of 60 seconds for MCP server responses.
Larger files might take longer for Unstructured to process, and Claude for Desktop might time out before such files are fully processed.
Claude for Desktop responds with information about the processed document.
You can find the processed file’s content in the path that you specified for PROCESSED_FILES_FOLDER
in the MCP server’s doc_processor.py
file.
Was this page helpful?