Custom MCP Server
README.md
# 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
## ๐ Prerequisites
- Python 3.10 or higher
- Node.js and npm (for Playwright MCP)
- OpenAI API key
## ๐ ๏ธ Installation
### 1. Clone/Download the Project
```bash
# If you have the files, navigate to the directory
cd mcp
```
### 2. Run Setup Script
```bash
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
```bash
# 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
```bash
python test_setup.py
```
## ๐ฏ Usage
### Interactive Mode
Start the interactive interface:
```bash
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:
```bash
# 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
```json
{
"command": "npx",
"args": ["@playwright/mcp@latest", "--headless", "--isolated"]
}
```
2. **Custom LLM MCP**: Text processing and generation
```json
{
"command": "python",
"args": ["custom_mcp_server.py"]
}
```
### Environment Variables
```bash
# Required
OPENAI_API_KEY=your_openai_api_key
# Optional
LOG_LEVEL=INFO
NODE_ENV=production
PLAYWRIGHT_BROWSERS_PATH=0
```
## ๐งช Examples
### Browser Automation Example
```bash
mcp> navigate https://httpbin.org/html
mcp> screenshot test.png
mcp> content
mcp> pdf webpage.pdf
```
### LLM Processing Example
```bash
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
```bash
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**
```bash
npx playwright install
```
2. **Python dependencies missing**
```bash
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**
- Install Node.js from https://nodejs.org/
### Debug Mode
Run with detailed logging:
```bash
LOG_LEVEL=DEBUG python user_interface.py --interactive
```
### Testing Individual Components
```bash
# 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:
```json
{
"mcpServers": {
"custom-mcp-host": {
"command": "python",
"args": ["path/to/mcp/user_interface.py", "--interactive"]
}
}
}
```
### Cursor Integration
Add to your `mcp.json`:
```json
{
"mcpServers": {
"custom-mcp-host": {
"command": "python",
"args": ["path/to/mcp/user_interface.py"]
}
}
}
```
## ๐ API Reference
### MCPClient Class
```python
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
```python
from playwright_mcp_config import PlaywrightMCPController
controller = PlaywrightMCPController()
await controller.initialize()
await controller.navigate_to_page("https://example.com")
```
### MCPHostServer Class
```python
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
- [FastMCP](https://github.com/jlowin/fastmcp) - Python framework for MCP
- [Playwright MCP](https://github.com/microsoft/playwright-mcp) - Browser automation
- [OpenAI](https://openai.com/) - LLM capabilities
- [Model Context Protocol](https://modelcontextprotocol.io/) - Standard protocolThis server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues