Skip to main content
Glama

FastAPI MCP Server

by arrehman3
sample_app.py2.89 kB
from fastapi import FastAPI, HTTPException from pydantic import BaseModel from typing import List, Optional import uvicorn from datetime import datetime app = FastAPI(title="Sample FastAPI App", version="1.0.0") # Data models class User(BaseModel): id: Optional[int] = None name: str email: str age: int class Task(BaseModel): id: Optional[int] = None title: str description: str completed: bool = False user_id: int # In-memory storage (for demo purposes) users_db = [] tasks_db = [] next_user_id = 1 next_task_id = 1 @app.get("/") async def root(): return {"message": "Welcome to Sample FastAPI App", "timestamp": datetime.now()} @app.get("/health") async def health_check(): return {"status": "healthy", "timestamp": datetime.now()} # User endpoints @app.get("/users", response_model=List[User]) async def get_users(): return users_db @app.post("/users", response_model=User) async def create_user(user: User): global next_user_id user.id = next_user_id next_user_id += 1 users_db.append(user) return user @app.get("/users/{user_id}", response_model=User) async def get_user(user_id: int): for user in users_db: if user.id == user_id: return user raise HTTPException(status_code=404, detail="User not found") # Task endpoints @app.get("/tasks", response_model=List[Task]) async def get_tasks(): return tasks_db @app.post("/tasks", response_model=Task) async def create_task(task: Task): global next_task_id task.id = next_task_id next_task_id += 1 tasks_db.append(task) return task @app.get("/tasks/{task_id}", response_model=Task) async def get_task(task_id: int): for task in tasks_db: if task.id == task_id: return task raise HTTPException(status_code=404, detail="Task not found") @app.put("/tasks/{task_id}", response_model=Task) async def update_task(task_id: int, task_update: Task): for i, task in enumerate(tasks_db): if task.id == task_id: task_update.id = task_id tasks_db[i] = task_update return task_update raise HTTPException(status_code=404, detail="Task not found") @app.delete("/tasks/{task_id}") async def delete_task(task_id: int): for i, task in enumerate(tasks_db): if task.id == task_id: del tasks_db[i] return {"message": "Task deleted successfully"} raise HTTPException(status_code=404, detail="Task not found") # Statistics endpoint @app.get("/stats") async def get_stats(): return { "total_users": len(users_db), "total_tasks": len(tasks_db), "completed_tasks": len([task for task in tasks_db if task.completed]), "pending_tasks": len([task for task in tasks_db if not task.completed]) } if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)

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/arrehman3/MCP'

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