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
{{ message }}
Repository navigation
Forward slash is being added on root resource URIs with oauth challenge #58956
A trailing forward slash is wrongly being added to the oauth challenge when it's a root resource, so:
http://localhost.guanchen.nl:8080-> results into redirect with forward slash (this is %2F encoded) please see:
Results into following error, because I'm not expecting the forward slash, so it's mismatching:
AADSTS9010010: The resource parameter provided in the request doesn't match with the requested scopes. Trace ID: 89693c07-dbfa-4e39-8b82-79d13216b601 Correlation ID: b9639ba4-eb89-484d-b9fd-b66cdf3c41ce Timestamp: 2026-10-25 11:09:00Z
http://localhost.guanchen.nl:8080/mcp (so postfixed with /mcp) just works, no forward slash is being added. This is fine for me to use, see:
URLs ending with forward slash is not possible to use with Entra ID by the way, apart from the unwanted behavior of adding the forward slash by OpenCode of course.
Thanks for the clear report. I reproduced this on 2.1.4 and it still happens on the latest dev (b79dce4).
To reproduce it, I ran a local mock MCP and authorization server whose protected-resource metadata publishes the root resource http://localhost:8080 (no trailing slash). The opencode config points at http://localhost:8080/mcp with a fixed client_id and redirect_uri. Running opencode mcp auth enframed builds an authorize URL with resource=http%3A%2F%2Flocalhost%3A8080%2F, so a slash is added that the server never published. Entra ID compares this value exactly, which is why you get AADSTS9010010. When the resource has a path, like /mcp, it is sent unchanged, which matches what you saw.
The script below reproduces it. It looks like the resource URL gets normalised when it is parsed, which adds a / to a bare root. The MCP spec recommends sending the form without the slash.
Related: #12308 (the same symptom with Entra on v1, closed) and #50036 (a trailing-slash mismatch on the OAuth issuer). Until this is fixed, the workaround you found (using a resource with a path such as /mcp) avoids the problem.
Reproduction script (repro.sh)
#!/bin/sh# Repro for #58956: PRM publishes resource "http://localhost:8080" (no slash);# check the `resource` param opencode puts on the authorize URL.# Usage: ./repro.sh (uses `opencode` from PATH)# From a source checkout, run the CLI from packages/cli so its bunfig preload also# applies to the spawned server, and point it at the config:# cd <repo>/packages/cli && OPENCODE_CONFIG=<dir>/proj/opencode.json BROWSER=true bun --conditions=browser src/index.ts mcp auth enframedset -e
DIR=$(cd "$(dirname "$0")"&& pwd)
OC=${OC:-opencode}
mkdir -p "$DIR/proj"
cat >"$DIR/server.ts"<<'TS'// Mock MCP resource server + authorization server. PRM publishes a ROOT resource (no trailing slash).const port = 8080, base = `http://localhost:${port}`Bun.serve({ port, fetch(req) { const u = new URL(req.url) console.log(req.method, u.pathname + u.search) if (u.pathname.startsWith("/.well-known/oauth-protected-resource")) return Response.json({ resource: base, authorization_servers: [base] }) if (u.pathname.startsWith("/.well-known/oauth-authorization-server") || u.pathname.startsWith("/.well-known/openid-configuration")) return Response.json({ issuer: base, authorization_endpoint: `${base}/authorize`, token_endpoint: `${base}/token`, response_types_supported: ["code"], code_challenge_methods_supported: ["S256"], grant_types_supported: ["authorization_code"] }) if (u.pathname === "/authorize") { console.log("AUTHORIZE resource param =", JSON.stringify(u.searchParams.get("resource"))) return new Response("ok") } return new Response("unauthorized", { status: 401, headers: { "www-authenticate": `Bearer resource_metadata="${base}/.well-known/oauth-protected-resource"` } })}})TS
cat >"$DIR/proj/opencode.json"<<'J'{ "$schema": "https://opencode.ai/config.json", "mcp": { "servers": { "enframed": { "type": "remote", "url": "http://localhost:8080/mcp", "oauth": { "client_id": "b6997777-3799-4c55-b78a-4ce96e3d959c", "redirect_uri": "http://localhost:6276/oauth/callback" } } } } }J
bun "$DIR/server.ts">"$DIR/server.log"2>&1& SRV=$!trap'kill $SRV' EXIT
sleep 1
cd"$DIR/proj"
OUT=$(BROWSER=true timeout 20 $OC mcp auth enframed 2>&1|| true)
URL=$(printf '%s\n'"$OUT"| grep -o 'http://localhost:8080/authorize[^ ]*'| head -1)echo"authorize URL: $URL"
RES=$(printf '%s'"$URL"| grep -o 'resource=[^&]*')echo"PRM resource: http://localhost:8080"echo"sent $RES"case"$RES"in*%2F) echo"BUG: trailing slash added";; *) echo"OK: no trailing slash";; esac
Activity
opencode-agent commentedon Oct 25, 2026
Thanks for the clear report. I reproduced this on 2.1.4 and it still happens on the latest
dev(b79dce4).To reproduce it, I ran a local mock MCP and authorization server whose protected-resource metadata publishes the root resource
http://localhost:8080(no trailing slash). The opencode config points athttp://localhost:8080/mcpwith a fixedclient_idandredirect_uri. Runningopencode mcp auth enframedbuilds an authorize URL withresource=http%3A%2F%2Flocalhost%3A8080%2F, so a slash is added that the server never published. Entra ID compares this value exactly, which is why you getAADSTS9010010. When the resource has a path, like/mcp, it is sent unchanged, which matches what you saw.The script below reproduces it. It looks like the resource URL gets normalised when it is parsed, which adds a
/to a bare root. The MCP spec recommends sending the form without the slash.Related: #12308 (the same symptom with Entra on v1, closed) and #50036 (a trailing-slash mismatch on the OAuth issuer). Until this is fixed, the workaround you found (using a resource with a path such as
/mcp) avoids the problem.Reproduction script (repro.sh)
Run it:
sh repro.sherwinkramer commentedon Oct 25, 2026
@opencode-agent can u generate a PR to solve this?