Spaces:
Running
Running
Commit
·
de8148c
1
Parent(s):
63ee82a
Update API validation messages for more clarity to the agent, and enhance Gradio interface examples
Browse files- api_validator.py +13 -9
- main.py +61 -18
api_validator.py
CHANGED
@@ -96,7 +96,7 @@ def validate_api_call(
|
|
96 |
{
|
97 |
"success": True,
|
98 |
"config_id": 123,
|
99 |
-
"message": "API call
|
100 |
"sample_response": {...},
|
101 |
"stop_at": "2025-06-11T12:00:00Z",
|
102 |
"start_at": "2025-06-04T12:00:00Z"
|
@@ -228,7 +228,7 @@ def validate_api_call(
|
|
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 |
-
"
|
232 |
}
|
233 |
)
|
234 |
|
@@ -239,8 +239,12 @@ def validate_api_call(
|
|
239 |
return {
|
240 |
"success": True,
|
241 |
"config_id": config_id,
|
242 |
-
"message": f"API call
|
243 |
-
"sample_response":
|
|
|
|
|
|
|
|
|
244 |
"start_at": start_datetime.isoformat(),
|
245 |
"stop_at": stop_at.isoformat(),
|
246 |
"schedule_interval_minutes": schedule_interval_minutes,
|
@@ -316,16 +320,16 @@ if __name__ == "__main__":
|
|
316 |
# Example usage
|
317 |
response = validate_api_call(
|
318 |
mcp_api_key="your_api_key",
|
319 |
-
name="
|
320 |
-
description="Monitor
|
321 |
method="GET",
|
322 |
-
base_url="https://
|
323 |
-
endpoint="
|
324 |
param_keys_values="",
|
325 |
header_keys_values="",
|
326 |
additional_params="{}",
|
327 |
schedule_interval_minutes=20,
|
328 |
stop_after_hours=24,
|
329 |
-
start_time=
|
330 |
)
|
331 |
print(response)
|
|
|
96 |
{
|
97 |
"success": True,
|
98 |
"config_id": 123,
|
99 |
+
"message": "API call tested and stored successfully",
|
100 |
"sample_response": {...},
|
101 |
"stop_at": "2025-06-11T12:00:00Z",
|
102 |
"start_at": "2025-06-04T12:00:00Z"
|
|
|
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 |
+
"api_response": result,
|
232 |
}
|
233 |
)
|
234 |
|
|
|
239 |
return {
|
240 |
"success": True,
|
241 |
"config_id": config_id,
|
242 |
+
"message": f"API call tested and stored successfully for '{name}'. Use this config_id in setup_scheduler() to activate monitoring.",
|
243 |
+
"sample_response": (
|
244 |
+
json.loads(result)
|
245 |
+
if result.startswith("{") or result.startswith("[")
|
246 |
+
else result
|
247 |
+
),
|
248 |
"start_at": start_datetime.isoformat(),
|
249 |
"stop_at": stop_at.isoformat(),
|
250 |
"schedule_interval_minutes": schedule_interval_minutes,
|
|
|
320 |
# Example usage
|
321 |
response = validate_api_call(
|
322 |
mcp_api_key="your_api_key",
|
323 |
+
name="Dog Facts API",
|
324 |
+
description="Monitor random dog facts from a free API",
|
325 |
method="GET",
|
326 |
+
base_url="https://dogapi.dog",
|
327 |
+
endpoint="api/v2/facts",
|
328 |
param_keys_values="",
|
329 |
header_keys_values="",
|
330 |
additional_params="{}",
|
331 |
schedule_interval_minutes=20,
|
332 |
stop_after_hours=24,
|
333 |
+
start_time="",
|
334 |
)
|
335 |
print(response)
|
main.py
CHANGED
@@ -1,27 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from apiCall import api_call
|
3 |
from api_validator import validate_api_call, setup_scheduler
|
4 |
-
|
5 |
-
|
6 |
-
def format_validation_result(result):
|
7 |
-
"""Format validation result for display"""
|
8 |
-
if result["success"]:
|
9 |
-
return f"✅ Success!\n\nConfig ID: {result['config_id']}\nMessage: {result['message']}\n\nSample Response:\n{result.get('sample_response', 'No sample response')}"
|
10 |
-
else:
|
11 |
-
return f"❌ Failed!\n\nMessage: {result['message']}"
|
12 |
-
|
13 |
-
|
14 |
-
def format_scheduler_result(result):
|
15 |
-
"""Format scheduler result for display"""
|
16 |
-
if result["success"]:
|
17 |
-
return f"✅ Scheduler Active!\n\nConfig ID: {result['config_id']}\nMessage: {result['message']}\n\nSchedule Details:\n{result.get('schedule_interval_minutes', 'N/A')} minutes interval\nStops at: {result.get('stop_at', 'N/A')}"
|
18 |
-
else:
|
19 |
-
return f"❌ Scheduler Failed!\n\nMessage: {result['message']}"
|
20 |
|
21 |
|
22 |
# API Validation Tab
|
23 |
validation_tab = gr.Interface(
|
24 |
-
fn=lambda *args:
|
25 |
inputs=[
|
26 |
gr.Textbox(
|
27 |
label="MCP API Key", placeholder="Enter your MCP API key", type="password"
|
@@ -66,11 +51,57 @@ validation_tab = gr.Interface(
|
|
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
|
72 |
scheduler_tab = gr.Interface(
|
73 |
-
fn=lambda *args:
|
74 |
inputs=[
|
75 |
gr.Number(label="Config ID (from validation step)", value=None),
|
76 |
gr.Textbox(
|
@@ -80,6 +111,18 @@ scheduler_tab = gr.Interface(
|
|
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
|
|
|
1 |
import gradio as gr
|
2 |
from apiCall import api_call
|
3 |
from api_validator import validate_api_call, setup_scheduler
|
4 |
+
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
# API Validation Tab
|
8 |
validation_tab = gr.Interface(
|
9 |
+
fn=lambda *args: json.dumps(validate_api_call(*args), indent=2),
|
10 |
inputs=[
|
11 |
gr.Textbox(
|
12 |
label="MCP API Key", placeholder="Enter your MCP API key", type="password"
|
|
|
51 |
outputs=gr.Textbox(label="Validation Result", lines=10),
|
52 |
title="API Validation & Storage",
|
53 |
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).",
|
54 |
+
flagging_mode="manual",
|
55 |
+
flagging_options=["Invalid Request", "API Error", "Config Issue", "Other"],
|
56 |
+
examples=[
|
57 |
+
[
|
58 |
+
"test_mcp_key_123",
|
59 |
+
"Dog Facts Monitor",
|
60 |
+
"Monitor random dog facts from a free API",
|
61 |
+
"GET",
|
62 |
+
"https://dogapi.dog",
|
63 |
+
"api/v2/facts",
|
64 |
+
"",
|
65 |
+
"",
|
66 |
+
"{}",
|
67 |
+
30,
|
68 |
+
2,
|
69 |
+
"",
|
70 |
+
],
|
71 |
+
[
|
72 |
+
"test_mcp_key_456",
|
73 |
+
"XIVAPI Item Search",
|
74 |
+
"Monitor FFXIV item data",
|
75 |
+
"GET",
|
76 |
+
"https://v2.xivapi.com/api",
|
77 |
+
"search",
|
78 |
+
'query: Name~"popoto"\nsheets: Item\nfields: Name,Description\nlanguage: en\nlimit: 1',
|
79 |
+
"",
|
80 |
+
"{}",
|
81 |
+
60,
|
82 |
+
4,
|
83 |
+
"",
|
84 |
+
],
|
85 |
+
[
|
86 |
+
"test_mcp_key_789",
|
87 |
+
"GitHub Issues Monitor",
|
88 |
+
"Monitor TypeScript repository issues",
|
89 |
+
"GET",
|
90 |
+
"https://api.github.com",
|
91 |
+
"repos/microsoft/TypeScript/issues",
|
92 |
+
"state: open\nper_page: 5",
|
93 |
+
"Accept: application/vnd.github.v3+json\nUser-Agent: MCP-Monitor",
|
94 |
+
"{}",
|
95 |
+
120,
|
96 |
+
12,
|
97 |
+
"",
|
98 |
+
],
|
99 |
+
],
|
100 |
)
|
101 |
|
102 |
# Scheduler Setup Tab
|
103 |
scheduler_tab = gr.Interface(
|
104 |
+
fn=lambda *args: json.dumps(setup_scheduler(*args), indent=2),
|
105 |
inputs=[
|
106 |
gr.Number(label="Config ID (from validation step)", value=None),
|
107 |
gr.Textbox(
|
|
|
111 |
outputs=gr.Textbox(label="Scheduler Result", lines=8),
|
112 |
title="Scheduler Setup",
|
113 |
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.",
|
114 |
+
flagging_mode="manual",
|
115 |
+
flagging_options=[
|
116 |
+
"Config Not Found",
|
117 |
+
"Invalid API Key",
|
118 |
+
"Scheduler Error",
|
119 |
+
"Other",
|
120 |
+
],
|
121 |
+
examples=[
|
122 |
+
[123456789, "test_mcp_key_123"],
|
123 |
+
[987654321, "test_mcp_key_456"],
|
124 |
+
[456789123, "test_mcp_key_789"],
|
125 |
+
],
|
126 |
)
|
127 |
|
128 |
# Create tabbed interface
|