Deploy Open-Source MCP Servers
Upload, deploy, and interact with open-source MCP servers on Clarifai
Besides building a custom MCP (Model Context Protocol) server for the Clarifai platform, you can also upload any open-source MCP server and expose it as a managed API endpoint — just like any model in the platform.
You can easily integrate third-party MCP servers with Clarifai by simply adding the mcp_server configuration to your config.yaml file.
This allows you to:
- Expose MCP servers as HTTP APIs accessible through Clarifai
- Use the FastMCP client to interact with deployed MCP servers
- Seamlessly integrate MCP tools with LLMs to extend model capabilities
Step 1: Perform Prerequisites
Get an MCP Server
You can get open-source MCP servers from third-party repositories, such as mcpservers.org or mcp.so.
For this example, let's use the DuckDuckGo MCP server to demonstrate how to upload and deploy an open-source MCP server on Clarifai. This server provides tools for web search, browsing, and information retrieval, and requires no authentication tokens or secrets — making it easy to deploy and use. You can also follow its tutorial here.
Get an Agentic Model
Integrating large language models (LLMs) with MCP servers enables agentic capabilities, allowing models to discover and use external tools autonomously to complete tasks. MCP servers expose functionalities that models can invoke as function-calling tools during conversations.
With MCP server integration, an agentic model can iteratively discover tools, execute them, and reason over the results to produce more capable and context-aware responses.
Note: For a model to support agentic behavior through MCP servers on the Clarifai platform, it must extend the standard
OpenAIModelClasswith theAgenticModelClass. This enables:
- Tool discovery and execution handled by the agentic model class
- Iterative tool calling within a single predict or generate request
- Compatibility with the OpenAI-compatible API and Clarifai SDKs
- Support for both streaming and non-streaming modes
The
AgenticModelClassmanages the full agentic loop: it discovers available MCP tools at model load time, injects them into the LLM context, and iteratively calls tools and feeds results back to the model until a final response is produced.You can see an example implementation of
AgenticModelClassin this1/model.pyfile.
To upload a model with agentic capabilities, simply use the AgenticModelClass — all other functionalities and steps remain the same as uploading a standard model on Clarifai. You can follow this example.
These are some example models with agentic capabilities enabled:
Install Packages
Install the following Python packages to work with the DuckDuckGo Browser MCP server:
clarifai— The latest version of the Clarifai Python SDK, required to integrate your MCP server with the Clarifai platform. This package also comes with the Clarifai Command Line Interface (CLI), which you’ll use to upload the server.fastmcp— The core framework for interacting with MCP servers.openai— This leverage Clarifai’s OpenAI-compatible endpoint endpoint to run inferences using the OpenAI client libraryanyio— An asynchronous I/O library used by FastMCP.requests— A lightweight HTTP client for making HTTP requests.mcp— The Model Context Protocol library.
You can run the following command to install them:
- Bash
pip install --upgrade clarifai fastmcp openai anyio requests mcp
Get Credentials
You need to have the following Clarifai credentials:
- App ID — Create a Clarifai application and get its ID. This is where your MCP server will reside on the Clarifai platform.
- User ID — In the collapsible left sidebar, select Settings and choose Account from the dropdown list. Then, locate your user ID.
- Personal Access Token (PAT) — From the same Settings option, choose Secrets to generate or copy your PAT. This token is used to authenticate your connection with the Clarifai platform.
Then, set the CLARIFAI_PAT as an environment variable.
- Unix-Like Systems
- Windows
export CLARIFAI_PAT=YOUR_PERSONAL_ACCESS_TOKEN_HERE
set CLARIFAI_PAT=YOUR_PERSONAL_ACCESS_TOKEN_HERE
Create Files
On the Clarifai platform, MCP servers are treated just like models and follow the same underlying architecture.
To upload an MCP server, you need to create a project directory and organize your files according to Clarifai’s custom model requirements, as shown below:
your_model_directory/
├── 1/
│ └── model.py
├── requirements.txt
├── config.yaml
├── Dockerfile