import gradio as gr # MCP Server Functions def multiply_server(a, b): """Multiply two numbers""" try: result = float(a) * float(b) return f"Result: {a} × {b} = {result}" except ValueError: return "Error: Please enter valid numbers" def hello_server(name): """Greet a user""" if name.strip(): return f"Hello, {name}! Welcome to the MCP server." else: return "Hello! Please enter your name." # Create Gradio Interface with gr.Blocks(title="Simple MCP Server", theme=gr.themes.Soft()) as demo: gr.Markdown("# 🌐 Simple MCP Server\nTwo basic MCP servers: Multiply and Hello") with gr.Tabs(): # Multiply Server Tab with gr.Tab("✖️ Multiply Server"): gr.Markdown("### Multiply two numbers") with gr.Row(): mult_a = gr.Number(label="First Number", value=5) mult_b = gr.Number(label="Second Number", value=3) mult_btn = gr.Button("Multiply", variant="primary") mult_output = gr.Textbox(label="Result", lines=2) mult_btn.click(multiply_server, inputs=[mult_a, mult_b], outputs=mult_output) # Hello Server Tab with gr.Tab("👋 Hello Server"): gr.Markdown("### Get a personalized greeting") hello_name = gr.Textbox(label="Your Name", placeholder="Enter your name") hello_btn = gr.Button("Say Hello", variant="primary") hello_output = gr.Textbox(label="Greeting", lines=2) hello_btn.click(hello_server, inputs=[hello_name], outputs=hello_output) if __name__ == "__main__": demo.launch(mcp_server=True)