@@ -58,36 +58,43 @@ export function get_documentation(server: SvelteMcp) {
5858 const response = await fetchWithTimeout ( matchedSection . url ) ;
5959 if ( response . ok ) {
6060 const content = await response . text ( ) ;
61- return `## ${ matchedSection . title } \n\n${ content } ` ;
61+ return { success : true , content : `## ${ matchedSection . title } \n\n${ content } ` } ;
6262 } else {
63- return `## ${ matchedSection . title } \n\nError: Could not fetch documentation (HTTP ${ response . status } )` ;
63+ return { success : false , content : `## ${ matchedSection . title } \n\nError: Could not fetch documentation (HTTP ${ response . status } )` } ;
6464 }
6565 } catch ( error ) {
66- return `## ${ matchedSection . title } \n\nError: Failed to fetch documentation - ${ error } ` ;
66+ return { success : false , content : `## ${ matchedSection . title } \n\nError: Failed to fetch documentation - ${ error } ` } ;
6767 }
6868 } else {
69- const formattedSections = availableSections
70- . map (
71- ( section ) =>
72- `* title: ${ section . title } , use_cases: ${ section . use_cases } , path: ${ section . url } ` ,
73- )
74- . join ( '\n' ) ;
75-
76- const introText = 'List of available Svelte documentation sections and its inteneded uses:' ;
77-
78- const outroText =
79- 'Use the title or path with the get-documentation tool to get more details about a specific section.' ;
80-
81- return `## ${ requestedSection } \n\nError: Section not found.\n\n${ introText } \n\n${ formattedSections } \n\n${ outroText } ` ;
69+ return { success : false , content : `## ${ requestedSection } \n\nError: Section not found.` } ;
8270 }
8371 } )
8472 ) ;
8573
74+ const hasAnySuccess = results . some ( result => result . success ) ;
75+ let finalText = results . map ( r => r . content ) . join ( '\n\n---\n\n' ) ;
76+
77+ if ( ! hasAnySuccess ) {
78+ const formattedSections = availableSections
79+ . map (
80+ ( section ) =>
81+ `* title: ${ section . title } , use_cases: ${ section . use_cases } , path: ${ section . url } ` ,
82+ )
83+ . join ( '\n' ) ;
84+
85+ const introText = 'List of available Svelte documentation sections and its inteneded uses:' ;
86+
87+ const outroText =
88+ 'Use the title or path with the get-documentation tool to get more details about a specific section.' ;
89+
90+ finalText += `\n\n---\n\n${ introText } \n\n${ formattedSections } \n\n${ outroText } ` ;
91+ }
92+
8693 return {
8794 content : [
8895 {
8996 type : 'text' ,
90- text : results . join ( '\n\n---\n\n' ) ,
97+ text : finalText ,
9198 } ,
9299 ] ,
93100 } ;
0 commit comments