Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-api): u5 carry mcpServerName in mcp oauth return deep-link
Diego Zacarias7810aa8392df
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 9ccaa8511..a599a958f 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.438",+ "version": "0.1.439","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.438",+ "version": "0.1.439","dependencies": {"@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-api/package.json b/control-api/package.jsonindex 4275b8035..aec17b6c5 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.438",+ "version": "0.1.439","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/oauth/callback.ts b/control-api/src/oauth/callback.tsindex 4b8057ea6..52bd02527 100644--- a/control-api/src/oauth/callback.ts+++ b/control-api/src/oauth/callback.ts@@ -166,6 +166,14 @@ export type CallbackResult =* deep-link (U5).*/source?: 'mcp'+ /**+ * The consented mcp-server's name — present only on the `source:'mcp'`+ * path. Comes from the signed state (authoritative), never a body param.+ * The route forwards it into the deep-link (`&mcpServerName=…`) so the+ * desktop can correlate which suspended task to resume under concurrent+ * suspensions.+ */+ mcpServerName?: string}| { kind: 'invalid_state'; reason: string }| { kind: 'unknown_oauth_client' }@@ -393,6 +401,9 @@ async function handleMcpOAuthCallback(backgroundRequested: false,backgroundEnabled: false,source: 'mcp',+ // Authoritative — from the signed state, never a body param. Lets the+ // desktop correlate which suspended task to resume.+ mcpServerName: claims.mcpServerName,}}diff --git a/control-api/src/routes/external/oauthCallback.ts b/control-api/src/routes/external/oauthCallback.tsindex e43f11a95..cffec340d 100644--- a/control-api/src/routes/external/oauthCallback.ts+++ b/control-api/src/routes/external/oauthCallback.ts@@ -138,6 +138,7 @@ export function createOAuthCallbackRouter(gateway: K8sGateway): Router {backgroundRequested: result.backgroundRequested,backgroundEnabled: result.backgroundEnabled,source: result.source,+ mcpServerName: result.mcpServerName,}))case 'invalid_state':@@ -196,7 +197,12 @@ export function buildPublicCallbackUrl(export function renderSuccessHtml(provider: string,oauthClientId: string,- opts?: { backgroundRequested?: boolean; backgroundEnabled?: boolean; source?: 'mcp' }+ opts?: {+ backgroundRequested?: boolean+ backgroundEnabled?: boolean+ source?: 'mcp'+ mcpServerName?: string+ }): string {// The user's browser hits this page on the platform's origin, not inside// the embed. Spec §9.9 — bounce to `clerum://oauth-completed?…` so the@@ -211,6 +217,11 @@ export function renderSuccessHtml(deepLink.searchParams.set('provider', safeProvider)if (opts?.source === 'mcp') {deepLink.searchParams.set('source', 'mcp')+ // Correlation key for the desktop resume (authoritative — from the signed+ // state). Robust against concurrent suspensions of different mcp-servers.+ if (opts.mcpServerName) {+ deepLink.searchParams.set('mcpServerName', opts.mcpServerName)+ }}const deepLinkHref = htmlAttrEscape(deepLink.toString())// JSON.stringify gives valid JS string literal; `<` → `<` blocksdiff --git a/control-api/test/oauth.callback.mcp.test.ts b/control-api/test/oauth.callback.mcp.test.tsindex fcf217c50..db8ce3f89 100644--- a/control-api/test/oauth.callback.mcp.test.ts+++ b/control-api/test/oauth.callback.mcp.test.ts@@ -149,6 +149,7 @@ describe('handleOAuthCallback — mcp subject (U5)', () => {backgroundRequested: false,backgroundEnabled: false,source: 'mcp',+ mcpServerName: 'gdrive',})expect(db.query).toHaveBeenCalledTimes(1)diff --git a/control-api/test/oauth.successHtml.test.ts b/control-api/test/oauth.successHtml.test.tsindex a76d78eb8..b17610dfb 100644--- a/control-api/test/oauth.successHtml.test.ts+++ b/control-api/test/oauth.successHtml.test.ts@@ -40,17 +40,27 @@ describe('renderSuccessHtml (spec §9.9 OAuth callback success page)', () => {expect(metaContent).not.toMatch(/&(?!amp;|quot;|lt;|gt;|#)/)})- it('recipe subject (no source opt) emits a FROZEN deep-link with NO source param', () => {+ it('recipe subject (no source opt) emits a FROZEN deep-link with NO source/mcpServerName param', () => {const html = renderSuccessHtml('slack', 'slack-bot')const metaContent = /content="0;url=([^"]+)"/.exec(html)?.[1] ?? ''expect(metaContent).not.toContain('source')- // Same when opts is present but source is absent.- const html2 = renderSuccessHtml('slack', 'slack-bot', { backgroundEnabled: true })- expect(/content="0;url=([^"]+)"/.exec(html2)?.[1] ?? '').not.toContain('source')+ expect(metaContent).not.toContain('mcpServerName')+ // Same when opts is present but source is absent — a stray mcpServerName in+ // opts must NOT leak into the recipe deep-link (only the mcp path forwards it).+ const html2 = renderSuccessHtml('slack', 'slack-bot', {+ backgroundEnabled: true,+ mcpServerName: 'should-not-appear',+ })+ const meta2 = /content="0;url=([^"]+)"/.exec(html2)?.[1] ?? ''+ expect(meta2).not.toContain('source')+ expect(meta2).not.toContain('mcpServerName')})- it('mcp subject appends &source=mcp on the SAME oauth-completed host, keeping clientId', () => {- const html = renderSuccessHtml('google', 'google-drive', { source: 'mcp' })+ it('mcp subject appends &source=mcp AND &mcpServerName=<X> on the same oauth-completed host', () => {+ const html = renderSuccessHtml('google', 'google-drive', {+ source: 'mcp',+ mcpServerName: 'gdrive',+ })const metaContent = /content="0;url=([^"]+)"/.exec(html)?.[1] ?? ''// HTML-attribute context escapes `&` → `&`; decode for a clean parse.const url = new URL(metaContent.replace(/&/g, '&'))@@ -59,6 +69,7 @@ describe('renderSuccessHtml (spec §9.9 OAuth callback success page)', () => {expect(url.searchParams.get('clientId')).toBe('google-drive')expect(url.searchParams.get('provider')).toBe('google')expect(url.searchParams.get('source')).toBe('mcp')+ expect(url.searchParams.get('mcpServerName')).toBe('gdrive')})it('JSON-escapes the URL inside the inline <script> to block </script> injection', () => {