Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-api): drop repeated scopes from a remote install's effective list (BR1-L5)

Diego Zacarias1bab0ca1c307
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index c4b0d40b7..78224d160 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.806",
+ "version": "0.1.807",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.806",
+ "version": "0.1.807",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index 8a49a47d1..5be4c67a6 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.806",
+ "version": "0.1.807",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/remoteMcp.ts b/control-api/src/routes/admin/remoteMcp.ts
index 85d3e9d1f..28608abec 100644
--- a/control-api/src/routes/admin/remoteMcp.ts
+++ b/control-api/src/routes/admin/remoteMcp.ts
@@ -246,10 +246,16 @@ export interface RemoteOAuthSpec {
/**
* The scopes an install requests: the operator's list when given, else the advertised
- * defaults, plus whatever the authorization-server profile always requires.
+ * defaults, plus whatever the authorization-server profile always requires. Duplicates
+ * are dropped (first occurrence wins) here rather than in `withProfileScopes`, which the
+ * runtime also applies to already-installed CRs whose wire must not change.
*/
export function effectiveRemoteScopes(result: DiscoveryResult, override?: string[]): string[] {
- return withProfileScopes(override ?? defaultScopes(result.prm, result.as), result.asProfile)
+ const scopes = withProfileScopes(
+ override ?? defaultScopes(result.prm, result.as),
+ result.asProfile
+ )
+ return [...new Set(scopes)]
}
export function buildRemoteOAuthSpec(
diff --git a/control-api/test/routes.adminRemoteMcp.test.ts b/control-api/test/routes.adminRemoteMcp.test.ts
index 342c35fa8..ff230ba51 100644
--- a/control-api/test/routes.adminRemoteMcp.test.ts
+++ b/control-api/test/routes.adminRemoteMcp.test.ts
@@ -3100,4 +3100,32 @@ describe('Microsoft Entra ID — remote install with scopes, scope audience and
expect(JSON.parse(post?.body ?? '{}').scope).toBe('custom')
expect((await installedOauth(gw, 'notion-dcr-scopes')).scopes).toEqual(['custom'])
})
+
+ it('DCR without a profile: a repeated scope is requested and installed once, in first-seen order', async () => {
+ const gw = gatewayWithContext()
+ const { db } = makeInMemoryDynamicClientsDb()
+ const { transport, calls } = makeDcrTransport({
+ responseJson: JSON.stringify(DCR_PUBLIC_REGISTRATION_RESPONSE),
+ redirectUris: 'requested',
+ })
+ const pilot = dcrPilot('public')
+ const app = makeApp(gw, genericProbe, {
+ ...(await pilotDeps(pilot)),
+ db,
+ dcr: { transport, resolveDns: PUBLIC_IP },
+ })
+ const res = await request(app)
+ .post('/admin/mcp-servers/remote')
+ .send({
+ serverName: 'notion-dcr-dup-scopes',
+ contextRef: 'ctx-a',
+ baseUrl: pilot.mcpUrl,
+ mode: 'dcr',
+ scopes: ['a', 'b', 'a'],
+ })
+ expect(res.status).toBe(201)
+ const post = calls.find(c => c.method === 'POST')
+ expect(JSON.parse(post?.body ?? '{}').scope).toBe('a b')
+ expect((await installedOauth(gw, 'notion-dcr-dup-scopes')).scopes).toEqual(['a', 'b'])
+ })
})