Skip to main content
Glama

set_filesystem_default

Set an absolute path as the default for resolving relative paths in filesystem operations during the session. Cleared on server restart.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesThe absolute path to set as the default for resolving relative paths during this session.

Implementation Reference

  • Core handler function that executes the tool logic: sets the default filesystem path in serverState and returns confirmation.
    export const setFilesystemDefaultLogic = async (input: SetFilesystemDefaultInput, context: RequestContext): Promise<SetFilesystemDefaultOutput> => { const { path: newPath } = input; // The validation (absolute check, sanitization) happens within serverState.setDefaultFilesystemPath serverState.setDefaultFilesystemPath(newPath, context); const currentPath = serverState.getDefaultFilesystemPath(); return { message: `Default filesystem path successfully set to: ${currentPath}`, currentDefaultPath: currentPath, }; };
  • Zod schema defining the input structure for the tool: requires an absolute path string.
    export const SetFilesystemDefaultInputSchema = z.object({ path: z.string().min(1, 'Path cannot be empty') .describe('The absolute path to set as the default for resolving relative paths during this session.'), });
  • Registers the 'set_filesystem_default' tool on the MCP server instance, providing name, description, input schema, and an async handler that calls the core logic.
    export const registerSetFilesystemDefaultTool = async (server: McpServer): Promise<void> => { 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 as SetFilesystemDefaultInput; 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 } ); };
  • Top-level call to registerSetFilesystemDefaultTool as part of all filesystem tools during server initialization.
    registerReadFileTool(server), registerSetFilesystemDefaultTool(server), registerWriteFileTool(server), registerUpdateFileTool(server), registerListFilesTool(server), registerDeleteFileTool(server), registerDeleteDirectoryTool(server), registerCreateDirectoryTool(server), registerMovePathTool(server), registerCopyPathTool(server) ];
  • Index file exporting the registration function for convenient import.
    export { registerSetFilesystemDefaultTool } from './registration.js';

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cyanheads/filesystem-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server