Sponsored by Deepsite.site

Beginner's Guide to MCP Servers

Created By
astensby7 months ago
Content

Beginner's Guide to MCP Servers

A simple demonstration project to help beginners understand and build Model Context Protocol (MCP) servers with minimal coding experience.

What is MCP?

Model Context Protocol (MCP) is a way for AI assistants (like Claude, ChatGPT, etc.) to connect to external tools and data sources. Think of it as a bridge that allows AI to:

  • Fetch real-time information from the internet
  • Interact with your local files and applications
  • Perform specific tasks on your behalf

This project contains two example MCP servers that demonstrate different types of functionality.

What's Included

This project includes two MCP servers:

1. Motivational Quotes & Task Manager Server (motivational_server.py)

Demonstrates local file operations and task management:

  • Hello Tool: A simple greeting function
  • Random Quotes: Gets motivational quotes from a local JSON file
  • Task Manager: Add, list, and complete tasks stored locally

1. Any API Server (server.py)

Demonstrates connecting to external APIs:

  • Norwegian Police Incidents: Fetches real-time police incidents from Norway's public API
  • Stock Market Tools: Search for company stock tickers and get current stock prices (requires a free Alpha Vantage API key)

Prerequisites

Before you start, make sure you have:

  • Python 3.11 or higher installed on your computer

Installation & Setup

Step 1: Clone or Download This Project

Download this project to your computer and navigate to the project folder in your terminal.

Step 2: Create a Virtual Environment

python -m venv .venv

Step 3: Activate the Virtual Environment

On macOS/Linux:

source .venv/bin/activate

On Windows:

.venv\Scripts\activate

Step 4: Install Dependencies

pip install -e .

Step 5: (Optional) Set Up Stock Market API

To use the stock market features, you'll need a free API key from Alpha Vantage:

  1. Go to Alpha Vantage and get a free API key
  2. Set it as an environment variable:
    export ALPHA_VANTAGE_API_KEY=your_api_key_here
    

How to Use With AI Assistants

With Claude Desktop

  1. Open your Claude Desktop configuration file
  2. Add the server configuration:
{
  "mcpServers": {
    "HelloServer": {
      "command": "/opt/homebrew/bin/uv",
      "args": [
        "--directory",
        "/path/to/your/project",
        "run",
        "--with",
        "mcp[cli]",
        "mcp",
        "run",
        "server.py"        
      ],
      "env": {
        "ALPHA_VANTAGE_API_KEY": "demo"
      }
    }
  }
}

With Other MCP Clients

Refer to your MCP client's documentation for connection instructions.

Available Tools

Main Server Tools

  • hello() - Returns a greeting message
  • get_police_incidents() - Fetches latest police incidents from Norway
  • get_incidents_by_district(district_name) - Get incidents from a specific police district
  • get_incidents_by_municipality(municipality_name) - Get incidents from a specific municipality
  • search_stock_ticker(company_name) - Search for a company's stock ticker symbol
  • get_stock_price(symbol) - Get current stock price for a ticker symbol

Motivational Server Tools

  • hello() - Returns a greeting message
  • get_random_quote() - Returns a random motivational quote
  • add_task(description) - Adds a new task to your task list
  • list_tasks(status_filter) - Lists tasks (optionally filter by "pending" or "complete")
  • mark_task_complete(task_id) - Marks a task as complete

Project Structure

gritai-basic-mcp-server/
├── server.py              # Main server with API integrations
├── motivational_server.py # Server with local file operations
├── quotes.json           # Motivational quotes database
├── tasks.json            # Task storage file
├── pyproject.toml        # Project configuration
└── README.md            # This file

Customizing the Servers

Adding New Quotes

Edit quotes.json to add your own motivational quotes:

{
  "quote": "Your inspiring quote here",
  "author": "Quote Author"
}

Adding New Tools

To add a new tool to either server, use the @mcp.tool() decorator:

@mcp.tool()
def your_new_tool(parameter: str) -> str:
    """Description of what your tool does."""
    # Your tool logic here
    return "Result"

Troubleshooting

Common Issues

"Module not found" errors

  • Make sure you've activated your virtual environment
  • Run pip install -e . to install dependencies

API errors for stock tools

  • Check that your Alpha Vantage API key is set correctly
  • Free API keys have rate limits

File not found errors

  • Make sure you're running the server from the project directory
  • Check that quotes.json and tasks.json exist

Getting Help

  • Check the MCP documentation
  • Review the code comments for implementation details
  • The servers include error handling to help identify issues

Next Steps

Once you're comfortable with these examples:

  1. Try modifying the existing tools
  2. Add your own API integrations
  3. Create tools that interact with your local files
  4. Explore the MCP specification to understand advanced features
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Serper MCP ServerA Serper MCP Server
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
CursorThe AI Code Editor
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
WindsurfThe new purpose-built IDE to harness magic
DeepChatYour AI Partner on Desktop
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
ChatWiseThe second fastest AI chatbot™
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Amap Maps高德地图官方 MCP Server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Tavily Mcp
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Playwright McpPlaywright MCP server
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.