Skip to main content
Glama

move_document

Move documentation files between locations and optionally update references in other files to maintain link integrity.

Instructions

Move a document from one location to another. Optionally updates references to the document in other files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo
sourcePathYes
destinationPathYes
updateReferencesNo

Implementation Reference

  • The primary handler method in DocumentHandler class that executes the move_document tool. Validates paths, copies file content, deletes source, optionally updates references in other docs, and returns ToolResponse.
    async moveDocument(
      sourcePath: string,
      destinationPath: string,
      updateReferences = true
    ): Promise<ToolResponse> {
      try {
        const validSourcePath = await this.validatePath(sourcePath);
        const validDestPath = await this.validatePath(destinationPath);
    
        // Check if source exists
        try {
          await fs.access(validSourcePath);
        } catch {
          throw new Error(`Source file does not exist: ${sourcePath}`);
        }
    
        // Create destination directory if it doesn't exist
        const destDir = path.dirname(validDestPath);
        await fs.mkdir(destDir, { recursive: true });
    
        // Read the source file
        const content = await fs.readFile(validSourcePath, "utf-8");
    
        // Write to destination
        await fs.writeFile(validDestPath, content, "utf-8");
    
        // Delete the source file
        await fs.unlink(validSourcePath);
    
        // Update references if requested
        let referencesUpdated = 0;
        if (updateReferences) {
          referencesUpdated = await this.updateReferences(
            sourcePath,
            destinationPath
          );
        }
    
        return {
          content: [
            {
              type: "text",
              text:
                `Successfully moved document from ${sourcePath} to ${destinationPath}` +
                (referencesUpdated > 0
                  ? `. Updated ${referencesUpdated} references.`
                  : ""),
            },
          ],
          metadata: {
            sourcePath,
            destinationPath,
            referencesUpdated,
          },
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            { type: "text", text: `Error moving document: ${errorMessage}` },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining input for move_document tool: sourcePath, destinationPath, and optional updateReferences.
    export const MoveDocumentSchema = ToolInputSchema.extend({
      sourcePath: z.string(),
      destinationPath: z.string(),
      updateReferences: z.boolean().default(true),
    });
  • src/index.ts:259-263 (registration)
    Tool registration in listTools handler: defines name 'move_document', description, and converts MoveDocumentSchema to JSON schema.
    name: "move_document",
    description:
      "Move a document from one location to another. Optionally updates references to the " +
      "document in other files.",
    inputSchema: zodToJsonSchema(MoveDocumentSchema) as any,
  • src/index.ts:414-426 (registration)
    Tool call handler in CallToolRequestSchema switch: parses args with MoveDocumentSchema and calls documentHandler.moveDocument (note: case label is 'move_documentation_document' but error mentions 'move_document').
    case "move_documentation_document": {
      const parsed = MoveDocumentSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for move_document: ${parsed.error}`
        );
      }
      return await documentHandler.moveDocument(
        parsed.data.sourcePath,
        parsed.data.destinationPath,
        parsed.data.updateReferences
      );
    }
  • Private helper method called by moveDocument (and rename) to scan all .md files and update markdown links and direct path references from oldPath to newPath.
    private async updateReferences(
      oldPath: string,
      newPath: string
    ): Promise<number> {
      // Normalize paths for comparison
      const normalizedOldPath = oldPath.replace(/\\/g, "/");
      const normalizedNewPath = newPath.replace(/\\/g, "/");
    
      // Find all markdown files
      const files = await glob("**/*.md", { cwd: this.docsDir });
      let updatedCount = 0;
    
      for (const file of files) {
        const filePath = path.join(this.docsDir, file);
        const content = await fs.readFile(filePath, "utf-8");
    
        // Look for references to the old path
        // Match markdown links: [text](path)
        const linkRegex = new RegExp(
          `\\[([^\\]]+)\\]\\(${normalizedOldPath.replace(
            /[.*+?^${}()|[\]\\]/g,
            "\\$&"
          )}\\)`,
          "g"
        );
    
        // Match direct path references
        const pathRegex = new RegExp(
          normalizedOldPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
          "g"
        );
    
        // Replace references
        let updatedContent = content.replace(
          linkRegex,
          `[$1](${normalizedNewPath})`
        );
        updatedContent = updatedContent.replace(pathRegex, normalizedNewPath);
    
        // If content changed, write the updated file
        if (updatedContent !== content) {
          await fs.writeFile(filePath, updatedContent, "utf-8");
          updatedCount++;
        }
      }
    
      return updatedCount;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool performs a move operation (implying mutation) and optionally updates references, but lacks critical details: whether it requires specific permissions, if the move is reversible, what happens to broken links if references aren't updated, or any rate limits. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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?

The description is concise with two sentences that efficiently convey the core action and an optional feature. It's front-loaded with the primary purpose, though it could be slightly more structured by explicitly listing key parameters or constraints. There's no wasted text, making it appropriately sized for the tool's complexity.

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 tool's mutation nature, 4 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It fails to address critical aspects like error conditions, return values, permissions needed, or how references are updated. For a move operation that could affect document integrity, more context is necessary to ensure safe and correct usage.

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 0%, so the schema provides no parameter details. The description adds minimal semantics by implying 'path' might be involved (though not listed in schema) and mentioning 'updateReferences' functionality. However, it doesn't explain the purpose of 'sourcePath' vs 'destinationPath' or clarify if 'path' is required, leaving 4 parameters largely undocumented. This partial compensation earns a baseline score.

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 verb 'move' and resource 'document' with the action 'from one location to another', making the purpose evident. It distinguishes from siblings like 'rename_document' (which changes name) and 'edit_document' (which modifies content). However, it doesn't explicitly differentiate from 'create_folder' or 'list_documents', which slightly reduces specificity.

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 like 'rename_document' (for name changes) or 'create_folder' (for creating new locations). It mentions an optional feature ('updates references') but doesn't explain when this should be enabled or avoided, leaving usage context implied rather than explicit.

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/alekspetrov/mcp-docs-service'

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