@ai-sdk/harness-codex 0.0.0-6b196531-20260710185421
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +391 -0
- package/LICENSE +13 -0
- package/README.md +73 -0
- package/dist/bridge/host-tool-mcp.mjs +103 -0
- package/dist/bridge/host-tool-mcp.mjs.map +1 -0
- package/dist/bridge/index.mjs +1297 -0
- package/dist/bridge/index.mjs.map +1 -0
- package/dist/bridge/package.json +12 -0
- package/dist/bridge/pnpm-lock.yaml +879 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +899 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
- package/src/bridge/cli-relay.ts +198 -0
- package/src/bridge/codex-step-tracker.ts +83 -0
- package/src/bridge/host-tool-mcp.ts +160 -0
- package/src/bridge/index.ts +746 -0
- package/src/bridge/package.json +12 -0
- package/src/bridge/pnpm-lock.yaml +879 -0
- package/src/bridge/tool-relay-auth.ts +195 -0
- package/src/codex-auth.ts +119 -0
- package/src/codex-bridge-protocol.ts +38 -0
- package/src/codex-harness.ts +1132 -0
- package/src/index.ts +13 -0
- package/src/version.ts +6 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// MCP-stdio tool server spawned by the codex CLI when
|
|
3
|
+
// `mcp_servers.harness-tools` is configured. Exposes host-defined tools
|
|
4
|
+
// over MCP-stdio and round-trips each call to the bridge's HTTP relay.
|
|
5
|
+
//
|
|
6
|
+
// Env vars (set by the bridge when starting a turn):
|
|
7
|
+
// TOOL_SCHEMAS — JSON array of { name, description, inputSchema }
|
|
8
|
+
// TOOL_RELAY_URL — http://127.0.0.1:<port> of the bridge relay server
|
|
9
|
+
// Relay authorization is issued by bridge runtime events, not an env token.
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* CONSTRAINT — the third-party imports below are NEVER bundled into the
|
|
13
|
+
* compiled `bridge/host-tool-mcp.mjs`. They are declared `external` in
|
|
14
|
+
* tsup.config.ts and resolved at runtime from the node_modules that the
|
|
15
|
+
* bridge installs *inside the sandbox* from `src/bridge/package.json` (and
|
|
16
|
+
* its pinned `pnpm-lock.yaml`). That bridge package.json — NOT this host
|
|
17
|
+
* package — is the single source of truth for these packages and their
|
|
18
|
+
* versions; the published `@ai-sdk/harness-codex` package does not provide
|
|
19
|
+
* them at runtime.
|
|
20
|
+
*
|
|
21
|
+
* When adding or changing a third-party import here you MUST keep all three
|
|
22
|
+
* in sync, or this server will either get the dependency bundled in or fail
|
|
23
|
+
* to resolve it in the sandbox:
|
|
24
|
+
* 1. the import statement below,
|
|
25
|
+
* 2. the `external` array in tsup.config.ts, and
|
|
26
|
+
* 3. the dependency entry in `src/bridge/package.json`.
|
|
27
|
+
*/
|
|
28
|
+
import * as mcpServerModule from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
29
|
+
import * as mcpStdioModule from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
30
|
+
import { z } from 'zod/v4';
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
const { McpServer } = mcpServerModule as any;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
const { StdioServerTransport } = mcpStdioModule as any;
|
|
36
|
+
|
|
37
|
+
type ToolSchema = {
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
inputSchema?: JsonSchemaObject;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type JsonSchemaObject = {
|
|
44
|
+
type?: string | string[];
|
|
45
|
+
description?: string;
|
|
46
|
+
properties?: Record<string, JsonSchemaObject>;
|
|
47
|
+
required?: string[];
|
|
48
|
+
items?: JsonSchemaObject;
|
|
49
|
+
enum?: unknown[];
|
|
50
|
+
const?: unknown;
|
|
51
|
+
oneOf?: JsonSchemaObject[];
|
|
52
|
+
anyOf?: JsonSchemaObject[];
|
|
53
|
+
additionalProperties?: boolean | JsonSchemaObject;
|
|
54
|
+
nullable?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const schemas: ToolSchema[] = JSON.parse(process.env.TOOL_SCHEMAS || '[]');
|
|
58
|
+
const relayUrl = process.env.TOOL_RELAY_URL || '';
|
|
59
|
+
|
|
60
|
+
if (!schemas.length || !relayUrl) {
|
|
61
|
+
process.stderr.write(
|
|
62
|
+
'[host-tool-mcp] Missing TOOL_SCHEMAS or TOOL_RELAY_URL; exiting\n',
|
|
63
|
+
);
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const server = new McpServer({ name: 'harness-tools', version: '1.0.0' });
|
|
68
|
+
|
|
69
|
+
for (const schema of schemas) {
|
|
70
|
+
const shape = toZodShape(schema.inputSchema);
|
|
71
|
+
server.tool(
|
|
72
|
+
schema.name,
|
|
73
|
+
schema.description ?? '',
|
|
74
|
+
shape,
|
|
75
|
+
async (input: Record<string, unknown>) => {
|
|
76
|
+
const requestId = crypto.randomUUID();
|
|
77
|
+
try {
|
|
78
|
+
const res = await fetch(relayUrl, {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
headers: {
|
|
81
|
+
'Content-Type': 'application/json',
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify({ requestId, toolName: schema.name, input }),
|
|
84
|
+
});
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
const body = await res.text();
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Tool relay ${schema.name} failed with ${res.status}: ${body.slice(0, 500)}`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const data = (await res.json()) as { result?: unknown };
|
|
92
|
+
return {
|
|
93
|
+
content: [
|
|
94
|
+
{
|
|
95
|
+
type: 'text' as const,
|
|
96
|
+
text: JSON.stringify(data.result ?? null),
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
} catch (err) {
|
|
101
|
+
return {
|
|
102
|
+
content: [{ type: 'text' as const, text: `Error: ${String(err)}` }],
|
|
103
|
+
isError: true,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function toZodShape(
|
|
111
|
+
schema: JsonSchemaObject | undefined,
|
|
112
|
+
): Record<string, z.ZodTypeAny> {
|
|
113
|
+
if (!schema?.properties) return {};
|
|
114
|
+
const required = new Set(schema.required ?? []);
|
|
115
|
+
const shape: Record<string, z.ZodTypeAny> = {};
|
|
116
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
117
|
+
const propType = toZodType(propSchema);
|
|
118
|
+
shape[key] = required.has(key) ? propType : propType.optional();
|
|
119
|
+
}
|
|
120
|
+
return shape;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function toZodType(schema: JsonSchemaObject | undefined): z.ZodTypeAny {
|
|
124
|
+
if (!schema) return z.any();
|
|
125
|
+
const types = Array.isArray(schema.type)
|
|
126
|
+
? schema.type.filter((t): t is string => t !== 'null')
|
|
127
|
+
: ([schema.type].filter(Boolean) as string[]);
|
|
128
|
+
let zType: z.ZodTypeAny;
|
|
129
|
+
switch (types[0]) {
|
|
130
|
+
case 'string':
|
|
131
|
+
zType = z.string();
|
|
132
|
+
break;
|
|
133
|
+
case 'number':
|
|
134
|
+
zType = z.number();
|
|
135
|
+
break;
|
|
136
|
+
case 'integer':
|
|
137
|
+
zType = z.number().int();
|
|
138
|
+
break;
|
|
139
|
+
case 'boolean':
|
|
140
|
+
zType = z.boolean();
|
|
141
|
+
break;
|
|
142
|
+
case 'array':
|
|
143
|
+
zType = z.array(toZodType(schema.items));
|
|
144
|
+
break;
|
|
145
|
+
case 'object':
|
|
146
|
+
zType = z.object(toZodShape(schema));
|
|
147
|
+
break;
|
|
148
|
+
case 'null':
|
|
149
|
+
zType = z.null();
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
zType = z.any();
|
|
153
|
+
}
|
|
154
|
+
if (schema.description) zType = zType.describe(schema.description);
|
|
155
|
+
if (schema.nullable) zType = zType.nullable();
|
|
156
|
+
return zType;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const transport = new StdioServerTransport();
|
|
160
|
+
await server.connect(transport);
|