Skip to main content
Glama
theburgerllc

AI Development Pipeline MCP

by theburgerllc

read_project_file

Read files from the VS Code workspace directory to access project content for AI-assisted development tasks.

Instructions

Read a local file from the VS Code workspace (restricted to workspace directory)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • The async handler function for the 'read_project_file' tool. It validates the input path using validatePath helper, reads the file content using fs.readFileSync, and returns the content or an error message.
    async ({ path }) => {
      try {
        const safePath = validatePath(path);
        const content = fs.readFileSync(safePath, 'utf8');
        return { content: [{ type: 'text', text: content }] };
      } catch (err: any) {
        return { content: [{ type: 'text', text: `File read error: ${err.message}` }] };
      }
    }
  • Zod schema for the tool input, defining a required 'path' parameter as a string.
    { path: z.string() },
  • Registration of the 'read_project_file' tool on the MCP server, including name, description, schema, and handler.
    server.tool(
      'read_project_file',
      'Read a local file from the VS Code workspace (restricted to workspace directory)',
      { path: z.string() },
      async ({ path }) => {
        try {
          const safePath = validatePath(path);
          const content = fs.readFileSync(safePath, 'utf8');
          return { content: [{ type: 'text', text: content }] };
        } catch (err: any) {
          return { content: [{ type: 'text', text: `File read error: ${err.message}` }] };
        }
      }
    );
  • Helper function to securely resolve and validate file paths, ensuring they are within the workspace root to prevent path traversal attacks. Used by the read_project_file handler.
    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;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/theburgerllc/ai-development-pipeline-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server