MCP ExplorerExplorer

Mcp Server Python

@Perteghellaon a year ago
1 MIT
FreeCommunity
AI Systems
#mcp#mcp-server#python#sse
Simple implementation of a Model Communication Protocol (MCP) server using Python over the network using sse transport

Overview

What is Mcp Server Python

MCP-Server-python is a simple implementation of a Model Communication Protocol (MCP) server developed in Python. It is designed to demonstrate the basic functionality of an MCP server and can be utilized for testing and development purposes over a network using SSE transport.

Use cases

Use cases for MCP-Server-python include developing and testing applications that require a communication protocol, creating demo environments for educational purposes, and integrating with tools like Cursor or Claude for enhanced functionality.

How to use

To use MCP-Server-python, first create and activate a virtual environment, then install the required dependencies. Start the server by running ‘python3 server.py’ and verify it is running on port 8000 using commands like ‘netstat’ or ‘curl’.

Key features

Key features of MCP-Server-python include a simple setup process, support for SSE transport, a comprehensive test suite using pytest, and the ability to integrate with other tools through configuration files.

Where to use

MCP-Server-python can be used in various fields such as software development for testing and prototyping, educational purposes for learning about server-client communication, and integration with other applications that require real-time data exchange.

Content

MCP Server Demo in python

This repository contains a simple implementation of a Model Communication Protocol (MCP) server using Python. The server is designed to demonstrate the basic functionality of an MCP server and can be used for testing and development purposes.

The server uses uvicorn by default, running on port 8000. To expose the server over the network, use the sse transport.


Setup Instructions

1. Create and Activate a Virtual Environment

Run the following commands to set up your Python environment:

python3 -m venv .venv
source .venv/bin/activate
uv pip install -r requirements.txt

Starting the Server

To start the server, run:

python3 server.py

Verify the Server is Running

You can verify that the server is running on port 8000 using the following commands:

  • Check active connections:

    netstat -n | grep 8000
    
  • Check processes using the port:

    lsof -i :8000
    
  • Test the server with curl:

    curl http://0.0.0.0:8000/sse
    

Running Tests

The project includes a comprehensive test suite using pytest. To run the tests:

# Install test dependencies
pip install -r requirements.txt

# Run tests with verbose output
pytest -v

# Run tests with coverage report
pytest --cov=.

Test Coverage

The test suite includes:

  • Basic functionality tests for addition and subtraction
  • Input validation and type checking
  • Edge cases with large numbers
  • API endpoint testing for greetings

All tests are located in test_server.py and cover:

  • add() function
  • subtract() function
  • get_greeting() function
  • Type error handling
  • Edge cases handling

Tools Using the Server

To integrate this server with tools like Cursor or Claude, use the following mcp.json configuration file:

{
  "mcpServers": {
    "demo-server": {
      "transport": "sse",
      "url": "http://localhost:8000/sse"
    }
  }
}

Notes

  • By default, the server uses stdio transport. To expose it over the network, ensure you configure it to use sse transport.
  • The server runs on localhost and listens on port 8000 using uvicorn.

Feel free to contribute or open issues if you encounter any problems!

FastAPI come tool MCP

da una idea vista qui https://medium.com/@CodePulse/5-open-source-mcp-servers-thatll-make-your-ai-agents-unstoppable-89498fcada16

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers