0% found this document useful (0 votes)
163 views7 pages

MCP Server Quickstart Guide

This document is a user guide for building a weather server using the MCP framework and connecting it to Claude for Desktop. It provides step-by-step instructions on setting up the environment, coding the server, and testing it with commands. The tutorial emphasizes the use of tools to fetch weather alerts and forecasts through the National Weather Service API.

Uploaded by

prashant kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views7 pages

MCP Server Quickstart Guide

This document is a user guide for building a weather server using the MCP framework and connecting it to Claude for Desktop. It provides step-by-step instructions on setting up the environment, coding the server, and testing it with commands. The tutorial emphasizes the use of tools to fetch weather alerts and forecasts through the National Weather Service API.

Uploaded by

prashant kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

User Guide SDKs Specification GitHub

Search... Ctrl K
Quickstart On this page

Python SDK For Server Developers Copy page What we’ll be building
Core MCP Concepts
TypeScript SDK Get started building your own server to use in Claude for Desktop
and other clients. Test with commands
Java SDK What’s happening under the hood
Kotlin SDK In this tutorial, we’ll build a simple MCP weather server and connect it to a Troubleshooting
C# SDK host, Claude for Desktop. We’ll start with a basic setup, and then progress Next steps
Swift SDK to more complex use cases.

Get Started
What we’ll be building
Introduction
Many LLMs do not currently have the ability to fetch the forecast and severe
Quickstart
weather alerts. Let’s use MCP to solve that!
For Server Developers
For Client Developers 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,
For Claude Desktop Users
Claude for Desktop):
Example Servers
Example Clients
FAQs

Tutorials
Building MCP with LLMs
Debugging
Inspector

Concepts
Core architecture
Resources
Prompts
Tools
Sampling
Roots
Transports

Development
What's New
Roadmap
Contributing

Servers can connect to any client. We’ve chosen Claude for Desktop here
for simplicity, but we also have guides on building your own client as well
as a list of other clients here.

Why Claude for Desktop and not [Link]?

Core MCP Concepts


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.

Python Node Java Kotlin C#

Let’s get started with building our weather server! You can find the
complete code for what we’ll be building here.

Prerequisite knowledge
This quickstart assumes you have familiarity with:

Python
LLMs like Claude

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:

MacOS/Linux Windows

curl -LsSf [Link] | sh

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:

MacOS/Linux Windows

# Create a new directory for our project


uv init weather
cd weather

# Create virtual environment and activate it


uv venv
source .venv/bin/activate

# Install dependencies
uv add "mcp[cli]" httpx

# Create our server file


touch [Link]

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 [Link] :

from typing import Any


import httpx
from [Link] import FastMCP

# Initialize FastMCP server


mcp = FastMCP("weather")
# Constants
NWS_API_BASE = "[Link]
USER_AGENT = "weather-app/1.0"

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:

async def make_nws_request(url: str) -> dict[str, Any] | None:


