mcpField
M
MCP Demo

MCP Demo

Local
github.com/tanjibpaDeveloper Tools0Updated 80w ago

About MCP Demo

MCP Demo is a Python MCP server example for developers exploring database-backed data operations. It uses PostgreSQL to manage organizations and devices, with tools that also calculate distances.

Key features

  1. 01Manage organizations and devices in PostgreSQL
  2. 02Fetch organizations and devices
  3. 03Filter devices by organization
  4. 04Calculate device-to-organization distances

Use cases

  1. 01Query organizations and devices in the database
  2. 02View each device's organization and distance

MCP support

As an MCP server, it exposes tools for querying organizations and devices and calculating distances to MCP clients.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

MCP Demo

This repository contains a demo implementation of a Model Context Protocol (MCP) server. The server is designed to manage organizations and devices, calculate distances between devices and their associated organizations, and provide a set of tools for interacting with the data.

Features

  • Database Integration: Connects to a PostgreSQL database to manage organizations and devices.
  • Distance Calculation: Uses the Haversine formula to calculate distances between devices and their associated organizations.
  • MCP Tools: Provides tools to fetch organizations, devices, and calculate distances.

Prerequisites

  • Python 3.12.5
  • PostgreSQL database

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd mcp-demo
    
  2. Set up a virtual environment:

    uv venv
    source .venv/bin/activate
    
  3. Configure the environment variables in a .env file:

    DB_NAME=mcp
    DB_USER=mcp_user
    DB_PASSWORD=pa$$word
    DB_HOST=localhost
    DB_PORT=5432
    
  4. Set up the database:

    psql -U <username> -d <database> -f tables.sql
    

Usage

  1. Run the MCP server:

    uv run main.py
    
  2. Use the provided tools to interact with the server:

    • get_organizations: Fetch all organizations from the database.
    • get_devices: Fetch all devices from the database.
    • get_devices_by_organization: Fetch devices for a specific organization.
    • list_devices_with_distance: List devices and their distances from their associated organizations.

Project Structure

  • main.py: Main entry point for the MCP server.
  • tables.sql: SQL script to set up the database schema and seed data.
  • .env: Environment variables for database configuration.
  • pyproject.toml: Project metadata and dependencies.

Dependencies

  • httpx: HTTP client for Python.
  • mcp[cli]: MCP framework for building servers.
  • psycopg2: PostgreSQL database adapter for Python.

Claude Desktop MCP Server Configuration

To configure Claude Desktop for this MCP server project, follow these steps:

  1. Install Claude Desktop on your machine from the official website.

  2. Open Claude Desktop and navigate to the settings menu.

  3. Add a new project configuration for the MCP server:

     code ~/Library/Application\ Support/Claude/claude_desktop_config.json
    
  4. Add the mcp servers

{
    "mcpServers": {
        "devices": {
            "command": "uv",
            "args": [
                "--directory",
                "/path/to/mcp-demo",
                "run",
                "main.py"
            ],
            "env": {
                "DB_NAME": "mcp",
                "DB_USER": "mcp_user",
                "DB_PASSWORD": "pa$$word",
                "DB_HOST": "localhost",
                "DB_PORT": "5432"
            }
        }
    }
}
  1. Run query, for example: List the devices in DB and show me how far are they from their organization address. Also, add get the mac addresses of the devices.

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.