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

Function get_weather

examples/tools_runner_search_tool.py:15–44  ·  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

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected