read_from_project
Retrieve specific file content from registered Claude Code projects by specifying project ID, file path, and optional line ranges for targeted code access.
Instructions
Read file content from registered project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | ID of registered project | |
| filePath | Yes | Relative path within project | |
| startLine | No | Start reading from line N (1-indexed) | |
| endLine | No | Stop reading at line N (1-indexed) |
Implementation Reference
- src/tools/read_from_project.ts:6-57 (handler)The main execution logic for the read_from_project tool, handling file reading from projects with security, line ranges, and error handling.export async function readFromProject(args: ReadFromProjectArgs): Promise<{ content: string; path: string; }> { const projectManager = new ProjectManager(); const project = await projectManager.getProject(args.projectId); if (!project) { throw new MCPError(ErrorCode.PROJECT_NOT_FOUND, `Project '${args.projectId}' not found`); } // Prevent directory traversal if (args.filePath.includes('..') || isAbsolute(args.filePath)) { throw new MCPError(ErrorCode.INVALID_PATH, `Invalid file path: ${args.filePath}`); } const fullPath = join(project.rootPath, args.filePath); try { const stats = await stat(fullPath); if (!stats.isFile()) { throw new MCPError(ErrorCode.INVALID_PATH, `Path is not a file: ${args.filePath}`); } let content = await readFile(fullPath, 'utf-8'); // Handle line ranges if specified if (args.startLine !== undefined || args.endLine !== undefined) { const lines = content.split('\n'); const start = (args.startLine || 1) - 1; const end = args.endLine || lines.length; content = lines.slice(start, end).join('\n'); } // Update last accessed project.lastAccessed = new Date().toISOString(); return { content, path: fullPath }; } catch (error: any) { if (error.status === ErrorCode.INVALID_PATH || error instanceof MCPError) { throw error; } if (error.code === 'ENOENT') { throw new MCPError(ErrorCode.FILE_NOT_FOUND, `File '${args.filePath}' not found in project`); } throw new MCPError(ErrorCode.INTERNAL_ERROR, `Failed to read file: ${error.message}`); } }
- src/models/types.ts:106-111 (schema)TypeScript interface defining the input parameters for the read_from_project tool.export interface ReadFromProjectArgs { projectId: string; filePath: string; startLine?: number; endLine?: number; }
- src/index.ts:96-108 (registration)Tool registration in ListToolsRequestHandler, including name, description, and input schema.name: 'read_from_project', description: 'Read file content from registered project', inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: 'ID of registered project' }, filePath: { type: 'string', description: 'Relative path within project' }, startLine: { type: 'number', description: 'Start reading from line N (1-indexed)' }, endLine: { type: 'number', description: 'Stop reading at line N (1-indexed)' } }, required: ['projectId', 'filePath'] } }
- src/index.ts:133-136 (registration)Handler dispatch in CallToolRequestHandler that invokes the readFromProject function.case 'read_from_project': return { content: [{ type: 'text', text: JSON.stringify(await readFromProject(args as unknown as ReadFromProjectArgs), null, 2) }] };