Skip to main content

A simple MCP (Model Context Protocol) Server example

Project description

MCP Server Example

A simple Python-based MCP (Model Context Protocol) Server that demonstrates the basic capabilities of an MCP server.

Features

This MCP server provides:

Tools

  • greeting: Generate personalized greetings with different styles
  • calculator: Perform basic arithmetic operations (add, subtract, multiply, divide)

Resources

  • sample://users: A list of sample user data
  • sample://products: A list of sample product data

Prompts

  • code_review: Generate code review checklists for different programming languages and complexity levels

Installation

From PyPI (when published)

pip install mcp-server-example

From Source

git clone https://github.com/rahmac/mcp_poc.git
cd mcp_poc
pip install -e .

Development Installation

git clone https://github.com/rahmac/mcp_poc.git
cd mcp_poc
pip install -e ".[dev]"

Usage

Running the Server

The server can be run directly:

mcp-server-example

Or using Python:

python -m mcp_server_example.server

Using with MCP Clients

This server implements the MCP protocol and can be used with any MCP-compatible client. The server communicates via stdio.

Example Configuration

For MCP clients that use configuration files:

{
  "servers": {
    "example": {
      "command": "mcp-server-example",
      "args": []
    }
  }
}

API Reference

Tools

greeting

Generate a personalized greeting.

Parameters:

  • name (string, required): The name of the person to greet
  • greeting_type (string, optional): Type of greeting - "hello", "hi", or "howdy" (default: "hello")

Example:

{
  "name": "greeting",
  "arguments": {
    "name": "Alice",
    "greeting_type": "hi"
  }
}

calculator

Perform basic arithmetic operations.

Parameters:

  • operation (string, required): The operation - "add", "subtract", "multiply", or "divide"
  • a (number, required): First number
  • b (number, required): Second number

Example:

{
  "name": "calculator",
  "arguments": {
    "operation": "add",
    "a": 5,
    "b": 3
  }
}

Resources

sample://users

Returns a JSON array of sample user objects with id, name, and email fields.

sample://products

Returns a JSON array of sample product objects with id, name, and price fields.

Prompts

code_review

Generate a code review checklist.

Parameters:

  • language (string, required): Programming language
  • complexity (string, optional): Complexity level - "basic", "intermediate", or "advanced" (default: "intermediate")

Development

Setting up Development Environment

# Clone the repository
git clone https://github.com/rahmac/mcp_poc.git
cd mcp_poc

# Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

Running Tests

pytest

Code Formatting

# Format code
black src/ tests/

# Sort imports
isort src/ tests/

# Type checking
mypy src/

Building for PyPI

# Build the package
python -m build

# Upload to PyPI (requires credentials)
twine upload dist/*

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Run the test suite
  6. Submit a pull request

Changelog

0.1.0 (2024-06-10)

  • Initial release
  • Basic MCP server implementation
  • Greeting and calculator tools
  • Sample resources
  • Code review prompt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_server_poc_rahmac-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_server_poc_rahmac-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_server_poc_rahmac-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_server_poc_rahmac-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for mcp_server_poc_rahmac-0.1.0.tar.gz
Algorithm Hash digest
SHA256 662f59c45120141186d5e5c36b1a83b87cd4ac02c6dae52946ef74a7ea8678d8
MD5 3b8003e26edfbe6d97aeefd484bb3484
BLAKE2b-256 f633d7df58df9c48fab9b363bcca86be4bcada0ecf0c9833b20708dc9e29701b

See more details on using hashes here.

File details

Details for the file mcp_server_poc_rahmac-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_server_poc_rahmac-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e32a2bc6913559f8b50b8ebe836b7139784b959ff07f52e2106850a61a0e39c
MD5 2ae1f086aaba6d34d32b8abbeae56659
BLAKE2b-256 167f434bba7faeb0f653cfd5f30436ed57e7d3baaa002731717d4ffa42bc0514

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page