check_file_exists
Verify whether a specific file exists within your workspace directory to prevent errors in development workflows.
Instructions
Check if a local file exists (restricted to workspace directory)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- local-mcp-server.ts:111-119 (handler)The main handler function for the 'check_file_exists' tool. It validates the input path using validatePath, then uses fs.existsSync to check if the file exists, returning a text response indicating existence or not.async ({ path }) => { try { const safePath = validatePath(path); const exists = fs.existsSync(safePath); return { content: [{ type: 'text', text: exists ? 'File exists' : 'File does not exist' }] }; } catch (err: any) { return { content: [{ type: 'text', text: `File check error: ${err.message}` }] }; } }
- local-mcp-server.ts:107-120 (registration)Registration of the 'check_file_exists' tool on the MCP server, including name, description, schema, and handler.server.tool( 'check_file_exists', 'Check if a local file exists (restricted to workspace directory)', { path: z.string() }, async ({ path }) => { try { const safePath = validatePath(path); const exists = fs.existsSync(safePath); return { content: [{ type: 'text', text: exists ? 'File exists' : 'File does not exist' }] }; } catch (err: any) { return { content: [{ type: 'text', text: `File check error: ${err.message}` }] }; } } );
- local-mcp-server.ts:110-110 (schema)Input schema for the tool: requires a 'path' parameter as a string, validated with Zod.{ path: z.string() },
- local-mcp-server.ts:15-21 (helper)Helper function used by the tool to validate and resolve the file path, preventing path traversal attacks by ensuring it stays within the workspace root.function validatePath(filePath: string): string { const resolvedPath = path.resolve(WORKSPACE_ROOT, filePath); if (!resolvedPath.startsWith(WORKSPACE_ROOT)) { throw new Error('Path traversal detected - access denied'); } return resolvedPath; }