Skip to main content
Glama

file_reserve

Reserve file paths or glob patterns to prevent agent conflicts. Reservations expire after a configurable TTL; use check_only to check without reserving.

Instructions

Reserve files or glob patterns to prevent conflicts between agents. Use check_only=true to check for conflicts without reserving. Reservations expire after TTL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternsYesFile paths or glob patterns to reserve (e.g. ['src/auth/**', 'package.json'])
agentYesAgent reserving the files
ttl_minutesNoReservation TTL in minutes (default 15)
check_onlyNoIf true, only check for conflicts without creating reservations

Implementation Reference

  • The async handler function for the 'file_reserve' tool. It checks for conflicts, optionally checks only (check_only mode), cleans expired reservations, and inserts new reservation records into the file_reservations table.
      async ({ patterns, agent, ttl_minutes, check_only }) => {
        const db = getDb();
        const now = new Date();
        const expiresAt = new Date(
          now.getTime() + ttl_minutes * 60 * 1000
        ).toISOString();
    
        // Clean expired reservations first
        db.prepare(
          `DELETE FROM file_reservations WHERE expires_at < datetime('now')`
        ).run();
    
        // Check for conflicts
        const existing = db
          .prepare(`SELECT * FROM file_reservations WHERE agent != ?`)
          .all(agent) as Array<{ pattern: string; agent: string; expires_at: string }>;
    
        const conflicts = existing.filter((r) =>
          patterns.some(
            (p) => patternsOverlap(p, r.pattern)
          )
        );
    
        if (conflicts.length > 0) {
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  reserved: false,
                  has_conflicts: true,
                  conflicts: conflicts.map((c) => ({
                    pattern: c.pattern,
                    held_by: c.agent,
                    expires_at: c.expires_at,
                  })),
                }),
              },
            ],
          };
        }
    
        // Check-only mode: return clean result without reserving
        if (check_only) {
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  reserved: false,
                  has_conflicts: false,
                  conflicts: [],
                }),
              },
            ],
          };
        }
    
        const insert = db.prepare(
          `INSERT INTO file_reservations (id, pattern, agent, expires_at) VALUES (?, ?, ?, ?)`
        );
    
        const ids: string[] = [];
        const tx = db.transaction(() => {
          for (const pattern of patterns) {
            const id = generateId("res");
            insert.run(id, pattern, agent, expiresAt);
            ids.push(id);
          }
        });
        tx();
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify({
                reserved: true,
                has_conflicts: false,
                reservation_ids: ids,
                agent,
                patterns,
                expires_at: expiresAt,
              }),
            },
          ],
        };
      }
    );
  • Zod schema for the 'file_reserve' tool inputs: patterns (array of strings), agent (string with regex validation), ttl_minutes (number, 1-1440, default 15), check_only (boolean, default false).
    {
      patterns: z
        .array(z.string())
        .describe("File paths or glob patterns to reserve (e.g. ['src/auth/**', 'package.json'])"),
      agent: z.string().max(256).regex(/^[a-zA-Z0-9_.-]+$/).describe("Agent reserving the files"),
      ttl_minutes: z
        .number()
        .min(1)
        .max(1440)
        .default(DEFAULT_TTL_MINUTES)
        .describe("Reservation TTL in minutes (default 15)"),
      check_only: z
        .boolean()
        .default(false)
        .describe("If true, only check for conflicts without creating reservations"),
    },
  • src/server.ts:20-21 (registration)
    Registration of the file tools (including file_reserve) in the MCP server via registerFileTools(server).
    registerFileTools(server);
  • The registerFileTools function that registers both 'file_reserve' and 'file_release' tools on the MCP server.
    export function registerFileTools(server: McpServer): void {
      // ── Reserve Files ──────────────────────────────────
      server.tool(
        "file_reserve",
        "Reserve files or glob patterns to prevent conflicts between agents. Use check_only=true to check for conflicts without reserving. Reservations expire after TTL.",
        {
          patterns: z
            .array(z.string())
            .describe("File paths or glob patterns to reserve (e.g. ['src/auth/**', 'package.json'])"),
          agent: z.string().max(256).regex(/^[a-zA-Z0-9_.-]+$/).describe("Agent reserving the files"),
          ttl_minutes: z
            .number()
            .min(1)
            .max(1440)
            .default(DEFAULT_TTL_MINUTES)
            .describe("Reservation TTL in minutes (default 15)"),
          check_only: z
            .boolean()
            .default(false)
            .describe("If true, only check for conflicts without creating reservations"),
        },
        async ({ patterns, agent, ttl_minutes, check_only }) => {
          const db = getDb();
          const now = new Date();
          const expiresAt = new Date(
            now.getTime() + ttl_minutes * 60 * 1000
          ).toISOString();
    
          // Clean expired reservations first
          db.prepare(
            `DELETE FROM file_reservations WHERE expires_at < datetime('now')`
          ).run();
    
          // Check for conflicts
          const existing = db
            .prepare(`SELECT * FROM file_reservations WHERE agent != ?`)
            .all(agent) as Array<{ pattern: string; agent: string; expires_at: string }>;
    
          const conflicts = existing.filter((r) =>
            patterns.some(
              (p) => patternsOverlap(p, r.pattern)
            )
          );
    
          if (conflicts.length > 0) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    reserved: false,
                    has_conflicts: true,
                    conflicts: conflicts.map((c) => ({
                      pattern: c.pattern,
                      held_by: c.agent,
                      expires_at: c.expires_at,
                    })),
                  }),
                },
              ],
            };
          }
    
          // Check-only mode: return clean result without reserving
          if (check_only) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    reserved: false,
                    has_conflicts: false,
                    conflicts: [],
                  }),
                },
              ],
            };
          }
    
          const insert = db.prepare(
            `INSERT INTO file_reservations (id, pattern, agent, expires_at) VALUES (?, ?, ?, ?)`
          );
    
          const ids: string[] = [];
          const tx = db.transaction(() => {
            for (const pattern of patterns) {
              const id = generateId("res");
              insert.run(id, pattern, agent, expiresAt);
              ids.push(id);
            }
          });
          tx();
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  reserved: true,
                  has_conflicts: false,
                  reservation_ids: ids,
                  agent,
                  patterns,
                  expires_at: expiresAt,
                }),
              },
            ],
          };
        }
      );
    
      // ── Release File Reservations ──────────────────────
      server.tool(
        "file_release",
        "Release file reservations held by an agent.",
        {
          agent: z.string().max(256).regex(/^[a-zA-Z0-9_.-]+$/).describe("Agent releasing reservations"),
          patterns: z
            .array(z.string())
            .optional()
            .describe("Specific patterns to release (omit to release all)"),
        },
        async ({ agent, patterns }) => {
          const db = getDb();
    
          if (patterns && patterns.length > 0) {
            const placeholders = patterns.map(() => "?").join(",");
            const result = db
              .prepare(
                `DELETE FROM file_reservations WHERE agent = ? AND pattern IN (${placeholders})`
              )
              .run(agent, ...patterns);
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    released: true,
                    count: result.changes,
                    agent,
                    patterns,
                  }),
                },
              ],
            };
          }
    
          const result = db
            .prepare(`DELETE FROM file_reservations WHERE agent = ?`)
            .run(agent);
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  released: true,
                  count: result.changes,
                  agent,
                }),
              },
            ],
          };
        }
      );
    }
  • The patternsOverlap helper function used to determine if two file patterns overlap (exact match, parent directory, or wildcard containment).
    function patternsOverlap(a: string, b: string): boolean {
      if (a === b) return true;
      // Normalize: remove trailing slashes
      const na = a.replace(/\/+$/, "");
      const nb = b.replace(/\/+$/, "");
      if (na === nb) return true;
      // Check if one is a parent directory of the other
      const aBase = na.replace(/\/\*\*$/, "").replace(/\/\*$/, "");
      const bBase = nb.replace(/\/\*\*$/, "").replace(/\/\*$/, "");
      // If either has wildcards, check prefix containment
      if (na.includes("*") || nb.includes("*")) {
        return aBase.startsWith(bBase) || bBase.startsWith(aBase);
      }
      // Exact file paths: check if one is under the other's directory
      return na.startsWith(nb + "/") || nb.startsWith(na + "/");
    }
  • TypeScript interface FileReservation defining the shape of a reservation record (id, pattern, agent, expires_at, created_at).
    // ── File Reservation Types ──────────────────────────────
    export interface FileReservation {
      id: string;
      pattern: string;
      agent: string;
      expires_at: string;
      created_at: string;
    }
  • SQL schema for the file_reservations table including the index on agent column.
    CREATE TABLE IF NOT EXISTS file_reservations (
      id TEXT PRIMARY KEY,
      pattern TEXT NOT NULL,
      agent TEXT NOT NULL,
      expires_at TEXT NOT NULL,
      created_at TEXT NOT NULL DEFAULT (datetime('now'))
    );
    
    CREATE INDEX IF NOT EXISTS idx_tasks_board ON tasks(board_id);
    CREATE INDEX IF NOT EXISTS idx_tasks_status ON tasks(status);
    CREATE INDEX IF NOT EXISTS idx_contracts_project ON contracts(project);
    CREATE INDEX IF NOT EXISTS idx_reservations_agent ON file_reservations(agent);
