Skip to main content
Glama

close_file

Destructive

Close open DOCX or Google Docs file sessions to free resources and ensure data integrity. Use to end individual sessions or confirm closure of all sessions.

Instructions

Close an open file session, or close all sessions with explicit confirmation. Supports DOCX and Google Docs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathNoPath to the DOCX file.
google_doc_idNoGoogle Doc ID or URL (alternative to file_path). Extract from URL: docs.google.com/document/d/{ID}/edit
clear_allNo
confirmNo

Implementation Reference

  • The handler implementation for the `close_file` tool, which handles closing document file sessions.
    export async function closeFile(
      manager: SessionManager,
      params: {
        file_path?: string;
        clear_all?: boolean;
        confirm?: boolean;
      },
    ): Promise<ToolResponse> {
      try {
        const clearAll = params.clear_all === true;
        const filePath = typeof params.file_path === 'string' ? params.file_path.trim() : '';
        const hasFilePath = filePath.length > 0;
    
        if (clearAll) {
          if (params.confirm !== true) {
            return err(
              'CONFIRMATION_REQUIRED',
              'clear_all=true requires confirm=true.',
              'Re-run with confirm=true to close every active file session.',
            );
          }
          if (hasFilePath) {
            return err(
              'INVALID_CLEAR_TARGET',
              'clear_all=true cannot be combined with file_path.',
              'Use clear_all=true, confirm=true by itself, or remove clear_all and target a file_path.',
            );
          }
          const clearedPaths = await manager.clearAllSessions();
          return ok({
            clear_mode: 'all',
            cleared_file_paths: clearedPaths,
            cleared_count: clearedPaths.length,
          });
        }
    
        if (!hasFilePath) {
          return err(
            'INVALID_CLEAR_TARGET',
            'close_file requires file_path, or clear_all=true.',
            'Provide file_path to close a file session, or clear_all=true with confirm=true.',
          );
        }
    
        const cleared = await manager.clearSessionByPath(filePath);
        if (!cleared) {
          return ok({
            clear_mode: 'file_path',
            file_path: filePath,
            cleared_file_paths: [],
            cleared_count: 0,
            message: 'No active session found for this file.',
          });
        }
    
        return ok({
          clear_mode: 'file_path',
          file_path: cleared,
          cleared_file_paths: [cleared],
          cleared_count: 1,
        });
      } catch (e: unknown) {
        return err(
          'CLOSE_FILE_ERROR',
          `Failed to close file session(s): ${errorMessage(e)}`,
        );
      }
    }
  • The tool definition and schema for `close_file` in the tool catalog.
      name: 'close_file',
      description: 'Close an open file session, or close all sessions with explicit confirmation. Supports DOCX and Google Docs.',
      input: z.object({
        ...FILE_FIELD_OPTIONAL,
        ...GOOGLE_DOC_ID_FIELD,
        clear_all: z.boolean().optional(),
        confirm: z.boolean().optional(),
      }),
      annotations: { readOnlyHint: false, destructiveHint: true },
    },
  • Registration of the `close_file` tool call in the server dispatcher.
    case 'close_file':
      if (isGDocsRequest(args)) return await dispatchGDocs(sessions, args, 'close_file');
      return await closeFile(sessions, args as Parameters<typeof closeFile>[1]);
Behavior3/5

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

Annotations already indicate destructive behavior. The description adds context about requiring 'explicit confirmation' for closing all sessions, which aligns with the destructive hint. However, it fails to clarify the consequences of closing (e.g., whether unsaved changes are discarded) or authorization requirements.

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

Conciseness4/5

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

Single, efficient sentence front-loaded with the core action. Information density is high without being verbose, though 'explicit confirmation' slightly conflates the confirm parameter with user intent.

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?

Adequate for identifying the tool's basic function, but insufficient for a destructive operation with no output schema. Critical gap: does not specify behavior regarding unsaved changes (data loss risk), which is essential given destructiveHint=true.

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?

With 50% schema coverage, the description partially compensates by implying clear_all ('close all sessions') and confirm ('explicit confirmation'), but does not explicitly map these concepts to parameter names or clarify if confirm is required only for clear_all.

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 closes file sessions and supports DOCX/Google Docs formats. However, it lacks explicit differentiation from sibling tools like 'save' (e.g., clarifying this does not persist changes).

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?

Implies usage through 'explicit confirmation' for bulk operations, hinting at safety requirements for destructive actions. However, it does not explicitly state when to use clear_all vs. single file close, or warn against using this when unsaved changes exist.

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/UseJunior/safe-docx'

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