Skip to main content
Glama

Model Context Protocol (MCP) Server

Model Context Protocol (MCP) Python Implementation

This project implements a functioning Model Context Protocol (MCP) server and client in Python, following the Anthropic MCP specification. It demonstrates the key patterns of the MCP protocol through a simple, interactive example.

What is MCP?

The Model Context Protocol (MCP) is an open standard built on JSON-RPC 2.0 for connecting AI models to external data sources and tools. It defines a client-server architecture where an AI application communicates with one or more MCP servers, each exposing capabilities such as:

  • Tools: Executable functions that perform actions
  • Resources: Data sources that provide information
  • Prompts: Predefined templates or workflows

MCP standardizes how these capabilities are discovered and invoked, serving as a "USB-C for AI" that allows models to interact with external systems in a structured way.

Project Structure

  • server/: MCP server implementation
    • server.py: WebSocket server that handles MCP requests and provides sample tools/resources
  • client/: MCP client implementation
    • client.py: Demo client that connects to the server and exercises all MCP capabilities

Features Demonstrated

This implementation showcases the core MCP protocol flow:

  1. Capability Negotiation: Client-server handshake via initialize
  2. Capability Discovery: Listing available tools and resources
  3. Tool Invocation: Calling the add_numbers tool with parameters
  4. Resource Access: Reading text content from a resource

Setup

  1. Create a virtual environment:
    python3 -m venv .venv source .venv/bin/activate
  2. Install dependencies:
    pip install -r requirements.txt

Usage

  1. Start the MCP server (in one terminal):
    python server/server.py
  2. Run the MCP client (in another terminal):
    python client/client.py

The client will connect to the server, perform the MCP handshake, discover capabilities, and demonstrate invoking tools and accessing resources with formatted output.

How It Works

MCP Server

The server:

  • Accepts WebSocket connections
  • Responds to JSON-RPC requests following the MCP specification
  • Provides a sample tool (add_numbers)
  • Provides a sample resource (example.txt)
  • Supports the MCP handshake and capability discovery

MCP Client

The client:

  • Connects to the server via WebSocket
  • Performs the MCP handshake
  • Discovers available tools and resources
  • Demonstrates calling a tool and reading a resource
  • Presents the results in a formatted display

Protocol Details

MCP implements these key methods:

MethodDescription
initializeHandshake to establish capabilities
tools/listList available tools
tools/callCall a tool with arguments
resources/listList available resources
resources/readRead resource content
prompts/listList available prompts

Extending the Project

You can extend this implementation by:

  • Adding more tools with different capabilities
  • Adding dynamic resources that change on each read
  • Implementing prompt templates for guided interactions
  • Creating more interactive client applications

References

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Eine Python-Implementierung des MCP-Servers, die es KI-Modellen ermöglicht, über ein standardisiertes Protokoll eine Verbindung mit externen Tools und Datenquellen herzustellen und den Toolaufruf und Ressourcenzugriff über JSON-RPC zu unterstützen.

  1. Was ist MCP?
    1. Projektstruktur
      1. Demonstrierte Funktionen
        1. Aufstellen
          1. Verwendung
            1. Wie es funktioniert
              1. MCP-Server
              2. MCP-Client
            2. Protokolldetails
              1. Erweiterung des Projekts
                1. Verweise

                  Related MCP Servers

                  • -
                    security
                    A
                    license
                    -
                    quality
                    A Python-based MCP server that integrates OpenAPI-described REST APIs into MCP workflows, enabling dynamic exposure of API endpoints as MCP tools.
                    Last updated -
                    117
                    MIT License
                    • Linux
                    • Apple
                  • -
                    security
                    A
                    license
                    -
                    quality
                    A streamlined foundation for building Model Context Protocol servers in Python, designed to make AI-assisted development of MCP tools easier and more efficient.
                    Last updated -
                    14
                    MIT License
                  • A
                    security
                    F
                    license
                    A
                    quality
                    A Python implementation of the Model Context Protocol (MCP) that connects client applications with AI models, primarily Anthropic's models, with setup instructions for local development and deployment.
                    Last updated -
                    4
                    • Apple
                    • Linux
                  • -
                    security
                    A
                    license
                    -
                    quality
                    A dynamic MCP server that automatically discovers Python files in a directory and exposes them as tools to any MCP-compatible AI client, allowing users to easily create and deploy custom AI tools.
                    Last updated -
                    MIT License

                  View all related MCP servers

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/suspicious-cow/MCP2'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server