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/src/mcp/tools.ts CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  type CliProgram,
14
14
  CliValueFormat,
15
15
  isCliLeaf,
16
- isJsonLeaf,
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 (isJsonLeaf(leaf) && leaf.inputSchema !== undefined) {
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 (isJsonLeaf(tool.leaf)) {
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);