A modern web interface for running AI agents powered by the Model Context Protocol (MCP)
Web Browser (Frontend: localhost:3000)
β HTTP POST /api/agent/run
Express Server (server.js)
β spawns: python mcp_agent.py
Python MCP Agent (mcp_agent.py)
β connects to external MCP servers
MCP Servers (filesystem, browser via npx)
β performs actual work
Results flow back: MCP β Agent β Express β Browser
mcp-web-agent/
βββ README.md # This file
βββ backend/ # Express API + MCP Agent
β βββ package.json
β βββ server.js # Express API Server
β βββ mcp_agent.py # Python MCP agent (core AI component)
β βββ tests/
β β βββ client_test.js # Direct MCP testing
β β βββ debug_script.js # Backend diagnostics
β βββ README.md # Backend-specific docs
βββ web_app/ # Static Web Frontend
βββ index.html # Main interface
βββ style.css # Styling
βββ script.js # Frontend logic
βββ package.json # Optional dev dependencies
βββ README.md # Frontend-specific docs
- Full Mode: Real web browsing with OpenAI Agents SDK + MCP servers
- Mock Mode: Testing mode when dependencies aren't fully set up
- Auto-detection: Automatically chooses best available mode
- File Generation: Creates structured markdown output files
- Real-time Execution: See agent progress live
- File Management: Download generated files directly
- Task Templates: Quick-start buttons for common tasks
- Error Handling: Comprehensive error reporting with details
- Responsive Design: Works on desktop and mobile
- Separation of Concerns: Frontend, API, and Agent are independent
- Scalable: Easy to extend with new MCP servers or capabilities
- Development Friendly: Mock mode for testing without full setup
- Production Ready: Robust error handling and logging
# 1. Install Python dependencies
pip install openai-agents-sdk python-dotenv
# 2. Install Node.js dependencies
npm install
# 3. Set up environment
echo "OPENAI_API_KEY=your_actual_openai_key_here" > .env
# 4. Ensure Node.js tools are available
node --version # Should be v16+
npx --version # Should work
# 5. Start the server
npm start
# 6. Open browser to http://localhost:3000# 1. Install basic dependencies
npm install
# 2. Start server (will run in mock mode)
npm start
# 3. Test interface at http://localhost:3000
# Mock agent will create sample files for testing# Test API server
curl http://localhost:3000/api/status
# Expected response:
# {"status":"healthy","timestamp":"...","server":"MCP Web Agent Server","python_agent":"mcp_agent.py"}# Test Python agent directly
echo "Find information about Python programming" | python mcp_agent.py
# Should show:
# - Mode detection (Full MCP or Mock)
# - Task processing steps
# - File creation confirmation- Open:
http://localhost:3000 - Click: "π° Find Recipe" button
- Click: "π Run Agent"
- Expect: Results within 30-60 seconds
Find information about Python web frameworks and save it to frameworks.md
Create a simple "Hello World" guide for beginners and save it to hello_guide.md
- β Real web browsing and research
- β Detailed, accurate content
- β Professional markdown files
- β 1-3 minute execution time
- β Simulated agent behavior
- β Sample content generation
- β File creation testing
- β 3-5 second execution time
# Quick connectivity test
"Create a simple hello world message and save it to hello.md"
# File system test
"Generate a basic markdown template and save it to template.md"
# Content generation test
"Write a short guide about getting started with programming"# Technology research
"Research the latest developments in artificial intelligence and create a summary report"
# Comparative analysis
"Compare React, Vue, and Angular frameworks and document the differences"
# Current information
"Find the latest news about climate change and create a summary with key points"
# Tutorial creation
"Find best practices for Python web development and create a beginner's guide"# Recipe research
"Find a great recipe for chocolate chip cookies and format it in markdown"
# Educational content
"Create a comprehensive guide about machine learning for beginners"
# Reference material
"Research REST API design patterns and create a reference document"
# How-to guides
"Find information about setting up a development environment and create a setup guide"[ACTION VERB] + [SPECIFIC TOPIC] + [OUTPUT FORMAT/FILE]
Examples:
β
"Research Python web frameworks and save findings to frameworks.md"
β
"Find current cryptocurrency prices and create a market report"
β
"Compare different project management tools and document pros/cons"
β "Tell me about stuff" (too vague)
β "Research everything about AI" (too broad)
β "Help me" (no specific action)
β Tasks requiring personal/private information
Cause: Express API server not running on port 3000
Solution:
# Check if server is running
curl http://localhost:3000/api/status
# If connection refused, start server:
npm start
# Check for port conflicts:
lsof -i :3000Cause: Missing Python dependencies or file permissions
Solutions:
# Install Python dependencies
pip install openai-agents-sdk python-dotenv
# Fix sandbox permissions
mkdir -p sandbox
chmod 755 sandbox
# Test Python agent directly
echo "test task" | python mcp_agent.pyCause: Missing OpenAI API key or SDK
Solutions:
# Check .env file exists and has key
cat .env
# Should show: OPENAI_API_KEY=sk-...
# Install full SDK
pip install openai-agents-sdk
# Verify Node.js for MCP servers
node --version # Need v16+
npx --version # Should workCause: Permission issues or agent not completing properly
Solutions:
# Create sandbox with proper permissions
mkdir -p sandbox
chmod 777 sandbox # Temporary fix
# Check agent logs in server console
# Look for "π Created file:" messages
# Test file creation manually
echo "test" > sandbox/test.txt
ls -la sandbox/# Terminal 1: API Server (keep running)
npm start
# Terminal 2: Frontend development (optional)
# Use any live server for public/ folder for faster frontend development- Modify code (server.js, mcp_agent.py, or frontend files)
- Restart server if needed (Ctrl+C, npm start)
- Test in browser (http://localhost:3000)
- Check logs in server terminal
- Iterate based on results
- Add new API endpoints
- Modify agent communication
- Add file handling features
- Add new MCP server connections
- Modify task processing logic
- Add new content generation types
- Add new UI components
- Modify styling and layout
- Add new task templates
package.json- Node.js project configurationserver.js- Express API servermcp_agent.py- Python MCP agent scriptpublic/index.html- Web interfacepublic/style.css- Stylingpublic/script.js- Frontend JavaScript
{
"dependencies": {
"express": "^5.1.0",
"cors": "^2.8.5"
}
}pip install openai-agents-sdk python-dotenvOPENAI_API_KEY=your_openai_api_key_here
- MCP Server (like old mcp_server.js): Provides tools for others to use
- MCP Agent (current mcp_agent.py): Uses tools from external servers + AI reasoning
- Full Mode: Real AI agent with web browsing capabilities
- Mock Mode: Testing mode that creates realistic sample content
- Frontend/Backend Separation: Independent development and deployment
- Extensible: Easy to add new MCP servers and capabilities
- Development Friendly: Mock mode for testing without full setup
When everything is working correctly, you should see:
- β Browser Status: "π’ Connected"
- β Agent Execution: Spinner during processing
- β Results Display: Agent output and file listing
- β File Downloads: Clickable links to generated files
- β Console Logs: Detailed execution information
This project creates a professional-grade MCP web agent system that combines:
- Modern Web Interface with real-time feedback
- Robust Backend API with comprehensive error handling
- Intelligent AI Agent capable of web browsing and file generation
- Flexible Architecture supporting both development and production use
The system demonstrates the power of the Model Context Protocol for creating sophisticated AI agents that can use external tools to accomplish complex tasks.
Powered by OpenAI Agents SDK + Model Context Protocol# mcp_agent