Blog
MCP connects AI to your app. Easy, right?
Connect an AI agent to your app with MCP. Learn how OAuth 2.1, scopes, DCR, and token security protect user accounts and private data in production.

Francisco Gaona
Founder and technical lead
Easy, my arse.
On paper, Model Context Protocol, or MCP, is lovely: define a few tools, connect your app to an AI agent, and it can look up data or take action.
For example:
- Check how your posts are performing.
- Generate a carousel from the content that worked best.
- Find customers in your CRM.
- Create an invoice.
- Turn on the office coffee machine because the sprint has gone to shit.
The promise is simple:
MCP lets an AI use your app’s tools and data.
And it does.
Once that app has real users, private data, and a public URL, more questions show up. A demo where the agent calls a function called get_analytics is fairly easy. Making sure each user sees only their own data, authorizes access, can revoke it, and does not hand their credentials to the first server with a nice name is a different story.
That is where OAuth, scopes, tokens, authorization-server discovery, and the famous DCR come in.
Yes, another acronym. As if we needed more.
MCP, without getting fancy
An MCP server exposes capabilities an agent can discover and use.
Imagine our analytics and carousel-generation app. Instead of making users open the app, check their posts, copy the data, and paste it into a chat, we could offer tools like:
get_top_posts
get_account_analytics
generate_carousel
get_carousel_status
The user could tell their agent:
Analyze my posts from the last month, find the topic that performed best, and create a seven-slide carousel.
The agent checks the analytics, interprets the results, and calls the generator.
MCP lets users work with their app through the agent they already use, without wedging another chatbot into a corner of the interface.
Then comes one tiny, unimportant question:
How does our app know who the hell is making the request?
The demo works. Now come the users
While developing locally, you can use an API key, save it in an environment variable, and pretend the problem is solved.
Works beautifully.
You can also leave your keys under the doormat and call it simplified home access.
In a real app, you need to answer a few questions:
- Which user is connecting the agent?
- Did they authorize that connection?
- Which tools can the agent use?
- Can it read data, or change it too?
- How long does that authorization last?
- How do you renew it?
- How do you revoke it?
- Which server was the token issued for?
- What happens if someone steals that token?
For remote MCP servers over HTTP, the specification uses OAuth 2.1-based authorization. The MCP server acts as a resource server, the agent acts as an OAuth client, and an authorization server identifies the user and issues the relevant tokens (1, 2).
Locally, with stdio, things work differently. Credentials can come through environment variables because the server runs on the user’s own machine. OAuth is designed mainly for remote HTTP connections (1, 2).
OAuth: the nightclub bouncer
OAuth does not prove that an app is wonderful. It controls who gets in and what they can do.
The simplified flow looks like this:
- The agent tries to use our MCP server.
- The server says authorization is required.
- The agent finds out where the user needs to authenticate.
- The user signs in and approves access.
- The agent receives a code.
- That code is exchanged for a token.
- The agent uses the token to call the tools it is allowed to use.
The MCP docs describe the server returning 401 Unauthorized at first and using WWW-Authenticate to point to the information needed to start authorization (2).
In plain English:
You can’t come in. Go over there, prove who you are, and come back with a valid wristband.
The token is the wristband. Scopes decide whether you can get on the dance floor, go upstairs, or end up playing the DJ’s table without anyone knowing how you got there.
Scopes: don’t hand someone a chainsaw to slice bread
Scopes define what the agent can do.
Our app might have something like:
analytics:read
carousels:read
carousels:create
account:read
If the user only wants to check analytics, the agent does not need permission to generate content.
Sounds obvious, but it is common to create one permission called full_access because it is more convenient during development.
And sure, it is more convenient.
Leaving every door open is also convenient when you pop out to buy bread.
A sensible integration should ask for the minimum permissions it needs and expand them only when a specific action requires it.
DCR: who are you?
DCR stands for Dynamic Client Registration.
In traditional OAuth, someone registers each client app in advance and gives it a client_id. That works when you already know which clients will connect.
MCP aims to let different agents discover and connect to different servers. You cannot spend every morning in a dashboard manually registering each new agent that shows up.
With DCR, the client can register itself with the authorization server. It provides details such as:
- Its name.
- Its redirect URIs.
- The response types it uses.
- Its supported authentication method.
- Other metadata needed to complete the flow.
The authorization server returns a client identifier and, where applicable, other registration credentials.
The MCP authorization specification builds on standards including OAuth 2.1, Dynamic Client Registration RFC 7591, Authorization Server Metadata RFC 8414, and Protected Resource Metadata RFC 9728 (1).
On paper:
The agent registers and we carry on.
In practice:
The agent sends a
redirect_uri, the identity provider rejects it, you fix the config, CORS breaks, you fix CORS, and then you find out the token was issued for the wrong resource.
Easy.
How we approached it in our app
In our case, we wanted to connect an agent to an app that does two things:
- Checks content analytics.
- Generates carousels from data, ideas, and existing posts.
We did not want a demo where we controlled both ends. We wanted users to connect their trusted agent while keeping each account’s data and permissions separate. We have also written about connecting GitHub to Microsoft 365 Copilot through MCP.
That meant separating a few pieces:
- MCP server: publishes the available tools.
- App API: performs the actual operations.
- Authorization server: identifies the user and issues tokens.
- MCP client: discovers tools and requests authorization.
- Scopes: limit the allowed operations.
- Token validation: checks that the token matches the right user, permissions, and server.
The MCP server should not trust a token just because it looks legitimate. It needs to check the signature, expiry, audience, and permissions.
The specification requires tokens to be bound to the resource they were issued for and forbids casually passing them to other services. It also recommends short-lived access tokens, secure storage, and refresh-token rotation for public clients (3).
A stolen token does not say:
Hi, I’m an attacker with bad intentions.
It says:
Hi, I’m Francisco, and here’s my perfectly valid token.
Defining the tools is the easy part
Creating an MCP tool is the satisfying bit:
{
"name": "generate_carousel",
"description": "Generate a carousel from a topic",
"inputSchema": {
"type": "object",
"properties": {
"topic": {
"type": "string"
},
"slides": {
"type": "integer"
}
},
"required": ["topic"]
}
}
You look at it and think:
Fuck, that’s it.
It is not.
You still need to decide:
- Which user runs the tool.
- Which account it uses.
- Whether that user can generate content.
- How many carousels they can create.
- What happens when they hit the limit.
- How to return an error the agent can understand.
- What to log so you can audit the operation.
- How to stop the same request from running three times.
- What happens if generation takes two minutes.
- How to stop an agent from making up parameters or actions.
MCP organizes the communication. It does not make the product, security, and architecture decisions for you.
The no-bullshit conclusion
MCP lets an AI use your app’s capabilities. It does not, by itself, solve identity, permissions, user separation, token security, audit trails, usage limits, the authorization experience, or integration errors.
A demo can work in an afternoon. A remote integration that is secure and ready for real users needs a lot more care, especially once OAuth, DCR, scopes, refresh tokens, audiences, and identity providers with strong opinions about your redirect show up.
Before connecting MCP, define what the agent can do on the user’s behalf, which permissions it needs, and how much access you are willing to grant. Without those answers, all you know is that a tool responds in your demo. You do not yet know whether a customer can use it safely.
References
Dealing with something similar?
Tell us what you want to build, fix, or decide. We will tell you what makes sense and what would be a waste of time.
Talk about your projectYou may also find useful
Artificial intelligence / Software / Architecture
MAI Code 2 vs GPT-6.1 Sol: which prepares better technical specs
Read articleArtificial intelligence / Software / Architecture
GPT-6 Luna vs MAI Code 2 Flash: we tested them with our code
Read articleArtificial intelligence / Business and product / Security and compliance / Software