You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/agents/model-context-protocol/mcp-server/authorization.mdx
+12-30Lines changed: 12 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Authorization
3
3
sidebar:
4
4
order: 3
5
5
group:
6
-
hideIndex: false
6
+
hideIndex: true
7
7
---
8
8
9
9
import { DirectoryListing } from"~/components";
@@ -16,40 +16,33 @@ When building a [Model Context Protocol (MCP)](https://modelcontextprotocol.io)
16
16
17
17
The Model Context Protocol uses [a subset of OAuth 2.1 for authorization](https://spec.modelcontextprotocol.io/specification/draft/basic/authorization/). OAuth allows your users to grant limited access to resources, without them having to share API keys or other credentials.
18
18
19
-
Cloudflare provides an [OAuth Provider Library](https://github.com/geelen/mcp-remote-examples/tree/main/.vendor/workers-oauth-provider) that implements the provider side of the OAuth 2.1 protocol, allowing you to easily add authorization to your MCP server.
19
+
Cloudflare provides an [OAuth Provider Library](https://github.com/cloudflare/ai/demos/remote-mcp-server/lib/workers-oauth-provider) that implements the provider side of the OAuth 2.1 protocol, allowing you to easily add authorization to your MCP server.
20
20
21
21
You can use the OAuth Provider Library in three ways:
22
22
23
23
1.**Your Worker handles authorization itself.** Your MCP server, running on Cloudflare, handles the complete OAuth flow. ([Example](/agents/model-context-protocol/mcp-server/getting-started/))
24
-
2.**Integrate with a third-party OAuth provider**, such as GitHub or Google. ([Example](/agents/model-context-protocol/mcp-server/examples/third-party-oauth-provider/))
25
-
3.**Integrate with your own OAuth provider**, including authorization-as-a-service providers such as Stytch and Auth0. ([Example](/agents/model-context-protocol/mcp-server/examples/external-oauth-provider/))
24
+
2.**Integrate directly with a third-party OAuth provider**, such as GitHub or Google. ([Example](/agents/model-context-protocol/mcp-server/examples/github/))
25
+
3.**Integrate with your own OAuth provider**, including authorization-as-a-service providers you might already rely on, such as Stytch and Auth0.
26
26
27
27
The following sections describe each of these options and link to runnable code examples for each.
28
28
29
29
## Authorization options
30
30
31
31
### (1) Your MCP Server handles authorization itself
32
32
33
-
Your MCP Server, using the Cloudflare [MCP Server SDK](/agents/model-context-protocol/mcp-server/getting-started/) and [OAuth Provider Library](/agents/model-context-protocol/mcp-server/authorization/oauth-provider-api-reference/), can handle the complete OAuth authorization flow, without any third-party involvement.
33
+
Your MCP Server, using [`workers-mcp`](/agents/model-context-protocol/mcp-server/getting-started/) and [OAuth Provider Library](/agents/model-context-protocol/mcp-server/authorization/oauth-provider-api-reference/), can handle the complete OAuth authorization flow, without any third-party involvement.
34
34
35
-
The [Workers OAuth Provider Library](/agents/model-context-protocol/mcp-server/authorization/oauth-provider-api-reference/) is a Cloudflare Worker that implements a [`fetch()` handler](/workers/runtime-apis/handlers/fetch/), and handles incoming requests to your MCP server. You provide your own handlers for your MCP Server's API, and autentication and authorization logic, and URI paths for the OAuth endpoints, and the SDK handles the rest.
35
+
The [Workers OAuth Provider Library](/agents/model-context-protocol/mcp-server/authorization/oauth-provider-api-reference/) is a Cloudflare Worker that implements a [`fetch()` handler](/workers/runtime-apis/handlers/fetch/), and handles incoming requests to your MCP server.
36
36
37
-
{/* TODO: Update link */}
38
-
The OAuth Provider Library comes with an [example handler implementation](https://github.com/geelen/mcp-remote-examples/tree/main/02-user-password/src/routes) for autentication and authorization, referenced below as `defaultHandler`:
39
-
40
-
{/* TODO: GithubCodeComponent */}
37
+
You provide your own handlers for your MCP Server's API, and autentication and authorization logic, and URI paths for the OAuth endpoints, as shown below:
41
38
42
39
```ts
43
-
importOAuthProviderfrom"workers-oauth-provider";
44
-
45
-
// TODO: Bunch of naming decisions here
46
40
exportdefaultnewOAuthProvider({
47
41
apiRoute: "/mcp",
48
42
// Your MCP server:
49
43
apiHandler: MyMCPServer.Router,
50
44
// Your handler for authentication and authorization:
51
45
defaultHandler: OAuthProvider.defaultHandler,
52
-
// TODO: Should these have default values?
53
46
authorizeEndpoint: "/authorize",
54
47
tokenEndpoint: "/token",
55
48
clientRegistrationEndpoint: "/register",
@@ -76,28 +69,23 @@ sequenceDiagram
76
69
Note over C,M: Begin standard MCP message exchange
77
70
```
78
71
79
-
Remember — [authentication is different from authorization](https://www.cloudflare.com/learning/access-management/authn-vs-authz/). Your MCP Server can handle authorization itself, while still relying on an external authentication service to first authenticate users. The [example](/agents/model-context-protocol/mcp-server/) in getting started provides a mock authentdcation flow. You will need to implement your own authentication handler — either handling authentication yourself, or using an external authentication service such as Clerk, Stytch, Auth0 or others.
80
-
81
-
For a step-by-step example, refer to the [Worker as OAuth Provider](/agents/model-context-protocol/mcp-server/authorization/worker-as-oauth-provider/) section., and refer to the [API reference docs for the OAuth Provider SDK](/agents/model-context-protocol/mcp-server/authorization/oauth-sdk/).
72
+
Remember — [authentication is different from authorization](https://www.cloudflare.com/learning/access-management/authn-vs-authz/). Your MCP Server can handle authorization itself, while still relying on an external authentication service to first authenticate users. The [example](/agents/model-context-protocol/mcp-server/getting-started) in getting started provides a mock authentdcation flow. You will need to implement your own authentication handler — either handling authentication yourself, or using an external authentication services.
82
73
83
74
### (2) Third-party OAuth Provider
84
75
85
-
The OAuth Provider Library can be configured to use a third-party OAuth provider, such as [GitHub](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) or [Google](https://developers.google.com/identity/protocols/oauth2).
76
+
The OAuth Provider Library can be configured to use a third-party OAuth provider, such as GitHub or Google. You can see a complete example of this in the [GitHub example](/agents/model-context-protocol/mcp-server/examples/github/).
86
77
87
78
When you use a third-party OAuth provider, you must provide a handler to the `OAuthProvider` that implements the OAuth flow for the third-party provider.
88
79
89
-
```ts
90
-
importOAuthProviderfrom"workers-oauth-provider";
80
+
```ts ins="MyAuthHandler"
91
81
importMyAuthHandlerfrom"./auth-handler";
92
82
93
-
// TODO: Bunch of naming decisions here
94
83
exportdefaultnewOAuthProvider({
95
84
apiRoute: "/mcp",
96
85
// Your MCP server:
97
86
apiHandler: MyMCPServer.Router,
98
-
//Your handler for authentication and authorization with the third-party provider:
87
+
//Replace this handler with your own handler for authentication and authorization with the third-party provider:
99
88
defaultHandler: MyAuthHandler,
100
-
// TODO: Should these have default values?
101
89
authorizeEndpoint: "/authorize",
102
90
tokenEndpoint: "/token",
103
91
clientRegistrationEndpoint: "/register",
@@ -134,13 +122,7 @@ Read the docs for the [Workers oAuth Provider Library](/agents/model-context-pro
134
122
135
123
If your application already implements an Oauth Provider itself, or you use Stytch, Auth0, or authorization-as-a-service provider, you can use this in the same way that you would use a third-party OAuth provider, described above in (2).
136
124
137
-
The following examples show how to use the OAuth Provider Library with an external OAuth provider:
-[Learn how to use the OAuth Provider SDK](/agents/model-context-protocol/mcp-server/authorization/oauth-provider-api-reference/)
145
-
-[Learn how to use a third-party OAuth provider](/agents/model-context-protocol/mcp-server/examples/third-party-oauth-provider/)
146
-
-[Learn how to bring your own OAuth provider](/agents/model-context-protocol/mcp-server/examples/external-oauth-provider/)
128
+
- Learn how to use a third-party OAuth provider, using the [GitHub](/agents/model-context-protocol/mcp-server/examples/github/) and [Slack](/agents/model-context-protocol/mcp-server/examples/slack/) examples.
0 commit comments