Behavior3/5

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

No annotations are provided, so the description must cover behavioral traits. It states that 'Reservations expire after TTL' and describes the check_only mode. However, it does not disclose whether the tool modifies state, requires permissions, or what happens on conflict. The coverage is adequate but not thorough.

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 three short sentences that front-load the core purpose, then provide a key usage tip, and finally note the TTL. There is no redundancy or fluff; every sentence earns its place.

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 output schema, the description should hint at return values (e.g., conflict status). It does not mention any results or error conditions. While it covers the main purpose and key behaviors, the lack of return value information leaves a gap for an AI agent needing to interpret the tool's response.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. The description adds value by explaining the check_only parameter's purpose and the TTL expiration behavior, going beyond the schema descriptions. This extra context justifies a score of 4.

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

Purpose5/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: 'Reserve files or glob patterns to prevent conflicts between agents.' It uses a specific verb (reserve) and resource (files/patterns), and the mention of TTL and check_only adds clarity. The tool name and description implicitly distinguish it from sibling file_release.

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 only one usage guideline: 'Use check_only=true to check for conflicts without reserving.' It does not explicitly state when to use this tool versus alternatives like file_release, nor does it mention contexts where reservation is inappropriate. This is minimal guidance.

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/lleontor705/forgespec-mcp'

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