Skip to content

Rakshith1997-netizen/mcp_server_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Demo MCP Server

A Model Context Protocol (MCP) server built with Python and FastMCP that provides utility tools for AI assistants and applications.

Overview

This MCP server exposes three useful tools that can be utilized by MCP-compatible clients:

  • Add Numbers: Perform simple addition operations
  • Get Secret Word: Retrieve a random secret word from a predefined list
  • Get Current Weather: Fetch real-time weather data for any city

Features

  • 🔧 Built with FastMCP for easy tool creation and server management
  • 🌐 SSE (Server-Sent Events) transport protocol support
  • 📝 Comprehensive logging for monitoring and debugging
  • 🌤️ Real-time weather data integration using wttr.in API
  • ⚙️ Configurable port via environment variables

Requirements

  • Python 3.8+
  • mcp package
  • requests package

Installation

  1. Clone or download this repository

  2. Install the required dependencies:

pip install mcp requests

Usage

Starting the Server

Run the server with default settings (port 8080):

python server.py

Or specify a custom port using an environment variable:

PORT=9000 python server.py

Available Tools

1. add(a: int, b: int) -> int

Adds two integers together.

Parameters:

  • a: First integer
  • b: Second integer

Returns: Sum of the two numbers

2. get_secret_word() -> str

Returns a random word from a predefined list.

Returns: A random word (apple, banana, or cherry)

3. get_current_weather(city: str) -> str

Fetches current weather information for a specified city.

Parameters:

  • city: Name of the city to get weather for

Returns: Weather information in text format

Configuration

The server can be configured using the following environment variables:

  • PORT: The port number on which the server will run (default: 8080)

Architecture

The server uses:

  • FastMCP: Simplifies the creation of MCP servers and tool definitions
  • SSE Transport: Server-Sent Events for real-time communication
  • wttr.in API: External service for weather data

Logging

The server implements comprehensive logging with the following levels:

  • INFO: General operational messages
  • ERROR: Error conditions and exceptions

Logs are output to the standard output stream (console).

Error Handling

  • Weather API failures are gracefully handled with error messages
  • Server exceptions are logged and result in proper cleanup
  • Request timeouts are set to 10 seconds for the weather API

Example Integration

This MCP server can be integrated with MCP-compatible clients such as:

  • Claude Desktop
  • Custom AI assistants
  • Automation tools that support the MCP protocol

Project Structure

mcp_server_python/
├── server.py       # Main server implementation
└── README.md       # This file

License

This project is open source and available for educational purposes.

Credits

This project was created as part of learning the Model Context Protocol (MCP) and server development.

Special thanks to FreeCodeCamp for providing excellent educational resources and tutorials that helped make this project possible.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages