doer-agent 0.5.9 → 0.6.0
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/dist/agent-bundled-skills.js +79 -0
- package/dist/agent-codex-app-rpc.js +63 -0
- package/dist/agent-codex-auth-rpc.js +96 -238
- package/dist/agent-codex-cli.js +1 -11
- package/dist/agent-runtime-utils.js +4 -65
- package/dist/agent-session-loop.js +0 -1
- package/dist/agent-settings-rpc.js +10 -82
- package/dist/agent-settings.js +1 -115
- package/dist/agent.js +47 -311
- package/dist/codex-app-server-client.js +148 -0
- package/dist/codex-app-server-manager.js +108 -0
- package/package.json +1 -4
- package/dist/agent-run-execution.js +0 -39
- package/dist/agent-run-lifecycle.js +0 -67
- package/dist/agent-run-rpc.js +0 -93
- package/dist/agent-run-state.js +0 -287
- package/dist/agent-runtime-utils.test.js +0 -38
- package/dist/agent-session-rpc.js +0 -1033
- package/dist/db-mcp-server.js +0 -377
package/dist/db-mcp-server.js
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import { createPool } from "mysql2/promise";
|
|
5
|
-
import { Pool as PostgresPool } from "pg";
|
|
6
|
-
import * as z from "zod/v4";
|
|
7
|
-
import { getAgentDatabaseConnectionById, readAgentSettingsConfig, resolveAgentDatabaseConnectionUrl, } from "./agent-settings.js";
|
|
8
|
-
const DEFAULT_ROW_LIMIT = 200;
|
|
9
|
-
const MAX_ROW_LIMIT = 1000;
|
|
10
|
-
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
11
|
-
const MAX_TIMEOUT_MS = 30_000;
|
|
12
|
-
const postgresPoolByKey = new Map();
|
|
13
|
-
const mysqlPoolByKey = new Map();
|
|
14
|
-
function parseWorkspaceRoot(argv) {
|
|
15
|
-
const flagIndex = argv.findIndex((token) => token === "--workspace-root");
|
|
16
|
-
const flagValue = flagIndex >= 0 ? argv[flagIndex + 1] : "";
|
|
17
|
-
const envValue = process.env.DOER_DB_WORKSPACE_ROOT?.trim() || process.env.WORKSPACE?.trim() || process.cwd();
|
|
18
|
-
return path.resolve((flagValue || envValue || process.cwd()).trim());
|
|
19
|
-
}
|
|
20
|
-
function formatJson(value) {
|
|
21
|
-
return JSON.stringify(value, null, 2);
|
|
22
|
-
}
|
|
23
|
-
function clampNumber(value, fallback, max) {
|
|
24
|
-
if (!Number.isFinite(value)) {
|
|
25
|
-
return fallback;
|
|
26
|
-
}
|
|
27
|
-
return Math.max(1, Math.min(max, Math.trunc(value)));
|
|
28
|
-
}
|
|
29
|
-
function normalizeSql(sql) {
|
|
30
|
-
const trimmed = sql.trim().replace(/;+$/g, "").trim();
|
|
31
|
-
if (!trimmed) {
|
|
32
|
-
throw new Error("sql is required");
|
|
33
|
-
}
|
|
34
|
-
if (trimmed.includes(";")) {
|
|
35
|
-
throw new Error("Multiple SQL statements are not supported");
|
|
36
|
-
}
|
|
37
|
-
return trimmed;
|
|
38
|
-
}
|
|
39
|
-
function requireConnection(args) {
|
|
40
|
-
const enabledConnections = args.settings.databases.connections.filter((connection) => connection.enabled);
|
|
41
|
-
const requestedId = args.connectionId?.trim() || args.settings.databases.defaultConnectionId || enabledConnections[0]?.id || "";
|
|
42
|
-
const connection = getAgentDatabaseConnectionById(args.settings, requestedId);
|
|
43
|
-
if (!connection || !connection.enabled) {
|
|
44
|
-
throw new Error(requestedId
|
|
45
|
-
? `Database connection not found or disabled: ${requestedId}`
|
|
46
|
-
: "No enabled database connections are configured");
|
|
47
|
-
}
|
|
48
|
-
return connection;
|
|
49
|
-
}
|
|
50
|
-
function requireConnectionUrl(connection) {
|
|
51
|
-
const url = resolveAgentDatabaseConnectionUrl(connection);
|
|
52
|
-
if (!url) {
|
|
53
|
-
if (connection.connection.mode === "env") {
|
|
54
|
-
throw new Error(`Database URL env is missing: ${connection.connection.urlEnv}`);
|
|
55
|
-
}
|
|
56
|
-
throw new Error(`Database URL is missing for connection: ${connection.id}`);
|
|
57
|
-
}
|
|
58
|
-
return url;
|
|
59
|
-
}
|
|
60
|
-
function getPostgresPool(connection) {
|
|
61
|
-
const connectionUrl = requireConnectionUrl(connection);
|
|
62
|
-
const key = `${connection.provider}:${connection.id}:${connectionUrl}`;
|
|
63
|
-
const existing = postgresPoolByKey.get(key);
|
|
64
|
-
if (existing) {
|
|
65
|
-
return existing;
|
|
66
|
-
}
|
|
67
|
-
const pool = new PostgresPool({
|
|
68
|
-
connectionString: connectionUrl,
|
|
69
|
-
max: 4,
|
|
70
|
-
});
|
|
71
|
-
postgresPoolByKey.set(key, pool);
|
|
72
|
-
return pool;
|
|
73
|
-
}
|
|
74
|
-
function getMysqlPool(connection) {
|
|
75
|
-
const connectionUrl = requireConnectionUrl(connection);
|
|
76
|
-
const key = `${connection.provider}:${connection.id}:${connectionUrl}`;
|
|
77
|
-
const existing = mysqlPoolByKey.get(key);
|
|
78
|
-
if (existing) {
|
|
79
|
-
return existing;
|
|
80
|
-
}
|
|
81
|
-
const pool = createPool({
|
|
82
|
-
uri: connectionUrl,
|
|
83
|
-
connectionLimit: 4,
|
|
84
|
-
namedPlaceholders: false,
|
|
85
|
-
multipleStatements: false,
|
|
86
|
-
});
|
|
87
|
-
mysqlPoolByKey.set(key, pool);
|
|
88
|
-
return pool;
|
|
89
|
-
}
|
|
90
|
-
function serializeRow(row) {
|
|
91
|
-
return Object.fromEntries(Object.entries(row));
|
|
92
|
-
}
|
|
93
|
-
async function runPostgresSql(args) {
|
|
94
|
-
const pool = getPostgresPool(args.connection);
|
|
95
|
-
const client = await pool.connect();
|
|
96
|
-
const rowLimit = clampNumber(args.rowLimit, DEFAULT_ROW_LIMIT, MAX_ROW_LIMIT);
|
|
97
|
-
const timeoutMs = clampNumber(args.timeoutMs, DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS);
|
|
98
|
-
let inTransaction = false;
|
|
99
|
-
try {
|
|
100
|
-
await client.query("BEGIN");
|
|
101
|
-
inTransaction = true;
|
|
102
|
-
await client.query(`SET LOCAL statement_timeout = ${timeoutMs}`);
|
|
103
|
-
if (args.connection.readOnly) {
|
|
104
|
-
await client.query("SET TRANSACTION READ ONLY");
|
|
105
|
-
}
|
|
106
|
-
const result = await client.query(normalizeSql(args.sql));
|
|
107
|
-
await client.query("COMMIT");
|
|
108
|
-
inTransaction = false;
|
|
109
|
-
return {
|
|
110
|
-
connectionId: args.connection.id,
|
|
111
|
-
rowCount: result.rowCount ?? result.rows.length,
|
|
112
|
-
rows: result.rows.slice(0, rowLimit).map((row) => serializeRow(row)),
|
|
113
|
-
fields: result.fields.map((field) => field.name),
|
|
114
|
-
truncated: result.rows.length > rowLimit,
|
|
115
|
-
readOnly: args.connection.readOnly,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
if (inTransaction) {
|
|
120
|
-
await client.query("ROLLBACK").catch(() => undefined);
|
|
121
|
-
}
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
finally {
|
|
125
|
-
client.release();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async function runMysqlSql(args) {
|
|
129
|
-
const pool = getMysqlPool(args.connection);
|
|
130
|
-
const client = await pool.getConnection();
|
|
131
|
-
const rowLimit = clampNumber(args.rowLimit, DEFAULT_ROW_LIMIT, MAX_ROW_LIMIT);
|
|
132
|
-
const timeoutMs = clampNumber(args.timeoutMs, DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS);
|
|
133
|
-
let inTransaction = false;
|
|
134
|
-
try {
|
|
135
|
-
await client.query(args.connection.readOnly ? "START TRANSACTION READ ONLY" : "START TRANSACTION");
|
|
136
|
-
inTransaction = true;
|
|
137
|
-
const [rows, fields] = await client.query({
|
|
138
|
-
sql: normalizeSql(args.sql),
|
|
139
|
-
timeout: timeoutMs,
|
|
140
|
-
});
|
|
141
|
-
await client.query("COMMIT");
|
|
142
|
-
inTransaction = false;
|
|
143
|
-
if (Array.isArray(rows)) {
|
|
144
|
-
const rowPackets = rows;
|
|
145
|
-
const fieldPackets = Array.isArray(fields) ? fields : [];
|
|
146
|
-
return {
|
|
147
|
-
connectionId: args.connection.id,
|
|
148
|
-
rowCount: rowPackets.length,
|
|
149
|
-
rows: rowPackets.slice(0, rowLimit).map((row) => serializeRow(row)),
|
|
150
|
-
fields: fieldPackets.map((field) => field.name),
|
|
151
|
-
truncated: rowPackets.length > rowLimit,
|
|
152
|
-
readOnly: args.connection.readOnly,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
const result = rows;
|
|
156
|
-
return {
|
|
157
|
-
connectionId: args.connection.id,
|
|
158
|
-
rowCount: typeof result.affectedRows === "number" ? result.affectedRows : 0,
|
|
159
|
-
rows: [],
|
|
160
|
-
fields: [],
|
|
161
|
-
truncated: false,
|
|
162
|
-
readOnly: args.connection.readOnly,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
if (inTransaction) {
|
|
167
|
-
await client.query("ROLLBACK").catch(() => undefined);
|
|
168
|
-
}
|
|
169
|
-
throw error;
|
|
170
|
-
}
|
|
171
|
-
finally {
|
|
172
|
-
client.release();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
async function runSql(args) {
|
|
176
|
-
if (args.connection.provider === "mysql") {
|
|
177
|
-
return runMysqlSql(args);
|
|
178
|
-
}
|
|
179
|
-
return runPostgresSql(args);
|
|
180
|
-
}
|
|
181
|
-
async function listTables(connection, schema) {
|
|
182
|
-
const normalizedSchema = schema?.trim();
|
|
183
|
-
if (connection.provider === "mysql") {
|
|
184
|
-
const pool = getMysqlPool(connection);
|
|
185
|
-
const [rows] = normalizedSchema
|
|
186
|
-
? await pool.query(`
|
|
187
|
-
SELECT table_schema, table_name
|
|
188
|
-
FROM information_schema.tables
|
|
189
|
-
WHERE table_schema = ? AND table_type = 'BASE TABLE'
|
|
190
|
-
ORDER BY table_schema, table_name
|
|
191
|
-
`, [normalizedSchema])
|
|
192
|
-
: await pool.query(`
|
|
193
|
-
SELECT table_schema, table_name
|
|
194
|
-
FROM information_schema.tables
|
|
195
|
-
WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE'
|
|
196
|
-
ORDER BY table_schema, table_name
|
|
197
|
-
`);
|
|
198
|
-
return rows.map((row) => ({
|
|
199
|
-
schema: String(row.table_schema),
|
|
200
|
-
name: String(row.table_name),
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
203
|
-
const pool = getPostgresPool(connection);
|
|
204
|
-
const result = normalizedSchema
|
|
205
|
-
? await pool.query(`
|
|
206
|
-
SELECT table_schema, table_name
|
|
207
|
-
FROM information_schema.tables
|
|
208
|
-
WHERE table_schema = $1 AND table_type = 'BASE TABLE'
|
|
209
|
-
ORDER BY table_schema, table_name
|
|
210
|
-
`, [normalizedSchema])
|
|
211
|
-
: await pool.query(`
|
|
212
|
-
SELECT table_schema, table_name
|
|
213
|
-
FROM information_schema.tables
|
|
214
|
-
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
|
|
215
|
-
AND table_type = 'BASE TABLE'
|
|
216
|
-
ORDER BY table_schema, table_name
|
|
217
|
-
`);
|
|
218
|
-
return result.rows.map((row) => ({
|
|
219
|
-
schema: String(row.table_schema),
|
|
220
|
-
name: String(row.table_name),
|
|
221
|
-
}));
|
|
222
|
-
}
|
|
223
|
-
async function describeTable(args) {
|
|
224
|
-
const schema = args.schema.trim();
|
|
225
|
-
const table = args.table.trim();
|
|
226
|
-
if (args.connection.provider === "mysql") {
|
|
227
|
-
const pool = getMysqlPool(args.connection);
|
|
228
|
-
const [rows] = await pool.query(`
|
|
229
|
-
SELECT column_name, column_type, is_nullable, column_default
|
|
230
|
-
FROM information_schema.columns
|
|
231
|
-
WHERE table_schema = ? AND table_name = ?
|
|
232
|
-
ORDER BY ordinal_position
|
|
233
|
-
`, [schema, table]);
|
|
234
|
-
return rows.map((row) => ({
|
|
235
|
-
name: String(row.column_name),
|
|
236
|
-
dataType: String(row.column_type),
|
|
237
|
-
nullable: String(row.is_nullable) === "YES",
|
|
238
|
-
defaultValue: row.column_default === null ? null : String(row.column_default),
|
|
239
|
-
}));
|
|
240
|
-
}
|
|
241
|
-
const pool = getPostgresPool(args.connection);
|
|
242
|
-
const result = await pool.query(`
|
|
243
|
-
SELECT column_name, data_type, is_nullable, column_default
|
|
244
|
-
FROM information_schema.columns
|
|
245
|
-
WHERE table_schema = $1 AND table_name = $2
|
|
246
|
-
ORDER BY ordinal_position
|
|
247
|
-
`, [schema, table]);
|
|
248
|
-
return result.rows.map((row) => ({
|
|
249
|
-
name: String(row.column_name),
|
|
250
|
-
dataType: String(row.data_type),
|
|
251
|
-
nullable: String(row.is_nullable) === "YES",
|
|
252
|
-
defaultValue: row.column_default === null ? null : String(row.column_default),
|
|
253
|
-
}));
|
|
254
|
-
}
|
|
255
|
-
async function main() {
|
|
256
|
-
const workspaceRoot = parseWorkspaceRoot(process.argv.slice(2));
|
|
257
|
-
const server = new McpServer({
|
|
258
|
-
name: "doer-database",
|
|
259
|
-
version: "0.1.0",
|
|
260
|
-
}, {
|
|
261
|
-
capabilities: {
|
|
262
|
-
tools: {},
|
|
263
|
-
},
|
|
264
|
-
instructions: "Inspect configured PostgreSQL or MySQL databases and run SQL queries through named connections.",
|
|
265
|
-
});
|
|
266
|
-
server.registerTool("db_list_connections", {
|
|
267
|
-
description: "List configured database connections available to the local agent.",
|
|
268
|
-
inputSchema: {},
|
|
269
|
-
}, async () => {
|
|
270
|
-
const settings = await readAgentSettingsConfig({ workspaceRoot });
|
|
271
|
-
const connections = settings.databases.connections
|
|
272
|
-
.filter((connection) => connection.enabled)
|
|
273
|
-
.map((connection) => ({
|
|
274
|
-
id: connection.id,
|
|
275
|
-
description: connection.description,
|
|
276
|
-
provider: connection.provider,
|
|
277
|
-
readOnly: connection.readOnly,
|
|
278
|
-
default: settings.databases.defaultConnectionId === connection.id,
|
|
279
|
-
configuredVia: connection.connection.mode,
|
|
280
|
-
urlResolved: Boolean(resolveAgentDatabaseConnectionUrl(connection)),
|
|
281
|
-
}));
|
|
282
|
-
return {
|
|
283
|
-
content: [
|
|
284
|
-
{
|
|
285
|
-
type: "text",
|
|
286
|
-
text: formatJson({ connections }),
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
structuredContent: { connections },
|
|
290
|
-
};
|
|
291
|
-
});
|
|
292
|
-
server.registerTool("db_list_tables", {
|
|
293
|
-
description: "List tables for a configured database connection.",
|
|
294
|
-
inputSchema: {
|
|
295
|
-
connectionId: z.string().optional().describe("Database connection id. Defaults to the configured default connection."),
|
|
296
|
-
schema: z.string().optional().describe("Optional schema or database name to filter by."),
|
|
297
|
-
},
|
|
298
|
-
}, async ({ connectionId, schema }) => {
|
|
299
|
-
const settings = await readAgentSettingsConfig({ workspaceRoot });
|
|
300
|
-
const connection = requireConnection({ settings, connectionId });
|
|
301
|
-
const tables = await listTables(connection, schema);
|
|
302
|
-
return {
|
|
303
|
-
content: [
|
|
304
|
-
{
|
|
305
|
-
type: "text",
|
|
306
|
-
text: formatJson({ connectionId: connection.id, provider: connection.provider, tables }),
|
|
307
|
-
},
|
|
308
|
-
],
|
|
309
|
-
structuredContent: { connectionId: connection.id, provider: connection.provider, tables },
|
|
310
|
-
};
|
|
311
|
-
});
|
|
312
|
-
server.registerTool("db_describe_table", {
|
|
313
|
-
description: "Describe the columns for a specific table.",
|
|
314
|
-
inputSchema: {
|
|
315
|
-
connectionId: z.string().optional().describe("Database connection id. Defaults to the configured default connection."),
|
|
316
|
-
schema: z.string().min(1).describe("Schema name for PostgreSQL, or database name for MySQL."),
|
|
317
|
-
table: z.string().min(1).describe("Table name."),
|
|
318
|
-
},
|
|
319
|
-
}, async ({ connectionId, schema, table }) => {
|
|
320
|
-
const settings = await readAgentSettingsConfig({ workspaceRoot });
|
|
321
|
-
const connection = requireConnection({ settings, connectionId });
|
|
322
|
-
const columns = await describeTable({
|
|
323
|
-
connection,
|
|
324
|
-
schema,
|
|
325
|
-
table,
|
|
326
|
-
});
|
|
327
|
-
return {
|
|
328
|
-
content: [
|
|
329
|
-
{
|
|
330
|
-
type: "text",
|
|
331
|
-
text: formatJson({ connectionId: connection.id, provider: connection.provider, schema: schema.trim(), table: table.trim(), columns }),
|
|
332
|
-
},
|
|
333
|
-
],
|
|
334
|
-
structuredContent: {
|
|
335
|
-
connectionId: connection.id,
|
|
336
|
-
provider: connection.provider,
|
|
337
|
-
schema: schema.trim(),
|
|
338
|
-
table: table.trim(),
|
|
339
|
-
columns,
|
|
340
|
-
},
|
|
341
|
-
};
|
|
342
|
-
});
|
|
343
|
-
server.registerTool("db_query", {
|
|
344
|
-
description: "Run a SQL query through a configured database connection.",
|
|
345
|
-
inputSchema: {
|
|
346
|
-
connectionId: z.string().optional().describe("Database connection id. Defaults to the configured default connection."),
|
|
347
|
-
sql: z.string().min(1).describe("A single SQL statement to execute."),
|
|
348
|
-
rowLimit: z.number().int().min(1).max(MAX_ROW_LIMIT).optional().describe("Maximum number of rows to return."),
|
|
349
|
-
timeoutMs: z.number().int().min(1).max(MAX_TIMEOUT_MS).optional().describe("Statement timeout in milliseconds."),
|
|
350
|
-
},
|
|
351
|
-
}, async ({ connectionId, sql, rowLimit, timeoutMs }) => {
|
|
352
|
-
const settings = await readAgentSettingsConfig({ workspaceRoot });
|
|
353
|
-
const connection = requireConnection({ settings, connectionId });
|
|
354
|
-
const result = await runSql({
|
|
355
|
-
connection,
|
|
356
|
-
sql,
|
|
357
|
-
rowLimit,
|
|
358
|
-
timeoutMs,
|
|
359
|
-
});
|
|
360
|
-
return {
|
|
361
|
-
content: [
|
|
362
|
-
{
|
|
363
|
-
type: "text",
|
|
364
|
-
text: formatJson({ ...result, provider: connection.provider }),
|
|
365
|
-
},
|
|
366
|
-
],
|
|
367
|
-
structuredContent: { ...result, provider: connection.provider },
|
|
368
|
-
};
|
|
369
|
-
});
|
|
370
|
-
const transport = new StdioServerTransport();
|
|
371
|
-
await server.connect(transport);
|
|
372
|
-
}
|
|
373
|
-
main().catch((error) => {
|
|
374
|
-
const message = error instanceof Error ? error.stack || error.message : String(error);
|
|
375
|
-
process.stderr.write(`${message}\n`);
|
|
376
|
-
process.exit(1);
|
|
377
|
-
});
|