"""Make a request to the NWS API with proper error handling.""
headers = {
"User-Agent": USER_AGENT,
"Accept": "application/geo+json"
}
async with [Link]() as client:
try:
response = await [Link](url, headers=headers, timeo
response.raise_for_status()
return [Link]()
except Exception:
return None

def format_alert(feature: dict) -> str:


"""Format an alert feature into a readable string."""
props = feature["properties"]
return f"""
Event: {[Link]('event', 'Unknown')}
Area: {[Link]('areaDesc', 'Unknown')}
Severity: {[Link]('severity', 'Unknown')}
Description: {[Link]('description', 'No description available')}
Instructions: {[Link]('instruction', 'No specific instructions p
"""

Implementing tool execution


The tool execution handler is responsible for actually executing the logic of
each tool. Let’s add it:

@[Link]()
async def get_alerts(state: str) -> str:
"""Get weather alerts for a US state.

Args:
state: Two-letter US state code (e.g. CA, NY)
"""
url = f"{NWS_API_BASE}/alerts/active/area/{state}"
data = await make_nws_request(url)

if not data or "features" not in data:


return "Unable to fetch alerts or no alerts found."

if not data["features"]:
return "No active alerts for this state."

alerts = [format_alert(feature) for feature in data["features"


return "\n---\n".join(alerts)

@[Link]()
async def get_forecast(latitude: float, longitude: float) -> str:
"""Get weather forecast for a location.

Args:
latitude: Latitude of the location
longitude: Longitude of the location
"""
# First get the forecast grid endpoint
points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
points_data = await make_nws_request(points_url)

if not points_data:
return "Unable to fetch forecast data for this location."

# Get the forecast URL from the points response


forecast_url = points_data["properties"]["forecast"]
forecast_data = await make_nws_request(forecast_url)

if not forecast_data:
return "Unable to fetch detailed forecast."

# Format the periods into a readable forecast


periods = forecast_data["properties"]["periods"]
forecasts = []
for period in periods[:5]: # Only show next 5 periods
forecast = f"""
{period['name']}:
Temperature: {period['temperature']}°{period['temperatureUnit']}
Wind: {period['windSpeed']} {period['windDirection']}
Forecast: {period['detailedForecast']}
"""
[Link](forecast)

return "\n---\n".join(forecasts)

Running the server


Finally, let’s initialize and run the server:

if __name__ == "__main__":
# Initialize and run the server
[Link](transport='stdio')

Your server is complete! Run uv run [Link] 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.

First, make sure you have Claude for Desktop installed. You can install the
latest version here. If you already have Claude for Desktop, make sure it’s
updated to the latest version.

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:

MacOS/Linux Windows

code ~/Library/Application\ Support/Claude/claude_desktop_config.js


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:

MacOS/Linux Windows

Python

{
"mcpServers": {
"weather": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather",
"run",
"[Link]"
]
}
}
}

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 [Link]

Save the file, and restart Claude for Desktop.

Test with commands


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 “Search
and tools” icon:

After clicking on the slider 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 tool settings 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.

What’s happening under the hood


When you ask a question:

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!

Troubleshooting
Claude for Desktop Integration Issues

Weather API Issues

For more advanced troubleshooting, check out our guide on Debugging


MCP

Next steps
Building a client Example servers
Learn how to build your own MCP Check out our gallery of official
client that can connect to your MCP servers and implementations
server

Debugging Guide Building MCP with LLMs


Learn how to effectively debug Learn how to use LLMs like
MCP servers and integrations Claude to speed up your MCP
development

Was this page helpful? Yes No

Introduction For Client Developers

Common questions

Powered by AI

The debugging guide is critical in the development and maintenance of MCP servers as it provides developers with methodologies and tools to identify and resolve issues that arise during server operation. Effective debugging ensures that tools and services built using the MCP framework function correctly and efficiently, minimizing downtime and improving reliability. The guide offers specific strategies for troubleshooting server-client configurations and integration issues, thus facilitating smoother development cycles and more effective use of server resources .

Setting up an MCP weather server involves several steps: First, developers create a project directory and initialize it with 'uv'. A virtual environment is created and dependencies are installed using 'uv'. The server file is set up with required imports and initialization of a FastMCP instance. Developer-defined Tools like 'get_alerts' and 'get_forecast' are implemented, which interact with the National Weather Service API. The server is run with 'uv run', and its functions are tested by configuring Claude for Desktop to recognize the server through a modified configuration JSON file. Testing involves ensuring that Claude for Desktop accurately recognizes and utilizes the server's tools, providing proper data as a response to user queries about weather conditions .

In the MCP weather server example, Tools are implemented as Python functions that encapsulate the logic for interacting with the National Weather Service API. For instance, 'get_alerts' is a Tool that fetches weather alerts for a specific US state by using the NWS API, formatted to be user-readable. Similarly, 'get_forecast' retrieves weather forecasts for a given location, processing and formatting data into a readable format. These Tools are then exposed to clients like Claude for Desktop, enabling dynamic interaction where client queries trigger specific Tools and return formatted data back to the client .

Building an MCP client may present challenges such as interoperability with existing MCP servers, handling data privacy and security during client-server communications, and ensuring the client can handle asynchronous operations effectively. To mitigate these challenges, developers can leverage thorough testing for compatibility with diverse server environments and follow best practices for secure data handling, such as encryption and secure authentication mechanisms. Using the MCP debugging tools can identify and resolve asynchronous issues or integration bugs early in development, ensuring stable client operation and effective use of server tools .

MCP servers provide three main types of capabilities: Resources, Tools, and Prompts. Resources are file-like data that can be read by clients, such as API responses or file contents. Tools are functions that can be called by the Language Model (LLM) with user approval, effectively enabling task execution through automation. Prompts are pre-written templates designed to assist users in accomplishing specific tasks . These capabilities can be leveraged by developers to build dynamic and interactive applications, such as a weather forecasting server that delivers updated alerts and forecasts to clients .

The MCP framework supports integration with LLMs like Claude by providing a structured environment where LLMs can access and invoke Tools on MCP servers, allowing them to perform tasks and return results in a user-friendly format. This integration allows large language models to carry out complex operations, such as querying weather data or processing file contents, through predefined MCP Tools. The advantages of this integration include enhanced capabilities for language models to handle diverse applications, delivering richer and more dynamic interactions with end-users, as well as streamlining processes that require a mix of natural language processing and computational tasks .

The cloud-based infrastructure of MCP enhances scalability and flexibility by allowing servers and services to be dynamically scaled according to demand. Cloud infrastructure removes the limitations of physical hardware, enabling developers to increase computational resources as needed. This flexibility allows MCP to accommodate fluctuating loads and a wide variety of applications across different domains. Additionally, cloud-based solutions simplify deployment and management, offering tools for continuous integration and delivery, which streamlines updates and maintenance processes. This scalability ensures consistent performance and high availability, essential for modern applications that demand reliability and responsiveness .

Integrating an MCP server with Claude for Desktop involves configuring the desktop client to recognize and interact with the MCP server. The integration process requires modifying the Claude desktop configuration file to include paths and commands needed to execute the server. This setup allows the client to utilize the MCP server's Tools for real-time data processing and interaction. The significance of this integration lies in its ability to provide seamless user experiences by linking dynamic server-side computations with client-side interactions, enabling robust applications such as real-time weather forecasts and alerts directly within the desktop environment .

Within the FastMCP framework, type hints and docstrings in Python contribute significantly to the construction and maintenance of MCP Tools. Type hints provide explicit definitions of input and output types for functions, ensuring that data types are consistent and understood by both the developer and the interpreting machine. Docstrings serve to document the purpose and behavior of Tools, aiding both in dynamic documentation generation and in assisting other developers to understand the functionality without needing to delve into the code deeply. These features collectively make the process of creating MCP Tools more structured and less error-prone, facilitating easier maintenance and scalability .

Using MCP SDKs for server development offers significant benefits, including language flexibility, which allows developers to choose from a variety of programming languages such as Python, TypeScript, Java, and Swift. This flexibility enables developers to work within their preferred or existing tech stacks without needing to learn a new programming language. The SDKs also provide tools and libraries that simplify complex tasks like Tool creation and server initialization, enhancing development speed and reducing boilerplate code . This cross-language support broadens the accessibility of the MCP, allowing for a more diverse range of applications and use cases to be addressed effectively using the same protocol .

You might also like