Skip to content

Commit 30c9544

Browse files
author
zoedsoupe
committed
feat: json format option
1 parent 8a95dfe commit 30c9544

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

src/mcp.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,41 @@ async function handleProjectEvaluation({
1818
code,
1919
timeout,
2020
arguments: args,
21+
json,
2122
}: ProjectEvalInputSchema): Promise<CallToolResult> {
2223
const result = await Tidewave.executeIsolated({ code, timeout, args });
2324

2425
if (!result.success) {
26+
if (json)
27+
return {
28+
content: [{ type: 'text', text: JSON.stringify(result) }],
29+
isError: true,
30+
};
31+
2532
return {
2633
content: [
2734
{
2835
type: 'text',
29-
// TODO: correctly format the exit
30-
text: `Failed to evaluate code. Process exited with reason: ${JSON.stringify(result)}`,
36+
text: `Failed to evaluate code. Process exited with reason: ${result.stderr}\n\n${result.result}`,
3137
},
3238
],
3339
isError: true,
3440
};
3541
}
3642

43+
if (json)
44+
return {
45+
content: [{ type: 'text', text: JSON.stringify(result) }],
46+
isError: false,
47+
};
48+
3749
return {
38-
// TODO: correctly format success output
39-
content: [{ type: 'text', text: JSON.stringify(result) }],
50+
content: [
51+
{
52+
type: 'text',
53+
text: `IO:\n\n${result.stdout}\n+${result.stderr}\n\nResult:${result.result}`,
54+
},
55+
],
4056
isError: false,
4157
};
4258
}

src/tools.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ const projectEvalDescription = `
3030
3131
The current NodeJS version is: ${process.version}
3232
33-
Use this tool every time you need to evaluate Elixir code,
33+
Use this tool every time you need to evaluate JavaScript/TypeScript code,
3434
including to test the behaviour of a function or to debug
3535
something. The tool also returns anything written to standard
36-
output. DO NOT use shell tools to evaluate Elixir code.
36+
output. DO NOT use shell tools to evaluate JavaScript/TypeScript code.
3737
38-
It also includes IEx helpers in the evaluation context.
39-
For example, to get all functions in a module, call.
38+
Imports are allowed only as the form of dynamic imports, e.g.:
39+
import('node:path').then(path => {...});
4040
`;
4141

4242
export const projectEvalInputSchema = z.object({
@@ -55,6 +55,11 @@ export const projectEvalInputSchema = z.object({
5555
.describe(
5656
'Optional. A timeout in milliseconds after which the execution stops if it did not finish yet.\nDefaults to 30000 (30 seconds).',
5757
),
58+
json: z
59+
.boolean()
60+
.optional()
61+
.default(false)
62+
.describe('Whether to return the result as JSON or not (string)'),
5863
});
5964

6065
const referenceDescription = `Module path in format 'module:symbol[#method|.method]'. Supports local files, dependencies, and Node.js builtins.

0 commit comments

Comments
 (0)