Skip to content

Commit f9e1bc1

Browse files
authored
Update remote-mcp-server.mdx to address various errors and new features. Fixes #23998
1 parent cbe2de1 commit f9e1bc1

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/content/docs/agents/guides/remote-mcp-server.mdx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ This is especially useful if users already need to log in to use your service. O
112112

113113
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.
114114

115-
### Step 1 — Create and deploy a new MCP server
115+
### Step 1 — Create a new MCP server
116116

117117
Run the following command to create a new MCP server:
118118

@@ -130,12 +130,6 @@ Now, you have the MCP server setup, with dependencies installed. Move into that
130130
cd my-mcp-server-github-auth
131131
```
132132

133-
Then, run the following command to deploy the MCP server:
134-
135-
```sh
136-
npx wrangler@latest deploy
137-
```
138-
139133
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`:
140134

141135
```ts ins="OAuthProvider.GitHubHandler"
@@ -162,8 +156,8 @@ You'll need to create two [GitHub OAuth Apps](https://docs.github.com/en/apps/oa
162156
Navigate to [github.com/settings/developers](https://github.com/settings/developers) to create a new OAuth App with the following settings:
163157

164158
- **Application name**: `My MCP Server (local)`
165-
- **Homepage URL**: `http://localhost:8787`
166-
- **Authorization callback URL**: `http://localhost:8787/callback`
159+
- **Homepage URL**: `http://localhost:8788`
160+
- **Authorization callback URL**: `http://localhost:8788/callback`
167161

168162
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/).
169163

@@ -182,8 +176,7 @@ Run the following command to start the development server:
182176
npm start
183177
```
184178

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`.
187180
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.
188181

189182
```sh
@@ -196,9 +189,13 @@ Open the MCP inspector in your web browser:
196189
open http://localhost:5173
197190
```
198191

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.
200197

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.
202199

203200
#### Second — create a new OAuth App for production
204201

@@ -220,6 +217,37 @@ wrangler secret put GITHUB_CLIENT_ID
220217
wrangler secret put GITHUB_CLIENT_SECRET
221218
```
222219

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+
223251
#### Finally, connect to your MCP server
224252

225253
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

Comments
 (0)