Skip to content
Back to search

mcp-remote

Connect an MCP Client that only supports local (stdio) servers to a Remote MCP Server.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/punkpeye--mcp-remote/badge.svg)](/listings/punkpeye--mcp-remote)

HTML

<a href="/listings/punkpeye--mcp-remote"><img src="/api/listings/punkpeye--mcp-remote/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 767 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. # `mcp-remote`
  2. Connect an MCP Client that only supports local (stdio) servers to a Remote MCP Server, with auth support:
  3. ## Why is this necessary?
  4. So far, the majority of MCP servers in the wild are installed locally, using the stdio transport. This has some benefits: both the client and the server can implicitly trust each other as the user has granted them both permission to run. Adding secrets like API keys can be done using environment variables and never leave your machine. And building on `npx` and `uvx` has allowed users to avoid explicit install steps, too.
  5. But there's a reason most software that _could_ be moved to the web _did_ get moved to the web: it's so much easier to find and fix bugs & iterate on new features when you can push updates to all your users with a single deploy.
  6. With the latest MCP [Authorization specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization), we now have a secure way of sharing our MCP servers with the world _without_ running code on user's laptops. Or at least, you would, if all the popular MCP _clients_ supported it yet. Most are stdio-only, and those that _do_ support HTTP+SSE don't yet support the OAuth flows required.
  7. That's where `mcp-remote` comes in. As soon as your chosen MCP client supports remote, authorized servers, you can remove it. Until that time, drop in this one liner and dress for the MCP clients you want!
  8. ## Usage
  9. All the most popular MCP clients (Claude Desktop, Cursor & Windsurf) use the following config format:
  10. ```json
  11. {
  12. "mcpServers": {
  13. "remote-example": {
  14. "command": "npx",
  15. "args": [
  16. "mcp-remote",
  17. "https://remote.mcp.server/sse"
  18. ]
  19. }
  20. }
  21. }
  22. ```
  23. ### Custom Headers
  24. To bypass authentication, or to emit custom headers on all requests to your remote server, pass `--header` CLI arguments:
  25. ```json
  26. {
  27. "mcpServers": {
  28. "remote-example": {
  29. "command": "npx",
  30. "args": [
  31. "mcp-remote",
  32. "https://remote.mcp.server/sse",
  33. "--header",
  34. "Authorization: Bearer ${AUTH_TOKEN}"
  35. ],
  36. "env": {
  37. "AUTH_TOKEN": "..."
  38. }
  39. },
  40. }
  41. }
  42. ```
  43. **Note:** Cursor, Codex-Cli and Claude Desktop (Windows) have a bug where spaces inside `args` aren't escaped when it invokes `npx`, which ends up mangling these values. You can work around it using:
  44. ```jsonc
  45. {
  46. // rest of config...
  47. "args": [
  48. "mcp-remote",
  49. "https://remote.mcp.server/sse",
  50. "--header",
  51. "Authorization:${AUTH_HEADER}" // note no spaces around ':'
  52. ],
  53. "env": {
  54. "AUTH_HEADER": "Bearer <auth-token>" // spaces OK in env vars
  55. }
  56. },
  57. ```
  58. To keep a credential out of the process arguments — where any other user on the machine can read it from the process list — put the headers in a file instead and pass `--header-file`. One `Name: value` per line; `#` starts a comment.
  59. ```json
  60. "args": [
  61. "mcp-remote",
  62. "https://remote.mcp.server/sse",
  63. "--header-file",
  64. "/path/to/headers.txt"
  65. ]
  66. ```
  67. ```
  68. # credentials for the example server
  69. Authorization: Bearer my-token
  70. X-Custom-Header: custom-value
  71. ```
  72. A file that cannot be read is an error rather than a warning, so a mistyped path fails immediately instead of sending the request unauthenticated.
  73. ### Multiple Instances
  74. To run multiple instances of the same remote server with different configurations (e.g., different Atlassian tenants), use the `--resource` flag to isolate OAuth sessions:
  75. ```json
  76. {
  77. "mcpServers": {
  78. "atlassian_tenant1": {
  79. "command": "npx",
  80. "args": [
  81. "mcp-remote",
  82. "https://mcp.atlassian.com/v1/sse",
  83. "--resource",
  84. "https://tenant1.atlassian.net/"
  85. ]
  86. },
  87. "atlassian_tenant2": {
  88. "command": "npx",
  89. "args": [
  90. "mcp-remote",
  91. "https://mcp.atlassian.com/v1/sse",
  92. "--resource",
  93. "https://tenant2.atlassian.net/"
  94. ]
  95. }
  96. }
  97. }
  98. ```
  99. Each unique combination of server URL, resource, custom headers, and `--authorize-param` values will maintain separate OAuth sessions and token storage.
  100. The `--resource` value is sent as the RFC 8707 resource indicator on the authorization, token and
  101. refresh requests alike, so they always agree.
  102. ### Extra authorization parameters
  103. Some authorization servers require parameters of their own on the authorize call. Pass each as
  104. `--authorize-param key=value`, repeating the flag as needed:
  105. ```json
  106. "args": [
  107. "mcp-remote",
  108. "https://remote.mcp.server/mcp",
  109. "--authorize-param",
  110. "access_type=offline",
  111. "--authorize-param",
  112. "prompt=consent"
  113. ]
  114. ```
  115. Those two are what Google wants before it will part with a refresh token — it does not recognise the
  116. `offline_access` scope. Auth0 wants `audience=https://your-api` to issue a JWT rather than an opaque
  117. token. `login_hint=user@example.com` is also common.
  118. These apply to the authorization request only. `resource` is the exception: RFC 8707 wants the same
  119. value on the token and refresh requests too, and only `--resource` puts it there. Parameters the flow
  120. derives per request — `state`, `code_challenge`, `client_id`, `redirect_uri`, `response_type` — are
  121. refused, because a value that disagrees with the real one surfaces as an opaque server error.
  122. Changing these starts a new sign-in, since a parameter like `audience` decides which API the token is
  123. for and a token issued for one is not valid for another.
  124. Some authorization servers reject the resource parameter outright — Microsoft Entra ID v2 answers
  125. `AADSTS9010010`, for example. Pass `--disable-resource-parameter` to omit it entirely:
  126. ```json
  127. {
  128. "mcpServers": {
  129. "entra-example": {
  130. "command": "npx",
  131. "args": [
  132. "mcp-remote",
  133. "https://remote.mcp.server/mcp",
  134. "--disable-resource-parameter"
  135. ]
  136. }
  137. }
  138. }
  139. ```
  140. ### Flags
  141. * If `npx` is producing errors, consider adding `-y` as the first argument to auto-accept the installation of the `mcp-remote` package.
  142. ```json
  143. "command": "npx",
  144. "args": [
  145. "-y",
  146. "mcp-remote",
  147. "https://remote.mcp.server/sse"
  148. ]
  149. ```
  150. * To force `npx` to always check for an updated version of `mcp-remote`, add the `@latest` flag:
  151. ```json
  152. "args": [
  153. "mcp-remote@latest",
  154. "https://remote.mcp.server/sse"
  155. ]
  156. ```
  157. * To change which port `mcp-remote` listens for an OAuth redirect, add an additional argument after the server URL. By default the port is derived from the server URL, so every server gets a stable port of its own somewhere in `3335`-`49150`, and `mcp-remote` walks up to 8 ports from there if it finds one taken. A port you pass explicitly is used as-is: it implies a `redirect_uri` the authorization server has already been given, so `mcp-remote` fails rather than quietly moving to a different one. `--static-oauth-client-info` pins the port the same way, for the same reason.
  158. ```json
  159. "args": [
  160. "mcp-remote",
  161. "https://remote.mcp.server/sse",
  162. "9696"
  163. ]
  164. ```
  165. * To change which host `mcp-remote` registers as the OAuth callback URL (by default `localhost`), add the `--host` flag. An IPv6 address may be given with or without brackets; pair an IPv6 loopback address with `--bind-host ::1`, since the server listens on IPv4 loopback by default.
  166. ```json
  167. "args": [
  168. "mcp-remote",
  169. "https://remote.mcp.server/sse",
  170. "--host",
  171. "127.0.0.1"
  172. ]
  173. ```
  174. * To change the address the OAuth callback server listens on (by default `127.0.0.1`), add the `--bind-host` flag. In a container, use `0.0.0.0` so the browser's redirect reaches the published callback port; `--host` still sets the host in the callback URL, so it can stay `localhost`. With `--bind-host ::1` the callback URL defaults to `[::1]` instead, because `127.0.0.1` does not reach a server listening only on IPv6 loopback, and `localhost` may resolve to it; pass `--host` to override that. An empty value is ignored, so the server keeps listening on loopback. Anything that can reach the port can send it a callback, so publish it on the host's loopback only, e.g. `docker run -p 127.0.0.1:9696:9696 …`.
  175. ```json
  176. "args": [
  177. "mcp-remote",
  178. "https://remote.mcp.server/sse",
  179. "9696",
  180. "--bind-host",
  181. "0.0.0.0"
  182. ]
  183. ```
  184. * To change the path `mcp-remote` serves the OAuth callback on (by default `/oauth/callback`), add the `--callback-path` flag. The path must start with `/`, and `/wait-for-auth` is reserved.
  185. ```json
  186. "args": [
  187. "mcp-remote",
  188. "https://remote.mcp.server/sse",
  189. "--callback-path",
  190. "/custom/callback"
  191. ]
  192. ```
  193. * To send the browser to your own completion page after a successful OAuth token exchange, add `--auth-success-url`. The registered callback URL, state, PKCE flow and credential cache stay unchanged. No code, state, issuer or tokens are appended to the completion URL. Without this flag, the existing completion page is unchanged.
  194. ```json
  195. "args": [
  196. "mcp-remote",
  197. "https://remote.mcp.server/sse",
  198. "--auth-success-url",
  199. "https://app.example.com/cli-connected"
  200. ]
  201. ```
  202. The destination must be HTTPS, or HTTP on loopback. For HTTP on a trusted private network, also pass `--allow-http`. URLs containing credentials, a query or a fragment are rejected. A failed or timed-out exchange shows an error on the callback page instead of redirecting. `--auth-timeout` also bounds this wait (30 seconds by default). The option applies to browser authentication in both binaries, including mid-session reauthorization; device-code and client-credentials authentication have no browser callback.
  203. * To allow HTTP connections in trusted private networks, add the `--allow-http` flag. Note: This should only be used in secure private networks where traffic cannot be intercepted.
  204. ```json
  205. "args": [
  206. "mcp-remote",
  207. "http://internal-service.vpc/sse",
  208. "--allow-http"
  209. ]
  210. ```
  211. * To enable detailed debugging logs, add the `--debug` flag. This will write verbose logs to `~/.mcp-auth/{server_hash}_debug.log` with timestamps and detailed information about the auth process, connections, and token refreshing.
  212. ```json
  213. "args": [
  214. "mcp-remote",
  215. "https://remote.mcp.server/sse",
  216. "--debug"
  217. ]
  218. ```
  219. * To suppress default logs, add the `--silent` flag. This will prevent logs from being emitted, except in the case where `--debug` is also passed.
  220. ```json
  221. "args": [
  222. "mcp-remote",
  223. "https://remote.mcp.server/sse",
  224. "--silent"
  225. ]
  226. ```
  227. * To enable an outbound HTTP(S) proxy for mcp-remote, add the `--enable-proxy` flag. When enabled, mcp-remote will use the proxy settings from common environment variables (for example `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`).
  228. ```json
  229. "args": [
  230. "mcp-remote",
  231. "https://remote.mcp.server/sse",
  232. "--enable-proxy"
  233. ],
  234. "env": {
  235. "HTTPS_PROXY": "http://127.0.0.1:3128",
  236. "NO_PROXY": "localhost,127.0.0.1"
  237. }
  238. ```
  239. * To ignore specific tools from the remote server, add the `--ignore-tool` flag. This will filter out tools matching the specified patterns from both `tools/list` responses and block `tools/call` requests. Supports wildcard patterns with `*`.
  240. ```json
  241. "args": [
  242. "mcp-remote",
  243. "https://remote.mcp.server/sse",
  244. "--ignore-tool",
  245. "delete*",
  246. "--ignore-tool",
  247. "remove*"
  248. ]
  249. ```
  250. You can specify multiple `--ignore-tool` flags to ignore different patterns. Examples:
  251. - `delete*` - ignores all tools starting with "delete" (e.g., `deleteTask`, `deleteUser`)
  252. - `*account` - ignores all tools ending with "account" (e.g., `getAccount`, `updateAccount`)
  253. - `exactTool` - ignores only the tool named exactly "exactTool"
  254. * To change the timeout for the OAuth callback (by default `30` seconds), add the `--auth-timeout` flag with a value in seconds. This is useful if the authentication process on the server side takes a long time.
  255. ```json
  256. "args": [
  257. "mcp-remote",
  258. "https://remote.mcp.server/sse",
  259. "--auth-timeout",
  260. "60"
  261. ]
  262. ```
  263. * To change the network timeouts, add `--connect-timeout`, `--headers-timeout` or `--body-timeout`, each with a value in seconds. These apply to every outbound request, including the OAuth ones.
  264. * `--connect-timeout` bounds establishing the TCP connection (default `10`). Lower it to fail faster on an unreachable server.
  265. * `--headers-timeout` bounds waiting for response headers (default `300`).
  266. * `--body-timeout` bounds a gap between chunks of a response body (default `300`). This is the one that closes an idle SSE stream after five minutes; pass `0` to disable it for servers that push infrequently.
  267. ```json
  268. "args": [
  269. "mcp-remote",
  270. "https://remote.mcp.server/sse",
  271. "--connect-timeout",
  272. "30",
  273. "--body-timeout",
  274. "0"
  275. ]
  276. ```
  277. * To stop an idle connection being dropped, add the `--keep-alive` flag. The proxy then sends a `ping` every 30 seconds, which is enough traffic to keep a server — or a load balancer in front of one — from reaping a session that has been quiet for a few minutes. Use `--ping-interval` with a value in seconds to change the period; setting it turns keep-alive on, so the two flags are only both needed when you want the default period spelled out.
  278. This is the opposite end of the problem from `--body-timeout`: that one governs how long *we* wait, whereas this keeps the *other* side from hanging up.
  279. ```json
  280. "args": [
  281. "mcp-remote",
  282. "https://remote.mcp.server/sse",
  283. "--keep-alive",
  284. "--ping-interval",
  285. "60"
  286. ]
  287. ```
  288. * To connect over IPv4 only, add the `--ipv4` flag. Useful when a hostname resolves to both IPv4 and IPv6 addresses but the IPv6 routes silently black-hole rather than being refused — connection attempts then time out instead of failing over, and the request never completes.
  289. ```json
  290. "args": [
  291. "mcp-remote",
  292. "https://remote.mcp.server/sse",
  293. "--ipv4"
  294. ]
  295. ```
  296. ### Transport Strategies
  297. MCP Remote supports different transport strategies when connecting to an MCP server. This allows you to control whether it uses Server-Sent Events (SSE) or HTTP transport, and in what order it tries them.
  298. Specify the transport strategy with the `--transport` flag:
  299. ```bash
  300. npx mcp-remote https://example.remote/server --transport sse-only
  301. ```
  302. **Available Strategies:**
  303. - `http-first` (default): Tries HTTP transport first, falls back to SSE if HTTP fails with a 404 error
  304. - `sse-first`: Tries SSE transport first, falls back to HTTP if SSE fails with a 405 error
  305. - `http-only`: Only uses HTTP transport, fails if the server doesn't support it
  306. - `sse-only`: Only uses SSE transport, fails if the server doesn't support it
  307. ### Protocol Eras (2026-07-28 servers)
  308. The `2026-07-28` revision of MCP retired the `initialize` handshake and the session behind it. A
  309. server that implements it serves stateless requests that each carry their own protocol version and
  310. capabilities, and advertises itself through `server/discover` instead of answering a handshake.
  311. Most desktop hosts still speak the `2025-11-25` era. The specification's compatibility matrix puts
  312. that pair — legacy client, modern server — in the one cell that simply fails, because a legacy client
  313. has no way to fall forward. The fix it names is a *dual-era client*, which is what `mcp-remote`
  314. becomes with `--protocol auto`:
  315. ```bash
  316. npx mcp-remote https://example.remote/mcp --protocol auto
  317. ```
  318. **Available modes:**
  319. - `legacy` (default): sends the client's `initialize` straight through, exactly as every earlier
  320. release did. Nothing is probed.
  321. - `auto`: spends one `server/discover` on the first handshake. If a `2026-07-28` server answers,
  322. `mcp-remote` answers the local client's handshake itself and rewrites every later request into the
  323. modern era — per-request `_meta`, matching `MCP-Protocol-Version` header. If anything else answers,
  324. the handshake goes out untouched and nothing changes.
  325. It is off by default because every server in the wild today is a legacy one, and the probe is a round
  326. trip those connections do not need.
  327. The two modern surfaces with no `2025-11-25` equivalent are bridged as well:
  328. - **Change notifications.** The modern era only sends `notifications/tools/list_changed` and friends
  329. down a `subscriptions/listen` stream the client opens. A 2025-era client never opens one, so
  330. `mcp-remote` opens it on the client's behalf — asking for exactly the notifications the server said
  331. it can send — and passes each one on in the shape that era expects.
  332. - **Multi-round-trip requests.** When a server answers with `input_required`, asking for sampling,
  333. elicitation or roots mid-request, `mcp-remote` unpacks the embedded questions and puts them to the
  334. client as the ordinary server-initiated requests it already understands, then retries the original
  335. request with the answers and a byte-exact echo of the server's `requestState`. The client is never
  336. told any of this happened: it is still waiting on the one request it sent, and that is what it is
  337. answered with. Capped at 10 rounds.
  338. A question this proxy cannot put to a 2025-era client — anything outside sampling, elicitation and
  339. roots, or a URL-mode elicitation, or one the client never declared it supports — is reported as an
  340. error rather than dropped.
  341. Three methods the modern era retired are honoured by `mcp-remote` itself rather than forwarded to a
  342. server that no longer has them, because the capabilities the client is handed still advertise them:
  343. - `resources/subscribe` / `resources/unsubscribe` become entries on the `subscriptions/listen`
  344. stream, which is reopened whenever the set changes.
  345. - `logging/setLevel` is recorded and carried as the per-request `io.modelcontextprotocol/logLevel`
  346. that replaced it — without which a modern server sends no logs at all.
  347. ### Static OAuth Client Metadata
  348. MCP Remote supports providing static OAuth client metadata instead of using the mcp-remote defaults.
  349. This is useful when connecting to OAuth servers that expect specific client/software IDs or scopes.
  350. Provide the client metadata as a JSON string or as a `@` prefixed filepath with the `--static-oauth-client-metadata` flag:
  351. ```bash
  352. npx mcp-remote https://example.remote/server --static-oauth-client-metadata '{ "scope": "space separated scopes" }'
  353. # uses node readfile, so you probably want to use absolute paths if you're not sure what the cwd is
  354. npx mcp-remote https://example.remote/server --static-oauth-client-metadata '@/Users/username/Library/Application Support/Claude/oauth_client_metadata.json'
  355. ```
  356. What you provide is merged over the defaults, so this is also how you pin a value mcp-remote would
  357. otherwise negotiate. `token_endpoint_auth_method` is picked from the authorization server's
  358. `token_endpoint_auth_methods_supported`: `none` when the server accepts public clients, otherwise
  359. `client_secret_post`, otherwise `client_secret_basic`. Override it when the server needs something
  360. else:
  361. ```bash
  362. npx mcp-remote https://example.remote/server --static-oauth-client-metadata '{ "token_endpoint_auth_method": "client_secret_post" }'
  363. ```
  364. ### Static OAuth Client Information
  365. Per the [spec](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization#2-4-dynamic-client-registration),
  366. servers are encouraged but not required to support [OAuth dynamic client registration](https://datatracker.ietf.org/doc/html/rfc7591).
  367. For these servers, MCP Remote supports providing static OAuth client information instead.
  368. This is useful when connecting to OAuth servers that require pre-registered clients.
  369. Provide the client metadata as a JSON string or as a `@` prefixed filepath with the `--static-oauth-client-info` flag:
  370. ```bash
  371. export MCP_REMOTE_CLIENT_ID=xxx
  372. export MCP_REMOTE_CLIENT_SECRET=yyy
  373. npx mcp-remote https://example.remote/server --static-oauth-client-info "{ \"client_id\": \"$MCP_REMOTE_CLIENT_ID\", \"client_secret\": \"$MCP_REMOTE_CLIENT_SECRET\" }"
  374. # uses node readfile, so you probably want to use absolute paths if you're not sure what the cwd is
  375. npx mcp-remote https://example.remote/server --static-oauth-client-info '@/Users/username/Library/Application Support/Claude/oauth_client_info.json'
  376. ```
  377. ### Client ID Metadata Documents
  378. [SEP-991](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization) lets an
  379. authorization server accept an HTTPS URL as the `client_id`, where that URL serves a JSON document
  380. describing the client. Servers that support it advertise
  381. `"client_id_metadata_document_supported": true` in their authorization server metadata, and no
  382. dynamic registration is needed.
  383. Point mcp-remote at your document with `--client-metadata-url`:
  384. ```bash
  385. npx mcp-remote https://example.remote/server --client-metadata-url https://client.example.com/.well-known/oauth-client-metadata
  386. ```
  387. The URL must use HTTPS and have a path — a bare origin is rejected. If the server does not advertise
  388. support, mcp-remote registers dynamically as usual, so the flag is safe to leave in place.
  389. The document you host has to list the `redirect_uri` mcp-remote will send, which contains the OAuth
  390. callback port. Passing this flag makes that port strict: mcp-remote uses the port derived from the
  391. server URL (or the one you pass explicitly) and fails rather than quietly moving to another one, so
  392. the `redirect_uris` in your document stay correct. Run once to see the port it picked, or choose it
  393. yourself:
  394. ```bash
  395. npx mcp-remote https://example.remote/server 3334 --client-metadata-url https://client.example.com/.well-known/oauth-client-metadata
  396. ```
  397. ### Signing In Without a User
  398. Some servers are not protected on behalf of a person at all — an internal MCP server reached by a
  399. scheduled job, say, where there is no user to consent and no browser to consent in. For those,
  400. `--client-credentials` uses the
  401. [OAuth Client Credentials grant](https://datatracker.ietf.org/doc/html/rfc6749#section-4.4): the
  402. client presents its own credentials and is issued a token for itself.
  403. ```bash
  404. npx mcp-remote https://example.remote/mcp \
  405. --client-credentials \
  406. --static-oauth-client-info '{"client_id":"my-client","client_secret":"${MCP_CLIENT_SECRET}"}'
  407. ```
  408. The credentials come from `--static-oauth-client-info`, which accepts inline JSON or `@path/to/file.json`.
  409. **`${ENV_VAR}` placeholders are expanded from the environment** in both forms, so the secret need not sit
  410. in a command line where every other process on the machine can read it. Nothing logs the expanded value.
  411. The token endpoint, the scope and the RFC 8707 `resource` indicator are discovered and applied the same
  412. way as for every other flow, and `client_secret_basic` or `client_secret_post` is chosen from what the
  413. authorization server advertises. No refresh token is involved: the credentials are the durable thing, so
  414. an expired token is replaced by asking for another the same way the first was obtained.
  415. The token endpoint must use HTTPS, except for an HTTP loopback endpoint, and a redirect from it is
  416. followed only within the same origin — so the secret is never sent on to a host the endpoint merely
  417. points at.
  418. If an internal server does not publish RFC 9728 or RFC 8414/OIDC discovery metadata, provide its known
  419. token endpoint explicitly. This skips discovery and is accepted only with `--client-credentials`:
  420. ```bash
  421. npx mcp-remote https://example.remote/mcp \
  422. --client-credentials \
  423. --token-endpoint https://auth.example.com/oauth/token \
  424. --static-oauth-client-info '{"client_id":"my-client","client_secret":"${MCP_CLIENT_SECRET}"}' \
  425. --static-oauth-client-metadata '{"scope":"mcp.read mcp.write","token_endpoint_auth_method":"client_secret_basic"}'
  426. ```
  427. The explicit endpoint must use HTTPS, except for an HTTP loopback endpoint. Credentials and URL
  428. fragments are refused in the endpoint URL, and changing the endpoint selects a separate token cache.
  429. Discovery is also skipped on cold startup and 401 retries. Tokens are renewed before expiry using the
  430. same client credentials; if renewal fails, the current token is sent until the server refuses it. With
  431. an explicit endpoint, `scope` is omitted unless configured with `--static-oauth-client-metadata` or
  432. named in the server's 401 challenge, and `resource` is omitted unless set with `--resource`.
  433. ### Signing In Without a Browser
  434. The default flow needs a browser on this machine and a loopback port to redirect back to — which a
  435. cron job, an SSH session or a container does not have. If your authorization server supports the
  436. [OAuth Device Authorization Grant](https://datatracker.ietf.org/doc/html/rfc8628), `--device-code`
  437. moves the browser to whatever machine you are actually sitting at:
  438. ```bash
  439. npx mcp-remote https://example.remote/server --device-code
  440. ```
  441. mcp-remote prints a short code and a URL, then polls until you approve it:
  442. ```
  443. To authorize this client, visit:
  444. https://auth.example.com/activate
  445. And enter the code: WDJB-MJHT
  446. Waiting for approval...
  447. ```
  448. The output goes to stderr, which MCP clients capture into their own logs — so in a headless run,
  449. that log is where you read the code. This only has to happen once: the refresh token that comes back
  450. is stored like any other, and later runs are non-interactive.
  451. No callback server is started and no port is bound, so this is also the flow to use when the
  452. loopback port is unavailable.
  453. The server has to advertise `device_authorization_endpoint` in its authorization server metadata;
  454. mcp-remote fails with a clear message rather than falling back to a browser that isn't there. Note
  455. that servers offering this grant often expect a pre-registered client — pair it with
  456. `--static-oauth-client-info` if dynamic registration is refused.
  457. Both that endpoint and the token endpoint must use HTTPS, except for an HTTP loopback endpoint, and a
  458. redirect from either is followed only within the same origin. `--allow-http` does not relax this: it
  459. does not extend to the authorization server's endpoints.
  460. ### Load Balancer Session Stickiness
  461. MCP sessions live on one backend, so a server behind a load balancer needs every request from a
  462. client to reach the same node. AWS ALB, Azure Load Balancer and others do this with a cookie the
  463. client is expected to send back.
  464. mcp-remote keeps cookies the MCP server sets and replays them on later requests, including from the
  465. SSE stream onto the POSTs that follow it. Nothing to configure. Cookies are held in memory for the
  466. life of the process, never written to disk, and only ever sent back to the exact origin that set
  467. them — `Domain` is ignored, so nothing travels to another host.
  468. A `Cookie` you pass yourself with `--header` always wins.
  469. To turn it off:
  470. ```bash
  471. npx mcp-remote https://example.remote/server --disable-cookies
  472. ```
  473. ### Using the ID Token as the Bearer Credential
  474. By default mcp-remote sends the OAuth **access token**, which says what the caller is allowed to
  475. do. Some servers instead verify **who** the caller is: they validate an OIDC **ID token** against a
  476. JWKS endpoint and read identity claims such as `sub` and `email` from it. AWS Cognito in front of
  477. Bedrock AgentCore works this way, and rejects the access token outright.
  478. Pass `--use-id-token` to send the ID token instead:
  479. ```bash
  480. npx mcp-remote https://example.remote/server --use-id-token
  481. ```
  482. Only the credential presented to the MCP server changes — the refresh token and the renewal flow
  483. are untouched. Renewal follows the ID token's own `exp` claim rather than the access token's
  484. lifetime, since the ID token is what actually goes on the wire.
  485. An ID token is only issued when `openid` is among the requested scopes. If your server does not
  486. advertise it, ask for it explicitly:
  487. ```bash
  488. npx mcp-remote https://example.remote/server --use-id-token --static-oauth-client-metadata '{ "scope": "openid email" }'
  489. ```
  490. ### Claude Desktop
  491. [Official Docs](https://modelcontextprotocol.io/quickstart/user)
  492. In order to add an MCP server to Claude Desktop you need to edit the configuration file located at:
  493. * macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
  494. * Windows: `%APPDATA%\Claude\claude_desktop_config.json`
  495. If it does not exist yet, [you may need to enable it under Settings > Developer](https://modelcontextprotocol.io/quickstart/user#2-add-the-filesystem-mcp-server).
  496. Restart Claude Desktop to pick up the changes in the configuration file.
  497. Upon restarting, you should see a hammer icon in the bottom right corner
  498. of the input box.
  499. ### Cursor
  500. [Official Docs](https://docs.cursor.com/context/model-context-protocol). The configuration file is located at `~/.cursor/mcp.json`.
  501. As of version `0.48.0`, Cursor supports unauthed SSE servers directly. If your MCP server is using the official MCP OAuth authorization protocol, you still need to add a **"command"** server and call `mcp-remote`.
  502. ### Windsurf
  503. [Official Docs](https://docs.codeium.com/windsurf/mcp). The configuration file is located at `~/.codeium/windsurf/mcp_config.json`.
  504. ## Building Remote MCP Servers
  505. For instructions on building & deploying remote MCP servers, including acting as a valid OAuth client, see the following resources:
  506. * https://developers.cloudflare.com/agents/guides/remote-mcp-server/
  507. In particular, see:
  508. * https://github.com/cloudflare/workers-oauth-provider for defining an MCP-comlpiant OAuth server in Cloudflare Workers
  509. * https://github.com/cloudflare/agents/tree/main/examples/mcp for defining an `McpAgent` using the [`agents`](https://npmjs.com/package/agents) framework.
  510. For more information about testing these servers, see also:
  511. * https://developers.cloudflare.com/agents/guides/test-remote-mcp-server/
  512. Know of more resources you'd like to share? Please add them to this Readme and send a PR!
  513. ## Troubleshooting
  514. ### Clear your `~/.mcp-auth` directory
  515. `mcp-remote` stores all the credential information inside `~/.mcp-auth` (or wherever your `MCP_REMOTE_CONFIG_DIR` points to). If you're having persistent issues, try running:
  516. ```sh
  517. rm -rf ~/.mcp-auth
  518. ```
  519. Then restarting your MCP client.
  520. Credentials are stored under `mcp-remote-v1`, which names the layout of the store rather than the
  521. version of the package, so upgrading `mcp-remote` no longer signs you out. Releases before this
  522. change kept a separate directory per version — if you have `~/.mcp-auth/mcp-remote-0.x.y`
  523. directories left over, they hold old tokens and can be deleted.
  524. ### Check your Node version
  525. Make sure that the version of Node you have installed is [18 or
  526. higher](https://modelcontextprotocol.io/quickstart/server). Claude
  527. Desktop will use your system version of Node, even if you have a newer
  528. version installed elsewhere.
  529. ### Restart Claude
  530. When modifying `claude_desktop_config.json` it can helpful to completely restart Claude
  531. ### VPN Certs
  532. You may run into issues if you are behind a VPN, you can try setting the `NODE_EXTRA_CA_CERTS`
  533. environment variable to point to the CA certificate file. If using `claude_desktop_config.json`,
  534. this might look like:
  535. ```json
  536. {
  537. "mcpServers": {
  538. "remote-example": {
  539. "command": "npx",
  540. "args": [
  541. "mcp-remote",
  542. "https://remote.mcp.server/sse"
  543. ],
  544. "env": {
  545. "NODE_EXTRA_CA_CERTS": "{your CA certificate file path}.pem"
  546. }
  547. }
  548. }
  549. }
  550. ```
  551. ### Check the logs
  552. * [Follow Claude Desktop logs in real-time](https://modelcontextprotocol.io/docs/tools/debugging#debugging-in-claude-desktop)
  553. * MacOS / Linux:<br/>`tail -n 20 -F ~/Library/Logs/Claude/mcp*.log`
  554. * For bash on WSL:<br/>`tail -n 20 -f "C:\Users\YourUsername\AppData\Local\Claude\Logs\mcp.log"`
  555. * Powershell: <br/>`Get-Content "C:\Users\YourUsername\AppData\Local\Claude\Logs\mcp.log" -Wait -Tail 20`
  556. ## Debugging
  557. ### Debug Logs
  558. For troubleshooting complex issues, especially with token refreshing or authentication problems, use the `--debug` flag:
  559. ```json
  560. "args": [
  561. "mcp-remote",
  562. "https://remote.mcp.server/sse",
  563. "--debug"
  564. ]
  565. ```
  566. This creates detailed logs in `~/.mcp-auth/{server_hash}_debug.log` with timestamps and complete information about every step of the connection and authentication process. When you find issues with token refreshing, laptop sleep/resume issues, or auth problems, provide these logs when seeking support.
  567. ### Authentication Errors
  568. If you encounter the following error, returned by the `/callback` URL:
  569. ```
  570. Authentication Error
  571. Token exchange failed: HTTP 400
  572. ```
  573. You can run `rm -rf ~/.mcp-auth` to clear any locally stored state and tokens.
  574. ### "Client" mode
  575. Run the following on the command line (not from an MCP server):
  576. ```shell
  577. npx -p mcp-remote@latest mcp-remote-client https://remote.mcp.server/sse
  578. ```
  579. This will run through the entire authorization flow and attempt to list the tools & resources at the remote URL. Try this after running `rm -rf ~/.mcp-auth` to see if stale credentials are your problem, otherwise hopefully the issue will be more obvious in these logs than those in your MCP client.
  580. ## Acknowledgments
  581. [Glen Maddern](https://github.com/geelen) is the original author of `mcp-remote`. He built `mcp-remote` into one of the most popular building blocks in the MCP ecosystem.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.