File size: 2,954 Bytes
5b84775
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3637da
 
5b84775
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from mcp.server.fastmcp import FastMCP
import webbrowser
import urllib.parse
from datetime import datetime
import json

# Create an MCP server
mcp = FastMCP("Cypress")


# Add tool
@mcp.tool()
def google_search(query):
    """Search in google with query."""
    encoded_query = urllib.parse.quote_plus(query)
    url = f"https:///www.google.com/search?q={encoded_query}"
    webbrowser.open(url)


# Add tool
@mcp.tool()
def add(a: int, b: int)-> int:
   """Add two numbers."""
   return a + b


# Add a dynamic greeting resource
@mcp.resource("greeing://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting."""
    return f"Hello, {name}!"

# Resources
@mcp.resource("resource://server-status") 
def get_server_status() -> dict:
    """Get current server status information."""
    return {
        "status": "running",
        "timestamp": datetime.now().isoformat(),
        "version": "0.1.0",
        "features": ["tools", "resources", "prompts"]
    }


# Add a prompt
@mcp.prompt()
def explain_concept_prompt(concept: str, audience: str = "general") -> str:
    """Generate a prompt to explain a technical concept to a specific audience."""
    audience_instructions = {
        "beginner": "Use simple language, avoid jargon, and provide relatable analogies",
        "intermediate": "Use technical terms but explain them, provide examples",
        "expert": "Use precise technical language and focus on nuances",
        "general": "Use accesible language with some technical detail"
    }
    
    instruction = audience_instructions.get(audience, audience_instructions["general"])
    return f"""Explain the concept of '{concept}' to a {audience} audience.

Guidelines: {instruction}

Structure your explanation with:
1. A brief overview
2. Key components or aspects
3. Practical examples or use cases
4. Common misconceptions (if any)
5. Further learning resources"""


demo = gr.TabbedInterface(
    [
        gr.Interface(
            get_greeting, 
            gr.Textbox(), 
            gr.Textbox(), 
            api_name="get_greeting"
            ),
        gr.Interface(
            add,
            gr.Textbox(),
            gr.Textbox(), 
            api_name="add"
        ),
        gr.Interface(
            explain_concept_prompt,
            gr.Textbox(),
            gr.Textbox(),
            api_name="explain_concept_prompt"  
        ),
        gr.Interface(
            google_search,
            gr.Textbox(),
            gr.Textbox(),
            api_name="google_search"
        ),
        gr.Interface(
            get_server_status,
            gr.Textbox(),
            gr.Textbox(),
            api_name="get_server_status"
        )
       
       
    ],
    [
        "Get Greeting",
        "Add",
        "Explain Concept Prompt",
        "Google Search",
        "Get Server Status"
    ]
)

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