check_file_exists
Verify the existence of a file within the workspace directory to ensure availability for AI development workflows in the AI Development Pipeline MCP.
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)Handler function that validates the input path using validatePath helper and checks file existence with fs.existsSync, returning appropriate text response.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 MCP tool with server.tool, specifying name, description, input schema, and inline handler function.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)Zod schema for tool input: requires a 'path' string parameter.{ path: z.string() },
- local-mcp-server.ts:15-21 (helper)Security helper function validatePath that resolves the file path relative to WORKSPACE_ROOT and prevents path traversal attacks.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; }