read_code_file
Read Python code files to verify content before appending or executing, ensuring accurate code modifications and execution.
Instructions
Read the content of an existing Python code file. Use this to verify the current state of a file before appending more content or executing it.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Full path to the file to read |
Implementation Reference
- src/index.ts:281-309 (handler)The core handler function that implements the logic for the 'read_code_file' tool: checks if the file exists, reads its content using fs.readFile, and returns a structured JSON response.async function readCodeFile(filePath: string) { try { // Ensure file exists await access(filePath); // Read file content const content = await readFile(filePath, 'utf-8'); return { type: 'text', text: JSON.stringify({ status: 'success', content: content, file_path: filePath }), isError: false }; } catch (error) { return { type: 'text', text: JSON.stringify({ status: 'error', error: error instanceof Error ? error.message : String(error), file_path: filePath }), isError: true }; } }
- src/index.ts:843-858 (registration)The registration and dispatch handler in the CallToolRequestSchema switch statement that extracts arguments, validates file_path, calls the readCodeFile handler, and formats the MCP response.case "read_code_file": { const args = request.params.arguments as ReadCodeFileArgs; if (!args?.file_path) { throw new Error("File path is required"); } const result = await readCodeFile(args.file_path); return { content: [{ type: "text", text: result.text, isError: result.isError }] }; }
- src/index.ts:603-615 (schema)The tool schema registration in ListToolsRequestSchema, defining the name, description, and input schema requiring 'file_path' string.name: "read_code_file", description: "Read the content of an existing Python code file. Use this to verify the current state of a file before appending more content or executing it.", inputSchema: { type: "object", properties: { file_path: { type: "string", description: "Full path to the file to read" } }, required: ["file_path"] } },
- src/index.ts:709-711 (schema)TypeScript interface defining the input arguments for the 'read_code_file' tool.interface ReadCodeFileArgs { file_path?: string; }