mcp_server_example

Give-a-Go/mcp_server_example

3.2

If you are the rightful owner of mcp_server_example 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.

A simple example of a Model Context Protocol (MCP) server implementation using FastMCP.

Tools
1
Resources
0
Prompts
0

MCP Server Example

A simple example of a Model Context Protocol (MCP) server implementation using FastMCP. This server exposes a basic addition function that can be called by MCP clients.

What is MCP?

Model Context Protocol (MCP) is a protocol that allows AI models to interact with external tools and services. It enables AI models to call functions (tools) exposed by a server, passing arguments and receiving structured responses.

Features

  • Simple MCP server implementation
  • Exposes an addition function as a tool
  • Built with FastMCP for easy MCP server creation
  • Cross-platform support (Windows, macOS, Linux)

Prerequisites

  • Python 3.13 or higher
  • uv package manager (recommended) or pip
  • Windows, macOS, or Linux

Installation

Using uv (Recommended)

  1. Install uv if you haven't already:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. a. Install uv on windows

  3. powershell -c "irm https://astral.sh/uv/install.ps1 | more"
    
  4. Clone this repository:

    git clone https://github.com/yourusername/mcp_server_example.git
    cd mcp_server_example
    
  5. Create and activate a virtual environment (optional but recommended):

    Create a venv

    uv init
    
    uv venv
    # On Windows:
    .venv\Scripts\activate
    # On macOS/Linux:
    source .venv/bin/activate
    
  6. Install dependencies:

    uv pip install fastmcp
    

Running the Server

  1. Start the MCP server:

    fastmcp run server.py:mcp
    

Testing the Server

Using Windsurf

  1. Install the Windsurf extension in your IDE if you haven't already.

  2. In Windsurf, you can now connect to the MCP server using the following configuration:

` "command": "YOUR_PROJECT_PATH/mcp_server_example/.venv/bin/python", "args": [ "YOUR_PROJECT_PATH/mcp_server_example/mcp/server.py" ],

`

  1. Once connected, you should see the add tool available in the Windsurf interface.

Available Tools

add

Adds two numbers together.

Parameters:

  • a (int): First number
  • b (int): Second number

Returns:

  • int: The sum of a and b

Development

Adding New Tools

To add a new tool to the MCP server:

  1. Open mcp/server.py
  2. Add a new function with the @mcp.tool() decorator
  3. Define the function with type hints for parameters and return value

Example:

@mcp.tool()
def multiply(a: int, b: int) -> int:
    """Multiply two numbers together."""
    return a * b

Dependencies

  • fastmcp: The FastMCP framework for creating MCP servers