Skip to content

alimoradi296/utcp_vs_mcp_demo

Repository files navigation

UTCP vs. MCP Demo This project is a Python-based demonstration comparing the Universal Tool Calling Protocol (UTCP) and the Model Context Protocol (MCP) for integrating AI agents with external APIs. The demo uses a mock weather API to showcase differences in latency, setup complexity, authentication handling, and protocol flexibility. Project Overview The demo simulates an AI agent retrieving a 3-day weather forecast for a specified location (e.g., New York) using both UTCP and MCP. It includes:

A mock weather API server (weather_api.py). A UTCP implementation with a JSON manual and agent code (weather_utcp_manual.json, utcp_agent.py). An MCP implementation with a server and agent code (mcp_server.py, mcp_agent.py). A main script (demo.py) to execute and compare both approaches.

Key Features

Latency Measurement: Compares the time taken for UTCP (direct API calls) vs. MCP (server-mediated calls). Setup Complexity: UTCP uses a JSON manual (40 lines total); MCP requires a server (50 lines total). Authentication: UTCP handles API keys directly; MCP abstracts authentication to the server. Flexibility: UTCP supports multiple protocols (e.g., HTTP, gRPC); MCP is tied to server implementation.

Prerequisites

Python 3.8 or higher pip (Python package manager) Dependencies listed in requirements.txt

Installation

Clone the repository: git clone https://github.com/alimoradi296/utcp_vs_mcp_demo.git cd utcp_vs_mcp_demo

Create and activate a virtual environment (optional but recommended): python -m venv projvenv source projvenv/bin/activate # On Windows: projvenv\Scripts\activate

Install dependencies: pip install -r requirements.txt

File Structure

weather_api.py: Mock weather API server (runs on localhost:5000). weather_utcp_manual.json: UTCP manual defining the weather API’s endpoint and parameters. utcp_agent.py: UTCP agent code for direct API calls. mcp_server.py: MCP server to mediate API interactions (runs on localhost:5001). mcp_agent.py: MCP agent code to interact with the MCP server. demo.py: Main script to run and compare UTCP and MCP. requirements.txt: Python dependencies.

How to Run

Start the Weather API Server:Open a terminal, navigate to the project directory, and run: python weather_api.py

This starts the mock weather API on localhost:5000.

Start the MCP Server:Open a second terminal, navigate to the project directory, and run: python mcp_server.py

This starts the MCP server on localhost:5001.

Run the Demo:Open a third terminal, navigate to the project directory, and run: python demo.py

This executes both UTCP and MCP implementations, displaying responses, latencies, and a comparison.

Sample Output === Running UTCP Demo === UTCP Response: { "location": "New York", "forecast": [ {"day": 1, "temperature": 22.30, "conditions": "Rainy"}, ... ] } UTCP Latency: 0.0037 seconds

=== Running MCP Demo === MCP Response: { "location": "New York", "forecast": [ {"day": 1, "temperature": 11.98, "conditions": "Sunny"}, ... ] } MCP Latency: 0.0065 seconds

=== Comparison === UTCP Latency: 0.0037 seconds MCP Latency: 0.0065 seconds Latency Difference (MCP - UTCP): 0.0027 seconds ...

Results and Insights

Latency: UTCP is generally faster (3–4 ms) due to direct API calls, compared to MCP (5–7 ms) with its server intermediary. Anomalies (e.g., MCP faster in one run) may occur due to system initialization. Setup Complexity: UTCP is simpler, requiring only a JSON manual and agent code. MCP needs an additional server. Authentication: MCP abstracts API key handling to the server, simplifying agent logic. UTCP requires direct key management. Flexibility: UTCP supports multiple protocols via its manual, while MCP is limited to the server’s implementation.

Contributing Contributions are welcome! Please:

Fork the repository. Create a new branch (git checkout -b feature/your-feature). Commit changes (git commit -m "Add your feature"). Push to the branch (git push origin feature/your-feature). Open a pull request.

License This project is licensed under the MIT License. See the LICENSE file for details. Acknowledgments

Inspired by UTCP and MCP. Built with Python, Flask, and Requests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages