diff --git a/packages/mcp/mcp-manager/src/index.ts b/packages/mcp/mcp-manager/src/index.ts index 69f171807d..fa1b58a819 100644 --- a/packages/mcp/mcp-manager/src/index.ts +++ b/packages/mcp/mcp-manager/src/index.ts @@ -104,8 +104,6 @@ const ServerEntrySchema = z.object({ reconnect: z.any(), }) as z - - /** One server's child instance, probes, and any cleanup failure retained by the manager. */ interface ManagedRecord { oauth?: McpOAuthAuthorization @@ -621,10 +619,11 @@ export default class McpServerManager extends TypertRemoteService { const oauthKeys = new Set() for (const [name, entry] of Object.entries(entries)) { const path = `servers.${name}` + this.clientConfig(name, entry) if (entry.oauth !== undefined) { + if (entry.transport !== 'streamable-http') throw new Error(path + ': OAuth requires streamable-http') try { parseCredentialKey(entry.oauth.credentialKey) } catch (error) { throw new Error(`${path}.oauth.credentialKey: ${(error as TypeError).message}`, { cause: error }) } - if (entry.transport !== 'streamable-http') throw new Error(path + ': OAuth requires streamable-http') if (oauthKeys.has(entry.oauth.credentialKey)) throw new Error(path + ': OAuth credentialKey is already assigned to another server') oauthKeys.add(entry.oauth.credentialKey) } @@ -655,7 +654,6 @@ export default class McpServerManager extends TypertRemoteService { throw new Error(`${path}: "cwd" is not a streamable-http field — remove it or set transport: stdio`) } } - this.clientConfig(name, entry) } } diff --git a/packages/mcp/mcp-manager/tests/composition.spec.ts b/packages/mcp/mcp-manager/tests/composition.spec.ts index 6bbb40c9f1..abf0269115 100644 --- a/packages/mcp/mcp-manager/tests/composition.spec.ts +++ b/packages/mcp/mcp-manager/tests/composition.spec.ts @@ -138,4 +138,14 @@ describe('mcp-manager real composition', () => { expect(await readFile(profile.patchPath, 'utf8')).toBe(saved) expect(ctx.mcpManager.list()).toEqual([]) }) + + it('names the oauth field when a settings write supplies an OAuth configuration without a credential key', async () => { + const ctx = await registry() + const { profile } = await managerProfile(ctx, { base: { servers: {} } }) + const saved = await readFile(profile.patchPath, 'utf8') + await expect(ctx.settings.update('mcp', { servers: { one: { + transport: 'streamable-http', url: 'https://example.invalid/mcp', oauth: {}, enabled: false, + } } })).rejects.toThrow('servers.one.oauth expected') + expect(await readFile(profile.patchPath, 'utf8')).toBe(saved) + }) })