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

26 lines (25 loc) 1.31 kB
import { z } from 'zod'; import { serverState } from '../../state.js'; // Import the server state // Define the input schema using Zod for validation 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.'), }); /** * Sets the default filesystem path for the current session. * * @param {SetFilesystemDefaultInput} input - The input object containing the absolute path. * @param {RequestContext} context - The request context for logging and error handling. * @returns {Promise<SetFilesystemDefaultOutput>} A promise that resolves with a success message and the new default path. * @throws {McpError} Throws McpError if the path is invalid or not absolute. */ export const setFilesystemDefaultLogic = async (input, context) => { 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, }; };