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
+
1
4
export async function fetch_with_timeout (
2
5
url : string ,
3
6
timeout_ms : number = 10000 ,
@@ -14,10 +17,14 @@ export async function fetch_with_timeout(
14
17
}
15
18
16
19
export 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 ] ) => ( {
19
26
title : section . metadata . title ,
20
- use_cases : ' ',
27
+ use_cases : section . metadata . use_cases ?? 'read document for use cases ',
21
28
slug : section . slug ,
22
29
url : `https://svelte.dev/${ section . slug } /llms.txt` ,
23
30
} ) ) ;
You can’t perform that action at this time.
0 commit comments