Cover image
Try Now
2025-04-07

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

MCP Server Demo

Prerequisites

  • uv - An extremely fast Python package and project manager, written in Rust.

Overview

This guide walks through creating a simple Model Context Protocol (MCP) server and testing it with both the MCP Inspector and Claude Desktop. The content is based on the modelcontextprotocol/python-sdk README, with additional notes for clarity.

Steps to Create an MCP Server

1. Environment Setup

uv init mcp-server-demo
cd mcp-server-demo

# Specify Python version
echo "3.12" > .python-version

# Install Python before creating a new virtual environment
uv venv 

# Activate virtual environment
source .venv/bin/activate.fish

# Verify virtual environment (check if using the correct Python environment)
which python
path/to/mcp-server-demo/.venv/bin/python

# Install MCP dependencies (added to pyproject.toml)
uv add "mcp[cli]"

# Verify MCP dependencies were installed correctly
uv tree

Resolved 28 packages in 3ms
mcp-server-demo v0.1.0
└── mcp[cli] v1.6.0
    ├── ...

2. Creating a Simple MCP Server

# server.py
from mcp.server.fastmcp import FastMCP

# Create an MCP server
mcp = FastMCP("Demo")

# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b


# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting"""
    return f"Hello, {name}!"

3. Testing with MCP Inspector

Launch MCP Inspector

uv run mcp dev server.py

Starting MCP inspector...
⚙️ Proxy server listening on port 6277

Testing the add Tool

  1. Open the MCP Inspector
  2. Click "Connect"
  3. Click the "Tools" tab
  4. Click "List Tools" inside the "Tools" tab

Testing the get_greeting Resource

  1. Open the MCP Inspector
  2. Click "Connect"
  3. Click "Resources" Tab
  4. Click "List Templates"
  5. Find "get_greeting"
  6. Type a name (e.g., "John")
  7. Click "Read Resources"

Example response:

{
  "contents": [
    {
      "uri": "greeting://John",
      "mimeType": "text/plain",
      "text": "Hello, John!"
    }
  ]
}

4. Testing with Claude Desktop

Install the MCP Server in Claude Desktop

uv run mcp install server.py

[/dd/MM/YY HH:MM:SS] INFO     Added server 'Demo' to Claude config            claude.py:129
                     INFO     Successfully installed Demo in Claude app          cli.py:467

Verify Configuration

# For macOS/Linux
cat ~/Library/Application\ Support/Claude/claude_desktop_config.json

Example configuration:

{
    "mcpServers": {
        "Demo": {
            "command": "/absolute/path/to/uv",
            "args": [
                "run",
                "--with",
                "mcp[cli]",
                "mcp",
                "run",
                "/absolute/path/to/mcp-server-demo/server.py"
            ]
        }
    }
}

Note: After executing uv run mcp install server.py, the command is set as just "uv" in the configuration, but it requires an absolute path to work properly.

Using Claude Desktop with MCP

Checking Server Status

The Claude.app interface provides basic server status information:

  1. Click the connect icon to view:
    • Connected servers
    • Available prompts and resources
  2. Click the hammer icon to view:
    • Tools made available to the mode

Type in Claude Desktop:

Please use the add tool to sum 10 and 20

Using the get_greeting Resource

Note: There appears to be an issue retrieving resources from Claude Desktop. This section needs further investigation.

FAQ

How does Claude Desktop select which MCP server tools to use?

  • Claude connects to all configured MCP servers but selects tools based on the content of the user's query
  • If the question content is not suitable for using tools, the tools will not be used

References

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • pontusab
  • La comunidad de cursor y windsurf, encontrar reglas y MCP

  • jae-jae
  • Servidor MCP para obtener contenido de la página web con el navegador sin cabeza de dramaturgo.

  • ravitemer
  • Un poderoso complemento Neovim para administrar servidores MCP (protocolo de contexto del modelo)

  • patruff
  • Puente entre los servidores Ollama y MCP, lo que permite a LLM locales utilizar herramientas de protocolo de contexto del modelo

  • av
  • Ejecute sin esfuerzo LLM Backends, API, frontends y servicios con un solo comando.

  • chongdashu
  • Habilite clientes asistentes de IA como Cursor, Windsurf y Claude Desktop para controlar el motor irreal a través del lenguaje natural utilizando el Protocolo de contexto del modelo (MCP).

  • wgpsec
  • 一款基于各大企业信息 API 的工具 , 解决在遇到的各种针对国内企业信息收集难题。一键收集控股公司 解决在遇到的各种针对国内企业信息收集难题。一键收集控股公司 ICP 备案、 Aplicación 、小程序、微信公众号等信息聚合导出。支持 MCP 接入

    Reviews

    3 (1)
    Avatar
    user_V3UFpOkv
    2025-04-18

    The mcp-server-demo by sotayamashita is an impressive utility for developers looking to understand the basics of mcp application servers. It's well-structured and easy to navigate, with clear instructions that help you get started quickly. Check it out on [GitHub](https://github.com/sotayamashita/mcp-server-demo) for a solid foundation in server setup and management.