11#!/usr/bin/env node
22import "dotenv/config" ;
3- import {
4- McpServer ,
5- ResourceTemplate ,
6- } from "@modelcontextprotocol/sdk/server/mcp.js" ;
3+ import { McpServer , ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js" ;
74import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js" ;
85import { z } from "zod" ;
96import { VectorStoreService } from "../store/VectorStoreService" ;
@@ -40,7 +37,7 @@ export async function startServer() {
4037 prompts : { } ,
4138 resources : { } ,
4239 } ,
43- }
40+ } ,
4441 ) ;
4542
4643 // Scrape docs tool
@@ -56,11 +53,7 @@ export async function startServer() {
5653 . optional ( )
5754 . default ( 100 )
5855 . describe ( "Maximum number of pages to scrape" ) ,
59- maxDepth : z
60- . number ( )
61- . optional ( )
62- . default ( 3 )
63- . describe ( "Maximum navigation depth" ) ,
56+ maxDepth : z . number ( ) . optional ( ) . default ( 3 ) . describe ( "Maximum navigation depth" ) ,
6457 subpagesOnly : z
6558 . boolean ( )
6659 . optional ( )
@@ -80,16 +73,16 @@ export async function startServer() {
8073 } ) ;
8174
8275 return createResponse (
83- `Successfully scraped ${ result . pagesScraped } pages from ${ url } for ${ library } v${ version } .`
76+ `Successfully scraped ${ result . pagesScraped } pages from ${ url } for ${ library } v${ version } .` ,
8477 ) ;
8578 } catch ( error ) {
8679 return createError (
8780 `Failed to scrape documentation: ${
8881 error instanceof Error ? error . message : String ( error )
89- } `
82+ } `,
9083 ) ;
9184 }
92- }
85+ } ,
9386 ) ;
9487
9588 // Search docs tool
@@ -107,14 +100,10 @@ export async function startServer() {
107100 . string ( )
108101 . optional ( )
109102 . describe (
110- "Version of the library (supports exact versions like '18.0.0' or X-Range patterns like '5.x', '5.2.x')"
103+ "Version of the library (supports exact versions like '18.0.0' or X-Range patterns like '5.x', '5.2.x')" ,
111104 ) ,
112105 query : z . string ( ) . describe ( "Search query" ) ,
113- limit : z
114- . number ( )
115- . optional ( )
116- . default ( 5 )
117- . describe ( "Maximum number of results" ) ,
106+ limit : z . number ( ) . optional ( ) . default ( 5 ) . describe ( "Maximum number of results" ) ,
118107 exactMatch : z
119108 . boolean ( )
120109 . optional ( )
@@ -136,12 +125,12 @@ export async function startServer() {
136125------------------------------------------------------------
137126Result ${ i + 1 } : ${ r . metadata . url }
138127
139- ${ r . content } \n`
128+ ${ r . content } \n`,
140129 ) ;
141130
142131 return createResponse (
143132 `Search results for '${ query } ' in ${ library } v${ version } :
144- ${ formattedResults . join ( "" ) } `
133+ ${ formattedResults . join ( "" ) } `,
145134 ) ;
146135 } catch ( error ) {
147136 if ( error instanceof VersionNotFoundError ) {
@@ -151,39 +140,34 @@ ${formattedResults.join("")}`
151140 return createError (
152141 indexedVersions . length > 0
153142 ? `Version not found. Available indexed versions for ${ library } : ${ indexedVersions . join ( ", " ) } `
154- : `Version not found. No indexed versions available for ${ library } .`
143+ : `Version not found. No indexed versions available for ${ library } .` ,
155144 ) ;
156145 }
157146 return createError (
158147 `Failed to search documentation: ${
159148 error instanceof Error ? error . message : String ( error )
160- } `
149+ } `,
161150 ) ;
162151 }
163- }
152+ } ,
164153 ) ;
165154
166155 // List libraries tool
167- server . tool (
168- "list_libraries" ,
169- "List all indexed libraries" ,
170- { } ,
171- async ( ) => {
172- try {
173- const result = await tools . listLibraries . execute ( ) ;
156+ server . tool ( "list_libraries" , "List all indexed libraries" , { } , async ( ) => {
157+ try {
158+ const result = await tools . listLibraries . execute ( ) ;
174159
175- return createResponse (
176- `Indexed libraries:\n${ result . libraries . map ( ( lib ) => `- ${ lib . name } ` ) . join ( "\n" ) } `
177- ) ;
178- } catch ( error ) {
179- return createError (
180- `Failed to list libraries: ${
181- error instanceof Error ? error . message : String ( error )
182- } `
183- ) ;
184- }
160+ return createResponse (
161+ `Indexed libraries:\n${ result . libraries . map ( ( lib ) => `- ${ lib . name } ` ) . join ( "\n" ) } ` ,
162+ ) ;
163+ } catch ( error ) {
164+ return createError (
165+ `Failed to list libraries: ${
166+ error instanceof Error ? error . message : String ( error )
167+ } `,
168+ ) ;
185169 }
186- ) ;
170+ } ) ;
187171
188172 // Find version tool
189173 server . tool (
@@ -195,7 +179,7 @@ ${formattedResults.join("")}`
195179 . string ( )
196180 . optional ( )
197181 . describe (
198- "Target version to match (supports exact versions like '18.0.0' or X-Range patterns like '5.x', '5.2.x')"
182+ "Target version to match (supports exact versions like '18.0.0' or X-Range patterns like '5.x', '5.2.x')" ,
199183 ) ,
200184 } ,
201185 async ( { library, targetVersion } ) => {
@@ -214,10 +198,10 @@ ${formattedResults.join("")}`
214198 return createError (
215199 `Failed to find version: ${
216200 error instanceof Error ? error . message : String ( error )
217- } `
201+ } `,
218202 ) ;
219203 }
220- }
204+ } ,
221205 ) ;
222206
223207 server . prompt (
@@ -240,7 +224,7 @@ ${formattedResults.join("")}`
240224 } ,
241225 ] ,
242226 } ;
243- }
227+ } ,
244228 ) ;
245229
246230 server . resource (
@@ -258,7 +242,7 @@ ${formattedResults.join("")}`
258242 text : lib . name ,
259243 } ) ) ,
260244 } ;
261- }
245+ } ,
262246 ) ;
263247
264248 server . resource (
@@ -283,7 +267,7 @@ ${formattedResults.join("")}`
283267 text : v . version ,
284268 } ) ) ,
285269 } ;
286- }
270+ } ,
287271 ) ;
288272
289273 // Start server
@@ -299,10 +283,7 @@ ${formattedResults.join("")}`
299283 } ) ;
300284 } catch ( error ) {
301285 await storeService . shutdown ( ) ;
302- console . error (
303- "Error:" ,
304- error instanceof Error ? error . message : String ( error )
305- ) ;
286+ console . error ( "Error:" , error instanceof Error ? error . message : String ( error ) ) ;
306287 process . exit ( 1 ) ;
307288 }
308289}
0 commit comments