Thanks to visit codestin.com
Credit goes to github.com

Skip to content

amit-dingare/mcp-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OpenAI-Orchestrated MCP Framework

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.

🌟 Overview

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

🎯 Key Features

  • πŸ€– 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  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    β”‚
                                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

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

πŸš€ Quick Start

1. Installation

# Clone the repository
git clone <repository-url>
cd mcp-framework

# Install dependencies
pip install mcp fastmcp openai python-dotenv aiohttp

2. Configuration

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

3. Start the MCP Server

python mcp_server.py

4. Run the Orchestrated Client

# Interactive mode
python orchestrated_mcp_client.py --interactive

# Demo mode
python orchestrated_mcp_client.py

🎭 Demonstration: The Power of Prompts

Basic Tool Usage vs. Enhanced Prompts

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 ...]

Calculator Example

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 ...]

🧠 How the Intelligence Works

The OpenAI orchestrator automatically detects user intent:

Trigger Words for Enhanced Analysis:

  • "detailed" β†’ Uses prompts for comprehensive output
  • "report" β†’ Generates professional reports
  • "analysis" β†’ Provides analytical insights
  • "comprehensive" β†’ Creates thorough documentation

Simple Queries:

  • Basic questions β†’ Uses tools only
  • Quick lookups β†’ Returns raw data

πŸ› οΈ Available Tools

Weather Tool

  • Function: Get current weather for any location
  • API: OpenWeatherMap integration
  • Usage: "What's the weather in [city]?"

Calculator Tool

  • Function: Safe mathematical calculations
  • Features: Basic arithmetic, functions (sqrt, sin, cos, etc.)
  • Usage: "Calculate [expression]"

DuckDuckGo Search Tool

  • Function: Web search capabilities
  • Features: Real-time web search results
  • Usage: "Search for [query]" or "Research [topic]"

File Operations Tool

  • Function: File handling and management
  • Features: Read, write, and manipulate files
  • Usage: "Read file [filename]" or "Create file with [content]"

πŸ“ Available Prompts

Weather Report

  • Purpose: Transform weather data into professional reports
  • Includes: Analysis, recommendations, comfort ratings
  • Trigger: "detailed weather report"

Calculation Analysis

  • Purpose: Educational mathematical analysis
  • Includes: Step-by-step solutions, number properties, applications
  • Trigger: "mathematical analysis"

Company Research Report

  • Purpose: Comprehensive business analysis and reports
  • Includes: Market analysis, financial insights, strategic recommendations
  • Trigger: "company research report" or "business analysis"

System Prompt

  • Purpose: Core system instructions and behavior
  • Usage: Internal system guidance

🎯 Example Queries

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

Adding Resources

  1. Place any text/JSON file in resources/
  2. Access via: "Show me the [filename] resource"

πŸ”§ Adding New Capabilities

Adding a New Tool

  1. 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}"
  1. Restart the server - automatically loaded!

Adding a New Prompt

  1. 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}
  ]
}
  1. Restart the server - automatically loaded!

πŸ“š Available Resources

Company Information

  • File: company_info.txt
  • Content: Company overview, mission, values, products
  • Usage: "Show me company information"

Customer Data

  • File: customer_data.json
  • Content: Customer database with metrics and status
  • Usage: "Access customer data" or "Show customer information"

Monthly Report

  • File: monthly_report.txt
  • Content: Business performance metrics and analysis
  • Usage: "Display monthly report"

User Data

  • File: user_data.json
  • Content: User information and preferences
  • Usage: "Retrieve user data"

🎨 Customization

Modify System Prompt

Edit the _build_system_prompt() method in orchestrated_mcp_client.py to customize OpenAI's behavior.

Adjust Workflow Detection

Modify the trigger words in the workflow detection logic to change when prompts are used.

API Configuration

Add new API keys and settings to .env for additional tools.

πŸ” Troubleshooting

Common Issues

"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

Debug Mode

Enable verbose logging by modifying the print statements in both client and server files.

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Add new tools/prompts following the existing patterns
  4. Test with the orchestrated client
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Anthropic for the Model Context Protocol
  • FastMCP for the simplified server framework
  • OpenAI for intelligent orchestration capabilities

πŸš€ What's Next?

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! πŸŽ‰

About

code repo for MCP capabilities

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages