MCP Server Implementation
@yisu201506
Repository for MCP server implementation
Overview
What is MCP Server Implementation?
A Flask-based implementation of the Model Context Protocol (MCP) that extends Large Language Models with external tools like weather and calculator, using text-based tool invocation directly in the context window.
How to use MCP Server Implementation?
Clone the repository, create a Python virtual environment, install dependencies, set environment variables for API keys, then run flask run or gunicorn app:app. Send chat messages via the POST /chat endpoint with a JSON body containing a messages array.
Key features of MCP Server Implementation
- Complete MCP parsing, execution, and response handling
- Sample weather and calculator tools with parameter validation
- Maintains conversation context across multiple interactions
- Regex‑based parsing for flexible tool invocation detection
- Flask REST API for easy chat integration
Use cases of MCP Server Implementation
- Adding real‑time weather data to an LLM‑powered chatbot
- Enabling a language model to perform mathematical calculations
- Building custom tool integrations by inheriting from the Tool base class
- Demonstrating MCP workflow for educational or prototyping purposes
FAQ from MCP Server Implementation
What is MCP and how does it differ from function calling?
MCP places tool definitions in the prompt text and parses natural‑language responses for tool calls, while function calling uses structured JSON in API parameters and requires API support.
What are the runtime dependencies?
Python 3, Flask, Gunicorn (optional for production), and API keys for the LLM and weather service stored in environment variables.
Where is conversation state stored?
The server maintains conversation history across multiple interactions by adding processed responses and tool results back into the message history.
What transport does the server use?
HTTP via the Flask development server (default port 5000) or Gunicorn in production.
How are tools authenticated?
Weather tool requires a WEATHER_API_KEY environment variable; LLM requests require an LLM_API_KEY. Both are set in a .env file.