argsbarg 1.3.1 → 1.4.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/src/index.test.ts CHANGED
@@ -10,11 +10,19 @@ shell output regressions.
10
10
  import { completionBashScript, completionZshScript } from "./completion.ts";
11
11
  import { cliHelpRender } from "./help.ts";
12
12
  import { CliCommand, CliFallbackMode, CliOptionKind } from "./index.ts";
13
+ import {
14
+ collectMcpTools,
15
+ mcpToolCallToArgv,
16
+ mcpToolDescription,
17
+ sanitizeToolSegment,
18
+ } from "./mcp/tools.ts";
19
+ import { buildToolCallSuccess } from "./mcp/result.ts";
13
20
  import { ParseKind, parse, postParseValidate } from "./parse.ts";
14
21
  import { cliSchemaJson } from "./schema.ts";
15
22
  import { cliValidateRoot } from "./validate.ts";
16
23
  import { expect, test } from "bun:test";
17
24
  import { $ } from "bun";
25
+ import { join } from "node:path";
18
26
 
19
27
  test("bundled short presence flags", () => {
20
28
  const root: CliCommand = {
@@ -639,4 +647,349 @@ test("completion scripts offer --schema at the program root only", () => {
639
647
 
640
648
  const zsh = completionZshScript(root);
641
649
  expect(zsh).toContain("'--schema:Print the full command tree as JSON.'");
650
+ });
651
+
652
+ const nestedMcpFixture: CliCommand = {
653
+ key: "nested.ts",
654
+ description: "Nested groups demo.",
655
+ mcpServer: { name: "nested-demo", version: "1.0.0" },
656
+ commands: [
657
+ {
658
+ key: "stat",
659
+ description: "File metadata.",
660
+ options: [
661
+ {
662
+ name: "json",
663
+ description: "Emit handler output as JSON.",
664
+ kind: CliOptionKind.Presence,
665
+ },
666
+ ],
667
+ commands: [
668
+ {
669
+ key: "owner",
670
+ description: "Ownership helpers.",
671
+ commands: [
672
+ {
673
+ key: "lookup",
674
+ description: "Resolve owner info.",
675
+ options: [
676
+ {
677
+ name: "user-name",
678
+ description: "User to look up.",
679
+ kind: CliOptionKind.String,
680
+ shortName: "u",
681
+ },
682
+ ],
683
+ positionals: [
684
+ {
685
+ name: "path",
686
+ description: "File or directory.",
687
+ kind: CliOptionKind.String,
688
+ },
689
+ ],
690
+ handler: () => {},
691
+ },
692
+ ],
693
+ },
694
+ ],
695
+ },
696
+ {
697
+ key: "read",
698
+ description: "Print the first line of each file.",
699
+ positionals: [
700
+ {
701
+ name: "files",
702
+ description: "Paths to read.",
703
+ kind: CliOptionKind.String,
704
+ argMax: 0,
705
+ },
706
+ ],
707
+ handler: () => {},
708
+ },
709
+ {
710
+ key: "hidden",
711
+ description: "Internal debug.",
712
+ mcpTool: { enabled: false },
713
+ handler: () => {},
714
+ },
715
+ ],
716
+ fallbackCommand: "read",
717
+ fallbackMode: CliFallbackMode.MissingOrUnknown,
718
+ };
719
+
720
+ /** Sends NDJSON MCP requests to a subprocess and collects responses by id. */
721
+ async function mcpRequest(requests: object[]): Promise<Map<string | number, object>> {
722
+ const proc = Bun.spawn(["bun", "run", "examples/nested.ts", "mcp"], {
723
+ stdin: "pipe",
724
+ stdout: "pipe",
725
+ stderr: "pipe",
726
+ });
727
+
728
+ const input = requests.map((r) => JSON.stringify(r) + "\n").join("");
729
+ proc.stdin.write(input);
730
+ proc.stdin.end();
731
+
732
+ const timeout = setTimeout(() => proc.kill(), 10_000);
733
+ const stdout = await new Response(proc.stdout).text();
734
+ await proc.exited;
735
+ clearTimeout(timeout);
736
+
737
+ const byId = new Map<string | number, object>();
738
+ for (const line of stdout.split("\n")) {
739
+ const trimmed = line.trim();
740
+ if (!trimmed) {
741
+ continue;
742
+ }
743
+ const msg = JSON.parse(trimmed) as { id?: string | number };
744
+ if (msg.id !== undefined) {
745
+ byId.set(msg.id, msg);
746
+ }
747
+ }
748
+ return byId;
749
+ }
750
+
751
+ test("sanitizeToolSegment normalizes dotted app keys", () => {
752
+ expect(sanitizeToolSegment("minimal.ts")).toBe("minimal_ts");
753
+ });
754
+
755
+ test("mcpToolDescription formats CLI path and root-leaf prefix", () => {
756
+ expect(mcpToolDescription(["stat", "owner", "lookup"], "nested.ts", "Resolve owner info.")).toBe(
757
+ "stat owner lookup — Resolve owner info.",
758
+ );
759
+ expect(mcpToolDescription(["read"], "nested.ts", "Print files.")).toBe("read — Print files.");
760
+ expect(mcpToolDescription([], "helloapp", "Tiny demo.")).toBe("helloapp — Tiny demo.");
761
+ });
762
+
763
+ test("collectMcpTools lists user leaf commands only", () => {
764
+ const tools = collectMcpTools(nestedMcpFixture);
765
+ const names = tools.map((t) => t.name);
766
+ expect(names).toContain("stat_owner_lookup");
767
+ expect(names).toContain("read");
768
+ expect(names).not.toContain("hidden");
769
+ expect(names).not.toContain("mcp");
770
+ expect(names).not.toContain("completion");
771
+ const lookup = tools.find((t) => t.name === "stat_owner_lookup")!;
772
+ expect(lookup.description).toBe("stat owner lookup — Resolve owner info.");
773
+ });
774
+
775
+ test("collectMcpTools merges parent options into inputSchema", () => {
776
+ const tools = collectMcpTools(nestedMcpFixture);
777
+ const lookup = tools.find((t) => t.name === "stat_owner_lookup")!;
778
+ const schema = lookup.inputSchema as { properties: Record<string, unknown>; required?: string[] };
779
+ expect(schema.properties.json).toBeDefined();
780
+ expect(schema.required).toContain("path");
781
+ });
782
+
783
+ test("mcpToolCallToArgv builds nested lookup argv", () => {
784
+ const tools = collectMcpTools(nestedMcpFixture);
785
+ const lookup = tools.find((t) => t.name === "stat_owner_lookup")!;
786
+ const argv = mcpToolCallToArgv(nestedMcpFixture, lookup, {
787
+ "user-name": "alice",
788
+ path: "./x",
789
+ json: true,
790
+ });
791
+ expect(argv).toEqual(["stat", "owner", "lookup", "--json", "--user-name", "alice", "./x"]);
792
+ });
793
+
794
+ test("mcpToolCallToArgv expands varargs positionals", () => {
795
+ const tools = collectMcpTools(nestedMcpFixture);
796
+ const read = tools.find((t) => t.name === "read")!;
797
+ const argv = mcpToolCallToArgv(nestedMcpFixture, read, { files: ["a", "b"] });
798
+ expect(argv).toEqual(["read", "a", "b"]);
799
+ });
800
+
801
+ test("reserved command name mcp is rejected", () => {
802
+ const root: CliCommand = {
803
+ key: "app",
804
+ description: "",
805
+ commands: [
806
+ {
807
+ key: "mcp",
808
+ description: "bad",
809
+ handler: () => {},
810
+ },
811
+ ],
812
+ };
813
+ expect(() => cliValidateRoot(root)).toThrow(/Reserved command name: mcp/);
814
+ });
815
+
816
+ test("mcpServer on non-root node is rejected", () => {
817
+ const root: CliCommand = {
818
+ key: "app",
819
+ description: "",
820
+ commands: [
821
+ {
822
+ key: "x",
823
+ description: "cmd",
824
+ mcpServer: {},
825
+ handler: () => {},
826
+ },
827
+ ],
828
+ };
829
+ expect(() => cliValidateRoot(root)).toThrow(/mcpServer is only supported on the program root/);
830
+ });
831
+
832
+ test("mcpTool on root is rejected", () => {
833
+ const root: CliCommand = {
834
+ key: "app",
835
+ description: "",
836
+ mcpTool: { enabled: false },
837
+ handler: () => {},
838
+ };
839
+ expect(() => cliValidateRoot(root)).toThrow(/mcpTool is only supported on leaf commands/);
840
+ });
841
+
842
+ test("mcpTool on routing node is rejected", () => {
843
+ const root: CliCommand = {
844
+ key: "app",
845
+ description: "",
846
+ commands: [
847
+ {
848
+ key: "group",
849
+ description: "group",
850
+ mcpTool: { enabled: false },
851
+ commands: [
852
+ {
853
+ key: "leaf",
854
+ description: "leaf",
855
+ handler: () => {},
856
+ },
857
+ ],
858
+ },
859
+ ],
860
+ };
861
+ expect(() => cliValidateRoot(root)).toThrow(/mcpTool is only supported on leaf commands/);
862
+ });
863
+
864
+ test("buildToolCallSuccess returns stdout only", () => {
865
+ const result = buildToolCallSuccess("hello\n", "");
866
+ expect(result.isError).toBe(false);
867
+ expect(result.content).toEqual([{ type: "text", text: "hello\n" }]);
868
+ expect(result.structuredContent).toBeUndefined();
869
+ });
870
+
871
+ test("buildToolCallSuccess adds stderr as second content block", () => {
872
+ const result = buildToolCallSuccess("out\n", "warn\n");
873
+ expect(result.content).toEqual([
874
+ { type: "text", text: "out\n" },
875
+ { type: "text", text: "warn" },
876
+ ]);
877
+ expect(result.structuredContent).toBeUndefined();
878
+ });
879
+
880
+ test("buildToolCallSuccess stderr-only still includes stdout slot", () => {
881
+ const result = buildToolCallSuccess("", "warn\n");
882
+ expect(result.content).toEqual([
883
+ { type: "text", text: "" },
884
+ { type: "text", text: "warn" },
885
+ ]);
886
+ });
887
+
888
+ test("buildToolCallSuccess parses JSON structuredContent", () => {
889
+ const result = buildToolCallSuccess('{"a":1}\n', "");
890
+ expect(result.structuredContent).toEqual({ a: 1 });
891
+ expect(result.content[0]!.text).toBe('{"a":1}\n');
892
+ });
893
+
894
+ test("buildToolCallSuccess skips structuredContent for plain text", () => {
895
+ const result = buildToolCallSuccess("lookup user=x\n", "");
896
+ expect(result.structuredContent).toBeUndefined();
897
+ });
898
+
899
+ test("buildToolCallSuccess parses JSON primitives", () => {
900
+ const result = buildToolCallSuccess("true\n", "");
901
+ expect(result.structuredContent).toBe(true);
902
+ });
903
+
904
+ test("MCP initialize returns tools and resources capabilities", async () => {
905
+ const responses = await mcpRequest([{ jsonrpc: "2.0", id: 1, method: "initialize", params: {} }]);
906
+ const res = responses.get(1) as { result: { capabilities: Record<string, unknown> } };
907
+ expect(res.result.capabilities.tools).toBeDefined();
908
+ expect(res.result.capabilities.resources).toBeDefined();
909
+ });
910
+
911
+ test("MCP tools/list includes stat_owner_lookup", async () => {
912
+ const responses = await mcpRequest([{ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} }]);
913
+ const res = responses.get(2) as { result: { tools: { name: string; inputSchema: { required?: string[] } }[] } };
914
+ const lookup = res.result.tools.find((t) => t.name === "stat_owner_lookup");
915
+ expect(lookup).toBeDefined();
916
+ expect(lookup!.inputSchema.required).toContain("path");
917
+ });
918
+
919
+ test("MCP resources/read returns schema JSON", async () => {
920
+ const responses = await mcpRequest([
921
+ { jsonrpc: "2.0", id: 3, method: "resources/read", params: { uri: "argsbarg://schema" } },
922
+ ]);
923
+ const res = responses.get(3) as { result: { contents: { text: string }[] } };
924
+ const schema = JSON.parse(res.result.contents[0]!.text);
925
+ expect(schema.key).toBe("nested.ts");
926
+ });
927
+
928
+ test("MCP tools/call runs stat_owner_lookup", async () => {
929
+ const readme = join(import.meta.dir, "..", "README.md");
930
+ const responses = await mcpRequest([
931
+ {
932
+ jsonrpc: "2.0",
933
+ id: 4,
934
+ method: "tools/call",
935
+ params: {
936
+ name: "stat_owner_lookup",
937
+ arguments: { path: readme, "user-name": "test" },
938
+ },
939
+ },
940
+ ]);
941
+ const res = responses.get(4) as { result: { content: { text: string }[]; isError: boolean } };
942
+ expect(res.result.isError).toBe(false);
943
+ expect(res.result.content[0]!.text).toContain("lookup user=test");
944
+ });
945
+
946
+ test("MCP tools/call returns structuredContent for JSON stdout", async () => {
947
+ const readme = join(import.meta.dir, "..", "README.md");
948
+ const responses = await mcpRequest([
949
+ {
950
+ jsonrpc: "2.0",
951
+ id: 6,
952
+ method: "tools/call",
953
+ params: {
954
+ name: "stat_owner_lookup",
955
+ arguments: { path: readme, "user-name": "test", json: true },
956
+ },
957
+ },
958
+ ]);
959
+ const res = responses.get(6) as {
960
+ result: {
961
+ content: { text: string }[];
962
+ structuredContent?: { user: string; path: string };
963
+ isError: boolean;
964
+ };
965
+ };
966
+ expect(res.result.isError).toBe(false);
967
+ expect(res.result.structuredContent).toEqual({ user: "test", path: readme });
968
+ expect(JSON.parse(res.result.content[0]!.text.trim())).toEqual({ user: "test", path: readme });
969
+ });
970
+
971
+ test("MCP tools/call errors on missing required positional", async () => {
972
+ const responses = await mcpRequest([
973
+ {
974
+ jsonrpc: "2.0",
975
+ id: 5,
976
+ method: "tools/call",
977
+ params: { name: "stat_owner_lookup", arguments: { "user-name": "test" } },
978
+ },
979
+ ]);
980
+ const res = responses.get(5) as { result: { isError: boolean; content: { text: string }[] } };
981
+ expect(res.result.isError).toBe(true);
982
+ expect(res.result.content[0]!.text).toContain("Missing argument: path");
983
+ });
984
+
985
+ test("MCP ping returns empty result", async () => {
986
+ const responses = await mcpRequest([{ jsonrpc: "2.0", id: 99, method: "ping", params: {} }]);
987
+ const res = responses.get(99) as { result: Record<string, never> };
988
+ expect(res.result).toEqual({});
989
+ });
990
+
991
+ test("minimal.ts mcp without opt-in fails", async () => {
992
+ const { stderr, exitCode } = await $`bun run examples/minimal.ts mcp`.nothrow().quiet();
993
+ expect(exitCode).toBe(1);
994
+ expect(stderr.toString()).toContain("mcp");
642
995
  });
package/src/index.ts CHANGED
@@ -10,5 +10,5 @@ module layout.
10
10
  export { CliContext } from "./context.ts";
11
11
  export { cliErrWithHelp, cliRun } from "./runtime";
12
12
  export { CliFallbackMode, CliOptionKind, CliSchemaValidationError } from "./types.ts";
13
- export type { CliCommand, CliHandler, CliOption, CliPositional } from "./types.ts";
13
+ export type { CliCommand, CliHandler, CliMcpServerConfig, CliMcpToolConfig, CliOption, CliPositional } from "./types.ts";
14
14
  export { isInteractiveTty } from "./utils.ts";
package/src/invoke.ts ADDED
@@ -0,0 +1,192 @@
1
+ /*
2
+ This module invokes leaf CLI handlers without exiting the process.
3
+ It parses argv against the user schema, captures stdout/stderr, and patches
4
+ process.exit so MCP tool calls can run handlers repeatedly.
5
+ */
6
+
7
+ import { CliContext } from "./context.ts";
8
+ import { parse, postParseValidate, ParseKind } from "./parse.ts";
9
+ import { CliCommand } from "./types.ts";
10
+ import { format } from "node:util";
11
+
12
+ /** Outcome of a non-exiting CLI invocation. */
13
+ export type CliInvokeKind = "ok" | "help" | "schema" | "error";
14
+
15
+ /** Result of cliInvoke: captured output and exit metadata without process.exit. */
16
+ export interface CliInvokeResult {
17
+ /** Invocation outcome. */
18
+ kind: CliInvokeKind;
19
+ /** Simulated exit code. */
20
+ exitCode: number;
21
+ /** Captured stdout during handler execution. */
22
+ stdout: string;
23
+ /** Captured stderr during handler execution. */
24
+ stderr: string;
25
+ /** Set when kind === "error" (parse/validation message). */
26
+ errorMsg?: string;
27
+ }
28
+
29
+ /** Thrown internally when a patched process.exit fires during handler execution. */
30
+ class CliInvokeExit extends Error {
31
+ /** Exit code passed to process.exit. */
32
+ readonly code: number;
33
+
34
+ /** Creates an exit signal with the given status code. */
35
+ constructor(code: number) {
36
+ super(`process.exit(${code})`);
37
+ this.name = "CliInvokeExit";
38
+ this.code = code;
39
+ }
40
+ }
41
+
42
+ /** Looks up a subcommand or routing node by `key`. */
43
+ function findChild(cmds: CliCommand[], name: string): CliCommand | undefined {
44
+ return cmds.find((c) => c.key === name);
45
+ }
46
+
47
+ /**
48
+ * Parses argv against the user root, runs the leaf handler, and returns captured output.
49
+ * Never calls process.exit.
50
+ */
51
+ export async function cliInvoke(root: CliCommand, argv: string[]): Promise<CliInvokeResult> {
52
+ let pr = parse(root, argv);
53
+ pr = postParseValidate(root, pr);
54
+
55
+ if (pr.kind === ParseKind.Help) {
56
+ return {
57
+ kind: "help",
58
+ exitCode: 1,
59
+ stdout: "",
60
+ stderr: "",
61
+ errorMsg: "Help is not available via MCP tool calls.",
62
+ };
63
+ }
64
+
65
+ if (pr.kind === ParseKind.Schema) {
66
+ return {
67
+ kind: "schema",
68
+ exitCode: 1,
69
+ stdout: "",
70
+ stderr: "",
71
+ errorMsg: "Schema export is not available via MCP tool calls.",
72
+ };
73
+ }
74
+
75
+ if (pr.kind === ParseKind.Error) {
76
+ return {
77
+ kind: "error",
78
+ exitCode: 1,
79
+ stdout: "",
80
+ stderr: pr.errorMsg,
81
+ errorMsg: pr.errorMsg,
82
+ };
83
+ }
84
+
85
+ let current: CliCommand = root;
86
+ for (const seg of pr.path) {
87
+ const ch = findChild(current.commands ?? [], seg);
88
+ if (!ch) {
89
+ return {
90
+ kind: "error",
91
+ exitCode: 1,
92
+ stdout: "",
93
+ stderr: "Internal error: missing handler for path.",
94
+ errorMsg: "Internal error: missing handler for path.",
95
+ };
96
+ }
97
+ current = ch;
98
+ }
99
+
100
+ if (!("handler" in current) || !current.handler) {
101
+ return {
102
+ kind: "error",
103
+ exitCode: 1,
104
+ stdout: "",
105
+ stderr: "Internal error: missing handler for path.",
106
+ errorMsg: "Internal error: missing handler for path.",
107
+ };
108
+ }
109
+
110
+ const handler = current.handler;
111
+ const ctx = new CliContext(root.key, pr.path, pr.args, pr.opts, root);
112
+
113
+ let stdout = "";
114
+ let stderr = "";
115
+ const origExit = process.exit;
116
+ const origStdoutWrite = process.stdout.write.bind(process.stdout);
117
+ const origStderrWrite = process.stderr.write.bind(process.stderr);
118
+ const origConsoleLog = console.log;
119
+ const origConsoleError = console.error;
120
+ const origConsoleInfo = console.info;
121
+ const origConsoleWarn = console.warn;
122
+
123
+ process.exit = ((code?: number) => {
124
+ throw new CliInvokeExit(code ?? 0);
125
+ }) as typeof process.exit;
126
+
127
+ process.stdout.write = ((chunk: string | Uint8Array, ...args: unknown[]) => {
128
+ stdout += typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
129
+ if (typeof args[0] === "function") {
130
+ (args[0] as () => void)();
131
+ }
132
+ return true;
133
+ }) as typeof process.stdout.write;
134
+
135
+ process.stderr.write = ((chunk: string | Uint8Array, ...args: unknown[]) => {
136
+ stderr += typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
137
+ if (typeof args[0] === "function") {
138
+ (args[0] as () => void)();
139
+ }
140
+ return true;
141
+ }) as typeof process.stderr.write;
142
+
143
+ console.log = (...args: unknown[]) => {
144
+ stdout += format(...args) + "\n";
145
+ };
146
+ console.info = (...args: unknown[]) => {
147
+ stdout += format(...args) + "\n";
148
+ };
149
+ console.warn = (...args: unknown[]) => {
150
+ stderr += format(...args) + "\n";
151
+ };
152
+ console.error = (...args: unknown[]) => {
153
+ stderr += format(...args) + "\n";
154
+ };
155
+
156
+ try {
157
+ await Promise.resolve(handler(ctx));
158
+ return { kind: "ok", exitCode: 0, stdout, stderr };
159
+ } catch (err) {
160
+ if (err instanceof CliInvokeExit) {
161
+ if (err.code === 0) {
162
+ return { kind: "ok", exitCode: 0, stdout, stderr };
163
+ }
164
+ const msg = stderr.trim() || `Exit code ${err.code}`;
165
+ return { kind: "error", exitCode: err.code, stdout, stderr, errorMsg: msg };
166
+ }
167
+ if (err instanceof Error) {
168
+ return {
169
+ kind: "error",
170
+ exitCode: 1,
171
+ stdout,
172
+ stderr: err.message + "\n",
173
+ errorMsg: err.message,
174
+ };
175
+ }
176
+ return {
177
+ kind: "error",
178
+ exitCode: 1,
179
+ stdout,
180
+ stderr: "Unknown error\n",
181
+ errorMsg: "Unknown error",
182
+ };
183
+ } finally {
184
+ process.exit = origExit;
185
+ process.stdout.write = origStdoutWrite;
186
+ process.stderr.write = origStderrWrite;
187
+ console.log = origConsoleLog;
188
+ console.error = origConsoleError;
189
+ console.info = origConsoleInfo;
190
+ console.warn = origConsoleWarn;
191
+ }
192
+ }
@@ -0,0 +1,57 @@
1
+ /*
2
+ This module builds MCP tools/call success results from captured handler output.
3
+ */
4
+
5
+ /** Text content block in an MCP tool result. */
6
+ export interface McpTextContent {
7
+ type: "text";
8
+ text: string;
9
+ }
10
+
11
+ /** Successful MCP tools/call result payload. */
12
+ export interface McpToolCallSuccess {
13
+ content: McpTextContent[];
14
+ structuredContent?: unknown;
15
+ isError: false;
16
+ }
17
+
18
+ /** Parses stdout as JSON when the full trimmed string is valid JSON. */
19
+ function parseStructuredStdout(stdout: string): unknown | undefined {
20
+ const trimmed = stdout.trim();
21
+ if (trimmed.length === 0) {
22
+ return undefined;
23
+ }
24
+ try {
25
+ return JSON.parse(trimmed) as unknown;
26
+ } catch {
27
+ return undefined;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Builds a successful tools/call result from captured handler stdout/stderr.
33
+ * stderr is a second content block when non-empty; structuredContent is set when stdout is JSON.
34
+ */
35
+ export function buildToolCallSuccess(stdout: string, stderr: string): McpToolCallSuccess {
36
+ const content: McpTextContent[] = [];
37
+ if (stdout.length > 0) {
38
+ content.push({ type: "text", text: stdout });
39
+ }
40
+ const errText = stderr.trim();
41
+ if (errText.length > 0) {
42
+ if (content.length === 0) {
43
+ content.push({ type: "text", text: "" });
44
+ }
45
+ content.push({ type: "text", text: errText });
46
+ }
47
+ if (content.length === 0) {
48
+ content.push({ type: "text", text: "" });
49
+ }
50
+
51
+ const structuredContent = parseStructuredStdout(stdout);
52
+ const result: McpToolCallSuccess = { content, isError: false };
53
+ if (structuredContent !== undefined) {
54
+ result.structuredContent = structuredContent;
55
+ }
56
+ return result;
57
+ }