Skip to content

Commit 3417f25

Browse files
authored
fix: #597 hostedMcpTool fails to send authorization parameter to Responses API (#598)
1 parent d8862f8 commit 3417f25

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.changeset/long-mangos-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-core': patch
3+
---
4+
5+
fix: #597 hostedMcpTool fails to send authorization parameter to Responses API

packages/agents-core/src/tool.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export function hostedMcpTool<Context = UnknownContext>(
196196
type: 'mcp',
197197
server_label: options.serverLabel,
198198
server_url: options.serverUrl,
199+
authorization: options.authorization,
199200
require_approval: 'never',
200201
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
201202
headers: options.headers,
@@ -204,6 +205,7 @@ export function hostedMcpTool<Context = UnknownContext>(
204205
type: 'mcp',
205206
server_label: options.serverLabel,
206207
server_url: options.serverUrl,
208+
authorization: options.authorization,
207209
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
208210
headers: options.headers,
209211
require_approval:

packages/agents-core/test/tool.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ describe('create a tool using hostedMcpTool utility', () => {
4949
expect(t.providerData.type).toBe('mcp');
5050
expect(t.providerData.server_label).toBe('gitmcp');
5151
});
52+
53+
it('propagates authorization when approval is never required', () => {
54+
const t = hostedMcpTool({
55+
serverLabel: 'gitmcp',
56+
serverUrl: 'https://gitmcp.io/openai/codex',
57+
authorization: 'secret-token',
58+
requireApproval: 'never',
59+
});
60+
61+
expect(t.providerData.authorization).toBe('secret-token');
62+
});
63+
64+
it('propagates authorization when approval is required', () => {
65+
const t = hostedMcpTool({
66+
serverLabel: 'gitmcp',
67+
serverUrl: 'https://gitmcp.io/openai/codex',
68+
authorization: 'secret-token',
69+
requireApproval: {
70+
always: { toolNames: ['tool-name'] },
71+
},
72+
});
73+
74+
expect(t.providerData.authorization).toBe('secret-token');
75+
});
5276
});
5377

5478
describe('tool.invoke', () => {

0 commit comments

Comments
 (0)