Skip to content

Commit 81640c9

Browse files
committed
fix: describe filename and accept string version
1 parent 8587bc8 commit 81640c9

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/lib/mcp/index.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as v from 'valibot';
66
import { add_autofixers_issues } from './autofixers/add-autofixers-issues.js';
77
import { add_compile_issues } from './autofixers/add-compile-issues.js';
88
import { add_eslint_issues } from './autofixers/add-eslint-issues.js';
9+
import { basename } from 'node:path';
910

1011
const server = new McpServer(
1112
{
@@ -35,12 +36,17 @@ server.tool(
3536
schema: v.object({
3637
code: v.string(),
3738
desired_svelte_version: v.pipe(
38-
v.union([v.literal(4), v.literal(5)]),
39+
v.union([v.literal(4), v.literal(5), v.literal('4'), v.literal('5')]),
3940
v.description(
4041
'The desired svelte version...if possible read this from the package.json of the user project, otherwise use some hint from the wording (if the user asks for runes it wants version 5). Default to 5 in case of doubt.',
4142
),
4243
),
43-
filename: v.optional(v.string()),
44+
filename: v.pipe(
45+
v.optional(v.string()),
46+
v.description(
47+
'The filename of the component if available, it MUST be only the Component name with .svelte or .svelte.ts extension and not the entire path.',
48+
),
49+
),
4450
}),
4551
outputSchema: v.object({
4652
issues: v.array(v.string()),
@@ -54,18 +60,23 @@ server.tool(
5460
openWorldHint: false,
5561
},
5662
},
57-
async ({ code, filename, desired_svelte_version }) => {
63+
async ({ code, filename: filename_or_path, desired_svelte_version }) => {
5864
const content: {
5965
issues: string[];
6066
suggestions: string[];
6167
require_another_tool_call_after_fixing: boolean;
6268
} = { issues: [], suggestions: [], require_another_tool_call_after_fixing: false };
6369
try {
64-
add_compile_issues(content, code, desired_svelte_version, filename);
70+
// just in case the LLM sends a full path we extract the filename...it's not really needed
71+
// but it's nice to have a filename in the errors
72+
73+
const filename = filename_or_path ? basename(filename_or_path) : 'Component.svelte';
74+
75+
add_compile_issues(content, code, +desired_svelte_version, filename);
6576

66-
add_autofixers_issues(content, code, desired_svelte_version, filename);
77+
add_autofixers_issues(content, code, +desired_svelte_version, filename);
6778

68-
await add_eslint_issues(content, code, desired_svelte_version, filename);
79+
await add_eslint_issues(content, code, +desired_svelte_version, filename);
6980
} catch (e: unknown) {
7081
const error = e as Error & { start?: { line: number; column: number } };
7182
content.issues.push(

0 commit comments

Comments
 (0)