Skip to main content
Glama

read_project_files

Read project file contents to provide AI experts with code context for development, review, and optimization tasks.

Instructions

读取项目文件内容,让专家了解代码上下文

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes文件或目录路径(相对于当前工作目录)
patternNo文件匹配模式(如 *.ts, *.js),仅读取目录时有效
maxFilesNo最多读取文件数(默认 10)

Implementation Reference

  • Handler for 'read_project_files' tool: reads single file or directory contents (with optional pattern filter and maxFiles limit), truncates long contents, formats as Markdown, and returns as tool response.
    case 'read_project_files': {
      const { path: targetPath, pattern, maxFiles = 10 } = args as { path: string; pattern?: string; maxFiles?: number };
      const fullPath = join(process.cwd(), targetPath);
      
      if (!existsSync(fullPath)) {
        throw new Error(`路径不存在: ${targetPath}`);
      }
      
      const stat = statSync(fullPath);
      let result = '';
      
      if (stat.isFile()) {
        // 读取单个文件
        const content = readFileSync(fullPath, 'utf-8');
        result = `# 📄 ${targetPath}\n\n\`\`\`\n${content.slice(0, 10000)}${content.length > 10000 ? '\n... (内容已截断)' : ''}\n\`\`\``;
      } else if (stat.isDirectory()) {
        // 读取目录下的文件
        const files = readdirSync(fullPath)
          .filter(f => {
            if (pattern) {
              const regex = new RegExp(pattern.replace('*', '.*'));
              return regex.test(f);
            }
            return true;
          })
          .slice(0, maxFiles);
        
        result = `# 📁 ${targetPath}\n\n`;
        for (const file of files) {
          const filePath = join(fullPath, file);
          const fileStat = statSync(filePath);
          if (fileStat.isFile()) {
            const content = readFileSync(filePath, 'utf-8');
            result += `## ${file}\n\`\`\`\n${content.slice(0, 3000)}${content.length > 3000 ? '\n... (内容已截断)' : ''}\n\`\`\`\n\n`;
          }
        }
      }
      
      return {
        content: [{ type: 'text', text: result }],
      };
    }
  • Input schema definition for 'read_project_files' tool: requires 'path', optional 'pattern' and 'maxFiles'.
    inputSchema: {
      type: 'object',
      properties: {
        path: {
          type: 'string',
          description: '文件或目录路径(相对于当前工作目录)',
        },
        pattern: {
          type: 'string',
          description: '文件匹配模式(如 *.ts, *.js),仅读取目录时有效',
        },
        maxFiles: {
          type: 'number',
          description: '最多读取文件数(默认 10)',
        },
      },
      required: ['path'],
    },
  • src/server.ts:303-324 (registration)
    Tool registration entry in the tools array, including name, description, and input schema, used by MCP server for tool listing.
    {
      name: 'read_project_files',
      description: '读取项目文件内容,让专家了解代码上下文',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: '文件或目录路径(相对于当前工作目录)',
          },
          pattern: {
            type: 'string',
            description: '文件匹配模式(如 *.ts, *.js),仅读取目录时有效',
          },
          maxFiles: {
            type: 'number',
            description: '最多读取文件数(默认 10)',
          },
        },
        required: ['path'],
      },
    },

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/7836246/claude-team-mcp'

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