A powerful demonstration of the Model Context Protocol (MCP) with intelligent OpenAI orchestration that automatically decides which tools, resources, and prompts to use based on user intent.
This repository showcases a complete MCP ecosystem where:
- FastMCP Server dynamically loads capabilities from folders
- OpenAI Orchestration intelligently decides which MCP functions to call
- Smart Prompts transform raw tool data into professional reports
- No Manual Function Selection - OpenAI handles everything automatically
- π€ Intelligent Orchestration: OpenAI analyzes user intent and automatically selects appropriate MCP capabilities
- π Dynamic Loading: Tools, resources, and prompts loaded from simple folder structures
- π Workflow Automation: Automatic toolβprompt workflows for comprehensive responses
- β‘ Zero Configuration: Works out-of-the-box with sample tools and prompts
- π¨ Professional Output: Raw data transformed into polished reports and analyses
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β User Query βββββΆβ OpenAI βββββΆβ MCP Server β
β "Weather report β β Orchestrator β β β
β for Tokyo" β β β β βββ tools/ β
βββββββββββββββββββ β ββββββββββββββββ β β βββ resources/ β
β β Analyzes β β β βββ prompts/ β
βββββββββββββββββββ β β Intent β β βββββββββββββββββββ
β Professional ββββββ β β β β
β Weather Report β β β Selects β β β
β with Analysis β β β Tools & β β ββββββββΌβββββββ
βββββββββββββββββββ β β Prompts β β β 1. weather β
β ββββββββββββββββ β β 2. weather_ β
ββββββββββββββββββββ β report β
βββββββββββββββ
mcp-framework/
βββ orchestrated_mcp_client.py # OpenAI-powered orchestration client
βββ mcp_server.py # FastMCP server with dynamic loading
βββ .env # API keys and configuration
βββ tools/ # Tool implementations
β βββ calculator.py # Safe mathematical calculations
β βββ duckduckgo_search.py # Web search capabilities
β βββ file_operations.py # File handling operations
β βββ weather.py # Weather data from OpenWeatherMap
βββ resources/ # Static resources and documents
β βββ company_info.txt # Company information
β βββ customer_data.json # Customer database
β βββ monthly_report.txt # Business performance report
β βββ user_data.json # User information data
βββ prompts/ # Prompt templates
βββ calculation_analysis.json# Mathematical insights and analysis
βββ company_research_report.json# Comprehensive business reports
βββ system_prompt.txt # System instructions
βββ weather_report.json # Professional weather analysis
# Clone the repository
git clone <repository-url>
cd mcp-framework
# Install dependencies
pip install mcp fastmcp openai python-dotenv aiohttp
Create a .env
file with your API keys:
# Required for OpenAI orchestration
OPENAI_API_KEY=your_openai_api_key_here
# Required for weather tool
OPENWEATHER_API_KEY=your_openweather_api_key_here
python mcp_server.py
# Interactive mode
python orchestrated_mcp_client.py --interactive
# Demo mode
python orchestrated_mcp_client.py
Simple Query (Tool Only):
You: What's the weather in Tokyo?
Assistant: π€οΈ Weather in Tokyo, Japan:
Temperature: 22Β°C (feels like 24Β°C)
Conditions: Clear Sky
Humidity: 65%
Pressure: 1013 hPa
Wind Speed: 3.2 m/s
Enhanced Query (Tool + Prompt):
You: Give me a detailed weather report for Tokyo
Assistant: # π€οΈ Weather Report for Tokyo
## Current Conditions
π€οΈ Weather in Tokyo, Japan:
Temperature: 22Β°C (feels like 24Β°C)
Conditions: Clear Sky
Humidity: 65%
Pressure: 1013 hPa
Wind Speed: 3.2 m/s
## Detailed Analysis
### π‘οΈ Temperature Assessment
The current temperature of 22Β°C is quite comfortable for most activities...
### π Clothing Suggestions
- Light layers recommended
- T-shirt or light shirt with optional light jacket...
### πΆ Activity Recommendations
- Perfect for outdoor walks or jogging
- Excellent conditions for sightseeing...
[... continues with comprehensive analysis ...]
Basic Calculation:
You: Calculate 144 + 25
Assistant: π Result: 144 + 25 = 169
Mathematical Analysis:
You: Give me a detailed mathematical analysis of 144 + 25
Assistant: # π Mathematical Analysis Report
## Calculation Summary
π Result: 144 + 25 = 169
## Detailed Analysis
### π’ Expression Breakdown
This is a basic arithmetic addition involving two perfect squares...
### π Mathematical Insights
Interestingly, both numbers are perfect squares (12Β² and 5Β²)...
### π― Result Interpretation
The result 169 is also a perfect square (13Β²), creating a
Pythagorean relationship: 12Β² + 5Β² = 13Β²...
[... continues with educational content ...]
The OpenAI orchestrator automatically detects user intent:
- "detailed" β Uses prompts for comprehensive output
- "report" β Generates professional reports
- "analysis" β Provides analytical insights
- "comprehensive" β Creates thorough documentation
- Basic questions β Uses tools only
- Quick lookups β Returns raw data
- Function: Get current weather for any location
- API: OpenWeatherMap integration
- Usage:
"What's the weather in [city]?"
- Function: Safe mathematical calculations
- Features: Basic arithmetic, functions (sqrt, sin, cos, etc.)
- Usage:
"Calculate [expression]"
- Function: Web search capabilities
- Features: Real-time web search results
- Usage:
"Search for [query]"
or"Research [topic]"
- Function: File handling and management
- Features: Read, write, and manipulate files
- Usage:
"Read file [filename]"
or"Create file with [content]"
- Purpose: Transform weather data into professional reports
- Includes: Analysis, recommendations, comfort ratings
- Trigger:
"detailed weather report"
- Purpose: Educational mathematical analysis
- Includes: Step-by-step solutions, number properties, applications
- Trigger:
"mathematical analysis"
- Purpose: Comprehensive business analysis and reports
- Includes: Market analysis, financial insights, strategic recommendations
- Trigger:
"company research report"
or"business analysis"
- Purpose: Core system instructions and behavior
- Usage: Internal system guidance
Try these to see the orchestration in action:
# Weather Examples
"What's the weather in Paris?" # Tool only
"Give me a comprehensive weather report for London" # Tool + Prompt
# Calculator Examples
"Calculate sqrt(144)" # Tool only
"Provide detailed analysis of sqrt(144)" # Tool + Prompt
# Search Examples
"Search for Python tutorials" # Tool only
"Research artificial intelligence and create a report" # Tool + Prompt
# File Examples
"Read the company info file" # Resource access
"Show me customer data and create an analysis" # Resource + Prompt
# Business Examples
"Research Tesla" # Tool only
"Research Tesla and create a comprehensive report" # Tool + Prompt
- Place any text/JSON file in
resources/
- Access via:
"Show me the [filename] resource"
- Create
tools/my_tool.py
:
TOOL_NAME = "my_tool"
TOOL_DESCRIPTION = "Description of what this tool does"
async def tool_function(param: str) -> str:
"""Tool implementation"""
return f"Result: {param}"
- Restart the server - automatically loaded!
- Create
prompts/my_prompt.json
:
{
"name": "my_prompt",
"description": "What this prompt creates",
"template": "# {title}\n\n{content}",
"arguments": [
{"name": "title", "description": "Report title", "required": true},
{"name": "content", "description": "Main content", "required": true}
]
}
- Restart the server - automatically loaded!
- File:
company_info.txt
- Content: Company overview, mission, values, products
- Usage:
"Show me company information"
- File:
customer_data.json
- Content: Customer database with metrics and status
- Usage:
"Access customer data"
or"Show customer information"
- File:
monthly_report.txt
- Content: Business performance metrics and analysis
- Usage:
"Display monthly report"
- File:
user_data.json
- Content: User information and preferences
- Usage:
"Retrieve user data"
Edit the _build_system_prompt()
method in orchestrated_mcp_client.py
to customize OpenAI's behavior.
Modify the trigger words in the workflow detection logic to change when prompts are used.
Add new API keys and settings to .env
for additional tools.
"OpenAI API key not found"
- Ensure
OPENAI_API_KEY
is set in.env
"Weather API key not configured"
- Get free API key from OpenWeatherMap
- Add
OPENWEATHER_API_KEY
to.env
"Connection timeout"
- Check that MCP server is running
- Verify no port conflicts
"No tools/prompts loaded"
- Check file permissions
- Verify folder structure
- Review server startup logs
Enable verbose logging by modifying the print statements in both client and server files.
- Fork the repository
- Create your feature branch
- Add new tools/prompts following the existing patterns
- Test with the orchestrated client
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Anthropic for the Model Context Protocol
- FastMCP for the simplified server framework
- OpenAI for intelligent orchestration capabilities
This framework demonstrates the future of AI interactions:
- No manual function selection - AI decides everything
- Professional output - Raw data becomes polished reports
- Extensible architecture - Easy to add new capabilities
- Real-world applications - Ready for production use
Try it out and see how MCP + OpenAI orchestration transforms simple tools into intelligent, comprehensive AI assistants! π