Conversation
… custom MCP servers MCP servers hosted under a path (e.g. https://mcp.facebook.com/ads) publish their OAuth authorization server metadata at the path-aware well-known URL (/.well-known/oauth-authorization-server/ads). Discovery previously only queried the root document and, on 404, fell back to <origin>/authorize, <origin>/token and <origin>/register, dropping the server path entirely. For the Meta Ads MCP this produced a registration call against https://mcp.facebook.com/register (404) and an authorize redirect to https://mcp.facebook.com/authorize, which Meta's router rejects with "MCP server not found for path: /authorize". Try the RFC 8414 path-inserted metadata URL first when the MCP server URL has a path component, then fall back to the root document, keeping the existing origin-based defaults as the last resort.
Inakitajes
left a comment
There was a problem hiding this comment.
Thanks so much for contributing—this is a great catch. The path-aware lookup correctly identifies the metadata endpoint used by Meta Ads and fixes the immediate failure.
However, I don’t think we can merge this as-is yet:
- The full test suite currently fails. Running pnpm test results in 7 failures in tests/connectors-oauth.test.ts. Some mocks do not account for the additional metadata request, while other assertions still expect the root URL. Please update these integration tests.
- The MCP resource URL is not necessarily the authorization-server issuer. MCP requires clients to discover Protected Resource Metadata first (RFC 9728), read authorization_servers, and then apply RFC 8414 discovery to the selected issuer. Applying RFC 8414 directly to every MCP URL works for this Meta case, but it is not generally correct.
- The returned issuer is not validated. RFC 8414 §3.3 requires the metadata issuer to exactly match the issuer used to construct the discovery URL. Meta currently returns https://www.facebook.com from metadata discovered through https://mcp.facebook.com/ads, so supporting Meta may require a deliberate, narrowly documented compatibility exception rather than weakening validation globally.
- Fallback behavior is too permissive. The path-aware request currently falls back to the root document after any failure, including 401, 403, 429, or 500. This could silently select unrelated root metadata during an outage or configuration error. The fallback should at least be restricted to an explicit “not found” response and covered by tests.
Before merging, could you please:
- update all affected integration tests;
- add an end-to-end test covering path-aware discovery, client registration/static fallback, authorization URL generation, and token exchange;
- implement RFC 9728 protected-resource discovery before RFC 8414 discovery, or clearly scope this as a provider-specific compatibility workaround;
- define and test strict fallback semantics;
- add issuer-validation coverage and document any Meta-specific exception.
Also, the PR branch is currently behind the target branch. Please rebase it onto the latest peaberry-studio/arche:main and resolve any resulting conflicts before requesting another review. This will ensure the updated implementation and tests are validated against the current codebase.
Thanks again, he underlying issue is real, and the proposed URL construction is useful.
We just need to make sure the solution is safe and correct beyond the single Meta endpoint.
Problem
Custom MCP connectors fail to complete OAuth against servers that live under a URL path (e.g.
https://mcp.facebook.com/ads).discoverOAuthMetadata(apps/web/src/lib/connectors/oauth-metadata.ts) only queries/.well-known/oauth-authorization-serverat the host root and, on 404, falls back to<origin>/authorize|token|register— discarding the server's path segment.Observed against Meta's official Ads MCP:
https://mcp.facebook.com/register→ 404 → "Dynamic client registration failed for this MCP server".https://mcp.facebook.com/authorize→ Meta responds "MCP server not found for path: /authorize".The server's real metadata is published at the RFC 8414 path-aware location
https://mcp.facebook.com/.well-known/oauth-authorization-server/ads, withauthorization_endpointandtoken_endpointpointing at facebook.com/graph.facebook.com.Fix
Discovery now tries, in order:
/.well-known/oauth-authorization-server/<path>/.well-known/oauth-authorization-server(previous behavior)<origin>-based defaults (unchanged last resort)Endpoints from discovered metadata are used as-is, so servers whose authorization/token endpoints live on a different host (as Meta's do) work correctly. Behavior for servers without a path component is unchanged.
Testing
https://mcp.facebook.com/ads(metadata resolves; end-to-end OAuth additionally requires a pre-registered Meta app, since Meta's dynamic client registration is allowlisted).