Get started building your own server to use in Claude for Desktop and other clients.In this tutorial, we’ll build a simple MCP weather server and connect it to a host, Claude for Desktop. We’ll start with a basic setup, and then progress to more complex use cases.Many LLMs (including Claude) do not currently have the ability to fetch the forecast and severe weather alerts. Let’s use MCP to solve that!We’ll build a server that exposes two tools: get-alerts
and get-forecast
. Then we’ll connect the server to an MCP host (in this case, Claude for Desktop):Why Claude for Desktop and not Claude.ai?MCP servers can provide three main types of capabilities:1.
Resources: File-like data that can be read by clients (like API responses or file contents)
2.
Tools: Functions that can be called by the LLM (with user approval)
3.
Prompts: Pre-written templates that help users accomplish specific tasks
This tutorial will primarily focus on tools.Prerequisite knowledge#
This quickstart assumes you have familiarity with:System requirements#
Python 3.10 or higher installed.
You must use the Python MCP SDK 1.2.0 or higher.
Set up your environment#
First, let’s install uv
and set up our Python project and environment:powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Make sure to restart your terminal afterwards to ensure that the uv
command gets picked up.Now, let’s create and set up our project:
uv init weather
cd weather
uv venv
.venv\Scripts\activate
uv add mcp[cli] httpx
new-item weather.py
uv init weather
cd weather
uv venv
.venv\Scripts\activate
uv add mcp[cli] httpx
new-item weather.py
Now let’s dive into building your server.Building your server#
Importing packages and setting up the instance#
Add these to the top of your weather.py
:The FastMCP class uses Python type hints and docstrings to automatically generate tool definitions, making it easy to create and maintain MCP tools.Helper functions#
Next, let’s add our helper functions for querying and formatting the data from the National Weather Service API:The tool execution handler is responsible for actually executing the logic of each tool. Let’s add it:Running the server#
Finally, let’s initialize and run the server:Your server is complete! Run uv run weather.py
to confirm that everything’s working.Let’s now test your server from an existing MCP host, Claude for Desktop.Testing your server with Claude for Desktop#
Claude for Desktop is not yet available on Linux. Linux users can proceed to the Building a client tutorial to build an MCP client that connects to the server we just built.We’ll need to configure Claude for Desktop for whichever MCP servers you want to use. To do this, open your Claude for Desktop App configuration at ~/Library/Application Support/Claude/claude_desktop_config.json
in a text editor. Make sure to create the file if it doesn’t exist.For example, if you have VS Code installed:code $env:AppData\Claude\claude_desktop_config.json
You’ll then add your servers in the mcpServers
key. The MCP UI elements will only show up in Claude for Desktop if at least one server is properly configured.In this case, we’ll add our single weather server like so:{
"mcpServers": {
"weather": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather",
"run",
"weather.py"
]
}
}
}
{
"mcpServers": {
"weather": {
"command": "uv",
"args": [
"--directory",
"C:\\ABSOLUTE\\PATH\\TO\\PARENT\\FOLDER\\weather",
"run",
"weather.py"
]
}
}
}
You may need to put the full path to the uv
executable in the command
field. You can get this by running which uv
on MacOS/Linux or where uv
on Windows.
Make sure you pass in the absolute path to your server.
This tells Claude for Desktop:1.
There’s an MCP server named “weather”
2.
To launch it by running uv --directory /ABSOLUTE/PATH/TO/PARENT/FOLDER/weather run weather.py
Save the file, and restart Claude for Desktop.Let’s make sure Claude for Desktop is picking up the two tools we’ve exposed in our weather
server. You can do this by looking for the hammer
icon:After clicking on the hammer icon, you should see two tools listed:If your server isn’t being picked up by Claude for Desktop, proceed to the Troubleshooting section for debugging tips.If the hammer icon has shown up, you can now test your server by running the following commands in Claude for Desktop:What’s the weather in Sacramento?
What are the active weather alerts in Texas?
Since this is the US National Weather service, the queries will only work for US locations.1.
The client sends your question to Claude
2.
Claude analyzes the available tools and decides which one(s) to use
3.
The client executes the chosen tool(s) through the MCP server
4.
The results are sent back to Claude
5.
Claude formulates a natural language response
6.
The response is displayed to you!
Modified at 2025-03-12 06:34:35