# What is OAuth, and how does an AI agent use it to sign in to an MCP server?

The standard way to let one app act for you at another service without giving it your password; the app gets a limited, revocable access token instead. MCP servers use it to let AI agents sign in.

- Page: https://tecyfy.com/concepts/oauth
- Subject: AI agents (https://tecyfy.com/concepts)
- Level: intermediate
- Also called: OAuth 2.0, OAuth 2.1, OAuth client ID

When an AI agent needs to reach your data at another service, there are 2 ways to let it in. You can paste a long-lived key or password into its settings, or you can use OAuth: the agent sends you to the service's own sign-in page, you approve, and the agent receives an access token that works only for what you approved and can be taken back. OAuth 2.0 was set out by the IETF in RFC 6749 in 2012 and replaced OAuth 1.0; MCP builds on OAuth 2.1, a draft that updates it.

## The parts of an OAuth sign-in

- **The client** is the app that wants access: Claude Code, Cursor, ChatGPT.
- **The resource server** holds what the client wants. For an agent, that is the [MCP](https://tecyfy.com/concepts/model-context-protocol) server with the tools.
- **The authorization server** signs you in and issues tokens. It can be part of the same service or a separate one.
- **The access token** is what the client sends with each request instead of a password. A **refresh token** lets the client get a new access token without asking you again.

The client never sees your password, and the access it gets is the limited access you approved.

## How MCP uses OAuth

The MCP specification makes OAuth the standard sign-in for a protected MCP server. The server acts as an OAuth 2.1 resource server, the agent as an OAuth 2.1 client, and the flow uses PKCE (Proof Key for Code Exchange), which RFC 7636 added against an attack where the sign-in code is intercepted on its way back to the client. Tokens travel in a header, never in the address, and the server must check that each token was issued for it.

Before any of that, the client needs a **client ID**, the name the authorization server knows it by. MCP allows 3 ways to get one, in this order of preference:

1. **Pre-registration:** an admin created an OAuth app for this client on the service already.
2. **Client ID Metadata Documents:** the client ID is an `https` URL pointing to a small JSON file the client's maker publishes, with its name and allowed redirect addresses. The server reads the file, so nobody has to register anything.
3. **Dynamic Client Registration:** the client registers itself on the fly. The specification now marks this as deprecated, kept for older servers.

This is why some services ask you to paste a URL as the client ID. Databricks, for example, publishes ready OAuth apps for Claude Code, Claude, ChatGPT, Codex and Cursor whose client IDs are such URLs, and its MCP servers do not accept dynamic registration, so an agent that does not send a known client ID fails to sign in. Our guide to [connecting AI agents to Databricks MCP](/blog/connect-ai-agents-to-databricks-mcp) gives each client's exact setting.

Where an agent offers both, Databricks' own advice is the general one: OAuth reduces reliance on long-lived personal access tokens.

## Related

- [Model Context Protocol](https://tecyfy.com/concepts/model-context-protocol): An open standard for connecting AI applications to tools and data. A system offered once as an MCP server works in any application that speaks MCP.
- [API](https://tecyfy.com/concepts#api): Application Programming Interface - a set of protocols and tools for building software applications
- [Agent](https://tecyfy.com/concepts/agent): A model that uses tools in a loop, deciding each next step from what the last one returned, until the task is done.
- [Tool Use](https://tecyfy.com/concepts/tool-use): Giving a model a list of things it can ask to have done, such as search the web or read a file. The model asks; the program around it does the work and hands back the result.

## Sources

- [RFC 6749: The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749)
- [RFC 7636: Proof Key for Code Exchange by OAuth Public Clients](https://www.rfc-editor.org/rfc/rfc7636)
- [Authorization](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization)
- [Client Registration](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization/client-registration)
- [Connect to AI agent partners](https://docs.databricks.com/aws/en/partner-connect/ai-agents)
