| | """ |
| | Berlin Time MCP Server - A Gradio-based MCP server example |
| | =========================================================== |
| | |
| | This is a simple MCP (Model Context Protocol) server that provides |
| | a tool for getting the current time in Berlin timezone. |
| | |
| | MCP servers allow AI agents to discover and use tools in a standardized way. |
| | """ |
| |
|
| | from datetime import datetime |
| | import pytz |
| | import gradio as gr |
| |
|
| |
|
| | def get_berlin_time(): |
| | """ |
| | Get the current date and time in Berlin timezone. |
| | |
| | This function will be exposed as an MCP tool that AI agents can call |
| | when they need to know the current time in Berlin. |
| | |
| | Returns: |
| | dict: A dictionary containing: |
| | - time: Human-readable formatted time string |
| | - timezone: The timezone name (Europe/Berlin) |
| | - timestamp: ISO 8601 formatted timestamp |
| | - utc_offset: Current UTC offset for Berlin |
| | """ |
| | |
| | berlin_tz = pytz.timezone('Europe/Berlin') |
| | |
| | |
| | current_time = datetime.now(berlin_tz) |
| | |
| | |
| | formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S %Z") |
| | |
| | |
| | utc_offset = current_time.strftime("%z") |
| | |
| | |
| | return { |
| | "time": formatted_time, |
| | "timezone": "Europe/Berlin", |
| | "timestamp": current_time.isoformat(), |
| | "utc_offset": utc_offset, |
| | "day_of_week": current_time.strftime("%A"), |
| | "is_dst": bool(current_time.dst()) |
| | } |
| |
|
| |
|
| | |
| | demo = gr.Interface( |
| | fn=get_berlin_time, |
| | inputs=[], |
| | outputs=gr.JSON(label="Berlin Time Information"), |
| | title="๐ Berlin Time MCP Server", |
| | description=""" |
| | This is an MCP (Model Context Protocol) server that provides the current time in Berlin. |
| | |
| | **For Testing:** Click 'Submit' below to see the current Berlin time. |
| | |
| | **For AI Agents:** This server exposes the `get_berlin_time` tool via MCP protocol. |
| | AI agents can connect to this server and call this tool when they need Berlin time. |
| | """, |
| | api_name="get_berlin_time" |
| | ) |
| |
|
| | if __name__ == "__main__": |
| | |
| | demo.launch( |
| | mcp_server=True, |
| | share=False, |
| | server_name="0.0.0.0", |
| | server_port=7860 |
| | ) |
| |
|