Sponsored by Deepsite.site

MCP Demo

Created By
tanjibpa8 months ago
Content

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.
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Amap Maps高德地图官方 MCP Server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
WindsurfThe new purpose-built IDE to harness magic
DeepChatYour AI Partner on Desktop
Playwright McpPlaywright MCP server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
CursorThe AI Code Editor
Serper MCP ServerA Serper MCP Server
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors