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)