File tree Expand file tree Collapse file tree 3 files changed +26
-10
lines changed
packages/mcp-server/src/mcp Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 1+ import * as v from 'valibot' ;
2+
3+ export const documentation_sections_schema = v . record (
4+ v . string ( ) ,
5+ v . object ( {
6+ metadata : v . object ( {
7+ title : v . string ( ) ,
8+ use_cases : v . optional ( v . string ( ) ) ,
9+ } ) ,
10+ slug : v . string ( ) ,
11+ } ) ,
12+ ) ;
Original file line number Diff line number Diff line change 1+ import * as v from 'valibot' ;
2+ import { documentation_sections_schema } from '../mcp/schemas/index.js' ;
3+
14export async function fetch_with_timeout (
25 url : string ,
36 timeout_ms : number = 10000 ,
@@ -14,10 +17,14 @@ export async function fetch_with_timeout(
1417}
1518
1619export async function get_sections ( ) {
17- const sections = await fetch_with_timeout ( 'https://svelte.dev/docs/experimental/sections.json' ) ;
18- return Object . entries ( sections ) . map ( ( [ , section ] ) => ( {
20+ const sections = await fetch_with_timeout (
21+ 'https://svelte.dev/docs/experimental/sections.json' ,
22+ ) . then ( ( res ) => res . json ( ) ) ;
23+ const validated_sections = v . safeParse ( documentation_sections_schema , sections ) ;
24+ if ( ! validated_sections . success ) return [ ] ;
25+ return Object . entries ( validated_sections . output ) . map ( ( [ , section ] ) => ( {
1926 title : section . metadata . title ,
20- use_cases : ' ',
27+ use_cases : section . metadata . use_cases ?? 'read document for use cases ',
2128 slug : section . slug ,
2229 url : `https://svelte.dev/${ section . slug } /llms.txt` ,
2330 } ) ) ;
You can’t perform that action at this time.
0 commit comments