-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Question
I have created a new mcp tool in the main.py file along with the add tool. The add tool is showing in the claude desktop but the newly added one is not visible, can someone please tell me how to see list of all mcp.tools in claude desktop?
`"""
FastMCP quickstart example.
cd to the examples/snippets/clients
directory and run:
uv run server fastmcp_quickstart stdio
"""
import os
import requests
from mcp.server.fastmcp import FastMCP
Create an MCP server
mcp = FastMCP("Demo")
Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
Add a weather tool
@mcp.tool()
def get_weather(city: str) -> str:
"""Get current weather information for a city using OpenWeatherMap API"""
api_key = "9c6670473f13b951f8df8f5aeb30cfdc"
if not api_key:
return "Error: OpenWeatherMap API key not found. Please set OPENWEATHER_API_KEY environment variable."
try:
# OpenWeatherMap API endpoint
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
response = requests.get(url)
response.raise_for_status()
data = response.json()
# Extract relevant weather information
weather_desc = data['weather'][0]['description'].title()
temp = data['main']['temp']
feels_like = data['main']['feels_like']
humidity = data['main']['humidity']
city_name = data['name']
country = data['sys']['country']
return f"Weather in {city_name}, {country}:\n" \
f"Description: {weather_desc}\n" \
f"Temperature: {temp}°C (feels like {feels_like}°C)\n" \
f"Humidity: {humidity}%"
except requests.exceptions.RequestException as e:
return f"Error fetching weather data: {str(e)}"
except KeyError as e:
return f"Error parsing weather data: {str(e)}. Please check if the city name is correct."
except Exception as e:
return f"Unexpected error: {str(e)}"
Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
"""Get a personalized greeting"""
return f"Hello, {name}!"
Add a prompt
@mcp.prompt()
def greet_user(name: str, style: str = "friendly") -> str:
"""Generate a greeting prompt"""
styles = {
"friendly": "Please write a warm, friendly greeting",
"formal": "Please write a formal, professional greeting",
"casual": "Please write a casual, relaxed greeting",
}
return f"{styles.get(style, styles['friendly'])} for someone named {name}."`
Additional Context
No response