Skip to content

uzzalpro/mcp-agent

Repository files navigation

MCP Agent

An interactive MCP (Model Context Protocol) agent built with Python that leverages LangChain, Groq, and Playwright to provide intelligent browser automation and web interactions.

Overview

This project implements an MCP agent that can interact with multiple MCP servers including:

  • Playwright: Browser automation and web scraping
  • Airbnb: Search and retrieve Airbnb listings
  • DuckDuckGo Search: Web search capabilities

The agent uses Groq's Qwen model via LangChain for natural language understanding and decision-making, with built-in conversation memory for context-aware interactions.

Features

  • 🤖 Intelligent Agent: Powered by Groq's Qwen3-32B model via LangChain
  • 🌐 Browser Automation: Full Playwright integration for web interactions
  • 💬 Conversation Memory: Maintains context across multiple interactions
  • 🔌 MCP Integration: Seamlessly connects to multiple MCP servers
  • 📦 Modern Tooling: Built with uv for fast dependency management

Prerequisites

  • Python 3.12 or higher
  • uv package manager
  • Node.js and npm (for MCP servers that use npx)
  • Groq API key

Installation

1. Install uv

If you don't have uv installed, install it using one of these methods:

# Using curl
curl -LsSf https://astral.sh/uv/install.sh | sh

# Or using pip
pip install uv

2. Clone and Setup

cd mcp-agent

# Create virtual environment and install dependencies with uv
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
uv pip install -r requirements.txt
# Or use uv sync if you have a pyproject.toml
uv sync

3. Configure Environment Variables

Create a .env file in the project root:

GROQ_API_KEY=your_groq_api_key_here

You can get a Groq API key from console.groq.com.

4. Install Playwright Browsers (if needed)

The Playwright MCP server may require browser installation:

npx playwright install

Project Structure

mcp-agent/
├── main.py              # Main agent implementation
├── browser_mcp.json     # MCP server configuration
├── pyproject.toml       # Python project configuration
├── requirements.txt     # Python dependencies
├── uv.lock             # uv lock file
├── .env                # Environment variables (create this)
└── README.md           # This file

Usage

Running the Agent

# Activate virtual environment
source .venv/bin/activate

# Run the agent
python main.py

Interactive Commands

Once the agent is running, you can:

  • Chat normally: Type your questions or requests
  • Type clear: Clear the conversation history
  • Type exit or quit: End the conversation

Example Interactions

You: Search for Airbnb listings in San Francisco for next weekend

You: Take a screenshot of the first search result

You: Navigate to google.com and search for "Python MCP"

You: What was the first thing I asked you?

Configuration

MCP Servers

The browser_mcp.json file configures which MCP servers are available:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    },
    "airbnb": {
      "command": "npx",
      "args": ["-y", "@openbnb/mcp-server-airbnb"]
    },
    "duckduckgo-search": {
      "command": "npx",
      "args": ["-y", "duckduckgo-mcp-server"]
    }
  }
}

You can add or remove MCP servers by modifying this configuration file.

Agent Settings

In main.py, you can customize:

  • Model: Change the Groq model (default: qwen/qwen3-32b)
  • Max Steps: Adjust max_steps parameter (default: 15)
  • Memory: Toggle memory_enabled (default: True)
agent = MCPAgent(
    llm=llm,
    client=client,
    max_steps=15,        # Maximum reasoning steps
    memory_enabled=True, # Enable conversation memory
)

Dependencies

Core Libraries

  • mcp-use (>=1.4.0): Python library for interacting with MCP servers
  • langchain-groq (>=1.0.1): LangChain integration for Groq models
  • python-dotenv (>=1.2.1): Environment variable management

MCP Servers (via npx)

  • @playwright/mcp: Browser automation server
  • @openbnb/mcp-server-airbnb: Airbnb search server
  • duckduckgo-mcp-server: DuckDuckGo search server

How It Works

  1. Initialization: The agent loads MCP server configurations and initializes the Groq LLM
  2. User Input: Receives natural language commands from the user
  3. Reasoning: The LLM decides which MCP tools to use based on the request
  4. Execution: Calls appropriate MCP server tools (e.g., Playwright for browser actions)
  5. Response: Returns results to the user with conversation context maintained

Troubleshooting

Development

Adding New MCP Servers

  1. Add the server configuration to browser_mcp.json
  2. Restart the agent
  3. The agent will automatically discover and use the new server's tools

Extending Functionality

You can extend the agent by:

  • Adding custom tools to the MCPAgent
  • Implementing additional MCP servers
  • Customizing the LLM prompt or behavior
  • Adding new conversation commands

Resources

License

[Add your license here]

Contributing

[Add contribution guidelines here]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages