from agentor.mcp import LiteMCP, Context, get_context, get_token
from fastapi import Depends
import json
app = LiteMCP(
name="production-mcp-server",
version="2.0.0",
instructions="Production-ready MCP server with tools, prompts, and resources"
)
# Tool with authentication
@app.tool(description="Get weather data")
def get_weather(location: str) -> str:
"""Get weather for a location."""
token = get_token()
if not token or token != "valid-token":
return "Error: Unauthorized"
# Mock weather data
return f"Weather in {location}: Sunny, 72°F, Humidity: 45%"
# Tool with context
@app.tool(description="Personalized greeting")
def greet_user(name: str, ctx: Context = Depends(get_context)) -> str:
"""Greet user with personalization."""
session = ctx.cookies.get("session_id", "unknown")
return f"Hello {name}! Session: {session}"
# Prompt template
@app.prompt(description="Generate email draft")
def email_template(recipient: str, topic: str) -> list:
"""Create an email draft template."""
return [{
"role": "user",
"content": {
"type": "text",
"text": f"Draft a professional email to {recipient} about {topic}"
}
}]
# Resource
@app.resource(
uri="data://config",
name="Configuration",
mime_type="application/json"
)
def get_config(uri: str) -> str:
"""Get server configuration."""
config = {
"version": "2.0.0",
"features": ["weather", "greetings", "email"],
"max_requests": 1000
}
return json.dumps(config, indent=2)
if __name__ == "__main__":
app.serve(
host="0.0.0.0",
port=8000,
enable_cors=True
)