SmolAgents + MCP servers

by FaustoS88

280 downloads Not rated yet MIT license
GitHub

About

AI assistant using the SmolAgents library that integrates with Brave Search and Crawl4ai Model Context Protocols (MCP) servers for web searches and scraping. Modular design allows easy addition of new MCP servers and tools.

Details

License
MIT license

Explore

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name SmolAgents + MCP servers
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Before running this project, ensure you have the following dependencies installed:

- smolagents
- python-dotenv
- mcp
- @modelcontextprotocol/server-brave-search (installed globally via npm/npx)
- litellm

You can install the Python packages using pip:

pip install -r requirements.txt

Ensure you have Node.js and npm/npx and uv installed to run the MCP servers.

Create a .env file in the root directory of the project and add the following variables:

BRAVE_API_KEY=your_brave_api_key
OPENAI_API_KEY=your_openai_api_key

Replace your_brave_api_key and your_openai_api_key with your actual API keys.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "smolagents + mcp servers": {
            "SmolAgents-MCPs": {
                "command": "python",
                "args": [
                    "smolagent_with_mcp.py"
                ]
            }
        }
    }
}

McpServers

{
    "SmolAgents-MCPs": {
        "command": "python",
        "args": [
            "smolagent_with_mcp.py"
        ]
    }
}

This project demonstrates building an AI assistant using the SmolAgents library that can perform web searches and scrape/crawl websites by integrating with the Brave Search and the Crawl4ai Model Context Protocols (MCP) servers.

Requirements

Before running this project, ensure you have the following dependencies installed:

- smolagents
- python-dotenv
- mcp
- @modelcontextprotocol/server-brave-search (installed globally via npm/npx)
- litellm

You can install the Python packages using pip:

pip install -r requirements.txt

Ensure you have Node.js and npm/npx and uv installed to run the MCP servers.

Environment Variables

Create a .env file in the root directory of the project and add the following variables:

BRAVE_API_KEY=your_brave_api_key
OPENAI_API_KEY=your_openai_api_key

Replace your_brave_api_key and your_openai_api_key with your actual API keys.

Usage

1. Clone the repository or download the script (smolagent_with_mcp.py).
2. Navigate to the project directory in your terminal.
3. Run the script:

    python smolagent_with_mcp.py
    

4. Interact with the assistant by typing your search queries. Type exit or quit to terminate the session.

the code encapsulates the agent initialization and the main interaction loop within a Python class (SmolAgentWithMCP). This object-oriented approach offers modularity and makes it easier to extend the agent's capabilities, such as integrating additional MCP servers and their tools.

Notes

Ensure that npx is installed and available in your system's PATH, as it is required to run the Brave Search MCP server.
The ToolCallingAgent in SmolAgents is designed to output tool calls in a structured format (like JSON) which are then executed by the environment (in this case, the script's main loop using the MCPClient).

Adding More MCP Servers

The smolagent_with_mcp.py file is structured to allow for easily adding more MCP servers and their tools in a modular way. To add a new MCP server:

1. Define the StdioServerParameters for the new server. This involves specifying the command to run the server, its arguments, and any necessary environment variables (similar to how brave_server_params and crawl4ai_server_params are defined).

2. Add the newly defined server parameters object to the server_list in the main function. The BraveSearchAgentApp class will automatically initialize the new server and include its tools in the agent's capabilities.

Example:

```python

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.