From 1325db90b5bbb8b80f90d66f449a5091ba7869de Mon Sep 17 00:00:00 2001 From: truefoundry-saas Date: Fri, 20 Nov 2026 15:55:45 +0530 Subject: [PATCH 1/3] cherry-pick (needs manual conflict resolution) From b4cdb317e1de70db2b8c519b7b2722be99b7968a Mon Sep 17 00:00:00 2001 From: Rutvij Menavlikar <174306281+rutvij-menavlikar@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:55:47 +0530 Subject: [PATCH 2/3] fix(mcp): omit gateway redirectURL when authorize has no return_to (#1303) (cherry picked from commit 584a376708b64b7738e3c925c533793dd628cda6) --- .changeset/optional-mcp-authorize-return-to.md | 5 +++++ .github/fern/openapi/openapi.json | 5 +++-- docs/openapi.json | 5 +++-- .../requests/AuthorizeMcpServersRequest.ts | 2 +- packages/trueforge/src/apis/mcpServers.ts | 2 +- packages/trueforge/src/routes/mcpServerRoutes.ts | 8 +++++++- .../src/truefoundry/TrueFoundryMcpServerStore.ts | 16 ++++++++++------ .../trueforge/tests/unit/apis/mcpServers.test.ts | 7 +++++++ .../TrueFoundryMcpServerStore.test.ts | 14 +++++++++++++- python/trueforge_sdk/reference.md | 2 +- .../src/trueforge_sdk/mcp_servers/client.py | 4 ++-- .../src/trueforge_sdk/mcp_servers/raw_client.py | 4 ++-- 12 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 .changeset/optional-mcp-authorize-return-to.md diff --git a/.changeset/optional-mcp-authorize-return-to.md b/.changeset/optional-mcp-authorize-return-to.md new file mode 100644 index 0000000000..7b5be653fb --- /dev/null +++ b/.changeset/optional-mcp-authorize-return-to.md @@ -0,0 +1,5 @@ +--- +'@truefoundry/trueforge': patch +--- + +`GET /api/v1/mcp-servers/{name}/authorize` no longer sends a `redirectURL` to the TrueFoundry MCP gateway when `return_to` is omitted, so the gateway shows its own post-authentication page instead of redirecting to the TrueForge home. An empty `return_to` is now rejected with 400. diff --git a/.github/fern/openapi/openapi.json b/.github/fern/openapi/openapi.json index 6094fde1c7..71fde386df 100644 --- a/.github/fern/openapi/openapi.json +++ b/.github/fern/openapi/openapi.json @@ -7702,12 +7702,13 @@ } }, { - "description": "Same-origin path to land in the browser after consent.", + "description": "Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested.", "in": "query", "name": "return_to", "required": false, "schema": { - "description": "Same-origin path to land in the browser after consent.", + "description": "Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested.", + "minLength": 1, "type": "string" } } diff --git a/docs/openapi.json b/docs/openapi.json index 6094fde1c7..71fde386df 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -7702,12 +7702,13 @@ } }, { - "description": "Same-origin path to land in the browser after consent.", + "description": "Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested.", "in": "query", "name": "return_to", "required": false, "schema": { - "description": "Same-origin path to land in the browser after consent.", + "description": "Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested.", + "minLength": 1, "type": "string" } } diff --git a/packages/trueforge-sdk/src/api/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts b/packages/trueforge-sdk/src/api/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts index a401bd427b..678d302a4b 100644 --- a/packages/trueforge-sdk/src/api/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts +++ b/packages/trueforge-sdk/src/api/resources/mcpServers/client/requests/AuthorizeMcpServersRequest.ts @@ -5,6 +5,6 @@ * {} */ export interface AuthorizeMcpServersRequest { - /** Same-origin path to land in the browser after consent. */ + /** Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested. */ returnTo?: string; } diff --git a/packages/trueforge/src/apis/mcpServers.ts b/packages/trueforge/src/apis/mcpServers.ts index 347ba6860e..8ef81ae38e 100644 --- a/packages/trueforge/src/apis/mcpServers.ts +++ b/packages/trueforge/src/apis/mcpServers.ts @@ -425,7 +425,7 @@ export function createMcpServersRouter(deps: McpServersRouterDeps< const requestContext = deps.resolveRequestContext(c); const userRef = requestContext.subject.id; - if (returnTo && safeReturnTo(returnTo) !== returnTo) { + if (returnTo !== undefined && safeReturnTo(returnTo) !== returnTo) { return c.json({ error: { message: 'Invalid return_to: must be a same-origin relative path' } }, 400); } diff --git a/packages/trueforge/src/routes/mcpServerRoutes.ts b/packages/trueforge/src/routes/mcpServerRoutes.ts index dcec8de39c..a900dc06a3 100644 --- a/packages/trueforge/src/routes/mcpServerRoutes.ts +++ b/packages/trueforge/src/routes/mcpServerRoutes.ts @@ -266,7 +266,13 @@ export const listMcpServerToolsRoute = createRoute({ }); const McpAuthorizeQuerySchema = z.object({ - return_to: z.string().optional().describe('Same-origin path to land in the browser after consent.'), + return_to: z + .string() + .min(1) + .optional() + .describe( + 'Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested.', + ), }); export const authorizeMcpServerRoute = createRoute({ diff --git a/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts b/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts index 5b9dbf925c..c194712f50 100644 --- a/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts +++ b/packages/trueforge/src/truefoundry/TrueFoundryMcpServerStore.ts @@ -63,7 +63,7 @@ const X_TFY_MCP_HEADERS = 'x-tfy-mcp-headers'; * TODO: add an env var for the public UI path prefix (do not keep deriving mount path from * `PUBLIC_BASE_URL`) so tenant origin and path are independently configurable. */ -export function resolveAuthorizeRedirectURL(input: { returnTo?: string; publicBaseUrl: string }): string { +export function resolveAuthorizeRedirectURL(input: { returnTo: string; publicBaseUrl: string }): string { try { const origin = new URL(input.publicBaseUrl).origin; const publicBase = new URL(getPublicUiBasePath(), `${origin}/`); @@ -252,15 +252,19 @@ export class TrueFoundryMcpServerStore implements IMcpServ if (record === undefined) { throw new McpServerNotFoundError(input.name); } - const publicBaseUrl = await this.#client.getTenantControlPlaneUrl({ tenantName: input.tenant_id }); + const returnTo = input.returnTo; + const redirectURL = + returnTo === undefined + ? undefined + : resolveAuthorizeRedirectURL({ + returnTo: returnTo, + publicBaseUrl: await this.#client.getTenantControlPlaneUrl({ tenantName: input.tenant_id }), + }); const gatewayAuthorization = await this.#resolveGatewayAuthorization(); return this.#client.getMcpAuthorize({ accessToken: gatewayAuthorization.subjectToken, mcpServerId: record.id, - redirectURL: resolveAuthorizeRedirectURL({ - publicBaseUrl, - ...(input.returnTo !== undefined ? { returnTo: input.returnTo } : {}), - }), + ...(redirectURL !== undefined ? { redirectURL } : {}), }); } diff --git a/packages/trueforge/tests/unit/apis/mcpServers.test.ts b/packages/trueforge/tests/unit/apis/mcpServers.test.ts index b4e4dba5d1..8e73070815 100644 --- a/packages/trueforge/tests/unit/apis/mcpServers.test.ts +++ b/packages/trueforge/tests/unit/apis/mcpServers.test.ts @@ -786,6 +786,13 @@ describe('mcp-servers routers', () => { } }); + it('GET /{name}/authorize rejects an empty return_to with 400', async () => { + await seedDcrServerWithClient(); + + const response = await mcpServersRouter.request(`/${putBodyWithDcr.name}/authorize?return_to=`); + expect(response.status).toBe(400); + }); + it('GET /{name}/authorize returns 424 when upstream DCR registration fails', async () => { const asOrigin = 'https://auth-failure.example.com'; const mcpUrl = 'https://mcp-failure.example.com/sse'; diff --git a/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts b/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts index da4eaf3586..2d718b22d9 100644 --- a/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts +++ b/packages/trueforge/tests/unit/truefoundry/TrueFoundryMcpServerStore.test.ts @@ -179,9 +179,21 @@ describe('TrueFoundryMcpServerStore', () => { }); }); + it('omits upstream redirectURL when return_to is not given', async () => { + const { store, client } = createStore(); + await store.authorize({ tenant_id: TENANT, name: 'github', userRef: 'user-1' }); + expect(client.getTenantControlPlaneUrl).not.toHaveBeenCalled(); + expect(client.getMcpAuthorize).toHaveBeenCalledWith({ + accessToken: ACCESS_TOKEN, + mcpServerId: 'mcp-id-1', + }); + }); + it('throws when tenant control-plane URL is invalid', async () => { const { store } = createStore({ controlPlaneUrl: '' }); - await expect(store.authorize({ tenant_id: TENANT, name: 'github', userRef: 'user-1' })).rejects.toMatchObject({ + await expect( + store.authorize({ tenant_id: TENANT, name: 'github', userRef: 'user-1', returnTo: '/trueforge/' }), + ).rejects.toMatchObject({ message: 'Tenant control-plane URL is required for TrueFoundry MCP OAuth', statusCode: 500, }); diff --git a/python/trueforge_sdk/reference.md b/python/trueforge_sdk/reference.md index 46fef12c46..49e4230a28 100644 --- a/python/trueforge_sdk/reference.md +++ b/python/trueforge_sdk/reference.md @@ -822,7 +822,7 @@ client.mcp_servers.authorize(
-**return_to:** `typing.Optional[str]` — Same-origin path to land in the browser after consent. +**return_to:** `typing.Optional[str]` — Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested.
diff --git a/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/client.py b/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/client.py index 4bb0e997be..38428f1f6f 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/client.py +++ b/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/client.py @@ -104,7 +104,7 @@ def authorize( MCP server name. return_to : typing.Optional[str] - Same-origin path to land in the browser after consent. + Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested. request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -306,7 +306,7 @@ async def authorize( MCP server name. return_to : typing.Optional[str] - Same-origin path to land in the browser after consent. + Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested. request_options : typing.Optional[RequestOptions] Request-specific configuration. diff --git a/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/raw_client.py b/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/raw_client.py index a4c0cb9177..77c41d69e2 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/raw_client.py +++ b/python/trueforge_sdk/src/trueforge_sdk/mcp_servers/raw_client.py @@ -162,7 +162,7 @@ def authorize( MCP server name. return_to : typing.Optional[str] - Same-origin path to land in the browser after consent. + Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested. request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -532,7 +532,7 @@ async def authorize( MCP server name. return_to : typing.Optional[str] - Same-origin path to land in the browser after consent. + Same-origin path to land in the browser after consent. When omitted, no post-consent redirect is requested. request_options : typing.Optional[RequestOptions] Request-specific configuration. From 58d4f377f6eaec75f716a3f121c3b0fed14bad8a Mon Sep 17 00:00:00 2001 From: Rutvij Menavlikar <174306281+rutvij-menavlikar@users.noreply.github.com> Date: Fri, 20 Nov 2026 16:08:12 +0530 Subject: [PATCH 3/3] chore(changeset): include trueforge-sdk for return_to regeneration Co-authored-by: Cursor --- .changeset/optional-mcp-authorize-return-to.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/optional-mcp-authorize-return-to.md b/.changeset/optional-mcp-authorize-return-to.md index 7b5be653fb..5ce579e902 100644 --- a/.changeset/optional-mcp-authorize-return-to.md +++ b/.changeset/optional-mcp-authorize-return-to.md @@ -1,5 +1,6 @@ --- '@truefoundry/trueforge': patch +'@truefoundry/trueforge-sdk': patch --- `GET /api/v1/mcp-servers/{name}/authorize` no longer sends a `redirectURL` to the TrueFoundry MCP gateway when `return_to` is omitted, so the gateway shows its own post-authentication page instead of redirecting to the TrueForge home. An empty `return_to` is now rejected with 400.