Give-a-Go/mcp_server_example
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.
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)
-
Install uv if you haven't already:
curl -LsSf https://astral.sh/uv/install.sh | sh
-
a. Install uv on windows
-
powershell -c "irm https://astral.sh/uv/install.ps1 | more"
-
Clone this repository:
git clone https://github.com/yourusername/mcp_server_example.git cd mcp_server_example
-
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
-
Install dependencies:
uv pip install fastmcp
Running the Server
-
Start the MCP server:
fastmcp run server.py:mcp
Testing the Server
Using Windsurf
-
Install the Windsurf extension in your IDE if you haven't already.
-
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" ],
`
- Once connected, you should see the
add
tool available in the Windsurf interface.
Available Tools
add
Adds two numbers together.
Parameters:
a
(int): First numberb
(int): Second number
Returns:
- int: The sum of a and b
Development
Adding New Tools
To add a new tool to the MCP server:
- Open
mcp/server.py
- Add a new function with the
@mcp.tool()
decorator - 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