Skip to main content
Glama
Cytrogen

Local Project Sync

by Cytrogen

read_file_content

Retrieve content from specified project files using a prefixed path, enabling direct access to local code repositories for analysis and integration.

Instructions

读取项目内指定文件的内容,文件路径必须包含前缀,例如 '[backend/src]/main.ts'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes带前缀的完整文件路径, e.g., '[backend/src]/main.ts'

Implementation Reference

  • The handler function for the 'read_file_content' tool. It parses the filePath with prefix, resolves the absolute path using pathRegistry, performs security checks, reads the file content using fs.readFile, and returns it formatted in the MCP response format.
    async ({ filePath }) => {
      const match = filePath.match(/^(\[.*?\])\/(.*)$/s);
      if (!match) return { content: [{ type: "text", text: "错误:文件路径格式不正确,必须包含如 '[backend/src]/' 的前缀。" }] };
    
      const prefix = match[1];
      const relativePath = match[2];
      const rootPath = pathRegistry.get(prefix);
    
      if (!rootPath) return { content: [{ type: "text", text: `错误:未知的路径前缀 '${prefix}'。` }] };
    
      const resolvedPath = path.resolve(rootPath, relativePath);
      if (!resolvedPath.startsWith(path.resolve(rootPath))) return { content: [{ type: "text", text: "错误:禁止访问项目目录之外的文件。" }] };
    
      try {
        const fileContent = await fs.readFile(resolvedPath, "utf-8");
        return { content: [{ type: "text", text: `文件 '${filePath}' 的内容:\n---\n${fileContent}` }] };
      } catch (error: any) {
        let errorMessage = `读取文件 '${filePath}' 时发生错误。`;
        if (error.code === 'ENOENT') errorMessage = `错误:文件 '${filePath}' 未找到。`;
        console.error(errorMessage, error);
        return { content: [{ type: "text", text: errorMessage }] };
      }
    }
  • The input schema for the tool using Zod, defining the 'filePath' parameter.
    {
      filePath: z.string().describe("带前缀的完整文件路径, e.g., '[backend/src]/main.ts'"),
    },
  • src/index.ts:269-298 (registration)
    Registration of the 'read_file_content' tool using McpServer.tool() method, including name, description, schema, and handler.
    server.tool(
      "read_file_content",
      "读取项目内指定文件的内容,文件路径必须包含前缀,例如 '[backend/src]/main.ts'",
      {
        filePath: z.string().describe("带前缀的完整文件路径, e.g., '[backend/src]/main.ts'"),
      },
      async ({ filePath }) => {
        const match = filePath.match(/^(\[.*?\])\/(.*)$/s);
        if (!match) return { content: [{ type: "text", text: "错误:文件路径格式不正确,必须包含如 '[backend/src]/' 的前缀。" }] };
    
        const prefix = match[1];
        const relativePath = match[2];
        const rootPath = pathRegistry.get(prefix);
    
        if (!rootPath) return { content: [{ type: "text", text: `错误:未知的路径前缀 '${prefix}'。` }] };
    
        const resolvedPath = path.resolve(rootPath, relativePath);
        if (!resolvedPath.startsWith(path.resolve(rootPath))) return { content: [{ type: "text", text: "错误:禁止访问项目目录之外的文件。" }] };
    
        try {
          const fileContent = await fs.readFile(resolvedPath, "utf-8");
          return { content: [{ type: "text", text: `文件 '${filePath}' 的内容:\n---\n${fileContent}` }] };
        } catch (error: any) {
          let errorMessage = `读取文件 '${filePath}' 时发生错误。`;
          if (error.code === 'ENOENT') errorMessage = `错误:文件 '${filePath}' 未找到。`;
          console.error(errorMessage, error);
          return { content: [{ type: "text", text: errorMessage }] };
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It discloses the file path format constraint, which is useful behavioral context. However, it lacks details on permissions, error handling (e.g., if file doesn't exist), output format, or size limits, which are important for a file-reading operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and adds necessary constraint details. Every part earns its place with no wasted words, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is minimally complete for a simple read operation. It covers the basic action and parameter constraint, but lacks details on behavioral aspects like error cases or output structure, which could help the agent use it more effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter 'filePath' fully documented in the schema. The description adds minimal value by restating the path format example ('[backend/src]/main.ts'), which is already in the schema description. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '读取项目内指定文件的内容' (read the content of a specified file within the project). It specifies the verb (read) and resource (file content), but doesn't explicitly differentiate from siblings like 'read_file_section' or 'read_multiple_files' beyond the single-file focus implied by '指定文件' (specified file).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions the file path format requirement but doesn't compare to siblings like 'read_file_section' (for partial reads) or 'read_multiple_files' (for batch operations), leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/Cytrogen/local-project-sync'

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