Skip to main content
Glama

MCP Host Server with LLM Integration

A comprehensive Model Context Protocol (MCP) host server that integrates multiple MCP servers with your LLM configuration, featuring Playwright MCP for browser automation and a custom MCP server for LLM-powered tasks.

๐Ÿš€ Features

  • Custom MCP Host Server: Unified interface for multiple MCP servers

  • LLM Integration: Uses your existing OpenAI GPT-4o configuration

  • Playwright MCP Integration: Browser automation capabilities

  • Interactive User Interface: Command-line interface for easy interaction

  • Multiple Transport Support: HTTP, SSE, and STDIO transports

  • Task Orchestration: Complex task execution using available tools and LLM reasoning

Related MCP server: Browser Use Heroku

๐Ÿ“‹ Prerequisites

  • Python 3.10 or higher

  • Node.js and npm (for Playwright MCP)

  • OpenAI API key

๐Ÿ› ๏ธ Installation

1. Clone/Download the Project

# If you have the files, navigate to the directory
cd mcp

2. Run Setup Script

python setup.py

This will:

  • Install Python dependencies

  • Install Playwright MCP server

  • Install Playwright browsers

  • Create necessary directories

  • Set up configuration files

3. Configure Environment

# Copy the example environment file
cp .env.example .env

# Edit .env and add your OpenAI API key
# OPENAI_API_KEY=your_actual_api_key_here

4. Test Installation

python test_setup.py

๐ŸŽฏ Usage

Interactive Mode

Start the interactive interface:

python user_interface.py --interactive

Available Commands

General Commands

  • help - Show available commands

  • status - Show system status

  • history - Show command history

  • quit - Exit the application

Playwright Commands

  • navigate <url> - Navigate to a webpage

  • screenshot [filename] - Take a screenshot

  • click <selector> - Click an element

  • fill <selector> <text> - Fill a form field

  • content - Get page content

  • wait <selector> - Wait for element

  • js <script> - Execute JavaScript

  • pdf [filename] - Save page as PDF

LLM Commands

  • process <text> [task] - Process text with LLM

  • generate <topic> [type] [length] - Generate content

  • answer <question> [context] - Answer a question

  • brainstorm <topic> [num] [category] - Generate ideas

  • format <data> <from> <to> - Format data between formats

Complex Commands

  • task <description> - Execute complex task using available tools

  • list-tools [client] - List available tools

Command Line Mode

Execute single commands:

# Check status
python user_interface.py --command status

# Navigate to a page
python user_interface.py --command navigate --args https://example.com

# Take a screenshot
python user_interface.py --command screenshot --args webpage.png

๐Ÿ“ Project Structure

mcp/
โ”œโ”€โ”€ llm_config.py              # Your LLM configuration
โ”œโ”€โ”€ mcp_client.py              # MCP client implementation
โ”œโ”€โ”€ custom_mcp_server.py       # Custom MCP server with LLM tools
โ”œโ”€โ”€ playwright_mcp_config.py   # Playwright MCP configuration
โ”œโ”€โ”€ user_interface.py          # Interactive user interface
โ”œโ”€โ”€ setup.py                   # Setup script
โ”œโ”€โ”€ test_setup.py              # Test script
โ”œโ”€โ”€ requirements.txt           # Python dependencies
โ”œโ”€โ”€ .env.example               # Environment variables example
โ””โ”€โ”€ README.md                  # This file

๐Ÿ”ง Configuration

MCP Server Configuration

The system uses the following MCP servers:

  1. Playwright MCP: Browser automation

    {
      "command": "npx",
      "args": ["@playwright/mcp@latest", "--headless", "--isolated"]
    }
  2. Custom LLM MCP: Text processing and generation

    {
      "command": "python",
      "args": ["custom_mcp_server.py"]
    }

Environment Variables

# Required
OPENAI_API_KEY=your_openai_api_key

# Optional
LOG_LEVEL=INFO
NODE_ENV=production
PLAYWRIGHT_BROWSERS_PATH=0

๐Ÿงช Examples

Browser Automation Example

mcp> navigate https://httpbin.org/html
mcp> screenshot test.png
mcp> content
mcp> pdf webpage.pdf

LLM Processing Example

mcp> process "Climate change is a major global challenge" analyze
mcp> generate "renewable energy solutions" article medium
mcp> answer "What is photosynthesis?" "Plants convert sunlight to energy"
mcp> brainstorm "mobile app ideas" 5 business

Complex Task Example

mcp> task "Navigate to a news website, take a screenshot, extract the main headlines, and summarize them"

๐Ÿ› Troubleshooting

Common Issues

  1. Playwright browsers not installed

    npx playwright install
  2. Python dependencies missing

    pip install -r requirements.txt
  3. OpenAI API key not set

    • Check your .env file

    • Ensure the key starts with sk-

  4. Node.js/npm not found

Debug Mode

Run with detailed logging:

LOG_LEVEL=DEBUG python user_interface.py --interactive

Testing Individual Components

# Test LLM configuration
python -c "from llm_config import llm; print('LLM OK')"

# Test MCP client
python -c "from mcp_client import MCPClient; print('MCP Client OK')"

# Test Playwright MCP
npx @playwright/mcp@latest --help

๐Ÿ”„ Integration with Other Systems

Claude Desktop Integration

Add to your Claude Desktop configuration:

{
  "mcpServers": {
    "custom-mcp-host": {
      "command": "python",
      "args": ["path/to/mcp/user_interface.py", "--interactive"]
    }
  }
}

Cursor Integration

Add to your mcp.json:

{
  "mcpServers": {
    "custom-mcp-host": {
      "command": "python",
      "args": ["path/to/mcp/user_interface.py"]
    }
  }
}

๐Ÿ“š API Reference

MCPClient Class

from mcp_client import MCPClient

client = MCPClient(config)
await client.connect()
tools = await client.list_tools()
result = await client.call_tool("tool_name", parameters)

PlaywrightMCPController Class

from playwright_mcp_config import PlaywrightMCPController

controller = PlaywrightMCPController()
await controller.initialize()
await controller.navigate_to_page("https://example.com")

MCPHostServer Class

from mcp_client import MCPHostServer

host = MCPHostServer()
host.add_client("name", config)
await host.start_clients()
result = await host.execute_command("client", "command", params)

๐Ÿค Contributing

  1. Fork the repository

  2. Create a feature branch

  3. Make your changes

  4. Test with python test_setup.py

  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License.

๐Ÿ†˜ Support

For issues and questions:

  1. Check the troubleshooting section

  2. Run the test suite: python test_setup.py

  3. Check logs in the logs/ directory

  4. Refer to the FastMCP documentation: https://gofastmcp.com/

๐ŸŽ‰ Acknowledgments

Related MCP Connectors

Related MCP Servers