Serve Django and MCP from one uvicorn process #144
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
CrowderSoup/vTodo!144
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/asgi-mcp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes vTodo task #687 (Crowder Cloud workspace).
What changes
uvicorn config.asgi:applicationreplaces Gunicorn.config/asgi.pysends requests for the host ofVTODO_MCP_PUBLIC_URL(mcp.vtodo.crowdersoup.com) to the MCP app:/mcp,/.well-known/oauth-protected-resource…,/up, plus the CORS headers and preflight the old server had. Every other request goes to Django, inside vJournal'sThreadSensitiveContextguard, which returns the DB connection onCancelledErroror a disconnect./mcppath and the OAuth resource (token audience) are all unchanged. kamal-proxy now routes both hosts to the web role.VtodoClient, butmcp_server/inprocess.pyis arequestsadapter that hands each request to Django's WSGI handler on the tool's worker thread. So the API's checks still apply in one place: OAuth scope and audience, workspace roles, act-as, and themcpsource in the activity log. The whoami token check goes the same way. Sentry trace headers are passed along, so a tool call and its API requests are still one trace.python -m mcp_serveris now stdio only (oneVTODO_API_TOKENaccount against a remote vtodo). The standalone SSE/uvicorn mode is gone.CONN_MAX_AGEconnections. This switches to psycopg 3 with a pool per web process, the same as vJournal: max 10 behind PgBouncer, withprepare_threshold=None. The Celery worker role setsDB_POOL=Falseand keeps its persistent connections.mcprole is removed fromconfig/deploy.yml. Because kamal-proxy won't give web a host that another service still holds, the deploy workflow now runskamal build push, then removes the oldvtodo-mcpproxy service and container, then runskamal deploy --skip-push. MCP should only be down for the time it takes web to boot. Once the old service is gone, that step does nothing.Testing
makemigrations --checkis clean.tests/test_asgi.pycovers host dispatch, a real OAuth token through whoami, in-process tool calls (includingsource=mcpin the activity log), the 401 challenge, CORS preflight, and the metadata endpoint. The existing MCP HTTP tests now authenticate, because OAuth is always on over HTTP.create_taskandlist_tasksworked over MCP. 60 concurrent tool calls left 6 pooled connections, with no errors. Stdioinitializestill works.Before merging
The deploy sets
VTODO_API_URL=https://vtodo.crowdersoup.comin the shared env. That value is the OAuth issuer the MCP metadata advertises, so it has to match what django-oauth-toolkit reports. It's the same value the old mcp role used.🤖 Generated with Claude Code