A powerful Python implementation of a ReAct (Reasoning and Acting) AI agent that can communicate with MCP (Model Context Protocol) servers and use various LLM providers. Features comprehensive business intelligence tools and multiple demonstration scenarios.
- 🧠 ReAct Architecture: Implements the Reasoning and Acting pattern for intelligent problem-solving
- 🔗 MCP Client: Full STDIO protocol support for MCP servers
- 🤖 Multi-LLM Support: OpenAI, Anthropic, Google, Groq, OpenRouter
- 📊 Data Analysis: Advanced data analyst MCP server with business intelligence tools
- ⚡ Async Operations: Fully asynchronous for optimal performance
- ⚙️ Environment Configuration: Easy setup with .env file support
- 🎯 Multiple Demos: 5+ different showcase scenarios
PyMCP/
├── 📋 Core Components
│ ├── react_agent.py # Main ReAct agent implementation
│ ├── config.py # Configuration management (.env support)
│ └── requirements.txt # Dependencies
│
├── 🖥️ MCP Servers
│ ├── hello_mcp_server.py # Simple greeting/utility server
│ └── data_analyst_mcp_server.py # Advanced business intelligence server
│
├── 🎮 Examples & Demos
│ ├── example_usage.py # 7 different example scenarios
│ ├── power_demo.py # Ultimate business analysis challenge
│ └── showcase_demo.py # 6 comprehensive demonstrations
│
├── 🔧 Utilities
│ └── test_config.py # Configuration testing
│
└── 📚 Documentation
├── README.md # This file
├── SETUP.md # Quick start guide
└── .env.example # Configuration template
pip install -r requirements.txt
copy .env.example .env
# Edit .env with your API key and preferred provider
python test_config.py
# Quick start with multiple options
python example_usage.py
# Ultimate business analysis demo
python power_demo.py
# Comprehensive showcase (6 demos)
python showcase_demo.py
Configure your preferred LLM provider in .env
:
LLM_PROVIDER=openai
LLM_MODEL=gpt-4
LLM_API_KEY=your-openai-api-key
LLM_PROVIDER=groq
LLM_MODEL=meta-llama/llama-3-8b-8192
LLM_API_KEY=your-groq-api-key
LLM_PROVIDER=anthropic
LLM_MODEL=claude-3-sonnet-20240229
LLM_API_KEY=your-anthropic-api-key
LLM_PROVIDER=google
LLM_MODEL=gemini-pro
LLM_API_KEY=your-google-api-key
LLM_PROVIDER=openrouter
LLM_MODEL=anthropic/claude-3-sonnet
LLM_API_KEY=your-openrouter-api-key
Choose from multiple scenarios:
- Hello MCP Server - Simple greeting and utility tools
- Data Analyst MCP - Business intelligence and data analysis
- Filesystem MCP - File system operations (requires NPX)
- Web Search MCP - Web search capabilities (requires NPX)
- Configuration Demo - Environment-based setup
- Multi-Provider Test - Test different LLM providers
- Interactive Mode - Ask your own questions
python example_usage.py
# Choose option 1 or 2 for local servers (no NPX required)
The most comprehensive demonstration featuring:
- Complex Problem: Multi-step business analysis
- 200 Record Dataset: Realistic sales data
- 8 Analysis Steps: From data creation to executive recommendations
- Executive Report: Professional business insights
python power_demo.py
# Choose option 1 for full power demo
Professional demonstration suite:
- Business Data Analysis - Complex reasoning with sales data
- Data Detective - Pattern finding across multiple datasets
- Predictive Analytics - Forecasting and trend analysis
- Multi-step Optimization - 5-step business optimization
- Comparative Analysis - Multiple dataset comparison
- Interactive Mode - Custom queries
python showcase_demo.py
# Choose individual demos or run all sequentially
Simple server with basic utilities:
- say_hello - Greeting with custom messages
- get_time - Current time in multiple formats
- echo - Message echoing
- calculate - Basic arithmetic
Advanced business intelligence server:
- create_dataset - Generate realistic business data (sales, weather, students)
- analyze_data - Statistical analysis (summary, correlation, trends, outliers)
- filter_data - Complex data filtering with conditions
- visualize_data - Text-based charts and histograms
- predict_trend - Trend forecasting and predictions
- save_to_file/load_from_file - Data persistence
Thought: "I need to analyze business performance"
Action: create_dataset
Observation: "Created sales dataset with 200 records"
Thought: "Now I should understand the current situation"
Action: analyze_data
Observation: "Average sales: $2,345, range: $100-$5,000"
Thought: "I need to identify top performers"
Action: filter_data
Observation: "Found 45 high-value transactions"
...
- Multi-step Planning - Breaks complex requests into manageable steps
- Tool Orchestration - Intelligently chains tools together
- Adaptive Reasoning - Adjusts approach based on observations
- Goal Persistence - Stays focused on end objective
- Go to https://console.groq.com/keys
- Sign up for free account
- Generate API key (generous free tier)
- Go to https://platform.openai.com/api-keys
- Create account and API key
- Add billing information
- Go to https://console.anthropic.com/
- Create account and get API key
# The agent will:
# 1. Create a comprehensive sales dataset
# 2. Perform statistical analysis
# 3. Filter for high-performing products
# 4. Identify outliers and problems
# 5. Analyze trends and patterns
# 6. Create visualizations
# 7. Make predictions
# 8. Provide executive recommendations
# The agent will:
# 1. Create multiple datasets
# 2. Investigate patterns and correlations
# 3. Find anomalies and outliers
# 4. Cross-reference different data sources
# 5. Provide insights and conclusions
# Ask complex questions like:
# - "Create a dataset, analyze trends, and predict future performance"
# - "Compare different data patterns and find correlations"
# - "Investigate outliers and provide business recommendations"
- Reason - Agent thinks about what to do next
- Act - Calls appropriate MCP tools
- Observe - Analyzes results and adjusts approach
- Repeat - Continues until goal is achieved
- STDIO Communication - Full JSON-RPC protocol support
- Tool Discovery - Automatic detection of available tools
- Error Handling - Robust error recovery and reporting
- Async Operations - Non-blocking tool execution
Configuration Issues
python test_config.py # Test your .env setup
Missing Dependencies
pip install -r requirements.txt
API Key Problems
- Verify key is valid and has credits
- Check provider is correctly set in .env
- Try the free Groq option for testing
- Create new LLM class implementing
LLMInterface
- Add to
LLMProvider
enum - Update
LLMFactory.create_llm()
- Follow MCP protocol specification
- Implement tool discovery and execution
- Add to example configurations
- Use
ConfigLoader.load_from_env()
for setup - Create
MCPClient
with your server - Initialize
ReActAgent
with your LLM
This project is open source. Feel free to use, modify, and extend as needed.
Contributions welcome! Areas for improvement:
- Additional LLM providers
- New MCP server implementations
- Enhanced ReAct strategies
- More demonstration scenarios
- Performance optimizations