Skip to content

Commit e6cd895

Browse files
committed
fix: correct managed OAuth credential name lookup for gateway MCP clients
The managed OAuth credential is created with the suffix '-oauth' (e.g. 'my-gateway-oauth') but was being looked up with '-agent-oauth' in schema-mapper.ts and displayed with '-agent-oauth' in AddGatewayScreen. This mismatch caused the credential lookup to fail silently, resulting in an empty provider_name in the generated @requires_access_token decorator. The agent runtime then crashed with: ParamValidationError: Invalid length for parameter resourceCredentialProviderName, value: 0, valid min length: 1
1 parent 73156a4 commit e6cd895

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/cli/operations/agent/generate/__tests__/schema-mapper.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,23 @@ describe('mapGenerateConfigToRenderConfig', () => {
190190
expect(result.memoryProviders[0]!.strategies).toEqual(['SEMANTIC', 'USER_PREFERENCE', 'SUMMARIZATION']);
191191
});
192192
});
193+
194+
describe('gateway credential provider name mapping', () => {
195+
it('uses the correct credential name suffix (-oauth) matching GatewayPrimitive creation', async () => {
196+
// Regression test: credential is created as `${gatewayName}-oauth` by GatewayPrimitive,
197+
// so the lookup in mapGatewaysToGatewayProviders must use the same suffix.
198+
// Previously used '-agent-oauth' which caused provider_name="" in generated code.
199+
//
200+
// We verify this by checking the source code directly since ConfigIO requires
201+
// a full build environment to import.
202+
203+
const fs = await import('node:fs');
204+
const path = await import('node:path');
205+
const schemaMapperPath = path.resolve(import.meta.dirname ?? __dirname, '../schema-mapper.ts');
206+
const source = fs.readFileSync(schemaMapperPath, 'utf-8');
207+
208+
// The credential lookup must use `${gateway.name}-oauth` (not `-agent-oauth`)
209+
expect(source).toContain('`${gateway.name}-oauth`');
210+
expect(source).not.toContain('-agent-oauth');
211+
});
212+
});

src/cli/operations/agent/generate/schema-mapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async function mapGatewaysToGatewayProviders(): Promise<GatewayProviderRenderCon
199199

200200
if (gateway.authorizerType === 'CUSTOM_JWT' && gateway.authorizerConfiguration?.customJwtAuthorizer) {
201201
const jwtConfig = gateway.authorizerConfiguration.customJwtAuthorizer;
202-
const credName = `${gateway.name}-agent-oauth`;
202+
const credName = `${gateway.name}-oauth`;
203203
const credential = project.credentials.find(c => c.name === credName);
204204

205205
if (credential) {

src/cli/tui/screens/mcp/AddGatewayScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export function AddGatewayScreen({ onComplete, onExit, existingGateways, unassig
272272
? [{ label: 'Allowed Scopes', value: wizard.config.jwtConfig.allowedScopes.join(', ') }]
273273
: []),
274274
...(wizard.config.jwtConfig.agentClientId
275-
? [{ label: 'Agent Credential', value: `${wizard.config.name}-agent-oauth` }]
275+
? [{ label: 'Agent Credential', value: `${wizard.config.name}-oauth` }]
276276
: []),
277277
]
278278
: []),

0 commit comments

Comments
 (0)