MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / get_weather

Function get_weather

examples/tools_runner.py:12–41  ·  view source on GitHub ↗

Lookup the weather for a given city in either celsius or fahrenheit Args: location: The city and state, e.g. San Francisco, CA units: Unit for the output, either 'c' for celsius or 'f' for fahrenheit Returns: A dictionary containing the location, temperature, and wea

(location: str, units: Literal["c", "f"])

Source from the content-addressed store, hash-verified

10
11@beta_tool
12def get_weather(location: str, units: Literal["c", "f"]) -> str:
13 """Lookup the weather for a given city in either celsius or fahrenheit
14
15 Args:
16 location: The city and state, e.g. San Francisco, CA
17 units: Unit for the output, either 'c' for celsius or 'f' for fahrenheit
18 Returns:
19 A dictionary containing the location, temperature, and weather condition.
20 """
21 # Simulate a weather API call
22 print(f"Fetching weather for {location} in {units}")
23
24 # Here you would typically make an API call to a weather service
25 # For demonstration, we return a mock response
26 if units == "c":
27 return json.dumps(
28 {
29 "location": location,
30 "temperature": "20°C",
31 "condition": "Sunny",
32 }
33 )
34 else:
35 return json.dumps(
36 {
37 "location": location,
38 "temperature": "68°F",
39 "condition": "Sunny",
40 }
41 )
42
43
44def main() -> None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected