argsbarg 7.0.7 → 7.0.9
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 +20 -1
- package/README.md +1 -1
- package/docs/cli-program.md +22 -7
- package/docs/output-schema.md +1 -0
- package/index.d.ts +19 -6
- package/package.json +1 -1
- package/src/core/document-leaf.test.ts +208 -0
- package/src/core/json-leaf.test.ts +26 -0
- package/src/core/leaf-inputs.ts +70 -15
- package/src/core/parse.ts +7 -6
- package/src/core/types.ts +19 -7
- package/src/core/validate.ts +6 -5
- package/src/exports/cli.ts +1 -0
- package/src/help.test.ts +284 -1
- package/src/help.ts +412 -57
- package/src/http/openapi.ts +2 -2
- package/src/http/routes.ts +2 -2
- package/src/http/server.ts +9 -1
- package/src/index.ts +2 -0
- package/src/mcp/tools.ts +3 -3
- package/src/test/integration/http.test.ts +36 -0
package/src/mcp/tools.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
type CliProgram,
|
|
14
14
|
CliValueFormat,
|
|
15
15
|
isCliLeaf,
|
|
16
|
-
|
|
16
|
+
isDocumentLeaf,
|
|
17
17
|
leafOutputSchema,
|
|
18
18
|
} from "../core/types.ts";
|
|
19
19
|
import { docsMcpResources } from "../docs/mcp-resources.ts";
|
|
@@ -155,7 +155,7 @@ function positionalProperty(p: CliPositional): Record<string, unknown> {
|
|
|
155
155
|
|
|
156
156
|
/** Builds inputSchema for a leaf command. */
|
|
157
157
|
function buildInputSchema(leaf: CliLeaf): Record<string, unknown> {
|
|
158
|
-
if (
|
|
158
|
+
if (isDocumentLeaf(leaf) && leaf.inputSchema !== undefined) {
|
|
159
159
|
return leaf.inputSchema;
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -294,7 +294,7 @@ export function mcpToolCallToArgv(
|
|
|
294
294
|
tool: McpToolDef,
|
|
295
295
|
args: Record<string, unknown>,
|
|
296
296
|
): string[] | { error: string } {
|
|
297
|
-
if (
|
|
297
|
+
if (isDocumentLeaf(tool.leaf)) {
|
|
298
298
|
return [...tool.path];
|
|
299
299
|
}
|
|
300
300
|
|
|
@@ -448,6 +448,42 @@ describe("HTTP API routes", () => {
|
|
|
448
448
|
expect(body).toEqual({ error: "bad input" });
|
|
449
449
|
});
|
|
450
450
|
|
|
451
|
+
/** Tests that POST endpoints accept YAML request bodies. */
|
|
452
|
+
test("POST accepts YAML request body", async () => {
|
|
453
|
+
const yamlProgram = testProgram({
|
|
454
|
+
key: "app",
|
|
455
|
+
description: "Test app",
|
|
456
|
+
httpServer: { enabled: true },
|
|
457
|
+
commands: [
|
|
458
|
+
{
|
|
459
|
+
key: "create",
|
|
460
|
+
kind: "document",
|
|
461
|
+
description: "Create resource",
|
|
462
|
+
inputSchema: {
|
|
463
|
+
type: "object",
|
|
464
|
+
properties: { name: { type: "string" } },
|
|
465
|
+
required: ["name"],
|
|
466
|
+
},
|
|
467
|
+
handler: (ctx: CliContextType) => {
|
|
468
|
+
return { created: ctx.inputsAs<{ name: string }>().name };
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
],
|
|
472
|
+
});
|
|
473
|
+
cliValidateProgram(yamlProgram);
|
|
474
|
+
const res = await apiRequest(
|
|
475
|
+
yamlProgram,
|
|
476
|
+
new Request("http://127.0.0.1/create", {
|
|
477
|
+
method: "POST",
|
|
478
|
+
headers: { "content-type": "application/yaml" },
|
|
479
|
+
body: "name: test-resource",
|
|
480
|
+
}),
|
|
481
|
+
);
|
|
482
|
+
expect(res.status).toBe(201);
|
|
483
|
+
const body = (await res.json()) as Record<string, unknown>;
|
|
484
|
+
expect(body).toEqual({ created: "test-resource" });
|
|
485
|
+
});
|
|
486
|
+
|
|
451
487
|
test("GET /openapi.json lists REST paths", async () => {
|
|
452
488
|
const res = await apiRequest(program, new Request("http://127.0.0.1/openapi.json"));
|
|
453
489
|
expect(res.status).toBe(200);
|