Simple MCP Server
This example demonstrates how to build a minimal custom MCP (Model Context Protocol) server from scratch using FastMCP 2.0.
This is a great starting point for building your own custom MCP servers with business-specific tools and logic.
Running on Unikraft Cloud
To run this MCP server on Unikraft Cloud:
-
Install the CLI and a container runtime engine, for example Docker. Use the unikraft CLI or the legacy kraft CLI.
-
Clone the
examplesrepository andcdinto theexamples/mcp-server-simple/directory:
Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
When done, invoke the following command to deploy this app on Unikraft Cloud:
The output shows your instance details:
Code
In this case, the instance name is mcp-server-simple-bbdcb and the service cool-paper-b6mht7jv.
They're different for each run.
For testing, you can use the example client included in this directory.
First, install uv if you haven't already, then run:
Code
Code
You can list information about the instance by running:
Code
When done, you can delete the instance with:
Code
Available tools
This MCP Server provides the following tools:
- get_weather: Get simulated weather for a city
- get_time: Get current time in a timezone
- calculate: Perform basic arithmetic operations (add, subtract, multiply, divide)
Building your own tools
This example shows the basic structure of an MCP server using FastMCP. To add your own tools:
-
Define the tool using the
@mcp.tool()decorator:- Add type hints for parameters
- Include a docstring describing what the tool does
- Parameters are automatically converted to JSON schema
-
Write the tool function:
- Process the parameters
- Return a string result (or raise an exception for errors)
-
Test locally before deploying:
Code
Example:
Code
Architecture
The server uses FastMCP, a high-level framework for building MCP servers that features:
- HTTP Transport: Built-in Streamable HTTP transport
- Type-Safe: Automatic JSON schema generation from Python type hints
- Simple API: Decorator-based tool definitions
This provides:
- Standard MCP protocol support
- Automatic tool schema generation
- Built-in HTTP server
- Easy deployment to any platform
Learn more
- MCP Documentation
- FastMCP documentation
- Building MCP Servers
- Unikraft Cloud Documentation
- Building
DockerfileImages withBuildkit
Use the --help option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference or the legacy CLI Reference.