MCP ExplorerExplorer

Mcp Demo Ref

@SwetaAIS2024on 10 months ago
2 MIT
FreeCommunity
AI Systems
mcp usage demo for my reference

Overview

What is Mcp Demo Ref

mcp-demo-ref is a demonstration project for the Model Context Protocol (MCP), which facilitates communication and collaboration between different machine learning models or AI systems using a standardized messaging format.

Use cases

Use cases for mcp-demo-ref include scenarios where preprocessing and prediction tasks are separated, allowing models to communicate efficiently, such as in data pipelines, real-time analytics, and collaborative AI systems.

How to use

To use mcp-demo-ref, clone the repository from GitHub, ensure you have Python 3.x and Git installed, and follow the instructions in the README to run the preprocessing and prediction models that communicate via MCP messages.

Key features

Key features of mcp-demo-ref include the ability to share context through data exchange, collaborate on complex tasks, and allow interoperability between models built with different frameworks using JSON-based messages.

Where to use

mcp-demo-ref can be used in fields such as machine learning, artificial intelligence, and data science, where multiple models need to work together to achieve a common goal.

Content

MCP Theory

The Model Context Protocol is a framework for enabling communication and collaboration between multiple machine learning models or AI systems. It provides a standardised way for models to :

  1. Share the context : Exchange data, metadata and intermediate results
  2. Collaborate : Work together to solve complex tasks
  3. Interpolate : Allow models built with different frameworks or technologies to communicate seamlessly.

In short, MCP acts as a language or protocol that models use to talk to each other.

MCP Demo: Model Context Protocol

This is a simple demo of the Model Context Protocol (MCP) using Python.
It simulates how two models (a preprocessing model and a prediction model) can communicate
using JSON-based MCP messages.

Project Structure

image

mcp-demo

models

model_a.py - Preprocessing model

This script pre-processes the input data and generates an MCP message.

model_b.py - Prediction model

This script reads the MCP message from the data/mcp_message.json and makes the prediction.

data

mcp_message.json - MCP message file (generated by model_a.py)

A json file is created with the preprocessed data and metadata.

README.md - Project documentation

requirements.txt - List of dependencies

How to run this

Follow these steps to set up and run the MCP demo project on your local machine.

Prerequisites

  • Python 3.x: Make sure Python is installed on your system. You can download it from python.org.
  • Git: Install Git to clone the repository. Download it from git-scm.com.

Step 1: Clone the Repository

  1. Open your terminal or command prompt.
  2. Run the following command to clone the repository:
    git clone https://github.com/SwetaAIS2024/mcp-demo-ref.git
    
  3. Navigate into the project folder:
    cd mcp-demo-ref
    

Step 2: Set Up the Project

  1. Check if Python is installed:
    python --version
    
    or
    python3 --version
    
  2. (Optional) Create a virtual environment to isolate dependencies:
    python -m venv venv
    
    • Activate the virtual environment:
      • On macOS/Linux:
        source venv/bin/activate
        
      • On Windows:
        venv\Scripts\activate
        

Step 3: Run the Models

  1. Run model_a.py:

    • This script preprocesses the input data and generates an MCP message.
    • Run it using:
      python models/model_a.py
      
    • After running, check the data/ folder. You should see a file named mcp_message.json containing the MCP message.
  2. Run model_b.py:

    • This script reads the MCP message from data/mcp_message.json and makes a prediction.
    • Run it using:
      python models/model_b.py
      
    • You should see the prediction result printed in the terminal.

Expected Output

  • Output of model_a.py:

    • A JSON file (data/mcp_message.json) is created with the preprocessed data and metadata.
    • Example:
      {
        "context_id": "txn_12345",
        "model_name": "preprocessing_model",
        "output": {
          "amount": 150,
          "currency": "USD",
          "location": "New York",
          "timestamp": "2023-10-01T12:34:56Z"
        },
        "metadata": {
          "data_version": "v1.0",
          "preprocessing_steps": [
            "uppercase_currency",
            "clean_location"
          ]
        }
      }
  • Output of model_b.py:

    • The script reads the MCP message and makes a prediction.
    • Example:
      {
        "context_id": "txn_12345",
        "model_name": "fraud_prediction_model",
        "output": {
          "is_fraud": true
        },
        "metadata": {
          "model_version": "v1.0",
          "prediction_threshold": 100
        }
      }

Troubleshooting

  • If you encounter errors, ensure that:
    • Python is installed correctly.
    • You are in the correct project directory (mcp-demo-ref).
    • The data/ folder exists and is writable.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers