File size: 4,800 Bytes
f2881c1
108dc63
 
de8148c
1e513bd
 
 
 
108dc63
f119b25
 
1e513bd
 
 
 
 
 
 
 
 
 
f119b25
1e513bd
 
 
f119b25
 
 
1e513bd
f119b25
db4bc9c
 
 
 
 
f119b25
 
 
 
1e513bd
 
 
 
 
 
 
 
 
f119b25
 
1e513bd
 
63ee82a
de8148c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e513bd
 
 
 
108dc63
1e513bd
 
 
 
 
f119b25
1e513bd
 
63ee82a
de8148c
 
 
 
 
 
 
 
 
 
 
 
1e513bd
 
 
 
 
 
 
f2881c1
 
 
a0644e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import gradio as gr
from api_client import call_api
from api_monitor import validate_api_configuration, activate_monitoring
import json


# API Validation Tab
validation_tab = gr.Interface(
    fn=validate_api_configuration,
    inputs=[
        gr.Textbox(
            label="MCP API Key", placeholder="Enter your MCP API key", type="password"
        ),
        gr.Textbox(
            label="Monitoring Name", placeholder="e.g., 'NVDA Stock Price'", value=""
        ),
        gr.Textbox(
            label="Description",
            placeholder="What are you monitoring?",
            value="",
            lines=2,
        ),
        gr.Radio(choices=["GET", "POST", "PUT", "DELETE"], label="Method", value="GET"),
        gr.Textbox(label="Base URL", placeholder="https://api.example.com", value=""),
        gr.Textbox(label="Endpoint", placeholder="endpoint/path", value=""),
        gr.Textbox(
            label="Parameter Key-Value Pairs",
            placeholder="Enter one parameter per line in format 'key: value'",
            value="",
        ),
        gr.Textbox(
            label="Header Key-Value Pairs",
            placeholder="Enter one header per line in format 'key: value'",
            value="",
        ),
        gr.Textbox(
            label="Additional Parameters (JSON)",
            placeholder="Enter any additional parameters as JSON",
            value="{}",
        ),
        gr.Number(
            label="Schedule Interval (minutes)", value=20, minimum=1, maximum=1440
        ),
        gr.Number(label="Stop After (hours)", value=24, minimum=1, maximum=168),
        gr.Textbox(
            label="Start Time (optional)",
            placeholder="YYYY-MM-DD HH:MM:SS or leave empty for immediate start",
            value="",
        ),
    ],
    outputs=gr.Textbox(label="Validation Result", lines=10),
    title="API Validation & Storage",
    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).",
    flagging_mode="manual",
    flagging_options=["Invalid Request", "API Error", "Config Issue", "Other"],
    examples=[
        [
            "test_mcp_key_123",
            "Dog Facts Monitor",
            "Monitor random dog facts from a free API",
            "GET",
            "https://dogapi.dog",
            "api/v2/facts",
            "",
            "",
            "{}",
            30,
            2,
            "",
        ],
        [
            "test_mcp_key_456",
            "XIVAPI Item Search",
            "Monitor FFXIV item data",
            "GET",
            "https://v2.xivapi.com/api",
            "search",
            'query: Name~"popoto"\nsheets: Item\nfields: Name,Description\nlanguage: en\nlimit: 1',
            "",
            "{}",
            60,
            4,
            "",
        ],
        [
            "test_mcp_key_789",
            "GitHub Issues Monitor",
            "Monitor TypeScript repository issues",
            "GET",
            "https://api.github.com",
            "repos/microsoft/TypeScript/issues",
            "state: open\nper_page: 5",
            "Accept: application/vnd.github.v3+json\nUser-Agent: MCP-Monitor",
            "{}",
            120,
            12,
            "",
        ],
    ],
)

# Scheduler Setup Tab
scheduler_tab = gr.Interface(
    fn=activate_monitoring,
    inputs=[
        gr.Number(label="Config ID (from validation step)", value=None),
        gr.Textbox(
            label="MCP API Key", placeholder="Enter your MCP API key", type="password"
        ),
    ],
    outputs=gr.Textbox(label="Scheduler Result", lines=8),
    title="Scheduler Setup",
    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.",
    flagging_mode="manual",
    flagging_options=[
        "Config Not Found",
        "Invalid API Key",
        "Scheduler Error",
        "Other",
    ],
    examples=[
        [123456789, "test_mcp_key_123"],
        [987654321, "test_mcp_key_456"],
        [456789123, "test_mcp_key_789"],
    ],
)

# Create tabbed interface
demo = gr.TabbedInterface(
    [validation_tab, scheduler_tab],
    ["Validate & Store", "Activate Scheduler"],
    title="MCP API Monitoring System",
)

if __name__ == "__main__":
    demo.launch(mcp_server=True)