File size: 2,040 Bytes
140fcff
f379bec
 
 
 
 
 
 
 
 
 
140fcff
f379bec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from duckduckgo_search import DDGS
#from huggingface_hub import InferenceClient

# Simulated knowledge base
TROUBLESHOOTING_KB = {
    "wifi not working": [
        "Check if your router is turned on.",
        "Restart your router.",
        "Ensure your device is connected to the correct Wi-Fi network.",
        "Try connecting another device to determine if the issue is with your device or the network."
    ],
    "computer is slow": [
        "Close unused applications.",
        "Check for viruses using antivirus software.",
        "Restart your computer.",
        "Check for available updates and install them."
    ]
}

# Tool: search_knowledge_base
def search_knowledge_base(problem: str):
    problem = problem.lower()
    for key in TROUBLESHOOTING_KB:
        if key in problem:
            return TROUBLESHOOTING_KB[key]
    return ["No matching solution found in the knowledge base."]

# Tool: search_web
def search_web(query: str):
    results = []
    with DDGS() as ddgs:
        for r in ddgs.text(query, max_results=3):
            results.append({
                "title": r["title"],
                "body": r["body"],
                "href": r["href"]
            })
    return results

# Optional Tool: visit_webpage
def visit_webpage(url: str):
    return f"Stub for visiting {url}"

# Optional Tool: format_response
def format_response(text: str):
    return f"🛠️ Troubleshooting Steps:\n{text}"

# Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# 🧠 Troubleshooting MCP Server")

    with gr.Row():
        kb_input = gr.Textbox(label="Describe your problem")
        kb_output = gr.JSON(label="Knowledge Base Steps")
        gr.Button("Search KB").click(search_knowledge_base, inputs=kb_input, outputs=kb_output)

    with gr.Row():
        web_input = gr.Textbox(label="Enter search query")
        web_output = gr.JSON(label="Web Search Results")
        gr.Button("Search Web").click(search_web, inputs=web_input, outputs=web_output)

demo.launch(mcp_server=True)