Skip to content

Commit fbd8aaa

Browse files
authored
fix(core): add missing oauth fields support in subagent parsing (#26141)
1 parent 9e7c924 commit fbd8aaa

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

packages/core/src/agents/agentLoader.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,59 @@ Body`);
529529
});
530530
});
531531

532+
it('should convert mcp_servers with auth block in local agent (oauth with full fields)', () => {
533+
const markdown = {
534+
kind: 'local' as const,
535+
name: 'oauth-test-agent',
536+
description: 'An agent to test OAuth MCP with full fields',
537+
mcp_servers: {
538+
'test-server': {
539+
url: 'https://api.example.com/mcp',
540+
type: 'http' as const,
541+
auth: {
542+
type: 'oauth' as const,
543+
client_id: 'my-client-id',
544+
client_secret: 'my-client-secret',
545+
scopes: ['read', 'write'],
546+
authorization_url: 'https://auth.example.com/authorize',
547+
token_url: 'https://auth.example.com/token',
548+
issuer: 'https://auth.example.com',
549+
audiences: ['audience1'],
550+
redirect_uri: 'http://localhost:8080/callback',
551+
token_param_name: 'access_token',
552+
registration_url: 'https://auth.example.com/register',
553+
},
554+
timeout: 30000,
555+
},
556+
},
557+
system_prompt: 'You are a test agent.',
558+
};
559+
560+
const result = markdownToAgentDefinition(
561+
markdown,
562+
) as LocalAgentDefinition;
563+
expect(result.kind).toBe('local');
564+
expect(result.mcpServers).toBeDefined();
565+
expect(result.mcpServers!['test-server']).toMatchObject({
566+
url: 'https://api.example.com/mcp',
567+
type: 'http',
568+
oauth: {
569+
enabled: true,
570+
clientId: 'my-client-id',
571+
clientSecret: 'my-client-secret',
572+
scopes: ['read', 'write'],
573+
authorizationUrl: 'https://auth.example.com/authorize',
574+
tokenUrl: 'https://auth.example.com/token',
575+
issuer: 'https://auth.example.com',
576+
audiences: ['audience1'],
577+
redirectUri: 'http://localhost:8080/callback',
578+
tokenParamName: 'access_token',
579+
registrationUrl: 'https://auth.example.com/register',
580+
},
581+
timeout: 30000,
582+
});
583+
});
584+
532585
it('should pass through unknown model names (e.g. auto)', () => {
533586
const markdown = {
534587
kind: 'local' as const,
@@ -886,6 +939,12 @@ auth:
886939
- profile
887940
authorization_url: https://auth.example.com/authorize
888941
token_url: https://auth.example.com/token
942+
issuer: https://auth.example.com
943+
audiences:
944+
- audience1
945+
redirect_uri: http://localhost:8080/callback
946+
token_param_name: access_token
947+
registration_url: https://auth.example.com/register
889948
---
890949
`);
891950
const result = await parseAgentMarkdown(filePath);
@@ -900,6 +959,11 @@ auth:
900959
scopes: ['openid', 'profile'],
901960
authorization_url: 'https://auth.example.com/authorize',
902961
token_url: 'https://auth.example.com/token',
962+
issuer: 'https://auth.example.com',
963+
audiences: ['audience1'],
964+
redirect_uri: 'http://localhost:8080/callback',
965+
token_param_name: 'access_token',
966+
registration_url: 'https://auth.example.com/register',
903967
},
904968
});
905969
});

packages/core/src/agents/agentLoader.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ const mcpServerSchema = z.object({
7979
scopes: z.array(z.string()).optional(),
8080
authorization_url: z.string().url().optional(),
8181
token_url: z.string().url().optional(),
82+
issuer: z.string().url().optional(),
83+
audiences: z.array(z.string()).optional(),
84+
redirect_uri: z.string().url().optional(),
85+
token_param_name: z.string().optional(),
86+
registration_url: z.string().url().optional(),
8287
}),
8388
])
8489
.optional(),
@@ -148,6 +153,11 @@ const oauth2AuthSchema = z.object({
148153
scopes: z.array(z.string()).optional(),
149154
authorization_url: z.string().url().optional(),
150155
token_url: z.string().url().optional(),
156+
issuer: z.string().url().optional(),
157+
audiences: z.array(z.string()).optional(),
158+
redirect_uri: z.string().url().optional(),
159+
token_param_name: z.string().optional(),
160+
registration_url: z.string().url().optional(),
151161
});
152162

153163
const authConfigSchema = z
@@ -459,6 +469,11 @@ function convertFrontmatterAuthToConfig(
459469
scopes: frontmatter.scopes,
460470
authorization_url: frontmatter.authorization_url,
461471
token_url: frontmatter.token_url,
472+
issuer: frontmatter.issuer,
473+
audiences: frontmatter.audiences,
474+
redirect_uri: frontmatter.redirect_uri,
475+
token_param_name: frontmatter.token_param_name,
476+
registration_url: frontmatter.registration_url,
462477
};
463478

464479
default: {
@@ -552,6 +567,11 @@ export function markdownToAgentDefinition(
552567
scopes: config.auth.scopes,
553568
authorizationUrl: config.auth.authorization_url,
554569
tokenUrl: config.auth.token_url,
570+
issuer: config.auth.issuer,
571+
audiences: config.auth.audiences,
572+
redirectUri: config.auth.redirect_uri,
573+
tokenParamName: config.auth.token_param_name,
574+
registrationUrl: config.auth.registration_url,
555575
};
556576
}
557577
}

packages/core/src/agents/auth-provider/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export interface OAuth2AuthConfig extends BaseAuthConfig {
7777
authorization_url?: string;
7878
/** Override or provide the token endpoint URL. Discovered from agent card if omitted. */
7979
token_url?: string;
80+
issuer?: string;
81+
audiences?: string[];
82+
redirect_uri?: string;
83+
token_param_name?: string;
84+
registration_url?: string;
8085
}
8186

8287
/** Client config corresponding to OpenIdConnectSecurityScheme. */

0 commit comments

Comments
 (0)