Model Context Protocol (MCP) Server

Model Context Protocol (MCP) Server

A Python implementation of the MCP server that enables AI models to connect with external tools and data sources through a standardized protocol, supporting tool invocation and resource access via JSON-RPC.

Category
Visit Server

README

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:

Method Description
initialize Handshake to establish capabilities
tools/list List available tools
tools/call Call a tool with arguments
resources/list List available resources
resources/read Read resource content
prompts/list List 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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured