xiaohongshu
xiaohongshu
mcp-server
This skill should be used when setting up a stateless MCP (Model Context Protocol) server in FastAPI using the Official MCP SDK with 5 task management tools that interact with SQLModel database.
Full skill instructions
This skill provides guidance for setting up a stateless MCP server using the Official MCP SDK in FastAPI.
Create a stateless MCP server that provides 5 task management tools (add_task, list_tasks, complete_task, delete_task, update_task) with proper user isolation, database integration, and error handling.
Use this skill when:
backend/
├── mcp_server.py # Main MCP server with FastAPI integration
├── mcp_tools.py # Tool implementations
├── mcp_config.py # Server configuration
└── main.py # Updated with MCP server startup
| Tool | Parameters | Returns |
|---|---|---|
add_task | user_id: str, title: str, description?: str, priority?: int, due_date?: str | {success: bool, task_id: str, task: dict} |
list_tasks | user_id: str, status?: str, priority?: int | {success: bool, tasks: list[dict]} |
complete_task | user_id: str, task_id: str | {success: bool, task: dict} |
delete_task | user_id: str, task_id: str | {success: bool, deleted_task_id: str} |
update_task | user_id: str, task_id: str, title?: str, description?: str, priority?: int, due_date?: str | {success: bool, task: dict} |
from mcp.server.fastapi import FastAPIMCP
from fastapi import FastAPI
app = FastAPI()
mcp_server = FastAPIMCP(app)
@mcp_server.tool()
async def add_task(user_id: str, title: str, description: str = None) -> dict:
"""Add a new task for the specified user."""
# Extract user_id from context
# Validate parameters
# Execute with user_id filter: WHERE user_id = :user_id
# Return structured JSON response
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
engine = create_async_engine(DATABASE_URL)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async def get_db_session():
async with async_session() as session:
yield session
async def add_task(user_id: str, title: str, ...) -> dict:
if not user_id:
raise ValueError("user_id is required")
# Always filter by user_id in queries
statement = select(Task).where(
Task.id == task_id,
Task.user_id == user_id # Critical for isolation
)
For each tool, implement:
| Status | Condition | Example |
|---|---|---|
| 400 | Invalid input parameters | Missing required fields, invalid types |
| 401 | Missing/unauthorized user | No user_id provided |
| 403 | User not authorized | user_id doesn't match resource owner |
| 404 | Resource not found | Task doesn't exist |
| 500 | Internal error | Database connection failed |
Design tools to support chaining:
async def complete_task(user_id: str, task_id: str) -> dict:
"""Mark a task as complete. Can be called by other tools."""
task = await get_task_by_id(user_id, task_id)
if task:
task.completed = True
await session.commit()
return {"success": True, "task": task_to_dict(task)}
async def list_tasks(user_id: str, status: str = None) -> dict:
"""List tasks. Supports filtering by status."""
# This can chain to complete_task or other tools
mcp>=0.9.0
fastapi>=0.100.0
sqlmodel>=0.0.14
sqlalchemy>=2.0.0
cd backend
uvicorn mcp_server:app --host 0.0.0.0 --port 8001
# main.py
from mcp_server import mcp
app = FastAPI()
app.include_router(mcp.router)
@app.on_event("startup")
async def startup():
await mcp.run()
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience