Spaces:
Running
Running
Commit
·
63ee82a
1
Parent(s):
1e513bd
Prompt-engineered docstrings
Browse files- api_validator.py +90 -7
- main.py +2 -2
api_validator.py
CHANGED
@@ -20,7 +20,16 @@ def validate_api_call(
|
|
20 |
start_time,
|
21 |
):
|
22 |
"""
|
23 |
-
Validate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
Parameters:
|
26 |
- mcp_api_key: MCP API key serves as user identifier
|
@@ -36,8 +45,52 @@ def validate_api_call(
|
|
36 |
- stop_after_hours: Hours after which to stop (max 168 = 1 week)
|
37 |
- start_time: When to start the monitoring (datetime string or None for immediate)
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
Returns:
|
40 |
-
- Dictionary with success status, config_id, message, and sample_response
|
41 |
|
42 |
Example return:
|
43 |
{
|
@@ -48,6 +101,8 @@ def validate_api_call(
|
|
48 |
"stop_at": "2025-06-11T12:00:00Z",
|
49 |
"start_at": "2025-06-04T12:00:00Z"
|
50 |
}
|
|
|
|
|
51 |
"""
|
52 |
try:
|
53 |
# Validate input parameters
|
@@ -171,7 +226,6 @@ def validate_api_call(
|
|
171 |
"created_at": created_at.isoformat(),
|
172 |
"start_at": start_datetime.isoformat(),
|
173 |
"stop_at": stop_at.isoformat(),
|
174 |
-
|
175 |
# @JamezyKim This will be used to track the status of whether the api is confirmed or not
|
176 |
"is_validated": False,
|
177 |
"sample_response": result,
|
@@ -202,11 +256,38 @@ def validate_api_call(
|
|
202 |
|
203 |
def setup_scheduler(config_id, mcp_api_key):
|
204 |
"""
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
Parameters:
|
208 |
-
- config_id: The ID from
|
209 |
-
- mcp_api_key: User's MCP API key for verification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
|
211 |
Returns:
|
212 |
- Dictionary with success status and scheduling details
|
@@ -220,11 +301,13 @@ def setup_scheduler(config_id, mcp_api_key):
|
|
220 |
"stop_at": "2025-06-11T12:00:00Z",
|
221 |
"next_call_at": "2025-06-04T12:20:00Z"
|
222 |
}
|
|
|
|
|
223 |
"""
|
224 |
|
225 |
return {
|
226 |
"success": False,
|
227 |
-
"message": "Function not implemented yet",
|
228 |
"config_id": config_id,
|
229 |
}
|
230 |
|
|
|
20 |
start_time,
|
21 |
):
|
22 |
"""
|
23 |
+
TOOL: Validate and store API configuration for monitoring.
|
24 |
+
|
25 |
+
PURPOSE: Test an API endpoint and store the configuration if successful. This is STEP 1
|
26 |
+
of the monitoring setup process. If validation fails, retry with corrected parameters.
|
27 |
+
If successful, use the returned config_id in setup_scheduler() function.
|
28 |
+
|
29 |
+
WORKFLOW:
|
30 |
+
1. Call this function to validate API configuration
|
31 |
+
2. If success=False: Fix parameters and retry this function
|
32 |
+
3. If success=True: Use config_id in setup_scheduler() to activate monitoring
|
33 |
|
34 |
Parameters:
|
35 |
- mcp_api_key: MCP API key serves as user identifier
|
|
|
45 |
- stop_after_hours: Hours after which to stop (max 168 = 1 week)
|
46 |
- start_time: When to start the monitoring (datetime string or None for immediate)
|
47 |
|
48 |
+
Input Examples:
|
49 |
+
|
50 |
+
1. Simple GET request to monitor stock price:
|
51 |
+
mcp_api_key: "your_mcp_key_here"
|
52 |
+
name: "NVDA Stock Price"
|
53 |
+
description: "Monitor NVIDIA stock price every 30 minutes"
|
54 |
+
method: "GET"
|
55 |
+
base_url: "https://api.example.com"
|
56 |
+
endpoint: "stocks/NVDA"
|
57 |
+
param_keys_values: "symbol: NVDA\ninterval: 1min"
|
58 |
+
header_keys_values: "Authorization: Bearer your_token"
|
59 |
+
additional_params: "{}"
|
60 |
+
schedule_interval_minutes: 30
|
61 |
+
stop_after_hours: 24
|
62 |
+
start_time: ""
|
63 |
+
|
64 |
+
2. API with complex parameters:
|
65 |
+
mcp_api_key: "your_mcp_key_here"
|
66 |
+
name: "Weather Alert Monitor"
|
67 |
+
description: "Monitor severe weather alerts"
|
68 |
+
method: "POST"
|
69 |
+
base_url: "https://api.weather.com"
|
70 |
+
endpoint: "alerts"
|
71 |
+
param_keys_values: "lat: 40.7128\nlon: -74.0060"
|
72 |
+
header_keys_values: "X-API-Key: weather_key\nContent-Type: application/json"
|
73 |
+
additional_params: '{"severity": ["severe", "extreme"], "types": ["tornado", "hurricane"]}'
|
74 |
+
schedule_interval_minutes: 15
|
75 |
+
stop_after_hours: 48
|
76 |
+
start_time: "2024-06-15 09:00:00"
|
77 |
+
|
78 |
+
3. GitHub API monitoring:
|
79 |
+
mcp_api_key: "your_mcp_key_here"
|
80 |
+
name: "Repo Issues Monitor"
|
81 |
+
description: "Monitor new issues in repository"
|
82 |
+
method: "GET"
|
83 |
+
base_url: "https://api.github.com"
|
84 |
+
endpoint: "repos/microsoft/TypeScript/issues"
|
85 |
+
param_keys_values: "state: open\nper_page: 10"
|
86 |
+
header_keys_values: "Accept: application/vnd.github.v3+json\nUser-Agent: MyApp"
|
87 |
+
additional_params: "{}"
|
88 |
+
schedule_interval_minutes: 60
|
89 |
+
stop_after_hours: 168
|
90 |
+
start_time: ""
|
91 |
+
|
92 |
Returns:
|
93 |
+
- Dictionary with success status, config_id (needed for setup_scheduler), message, and sample_response
|
94 |
|
95 |
Example return:
|
96 |
{
|
|
|
101 |
"stop_at": "2025-06-11T12:00:00Z",
|
102 |
"start_at": "2025-06-04T12:00:00Z"
|
103 |
}
|
104 |
+
|
105 |
+
NEXT STEP: If success=True, call setup_scheduler(config_id, mcp_api_key) to activate monitoring
|
106 |
"""
|
107 |
try:
|
108 |
# Validate input parameters
|
|
|
226 |
"created_at": created_at.isoformat(),
|
227 |
"start_at": start_datetime.isoformat(),
|
228 |
"stop_at": stop_at.isoformat(),
|
|
|
229 |
# @JamezyKim This will be used to track the status of whether the api is confirmed or not
|
230 |
"is_validated": False,
|
231 |
"sample_response": result,
|
|
|
256 |
|
257 |
def setup_scheduler(config_id, mcp_api_key):
|
258 |
"""
|
259 |
+
TOOL: Activate periodic monitoring for a validated API configuration.
|
260 |
+
|
261 |
+
PURPOSE: Start automated recurring API calls based on a previously validated configuration.
|
262 |
+
This is STEP 2 of the monitoring setup process.
|
263 |
+
|
264 |
+
PREREQUISITE: Must call validate_api_call() first and obtain a config_id from successful validation.
|
265 |
+
|
266 |
+
WORKFLOW:
|
267 |
+
1. First call validate_api_call() to get config_id
|
268 |
+
2. If validation successful, call this function with the config_id
|
269 |
+
3. Monitoring will run automatically according to the validated schedule
|
270 |
|
271 |
Parameters:
|
272 |
+
- config_id: The ID from successful validate_api_call() execution (required)
|
273 |
+
- mcp_api_key: User's MCP API key for verification (must match validation step)
|
274 |
+
|
275 |
+
Input Examples:
|
276 |
+
|
277 |
+
1. Activate scheduler for stock monitoring:
|
278 |
+
config_id: 123456789
|
279 |
+
mcp_api_key: "your_mcp_key_here"
|
280 |
+
|
281 |
+
2. Activate scheduler for weather alerts:
|
282 |
+
config_id: 987654321
|
283 |
+
mcp_api_key: "your_mcp_key_here"
|
284 |
+
|
285 |
+
3. Activate scheduler for GitHub issues:
|
286 |
+
config_id: 456789123
|
287 |
+
mcp_api_key: "your_mcp_key_here"
|
288 |
+
|
289 |
+
NOTE: The config_id must be obtained from a successful validate_api_call() response.
|
290 |
+
The mcp_api_key must match the one used during validation.
|
291 |
|
292 |
Returns:
|
293 |
- Dictionary with success status and scheduling details
|
|
|
301 |
"stop_at": "2025-06-11T12:00:00Z",
|
302 |
"next_call_at": "2025-06-04T12:20:00Z"
|
303 |
}
|
304 |
+
|
305 |
+
ERROR HANDLING: If config_id not found or invalid, returns success=False with error message
|
306 |
"""
|
307 |
|
308 |
return {
|
309 |
"success": False,
|
310 |
+
"message": "Function not implemented yet; this is a placeholder.",
|
311 |
"config_id": config_id,
|
312 |
}
|
313 |
|
main.py
CHANGED
@@ -65,7 +65,7 @@ validation_tab = gr.Interface(
|
|
65 |
],
|
66 |
outputs=gr.Textbox(label="Validation Result", lines=10),
|
67 |
title="API Validation & Storage",
|
68 |
-
description="Validate your API configuration and
|
69 |
)
|
70 |
|
71 |
# Scheduler Setup Tab
|
@@ -79,7 +79,7 @@ scheduler_tab = gr.Interface(
|
|
79 |
],
|
80 |
outputs=gr.Textbox(label="Scheduler Result", lines=8),
|
81 |
title="Scheduler Setup",
|
82 |
-
description="Activate
|
83 |
)
|
84 |
|
85 |
# Create tabbed interface
|
|
|
65 |
],
|
66 |
outputs=gr.Textbox(label="Validation Result", lines=10),
|
67 |
title="API Validation & Storage",
|
68 |
+
description="STEP 1: Validate and test your API configuration. This tool tests the API call and stores the configuration if successful. If validation fails, retry with corrected parameters. If validation succeeds, proceed directly to 'Activate Scheduler' tab with the returned Config ID. Required for LLM tools that need to monitor external APIs periodically. Max monitoring period is 1 week (168 hours).",
|
69 |
)
|
70 |
|
71 |
# Scheduler Setup Tab
|
|
|
79 |
],
|
80 |
outputs=gr.Textbox(label="Scheduler Result", lines=8),
|
81 |
title="Scheduler Setup",
|
82 |
+
description="STEP 2: Activate periodic monitoring for a validated API configuration. PREREQUISITE: Must complete validation step first and obtain a Config ID. This tool sets up automated recurring API calls based on the validated configuration. Use the Config ID from the validation step output.",
|
83 |
)
|
84 |
|
85 |
# Create tabbed interface
|