Skip to main content
Glama

MCP Boilerplate Server

by shazaaly
server.py4.57 kB
from fastmcp import FastMCP import datetime mcp = FastMCP("Demo MCP Server") # Tools @mcp.tool def greet(name: str) -> str: """Greet a person by name""" return f"Hello, {name}!" @mcp.tool def add(a: int, b: int) -> int: """Add two numbers together""" return a + b @mcp.tool def multiply(a: int, b: int) -> int: """Multiply two numbers together""" return a * b @mcp.tool def get_user_info(user_id: int) -> dict: """Get user information by ID""" mock_users = { 1: {"name": "Alice", "email": "alice@example.com", "role": "admin"}, 2: {"name": "Bob", "email": "bob@example.com", "role": "user"}, 3: {"name": "Charlie", "email": "charlie@example.com", "role": "user"} } return mock_users.get(user_id, {"error": "User not found"}) # Resources @mcp.resource("resource://server-info") def get_server_info() -> dict: """Provides information about this MCP server""" return { "name": "Demo MCP Server", "version": "1.0.0", "description": "A demonstration MCP server with tools, resources, and prompts", "capabilities": ["tools", "resources", "prompts"], "uptime": str(datetime.datetime.now()) } @mcp.resource("data://users") def get_all_users() -> dict: """Provides a list of all available users""" return { "users": [ {"id": 1, "name": "Alice", "email": "alice@example.com", "role": "admin"}, {"id": 2, "name": "Bob", "email": "bob@example.com", "role": "user"}, {"id": 3, "name": "Charlie", "email": "charlie@example.com", "role": "user"} ], "total_count": 3 } @mcp.resource("config://settings") def get_server_settings() -> dict: """Provides server configuration settings""" return { "theme": "default", "timezone": "UTC", "max_connections": 100, "logging_level": "INFO", "features": { "authentication": False, "rate_limiting": False, "caching": True } } @mcp.resource("data://user/{user_id}") def get_user_resource(user_id: str) -> dict: """Provides detailed information about a specific user""" try: uid = int(user_id) mock_users = { 1: { "id": 1, "name": "Alice", "email": "alice@example.com", "role": "admin", "created_at": "2024-01-01T00:00:00Z", "permissions": ["read", "write", "admin"] }, 2: { "id": 2, "name": "Bob", "email": "bob@example.com", "role": "user", "created_at": "2024-01-02T00:00:00Z", "permissions": ["read"] }, 3: { "id": 3, "name": "Charlie", "email": "charlie@example.com", "role": "user", "created_at": "2024-01-03T00:00:00Z", "permissions": ["read", "write"] } } return mock_users.get(uid, {"error": f"User {user_id} not found"}) except ValueError: return {"error": "Invalid user ID format"} # Prompts @mcp.prompt def analyze_user_data(user_id: int, analysis_type: str = "summary") -> str: """Generate a prompt to analyze user data with specified analysis type""" return f"Please analyze the data for user ID {user_id} and provide a {analysis_type} analysis. Include insights about their role, permissions, and activity patterns." @mcp.prompt def generate_user_report(user_ids: str, report_format: str = "detailed") -> str: """Generate a prompt to create a user report for multiple users""" return f"Create a {report_format} report for users with IDs: {user_ids}. Include user information, roles, and permissions. Format the output as a professional report." @mcp.prompt def system_health_check(component: str = "all") -> str: """Generate a prompt to check system health for specified components""" return f"Perform a health check on the {component} component(s) of the MCP server. Check status, performance metrics, and identify any potential issues." @mcp.prompt def troubleshoot_issue(issue_description: str, severity: str = "medium") -> str: """Generate a troubleshooting prompt for server issues""" return f"Help troubleshoot this {severity} severity issue: {issue_description}. Provide step-by-step debugging instructions and potential solutions." if __name__ == "__main__": mcp.run()

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/shazaaly/mcp-boilerplate'

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