mirror of
https://github.com/sveltejs/ai-tools.git
synced 2026-07-04 03:19:38 +08:00
Compare commits
2 Commits
@sveltejs/
...
feat/error
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79e8436c6b | ||
|
|
c87ca0c8e8 |
5
.changeset/rich-wolves-double.md
Normal file
5
.changeset/rich-wolves-double.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@sveltejs/mcp': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: display similar result & error at the end
|
||||||
@@ -91,16 +91,56 @@ export async function get_documentation_handler({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const has_any_success = results.some((result) => result.success);
|
const successes = results.filter((r) => r.success);
|
||||||
let final_text = results.map((r) => r.content).join('\n\n---\n\n');
|
const failed_sections = sections.filter(
|
||||||
|
(s) =>
|
||||||
|
!available_sections.some(
|
||||||
|
(a) => a.title.toLowerCase() === s.toLowerCase() || a.slug === s || a.url === s,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
if (!has_any_success) {
|
if (successes.length > 0 && failed_sections.length === 0) {
|
||||||
const formatted_sections = await format_sections_list();
|
return successes.map((r) => r.content).join('\n\n---\n\n');
|
||||||
|
|
||||||
final_text += `\n\n---\n\n${SECTIONS_LIST_INTRO}\n\n${formatted_sections}\n\n${SECTIONS_LIST_OUTRO}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return final_text;
|
const parts: string[] = [];
|
||||||
|
|
||||||
|
if (successes.length > 0) {
|
||||||
|
parts.push(successes.map((r) => r.content).join('\n\n---\n\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
const fuzzy_results = failed_sections.map((requested) => {
|
||||||
|
const lower = requested.toLowerCase();
|
||||||
|
const matches = available_sections.filter(
|
||||||
|
(a) =>
|
||||||
|
a.title.toLowerCase().includes(lower) ||
|
||||||
|
a.slug.includes(lower) ||
|
||||||
|
lower.includes(a.slug.split('/').pop() ?? '') ||
|
||||||
|
a.use_cases.toLowerCase().includes(lower),
|
||||||
|
);
|
||||||
|
return { requested, matches };
|
||||||
|
});
|
||||||
|
|
||||||
|
const has_fuzzy = fuzzy_results.some((r) => r.matches.length > 0);
|
||||||
|
|
||||||
|
// Full list only when no successes and no fuzzy matches
|
||||||
|
if (successes.length === 0 && !has_fuzzy) {
|
||||||
|
const formatted_sections = await format_sections_list();
|
||||||
|
parts.push(`${SECTIONS_LIST_INTRO}\n\n${formatted_sections}\n\n${SECTIONS_LIST_OUTRO}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Similar results then errors
|
||||||
|
for (const { requested, matches } of fuzzy_results) {
|
||||||
|
if (matches.length > 0) {
|
||||||
|
const match_list = matches.map((m) => `- title: ${m.title}, section: ${m.slug}`).join('\n');
|
||||||
|
parts.push(
|
||||||
|
`${matches.length} similar result${matches.length > 1 ? 's' : ''} for "${requested}":\n${match_list}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
parts.push(`Section not found: "${requested}".`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.join('\n\n---\n\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_documentation(server: SvelteMcp) {
|
export function get_documentation(server: SvelteMcp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user