Skip to main content
Glama

MCP Time Server

by WhenjaySun
server.py989 B
from datetime import datetime import zoneinfo from mcp.server.fastmcp import FastMCP # Initialize FastMCP server mcp = FastMCP("time") @mcp.tool() def mcp_server_time(timezone: str = "Asia/Shanghai") -> str: """ Get the current time in the specified timezone. Args: timezone: The timezone to get the time for (default: Asia/Shanghai for UTC+8). Examples: "UTC", "America/New_York", "Europe/London". """ try: # Get current time in UTC now_utc = datetime.now(zoneinfo.ZoneInfo("UTC")) # Convert to target timezone target_zone = zoneinfo.ZoneInfo(timezone) current_time = now_utc.astimezone(target_zone) return current_time.isoformat() except Exception as e: return f"Error getting time: {str(e)}" # Expose Streamable HTTP app for uvicorn # This allows running with: uvicorn server:app app = mcp.streamable_http_app() if __name__ == "__main__": mcp.run()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/WhenjaySun/mcp-server-time'

If you have feedback or need assistance with the MCP directory API, please join our Discord server