Skip to main content
Glama

Get Git diff

git_diff

Generate Git repository diffs to analyze code changes, supporting working directory, staged files, or commit ranges for technical review and documentation.

Instructions

Retorna um diff do repositório atual. Use para entender alterações locais.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
baseNo
headNo
maxBytesNo
modeNoworking
pathSpecNo

Implementation Reference

  • The handler function for the 'git_diff' tool. It constructs git diff arguments based on the mode ('working', 'staged', 'range'), runs git diff and git diff --name-status using the runGit helper, processes the output to list changed files, truncates if necessary, and returns formatted content.
    async ({ mode = 'working', base, head, pathSpec, maxBytes = 200_000 }) => {
      let args: string[] = ['diff', '-U3']
    
      if (mode === 'staged') {
        args = ['diff', '--staged', '-U3']
      }
    
      if (mode === 'range' && (!base || !head)) {
        throw new Error('For mode=range informe base e head')
      }
    
      if (mode === 'range') {
        args = ['diff', `${base}...${head}`, '-U3']
      }
    
      if (pathSpec && pathSpec.length) {
        args.push('--', ...pathSpec)
      }
    
      const nameStatus = await runGit(
        mode === 'range'
          ? ['diff', '--name-status', `${base}...${head}`]
          : mode === 'staged'
          ? ['diff', '--staged', '--name-status']
          : ['diff', '--name-status']
      )
    
      const diff = await runGit(args)
      const truncated =
        diff.length > maxBytes
          ? diff.slice(0, maxBytes) + '\n\n[...truncated...]'
          : diff
    
      const files = nameStatus
        .split('\n')
        .filter(Boolean)
        .map((line) => {
          const [status, ...rest] = line.split(/\s+/)
          return { status, file: rest.join(' ') }
        })
    
      return {
        content: [
          {
            type: 'text',
            text: `Changed files:\n${files
              .map((f) => `${f.status}\t${f.file}`)
              .join('\n')}`,
          },
          { type: 'text', text: '\n--- DIFF START ---\n' + truncated },
        ],
      }
    }
  • Input schema for git_diff tool using Zod: mode (enum: working/staged/range), base/head (strings opt), pathSpec (array strings opt), maxBytes (number opt).
    inputSchema: {
      mode: z.enum(['working', 'staged', 'range']).default('working'),
      base: z.string().optional(),
      head: z.string().optional(),
      pathSpec: z.array(z.string()).optional(),
      maxBytes: z
        .number()
        .int()
        .positive()
        .max(5 * 1024 * 1024)
        .optional(),
    },
  • src/index.ts:13-85 (registration)
    Registers the 'git_diff' tool with McpServer using server.registerTool, providing title, description, inputSchema, and the handler function.
    server.registerTool(
      'git_diff',
      {
        title: 'Get Git diff',
        description:
          'Retorna um diff do repositório atual. Use para entender alterações locais.',
        inputSchema: {
          mode: z.enum(['working', 'staged', 'range']).default('working'),
          base: z.string().optional(),
          head: z.string().optional(),
          pathSpec: z.array(z.string()).optional(),
          maxBytes: z
            .number()
            .int()
            .positive()
            .max(5 * 1024 * 1024)
            .optional(),
        },
      },
      async ({ mode = 'working', base, head, pathSpec, maxBytes = 200_000 }) => {
        let args: string[] = ['diff', '-U3']
    
        if (mode === 'staged') {
          args = ['diff', '--staged', '-U3']
        }
    
        if (mode === 'range' && (!base || !head)) {
          throw new Error('For mode=range informe base e head')
        }
    
        if (mode === 'range') {
          args = ['diff', `${base}...${head}`, '-U3']
        }
    
        if (pathSpec && pathSpec.length) {
          args.push('--', ...pathSpec)
        }
    
        const nameStatus = await runGit(
          mode === 'range'
            ? ['diff', '--name-status', `${base}...${head}`]
            : mode === 'staged'
            ? ['diff', '--staged', '--name-status']
            : ['diff', '--name-status']
        )
    
        const diff = await runGit(args)
        const truncated =
          diff.length > maxBytes
            ? diff.slice(0, maxBytes) + '\n\n[...truncated...]'
            : diff
    
        const files = nameStatus
          .split('\n')
          .filter(Boolean)
          .map((line) => {
            const [status, ...rest] = line.split(/\s+/)
            return { status, file: rest.join(' ') }
          })
    
        return {
          content: [
            {
              type: 'text',
              text: `Changed files:\n${files
                .map((f) => `${f.status}\t${f.file}`)
                .join('\n')}`,
            },
            { type: 'text', text: '\n--- DIFF START ---\n' + truncated },
          ],
        }
      }
    )
  • runGit helper function that promisifies execFile to run git commands with given args, returns trimmed stdout. Used by git_diff handler to execute git diff and git --name-status.
    export async function runGit(args: string[], cwd = process.cwd()) {
      const { stdout } = await pexec('git', ['--no-pager', ...args], {
        cwd,
        maxBuffer: 1024 * 1024 * 20,
      })
      return stdout.trim()
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the tool returns a diff for understanding local changes, but lacks details on behavioral traits such as whether it requires specific Git states, how it handles errors, if it's read-only or has side effects, or any rate limits. This is a significant gap for a tool with 5 parameters and no annotation coverage.

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 appropriately sized and front-loaded with the core purpose in the first sentence, followed by a brief usage note. Both sentences earn their place by providing essential information without redundancy or unnecessary details, making it highly efficient and well-structured.

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

Completeness2/5

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

Given the complexity (5 parameters, 0% schema coverage, no annotations, no output schema), the description is incomplete. It doesn't explain the return values, parameter usage, or behavioral context needed for effective tool invocation. The description should do more to compensate for the lack of structured data, especially for a tool with multiple parameters and no output schema.

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

Parameters2/5

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

The schema description coverage is 0%, meaning none of the 5 parameters are documented in the schema. The description does not mention any parameters or add meaning beyond the schema, failing to compensate for the low coverage. This leaves the agent with no guidance on what parameters like 'base', 'head', 'mode', etc., mean or how to use them effectively.

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: 'Retorna um diff do repositório atual' (Returns a diff of the current repository). It specifies the verb (returns) and resource (diff of current repository), making the function unambiguous. However, it doesn't explicitly differentiate from the sibling tool 'create_github_issue', which serves a completely different purpose, so it doesn't fully earn a 5.

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

Usage Guidelines3/5

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

The description provides implied usage guidance: 'Use para entender alterações locais' (Use to understand local changes). This suggests when to use the tool (for understanding local changes) but doesn't explicitly state when not to use it or mention alternatives. There's no comparison with the sibling tool or other potential tools, leaving some ambiguity in tool selection.

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

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/gustavodetoni/mcp-issue'

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