@@ -239,66 +239,67 @@ export async function startServer(repoPath: string): Promise<void> {
239239 }
240240 } ) ;
241241
242- server . resource (
243- "Repository File Content" ,
244- new ResourceTemplate ( "repo://files/{filepath}" , { list : undefined } ) ,
245- { } , // metadata
246- async ( uri : URL , variables : Variables , _extra : RequestHandlerExtra < ServerRequest , ServerNotification > ) => {
247- const rawFilepathValue = variables . filepath ;
248- let relativeFilepath = '' ;
249- if ( typeof rawFilepathValue === 'string' ) {
250- relativeFilepath = rawFilepathValue . trim ( ) ;
251- } else if ( Array . isArray ( rawFilepathValue ) && rawFilepathValue . length > 0 && typeof rawFilepathValue [ 0 ] === 'string' ) {
252- logger . warn ( `Filepath parameter '${ JSON . stringify ( rawFilepathValue ) } ' resolved to an array. Using the first element: '${ rawFilepathValue [ 0 ] } '` ) ;
253- relativeFilepath = rawFilepathValue [ 0 ] . trim ( ) ;
254- } else if ( rawFilepathValue !== undefined ) {
255- logger . warn ( `Filepath parameter '${ Array . isArray ( rawFilepathValue ) ? JSON . stringify ( rawFilepathValue ) : rawFilepathValue } ' resolved to an unexpected type: ${ typeof rawFilepathValue } . Treating as empty.` ) ;
256- }
257- // If rawFilepathValue is undefined, or an empty array, or an array not containing a string at index 0, relativeFilepath remains ''.
258-
259- if ( ! relativeFilepath ) {
260- const errMsg = "File path cannot be empty." ;
261- logger . error ( `Error accessing resource for URI ${ uri . toString ( ) } : ${ errMsg } ` ) ;
262- return { contents : [ { uri : uri . toString ( ) , text : "" , error : errMsg } ] } ;
263- }
264-
265- try {
266- const resolvedRepoPath = path . resolve ( repoPath ) ; // Normalized
267- const requestedFullPath = path . resolve ( repoPath , relativeFilepath ) ; // Normalized
268-
269- // Initial security check: Ensure the resolved path is within the repoPath
270- if ( ! requestedFullPath . startsWith ( resolvedRepoPath + path . sep ) && requestedFullPath !== resolvedRepoPath ) {
271- throw new Error ( `Access denied: Path '${ relativeFilepath } ' attempts to traverse outside the repository directory.` ) ;
272- }
242+ // Temporarily commented out to diagnose "resources/list" serialization error
243+ // server.resource(
244+ // "Repository File Content",
245+ // new ResourceTemplate("repo://files/{filepath}", { list: undefined }),
246+ // {}, // metadata
247+ // async (uri: URL, variables: Variables, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {
248+ // const rawFilepathValue = variables.filepath;
249+ // let relativeFilepath = '';
250+ // if (typeof rawFilepathValue === 'string') {
251+ // relativeFilepath = rawFilepathValue.trim();
252+ // } else if (Array.isArray(rawFilepathValue) && rawFilepathValue.length > 0 && typeof rawFilepathValue[0] === 'string') {
253+ // logger.warn(`Filepath parameter '${JSON.stringify(rawFilepathValue)}' resolved to an array. Using the first element: '${rawFilepathValue[0]}'`);
254+ // relativeFilepath = rawFilepathValue[0].trim();
255+ // } else if (rawFilepathValue !== undefined) {
256+ // logger.warn(`Filepath parameter '${Array.isArray(rawFilepathValue) ? JSON.stringify(rawFilepathValue) : rawFilepathValue}' resolved to an unexpected type: ${typeof rawFilepathValue}. Treating as empty.`);
257+ // }
258+ // // If rawFilepathValue is undefined, or an empty array, or an array not containing a string at index 0, relativeFilepath remains ''.
259+
260+ // if (!relativeFilepath) {
261+ // const errMsg = "File path cannot be empty.";
262+ // logger.error(`Error accessing resource for URI ${uri.toString()}: ${errMsg}`);
263+ // return { contents: [{ uri: uri.toString(), text: "", error: errMsg }] };
264+ // }
265+
266+ // try {
267+ // const resolvedRepoPath = path.resolve(repoPath); // Normalized
268+ // const requestedFullPath = path.resolve(repoPath, relativeFilepath); // Normalized
269+
270+ // // Initial security check: Ensure the resolved path is within the repoPath
271+ // if (!requestedFullPath.startsWith(resolvedRepoPath + path.sep) && requestedFullPath !== resolvedRepoPath) {
272+ // throw new Error(`Access denied: Path '${relativeFilepath}' attempts to traverse outside the repository directory.`);
273+ // }
273274
274- let finalPathToRead = requestedFullPath ;
275- try {
276- const stats = await fs . lstat ( requestedFullPath ) ;
277- if ( stats . isSymbolicLink ( ) ) {
278- const symlinkTargetPath = await fs . realpath ( requestedFullPath ) ;
279- // Ensure the resolved symlink target is also within the repository
280- if ( ! path . resolve ( symlinkTargetPath ) . startsWith ( resolvedRepoPath + path . sep ) && path . resolve ( symlinkTargetPath ) !== resolvedRepoPath ) {
281- throw new Error ( `Access denied: Symbolic link '${ relativeFilepath } ' points outside the repository directory.` ) ;
282- }
283- finalPathToRead = symlinkTargetPath ; // Update path to read from the symlink's target
284- } else if ( ! stats . isFile ( ) ) {
285- throw new Error ( `Access denied: Path '${ relativeFilepath } ' is not a file.` ) ;
286- }
287- } catch ( statError : unknown ) {
288- if ( ( statError as NodeJS . ErrnoException ) . code === 'ENOENT' ) {
289- throw new Error ( `File not found: ${ relativeFilepath } ` ) ;
290- }
291- throw statError ; // Re-throw other stat/realpath errors
292- }
293-
294- const content = await fs . readFile ( finalPathToRead , "utf8" ) ;
295- return { contents : [ { uri : uri . toString ( ) , text : content } ] } ;
296- } catch ( error : unknown ) {
297- const errorMessage = error instanceof Error ? error . message : String ( error ) ;
298- logger . error ( `Error accessing resource for URI ${ uri . toString ( ) } (relative path: ${ relativeFilepath } ): ${ errorMessage } ` ) ;
299- return { contents : [ { uri : uri . toString ( ) , text : "" , error : errorMessage } ] } ;
300- }
301- } ) ;
275+ // let finalPathToRead = requestedFullPath;
276+ // try {
277+ // const stats = await fs.lstat(requestedFullPath);
278+ // if (stats.isSymbolicLink()) {
279+ // const symlinkTargetPath = await fs.realpath(requestedFullPath);
280+ // // Ensure the resolved symlink target is also within the repository
281+ // if (!path.resolve(symlinkTargetPath).startsWith(resolvedRepoPath + path.sep) && path.resolve(symlinkTargetPath) !== resolvedRepoPath) {
282+ // throw new Error(`Access denied: Symbolic link '${relativeFilepath}' points outside the repository directory.`);
283+ // }
284+ // finalPathToRead = symlinkTargetPath; // Update path to read from the symlink's target
285+ // } else if (!stats.isFile()) {
286+ // throw new Error(`Access denied: Path '${relativeFilepath}' is not a file.`);
287+ // }
288+ // } catch (statError: unknown) {
289+ // if ((statError as NodeJS.ErrnoException).code === 'ENOENT') {
290+ // throw new Error(`File not found: ${relativeFilepath}`);
291+ // }
292+ // throw statError; // Re-throw other stat/realpath errors
293+ // }
294+
295+ // const content = await fs.readFile(finalPathToRead, "utf8");
296+ // return { contents: [{ uri: uri.toString(), text: content }] };
297+ // } catch (error: unknown) {
298+ // const errorMessage = error instanceof Error ? error.message : String(error);
299+ // logger.error(`Error accessing resource for URI ${uri.toString()} (relative path: ${relativeFilepath}): ${errorMessage}`);
300+ // return { contents: [{ uri: uri.toString(), text: "", error: errorMessage }] };
301+ // }
302+ // });
302303
303304 registerTools ( server , qdrantClient , repoPath , suggestionModelAvailable ) ;
304305
0 commit comments