- Explore MCP Servers
- how-to-build-your-own-mcp
How To Build Your Own Mcp
Overview
What is How To Build Your Own Mcp
how-to-build-your-own-mcp is a project that provides a framework for creating your own MCP server, allowing developers to build custom tools and functionalities using the MCP library.
Use cases
Use cases include building a calculator tool, creating a data processing server, or developing a custom API for specific applications.
How to use
To use how-to-build-your-own-mcp, first install the UV Tool using the provided command. Then, create a new project with the MCP library, add the necessary components, and define your custom tools in the main.py file. Finally, run the server using ‘python main.py’.
Key features
Key features include the ability to create custom tools, a simple and intuitive API, and asynchronous support for handling multiple requests efficiently.
Where to use
how-to-build-your-own-mcp can be used in various fields such as software development, automation, and any application requiring custom server functionalities.
Content
Install UV Tool
curl -LsSf https://astral.sh/uv/install.sh | sh
Create New Project With MCP Library
# Create project
uv init stdio_mcp_server --bare
# Change to project directory
cd stdio_mcp_server
# Install MCP
uv add "mcp[cli]"
# create main.py file
touch main.py
from mcp.server.fastmcp import FastMCP
import asyncio
# 1. Create a FastMCP server instance
mcp = FastMCP(
name="sum_two_numbers_mcp_server",
)
# 2. Define a tool that sums two numbers
@mcp.tool(
name="sum_two_numbers",
description="A tool that sums two numbers.",
)
async def sum_two_numbers_tool(a: int, b: int) -> int:
"""A tool that sums two numbers."""
return f"The sum of {a} and {b} is {a + b} (Calculated by MCP server)."
if __name__ == "__main__":
# 3. Run the FastMCP server
asyncio.run(mcp.run())
# 4. Run with : python main.py