delete Old version of mcp implementation
Browse files
owl/{utils/mcp/mcp_servers_config.json → mcp_servers_config.json}
RENAMED
File without changes
|
owl/run_mcp.py
CHANGED
@@ -134,11 +134,9 @@ async def construct_society(
|
|
134 |
|
135 |
|
136 |
async def main():
|
137 |
-
config_path =
|
138 |
-
Path(__file__).parent / "utils/mcp/mcp_servers_config.json"
|
139 |
-
)
|
140 |
|
141 |
-
mcp_toolkit = MCPToolkit(config_path=config_path)
|
142 |
|
143 |
question = (
|
144 |
"I'd like a academic report about Guohao Li, including his research "
|
|
|
134 |
|
135 |
|
136 |
async def main():
|
137 |
+
config_path = Path(__file__).parent / "mcp_servers_config.json"
|
|
|
|
|
138 |
|
139 |
+
mcp_toolkit = MCPToolkit(config_path=str(config_path))
|
140 |
|
141 |
question = (
|
142 |
"I'd like a academic report about Guohao Li, including his research "
|
owl/utils/mcp/__init__.py
DELETED
File without changes
|
owl/utils/mcp/servers/__init__.py
DELETED
File without changes
|
owl/utils/mcp/servers/mcp_server.py
DELETED
@@ -1,136 +0,0 @@
|
|
1 |
-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
2 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
3 |
-
# you may not use this file except in compliance with the License.
|
4 |
-
# You may obtain a copy of the License at
|
5 |
-
#
|
6 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
7 |
-
#
|
8 |
-
# Unless required by applicable law or agreed to in writing, software
|
9 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
10 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11 |
-
# See the License for the specific language governing permissions and
|
12 |
-
# limitations under the License.
|
13 |
-
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
14 |
-
from typing import Any
|
15 |
-
|
16 |
-
import httpx
|
17 |
-
from mcp.server.fastmcp import FastMCP
|
18 |
-
|
19 |
-
mcp = FastMCP("weather")
|
20 |
-
|
21 |
-
NWS_API_BASE = "https://api.weather.gov"
|
22 |
-
USER_AGENT = "weather-app/1.0"
|
23 |
-
|
24 |
-
|
25 |
-
async def make_nws_request(url: str) -> dict[str, Any] | None:
|
26 |
-
r"""Make a request to the NWS API with proper error handling."""
|
27 |
-
headers = {"User-Agent": USER_AGENT, "Accept": "application/geo+json"}
|
28 |
-
async with httpx.AsyncClient() as client:
|
29 |
-
try:
|
30 |
-
response = await client.get(url, headers=headers, timeout=30.0)
|
31 |
-
response.raise_for_status()
|
32 |
-
return response.json()
|
33 |
-
except Exception:
|
34 |
-
return None
|
35 |
-
|
36 |
-
|
37 |
-
def format_alert(feature: dict) -> str:
|
38 |
-
r"""Format an alert feature into a readable string."""
|
39 |
-
props = feature["properties"]
|
40 |
-
return f"""
|
41 |
-
Event: {props.get('event', 'Unknown')}
|
42 |
-
Area: {props.get('areaDesc', 'Unknown')}
|
43 |
-
Severity: {props.get('severity', 'Unknown')}
|
44 |
-
Description: {props.get('description', 'No description available')}
|
45 |
-
Instructions: {props.get('instruction', 'No specific instructions provided')}
|
46 |
-
"""
|
47 |
-
|
48 |
-
|
49 |
-
@mcp.tool()
|
50 |
-
async def get_alerts(state: str) -> str:
|
51 |
-
r"""Get weather alerts for a US state.
|
52 |
-
|
53 |
-
Args:
|
54 |
-
state: Two-letter US state code (e.g. CA, NY)
|
55 |
-
"""
|
56 |
-
url = f"{NWS_API_BASE}/alerts/active/area/{state}"
|
57 |
-
data = await make_nws_request(url)
|
58 |
-
|
59 |
-
if not data or "features" not in data:
|
60 |
-
return "Unable to fetch alerts or no alerts found."
|
61 |
-
|
62 |
-
if not data["features"]:
|
63 |
-
return "No active alerts for this state."
|
64 |
-
|
65 |
-
alerts = [format_alert(feature) for feature in data["features"]]
|
66 |
-
return "\n---\n".join(alerts)
|
67 |
-
|
68 |
-
|
69 |
-
@mcp.tool()
|
70 |
-
async def get_forecast(latitude: float, longitude: float) -> str:
|
71 |
-
r"""Get weather forecast for a location.
|
72 |
-
|
73 |
-
Args:
|
74 |
-
latitude: Latitude of the location
|
75 |
-
longitude: Longitude of the location
|
76 |
-
"""
|
77 |
-
# First get the forecast grid endpoint
|
78 |
-
points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
|
79 |
-
points_data = await make_nws_request(points_url)
|
80 |
-
|
81 |
-
if not points_data:
|
82 |
-
return "Unable to fetch forecast data for this location."
|
83 |
-
|
84 |
-
# Get the forecast URL from the points response
|
85 |
-
forecast_url = points_data["properties"]["forecast"]
|
86 |
-
forecast_data = await make_nws_request(forecast_url)
|
87 |
-
|
88 |
-
if not forecast_data:
|
89 |
-
return "Unable to fetch detailed forecast."
|
90 |
-
|
91 |
-
# Format the periods into a readable forecast
|
92 |
-
periods = forecast_data["properties"]["periods"]
|
93 |
-
forecasts = []
|
94 |
-
for period in periods[:5]: # Only show next 5 periods
|
95 |
-
forecast = f"""
|
96 |
-
{period['name']}:
|
97 |
-
Temperature: {period['temperature']}°{period['temperatureUnit']}
|
98 |
-
Wind: {period['windSpeed']} {period['windDirection']}
|
99 |
-
Forecast: {period['detailedForecast']}
|
100 |
-
"""
|
101 |
-
forecasts.append(forecast)
|
102 |
-
|
103 |
-
return "\n---\n".join(forecasts)
|
104 |
-
|
105 |
-
|
106 |
-
def main(transport: str = "stdio"):
|
107 |
-
r"""Weather MCP Server
|
108 |
-
|
109 |
-
This server provides weather-related functionalities implemented via the Model Context Protocol (MCP).
|
110 |
-
It demonstrates how to establish interactions between AI models and external tools using MCP.
|
111 |
-
|
112 |
-
The server supports two modes of operation:
|
113 |
-
|
114 |
-
1. stdio mode (default):
|
115 |
-
|
116 |
-
- Communicates with clients via standard input/output streams, ideal for local command-line usage.
|
117 |
-
|
118 |
-
- Example usage: python mcp_server.py [--transport stdio]
|
119 |
-
|
120 |
-
2. SSE mode (Server-Sent Events):
|
121 |
-
|
122 |
-
- Communicates with clients over HTTP using server-sent events, suitable for persistent network connections.
|
123 |
-
|
124 |
-
- Runs by default at http://127.0.0.1:8000.
|
125 |
-
|
126 |
-
- Example usage: python mcp_server.py --transport sse
|
127 |
-
""" # noqa: E501
|
128 |
-
if transport == 'stdio':
|
129 |
-
mcp.run(transport='stdio')
|
130 |
-
elif transport == 'sse':
|
131 |
-
mcp.run(transport='sse')
|
132 |
-
|
133 |
-
|
134 |
-
if __name__ == "__main__":
|
135 |
-
# Hardcoded to use stdio transport mode
|
136 |
-
main("stdio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|