UNPKG

@cyanheads/filesystem-mcp-server

Version:

A Model Context Protocol (MCP) server for platform-agnostic file capabilities, including advanced search and replace, and directory tree traversal

45 lines (44 loc) 2.83 kB
import { BaseErrorCode } from '../../../types-global/errors.js'; import { ErrorHandler } from '../../../utils/internal/errorHandler.js'; import { logger } from '../../../utils/internal/logger.js'; import { requestContextService } from '../../../utils/internal/requestContext.js'; import { SetFilesystemDefaultInputSchema, setFilesystemDefaultLogic, } from './setFilesystemDefaultLogic.js'; /** * Registers the 'set_filesystem_default' tool with the MCP server. * * @param {McpServer} server - The McpServer instance to register the tool with. * @returns {Promise<void>} A promise that resolves when the tool is registered. * @throws {McpError} Throws an error if registration fails. */ export const registerSetFilesystemDefaultTool = async (server) => { const registrationContext = requestContextService.createRequestContext({ operation: 'RegisterSetFilesystemDefaultTool' }); logger.info("Attempting to register 'set_filesystem_default' tool", registrationContext); await ErrorHandler.tryCatch(async () => { server.tool('set_filesystem_default', // Tool name 'Sets a default absolute path for the current session. Relative paths used in other filesystem tools (like readFile) will be resolved against this default. The default is cleared on server restart.', // Description SetFilesystemDefaultInputSchema.shape, // Pass the schema shape async (params, extra) => { const typedParams = params; const callContext = requestContextService.createRequestContext({ operation: 'SetFilesystemDefaultToolExecution', parentId: registrationContext.requestId }); logger.info(`Executing 'set_filesystem_default' tool with path: ${typedParams.path}`, callContext); // ErrorHandler will catch McpErrors thrown by the logic (e.g., non-absolute path) const result = await ErrorHandler.tryCatch(() => setFilesystemDefaultLogic(typedParams, callContext), { operation: 'setFilesystemDefaultLogic', context: callContext, input: typedParams, // Input is automatically sanitized by ErrorHandler errorCode: BaseErrorCode.INTERNAL_ERROR // Default error if unexpected failure }); logger.info(`Successfully executed 'set_filesystem_default'. Current default: ${result.currentDefaultPath}`, callContext); // Format the successful response return { content: [{ type: 'text', text: result.message }], }; }); logger.info("'set_filesystem_default' tool registered successfully", registrationContext); }, { operation: 'registerSetFilesystemDefaultTool', context: registrationContext, errorCode: BaseErrorCode.CONFIGURATION_ERROR, critical: true }); };