Simplest-MCP-Server

day50-dev/Simplest-MCP-Server

3.3

If you are the rightful owner of Simplest-MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This repository provides a minimal example of a Model Context Protocol (MCP) server and client using the stdio method.

Tools
1
Resources
0
Prompts
0

Simplest MCP Ever

This repository demonstrates a minimal, working example of an MCP server and client. There's no LLM involved, this uses what's called the "stdio" method.

However, there are branches that introduce things such as LLMs. After understanding the base code, go to the various branches to see how things get stacked on top.

Functionality

This example server exposes a single tool:

  • get_users_favorite_number: This tool, when called, simply returns the string "42" as the user's favorite number. This is a very basic example illustrating the server's capability to expose tools and return results.

Repository Contents

  • server.py: This is the core of the MCP server. It defines:

    • The server initialization (Server("favorite-number-server")).
    • The list_tools function, responsible for providing the list of available tools to the client.
    • The call_tool function, which handles the execution of the tool based on the tool name and arguments.
  • test_mcp.py: This file contains an automated test for the MCP server. It connects to the server, lists the available tools, calls the get_users_favorite_number tool, and asserts that the returned value is "42".

  • test.sh: A simple shell script to execute the tests. It activates the virtual environment (if one exists) before running the test to ensure dependencies are correctly managed.

Getting Started

Follow these steps to run the example:

  1. Set up a Virtual Environment (Recommended):

    python3 -m venv venv
    source venv/bin/activate  # On Linux/macOS
    # venv\Scripts\activate  # On Windows
    
  2. Install the mcp library:

    python3 -m pip install mcp
    
  3. Run the Tests:

    ./test.sh
    

    This script will:

    • Activate the virtual environment (if it exists).
    • Execute the test_mcp.py file, which will start the server, connect to it, call the tool, and verify the results.

    If the test passes, you'll see the following output (or similar):

    ๐Ÿงช Testing Favorite Number MCP Server
    โœ“ Server initialized: favorite-number-server
    โœ“ Available tools: ['get_users_favorite_number']
    โœ“ Tool result: 42
    โœ“ Test passed! Favorite number is 42
    โœ… All tests passed!