Spaces:
Sleeping
Sleeping
serichard1
commited on
Commit
·
a9407b7
1
Parent(s):
cfbede6
support all clients et upload files
Browse files- gradio_mcp_server.py +1 -36
gradio_mcp_server.py
CHANGED
|
@@ -76,39 +76,4 @@ async def get_weather_data(station_code: str, page: int = 1, start: str = None,
|
|
| 76 |
"type": "error",
|
| 77 |
"station_code": station_code,
|
| 78 |
"message": f"Unexpected error fetching weather data: {str(e)}"
|
| 79 |
-
})
|
| 80 |
-
|
| 81 |
-
@mcp.tool()
|
| 82 |
-
async def list_available_stations() -> str:
|
| 83 |
-
"""Get a list of available weather stations from the API.
|
| 84 |
-
|
| 85 |
-
Returns:
|
| 86 |
-
JSON string containing available stations or error information
|
| 87 |
-
"""
|
| 88 |
-
base_url = "http://localhost:8888/weather/stations"
|
| 89 |
-
|
| 90 |
-
try:
|
| 91 |
-
response = requests.get(base_url, timeout=30)
|
| 92 |
-
response.raise_for_status()
|
| 93 |
-
|
| 94 |
-
stations_data = response.json()
|
| 95 |
-
|
| 96 |
-
return json.dumps({
|
| 97 |
-
"type": "success",
|
| 98 |
-
"data": stations_data,
|
| 99 |
-
"message": "Successfully retrieved list of available weather stations"
|
| 100 |
-
}, indent=2)
|
| 101 |
-
|
| 102 |
-
except requests.exceptions.ConnectionError:
|
| 103 |
-
return json.dumps({
|
| 104 |
-
"type": "error",
|
| 105 |
-
"message": "Could not connect to weather API at localhost:8888. Please ensure the weather service is running."
|
| 106 |
-
})
|
| 107 |
-
except Exception as e:
|
| 108 |
-
return json.dumps({
|
| 109 |
-
"type": "error",
|
| 110 |
-
"message": f"Error fetching station list: {str(e)}"
|
| 111 |
-
})
|
| 112 |
-
|
| 113 |
-
if __name__ == "__main__":
|
| 114 |
-
mcp.run(transport='stdio')
|
|
|
|
| 76 |
"type": "error",
|
| 77 |
"station_code": station_code,
|
| 78 |
"message": f"Unexpected error fetching weather data: {str(e)}"
|
| 79 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|