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/guides/remote-mcp-server.mdx
+41-13Lines changed: 41 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,7 +112,7 @@ This is especially useful if users already need to log in to use your service. O
112
112
113
113
In this example, we use GitHub as an OAuth provider, but you can connect your MCP server with any [OAuth provider](/agents/model-context-protocol/authorization/#2-third-party-oauth-provider) that supports the OAuth 2.0 specification, including Google, Slack, [Stytch](/agents/model-context-protocol/authorization/#stytch), [Auth0](/agents/model-context-protocol/authorization/#stytch), [WorkOS](/agents/model-context-protocol/authorization/#stytch), and more.
114
114
115
-
### Step 1 — Create and deploy a new MCP server
115
+
### Step 1 — Create a new MCP server
116
116
117
117
Run the following command to create a new MCP server:
118
118
@@ -130,12 +130,6 @@ Now, you have the MCP server setup, with dependencies installed. Move into that
130
130
cd my-mcp-server-github-auth
131
131
```
132
132
133
-
Then, run the following command to deploy the MCP server:
134
-
135
-
```sh
136
-
npx wrangler@latest deploy
137
-
```
138
-
139
133
You'll notice that in the example MCP server, if you open `src/index.ts`, the primary difference is that the `defaultHandler` is set to the `GitHubHandler`:
140
134
141
135
```ts ins="OAuthProvider.GitHubHandler"
@@ -162,8 +156,8 @@ You'll need to create two [GitHub OAuth Apps](https://docs.github.com/en/apps/oa
162
156
Navigate to [github.com/settings/developers](https://github.com/settings/developers) to create a new OAuth App with the following settings:
For the OAuth app you just created, add the client ID of the OAuth app as `GITHUB_CLIENT_ID` and generate a client secret, adding it as `GITHUB_CLIENT_SECRET` to a `.dev.vars` file in the root of your project, which [will be used to set secrets in local development](/workers/configuration/secrets/).
169
163
@@ -182,8 +176,7 @@ Run the following command to start the development server:
182
176
npm start
183
177
```
184
178
185
-
Your MCP server is now running on `http://localhost:8787/sse`.
186
-
179
+
Your MCP server is now running on `http://localhost:8788/sse`.
187
180
In a new terminal, run the [MCP inspector](https://github.com/modelcontextprotocol/inspector). The MCP inspector is an interactive MCP client that allows you to connect to your MCP server and invoke tools from a web browser.
188
181
189
182
```sh
@@ -196,9 +189,13 @@ Open the MCP inspector in your web browser:
196
189
open http://localhost:5173
197
190
```
198
191
199
-
In the inspector, enter the URL of your MCP server, `http://localhost:8787/sse`, and click **Connect**:
192
+
In the inspector, set **Transport Type** to `SSE` and enter the URL of your MCP server, `http://localhost:8788/sse`
193
+
194
+
In the main panel on the right, click the **Open OAuth Settings** button and then click **Quick OAuth Flow**.
195
+
196
+
You should be redirected to a GitHub login or authorization page. After authorizing the MCP Client (the inspector) access to your GitHub account, you will be redirected back to the inspector.
200
197
201
-
You should be redirected to a GitHub login or authorization page. After authorizing the MCP Client (the inspector) access to your GitHub account, you will be redirected back to the inspector. You should see the "List Tools" button, which will list the tools that your MCP server exposes.
198
+
Click **Connect** in the sidebar and you should see the "List Tools" button, which will list the tools that your MCP server exposes.
202
199
203
200
#### Second — create a new OAuth App for production
204
201
@@ -220,6 +217,37 @@ wrangler secret put GITHUB_CLIENT_ID
220
217
wrangler secret put GITHUB_CLIENT_SECRET
221
218
```
222
219
220
+
```
221
+
npx wrangler secret put COOKIE_ENCRYPTION_KEY # add any random string here e.g. openssl rand -hex 32
222
+
```
223
+
224
+
> [!IMPORTANT]
225
+
> When you create the first secret, Wrangler will ask if you want to create a new Worker. Submit "Y" to create a new Worker and save the secret.
226
+
227
+
#### Set up a KV namespace
228
+
- Create the KV namespace:
229
+
```bash
230
+
npx wrangler kv namespace create "OAUTH_KV"
231
+
```
232
+
- Update the `wrangler.jsonc` file with the resulting KV ID:
233
+
234
+
```json
235
+
{
236
+
"kvNamespaces": [
237
+
{
238
+
"binding": "OAUTH_KV",
239
+
"id": "<YOUR_KV_NAMESPACE_ID>"
240
+
}
241
+
]
242
+
}
243
+
```
244
+
#### Deploy your server
245
+
246
+
Deploy the MCP server to your Cloudflare `workers.dev` domain:
247
+
```bash
248
+
npm run deploy
249
+
```
250
+
223
251
#### Finally, connect to your MCP server
224
252
225
253
Now that you've added the ID and secret of your production OAuth app, you should now be able to connect to your MCP server running at `worker-name.account-name.workers.dev/sse` using the [AI Playground](https://playground.ai.cloudflare.com/), MCP inspector or ([other MCP clients](/agents/guides/remote-mcp-server/#connect-your-mcp-server-to-claude-and-other-mcp-clients)), and authenticate with GitHub.
0 commit comments