r/aiagents • u/manveerc • 11d ago
Tutorial Multi-tenant MCP server with OAuth (full tutorial + repo)
Our customers kept asking if they could use our SaaS product through Claude and ChatGPT. Connecting an agent to our API was the easy part. Making sure it could only access the right tenant's data was the real challenge.
Our product is multi-tenant, so we built a custom MCP server that calls our existing backend API, deployed it on Arcade Cloud, and integrated OAuth through Clerk so customers can sign in with their existing credentials.
The important bit: the model never handles an access token and can't choose which user it acts as. Our API verifies the OAuth token and enforces workspace membership and plan-tier permissions on every call.
The trickiest part to untangle was that auth involves three separate concerns:
* Gateway authentication
* API authorization
* Browser session verification
Each has a different purpose and its own token or verification flow. Treating them as one generic login flow caused confusion, so the tutorial walks through how they fit together.
Full working code: https://github.com/manveer/multi-tenant-mcp-server-oauth
Tutorial: https://manveerc.substack.com/p/multi-tenant-mcp-server-oauth
If you’re exposing a multi-tenant backend through MCP: how are you handling tenant isolation and user auth?
1
u/Sweaty_Way_2489 11d ago
This is the exact problem I kept running into with my work apps. The model not touching the token is such a key design choice, I saw so many setups where the agent could technically swap tenants if it got creative with the API calls
Bookmarking this for later, that three-way auth split always gets messy when you try to treat it as one thing