Spaces:
Running
Running
Commit
·
7bb59b0
1
Parent(s):
614a069
Initial docstring for retrieving monitored data
Browse files- api_monitor.py +50 -1
api_monitor.py
CHANGED
@@ -30,7 +30,7 @@ def validate_api_configuration(
|
|
30 |
PURPOSE: Test an API endpoint and store the configuration if successful. This is STEP 1
|
31 |
of the monitoring setup process. If validation fails, retry with corrected parameters. If successful, use the returned config_id in activate_monitoring() function.
|
32 |
|
33 |
-
|
34 |
before proceeding to activate_monitoring(). The API call may return success=True but contain
|
35 |
error messages (like "401 Unauthorized", "Invalid API key", etc.) in the sample_response.
|
36 |
|
@@ -386,3 +386,52 @@ if __name__ == "__main__":
|
|
386 |
time_to_start="",
|
387 |
)
|
388 |
print(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
PURPOSE: Test an API endpoint and store the configuration if successful. This is STEP 1
|
31 |
of the monitoring setup process. If validation fails, retry with corrected parameters. If successful, use the returned config_id in activate_monitoring() function.
|
32 |
|
33 |
+
CRITICAL: Even if success=True, you MUST manually check the 'sample_response' field
|
34 |
before proceeding to activate_monitoring(). The API call may return success=True but contain
|
35 |
error messages (like "401 Unauthorized", "Invalid API key", etc.) in the sample_response.
|
36 |
|
|
|
386 |
time_to_start="",
|
387 |
)
|
388 |
print(response)
|
389 |
+
|
390 |
+
|
391 |
+
def retrieve_monitored_data(config_id, mcp_api_key):
|
392 |
+
"""
|
393 |
+
TOOL: Retrieve monitored data for a specific API configuration.
|
394 |
+
|
395 |
+
PURPOSE: Fetch the latest monitored data for a given configuration ID.
|
396 |
+
This is STEP 3 of the monitoring setup process.
|
397 |
+
|
398 |
+
PREREQUISITE: Must call validate_api_configuration() first and obtain a config_id from successful validation, then activate_monitoring() to start monitoring.
|
399 |
+
|
400 |
+
This function can be called at any time after monitoring activation to retrieve the latest data collected by the monitoring system.
|
401 |
+
|
402 |
+
Parameters:
|
403 |
+
- config_id: The ID of the API configuration to retrieve data for (required)
|
404 |
+
- mcp_api_key: User's MCP API key for verification (must match validation step)
|
405 |
+
|
406 |
+
Input Examples:
|
407 |
+
1. Retrieve data for stock monitoring:
|
408 |
+
config_id: 123456789
|
409 |
+
mcp_api_key: "your_mcp_key_here"
|
410 |
+
|
411 |
+
2. Retrieve data for weather alerts:
|
412 |
+
config_id: 987654321
|
413 |
+
mcp_api_key: "your_mcp_key_here"
|
414 |
+
|
415 |
+
Returns:
|
416 |
+
- Dictionary with success status, data, and message
|
417 |
+
- If no data found, returns success=False with appropriate message
|
418 |
+
Example return:
|
419 |
+
{
|
420 |
+
"success": True,
|
421 |
+
"data": [
|
422 |
+
{"timestamp": "2025-06-04T12:00:00Z", "response": {...}},
|
423 |
+
{"timestamp": "2025-06-04T12:20:00Z", "response": {...}},
|
424 |
+
],
|
425 |
+
"message": "Data retrieved successfully for config_id 123456789"
|
426 |
+
}
|
427 |
+
- If config_id not found or invalid, returns success=False with error message
|
428 |
+
- If mcp_api_key does not match, returns success=False with error message
|
429 |
+
|
430 |
+
Example error return:
|
431 |
+
{
|
432 |
+
"success": False,
|
433 |
+
"message": "Invalid config_id or mcp_api_key",
|
434 |
+
"data": []
|
435 |
+
}
|
436 |
+
ERROR HANDLING: If config_id not found or invalid, returns success=False with error message
|
437 |
+
"""
|