Skip to content

Commit 3734ace

Browse files
Merge branch 'main' into mcp-docs
2 parents 8360b32 + 93008f1 commit 3734ace

26 files changed

+370
-59
lines changed

.changeset/crazy-coats-give.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+
Add remote MCP server (Streamable HTTP) support

.changeset/eighty-dingos-pump.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@openai/agents-core": patch
3+
"@openai/agents-openai": patch
4+
---
5+
6+
Add allowed_tools and headers to hosted mcp server factory method

.changeset/tired-experts-care.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+
Publishes types that were marked as internal but caused build errors when not exported in typings.

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The OpenAI Agents JS repository is a pnpm-managed monorepo that provides:
4343
- `pnpm-workspace.yaml`: Defines workspace packages.
4444
- `tsconfig.json`, `tsc-multi.json`: TypeScript configuration.
4545
- `vitest.config.ts`: Test runner configuration.
46-
- `eslint.config.js`: ESLint configuration.
46+
- `eslint.config.mjs`: ESLint configuration.
4747
- `package.json` (root): Common scripts (`build`, `test`, `lint`, `dev`, `docs:dev`, `examples:*`).
4848

4949
## Testing & Automated Checks
@@ -81,7 +81,7 @@ Before submitting changes, ensure all checks pass:
8181
```bash
8282
pnpm lint
8383
```
84-
- Code style follows `eslint.config.js` and Prettier defaults.
84+
- Code style follows `eslint.config.mjs` and Prettier defaults.
8585
- Comments must end with a period.
8686

8787
### Type Checking
@@ -128,7 +128,7 @@ Before submitting changes, ensure all checks pass:
128128

129129
## Style, Linting & Type Checking
130130

131-
- Follow ESLint rules (`eslint.config.js`), no unused imports, adhere to Prettier.
131+
- Follow ESLint rules (`eslint.config.mjs`), no unused imports, adhere to Prettier.
132132
- Run `pnpm lint` and fix all errors locally.
133133
- Use `pnpm build` to catch type errors.
134134

File renamed without changes.

examples/mcp/filesystem-example.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function main() {
1616
try {
1717
await withTrace('MCP Filesystem Example', async () => {
1818
const agent = new Agent({
19-
name: 'Assistant',
19+
name: 'MCP Assistant',
2020
instructions:
2121
'Use the tools to read the filesystem and answer questions based on those files. If you are unable to find any files, you can say so instead of assuming they exist.',
2222
mcpServers: [mcpServer],
@@ -25,20 +25,20 @@ async function main() {
2525
let message = 'Read the files and list them.';
2626
console.log(`Running: ${message}`);
2727
let result = await run(agent, message);
28-
console.log(result.finalOutput ?? result.output ?? result);
28+
console.log(result.finalOutput);
2929

3030
// Ask about books
3131
message = 'What is my #1 favorite book?';
3232
console.log(`\nRunning: ${message}\n`);
3333
result = await run(agent, message);
34-
console.log(result.finalOutput ?? result.output ?? result);
34+
console.log(result.finalOutput);
3535

3636
// Ask a question that reads then reasons
3737
message =
3838
'Look at my favorite songs. Suggest one new song that I might like.';
3939
console.log(`\nRunning: ${message}\n`);
4040
result = await run(agent, message);
41-
console.log(result.finalOutput ?? result.output ?? result);
41+
console.log(result.finalOutput);
4242
});
4343
} finally {
4444
await mcpServer.close();

examples/mcp/hosted-mcp-human-in-the-loop.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as readline from 'readline/promises';
2-
import { stdin, stdout } from 'node:process';
31
import { Agent, run, hostedMcpTool, RunToolApprovalItem } from '@openai/agents';
2+
import * as readline from 'node:readline/promises';
3+
import { stdin, stdout } from 'node:process';
44

5-
async function promptApproval(item: RunToolApprovalItem): Promise<boolean> {
5+
async function confirm(item: RunToolApprovalItem): Promise<boolean> {
66
const rl = readline.createInterface({ input: stdin, output: stdout });
77
const name = item.rawItem.name;
88
const params = JSON.parse(item.rawItem.providerData?.arguments || '{}');
@@ -14,9 +14,7 @@ async function promptApproval(item: RunToolApprovalItem): Promise<boolean> {
1414
}
1515

1616
async function main(verbose: boolean, stream: boolean): Promise<void> {
17-
// 'always' |
18-
// 'never' |
19-
// { never?: { toolNames: string[] }; always?: { toolNames: string[] } }
17+
// 'always' | 'never' | { never, always }
2018
const requireApproval = {
2119
never: { toolNames: ['search_codex_code', 'fetch_codex_documentation'] },
2220
always: { toolNames: ['fetch_generic_url_content'] },
@@ -54,17 +52,18 @@ async function main(verbose: boolean, stream: boolean): Promise<void> {
5452
console.log(`Done streaming; final result: ${result.finalOutput}`);
5553
} else {
5654
// Non-streaming
57-
let result = await run(agent, input, { maxTurns: 100 });
55+
let result = await run(agent, input);
5856
while (result.interruptions && result.interruptions.length) {
5957
for (const interruption of result.interruptions) {
60-
const approval = await promptApproval(interruption);
58+
// Human in the loop here
59+
const approval = await confirm(interruption);
6160
if (approval) {
6261
result.state.approve(interruption);
6362
} else {
6463
result.state.reject(interruption);
6564
}
6665
}
67-
result = await run(agent, result.state, { maxTurns: 100 });
66+
result = await run(agent, result.state);
6867
}
6968
console.log(result.finalOutput);
7069

examples/mcp/hosted-mcp-on-approval.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ async function promptApproval(item: RunToolApprovalItem): Promise<boolean> {
1414
}
1515

1616
async function main(verbose: boolean, stream: boolean): Promise<void> {
17-
// 'always' |
18-
// 'never' |
19-
// { never?: { toolNames: string[] }; always?: { toolNames: string[] } }
17+
// 'always' | 'never' | { never, always }
2018
const requireApproval = {
2119
never: {
2220
toolNames: ['fetch_codex_documentation', 'fetch_generic_url_content'],
@@ -34,6 +32,7 @@ async function main(verbose: boolean, stream: boolean): Promise<void> {
3432
serverUrl: 'https://gitmcp.io/openai/codex',
3533
requireApproval,
3634
onApproval: async (_context, item) => {
35+
// Human in the loop here
3736
const approval = await promptApproval(item);
3837
return { approve: approval, reason: undefined };
3938
},

examples/mcp/hosted-mcp-simple.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ async function main(verbose: boolean, stream: boolean): Promise<void> {
99
hostedMcpTool({
1010
serverLabel: 'gitmcp',
1111
serverUrl: 'https://gitmcp.io/openai/codex',
12-
requireApproval: 'never',
1312
}),
1413
],
1514
});

examples/mcp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"scripts": {
1010
"build-check": "tsc --noEmit",
1111
"start:stdio": "tsx filesystem-example.ts",
12+
"start:streamable-http": "tsx streamable-http-example.ts",
1213
"start:hosted-mcp-on-approval": "tsx hosted-mcp-on-approval.ts",
1314
"start:hosted-mcp-human-in-the-loop": "tsx hosted-mcp-human-in-the-loop.ts",
1415
"start:hosted-mcp-simple": "tsx hosted-mcp-simple.ts"

0 commit comments

Comments
 (0)