Skip to main content
Glama

update_doc

Update an existing document by modifying its title, text, or folder. Validates references and sends only changed fields.

Instructions

Update an existing document (title, text, or folder). Validates references and only sends changed fields.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYesDocument doc_id to update
updatesYesFields to update

Implementation Reference

  • Main handler for the update_doc tool. Validates inputs (doc_id, updates, folder reference), resolves folder names to IDs, calls DartClient.updateDoc(), and returns the updated document with a deep link URL.
    export async function handleUpdateDoc(input: UpdateDocInput): Promise<UpdateDocOutput> {
      const DART_TOKEN = process.env.DART_TOKEN;
    
      if (!DART_TOKEN) {
        throw new DartAPIError(
          'DART_TOKEN environment variable is required. Get your token from: https://app.dartai.com/?settings=account',
          401
        );
      }
    
      // ============================================================================
      // Step 1: Validate input and doc_id
      // ============================================================================
      if (!input || typeof input !== 'object') {
        throw new DartAPIError(
          'input is required and must be an object',
          400
        );
      }
    
      if (!input.doc_id || typeof input.doc_id !== 'string' || input.doc_id.trim() === '') {
        throw new DartAPIError(
          'doc_id is required and must be a non-empty string',
          400
        );
      }
    
      // ============================================================================
      // Step 2: Validate updates object
      // ============================================================================
      if (!input.updates || typeof input.updates !== 'object') {
        throw new ValidationError(
          'updates is required and must be an object',
          'updates'
        );
      }
    
      const updateKeys = Object.keys(input.updates);
      if (updateKeys.length === 0) {
        throw new ValidationError(
          'updates must contain at least one field to update',
          'updates'
        );
      }
    
      // ============================================================================
      // Step 3: Validate folder reference (if updating folder)
      // ============================================================================
      let resolvedFolder: string | undefined;
    
      if (input.updates.folder !== undefined) {
        if (input.updates.folder === null || input.updates.folder === '') {
          // Allow clearing folder
          resolvedFolder = input.updates.folder as string | undefined;
        } else if (typeof input.updates.folder === 'string') {
          // Validate folder exists
          let config: DartConfig;
          try {
            config = await handleGetConfig({ cache_bust: false });
          } catch (error) {
            if (error instanceof DartAPIError) {
              throw new DartAPIError(
                `Failed to retrieve workspace config for folder validation: ${error.message}`,
                error.statusCode,
                error.response
              );
            }
            throw error;
          }
    
          if (!config.folders || config.folders.length === 0) {
            throw new ValidationError(
              'No folders found in workspace configuration. Create a folder first in Dart AI.',
              'folder'
            );
          }
    
          const folder = findFolder(config.folders, input.updates.folder);
    
          if (!folder) {
            const folderNames = getFolderNames(config.folders);
            const availableFolders = folderNames.join(', ');
            throw new ValidationError(
              `Invalid folder: "${input.updates.folder}" not found in workspace. Available folders: ${availableFolders}`,
              'folder',
              folderNames
            );
          }
    
          resolvedFolder = folder.dart_id;
        } else {
          // Invalid type for folder
          throw new ValidationError(
            `folder must be a string or null (received: ${typeof input.updates.folder})`,
            'folder'
          );
        }
      }
    
      // ============================================================================
      // Step 4: Validate title and text (if provided)
      // ============================================================================
      if (input.updates.title !== undefined) {
        if (typeof input.updates.title !== 'string' || input.updates.title.trim() === '') {
          throw new ValidationError(
            'title must be a non-empty string',
            'title'
          );
        }
      }
    
      if (input.updates.text !== undefined) {
        if (typeof input.updates.text !== 'string') {
          throw new ValidationError(
            'text must be a string',
            'text'
          );
        }
      }
    
      // ============================================================================
      // Step 5: Build updates object with resolved references
      // ============================================================================
      const resolvedUpdates: { title?: string; text?: string; folder?: string } = {};
      const updatedFields: string[] = [];
    
      if (input.updates.title !== undefined) {
        resolvedUpdates.title = input.updates.title;
        updatedFields.push('title');
      }
    
      if (input.updates.text !== undefined) {
        resolvedUpdates.text = input.updates.text;
        updatedFields.push('text');
      }
    
      if (input.updates.folder !== undefined) {
        resolvedUpdates.folder = resolvedFolder;
        updatedFields.push('folder');
      }
    
      // ============================================================================
      // Step 6: Call DartClient.updateDoc()
      // ============================================================================
      const client = new DartClient({ token: DART_TOKEN });
    
      let updatedDoc;
      try {
        updatedDoc = await client.updateDoc({
          doc_id: input.doc_id,
          updates: resolvedUpdates,
        });
      } catch (error) {
        // Handle 404 errors specifically
        if (error instanceof DartAPIError && error.statusCode === 404) {
          throw new DartAPIError(
            `Document not found: No document with doc_id "${input.doc_id}" exists in workspace`,
            404,
            error.response
          );
        }
        // Re-throw other errors with enhanced context
        if (error instanceof DartAPIError) {
          throw new DartAPIError(
            `Failed to update document: ${error.message}`,
            error.statusCode,
            error.response
          );
        }
        throw error;
      }
    
      // ============================================================================
      // Step 7: Generate deep link URL and return output
      // ============================================================================
      const deepLinkUrl = `https://app.dartai.com/doc/${updatedDoc.doc_id}`;
    
      return {
        doc_id: updatedDoc.doc_id,
        updated_fields: updatedFields,
        doc: updatedDoc,
        url: deepLinkUrl,
      };
    }
  • Input type definition for update_doc tool: requires doc_id string and an updates object with optional title, text, and folder fields.
    export interface UpdateDocInput {
      doc_id: string;
      updates: {
        title?: string;
        text?: string;
        folder?: string;
      };
    }
  • Output type definition: returns doc_id, list of updated_fields, the full DartDoc object, and a deep link URL to the document.
    export interface UpdateDocOutput {
      doc_id: string;
      updated_fields: string[];
      doc: DartDoc;
      url: string;
    }
  • src/index.ts:730-759 (registration)
    Tool registration in the MCP server's tool list with name 'update_doc', description, and JSON Schema input definition.
    name: 'update_doc',
    description: 'Update an existing document (title, text, or folder). Validates references and only sends changed fields.',
    inputSchema: {
      type: 'object',
      properties: {
        doc_id: {
          type: 'string',
          description: 'Document doc_id to update',
        },
        updates: {
          type: 'object',
          description: 'Fields to update',
          properties: {
            title: {
              type: 'string',
              description: 'Document title',
            },
            text: {
              type: 'string',
              description: 'Document text (markdown supported)',
            },
            folder: {
              type: 'string',
              description: 'Folder dart_id or name',
            },
          },
        },
      },
      required: ['doc_id', 'updates'],
    },
  • src/index.ts:1148-1158 (registration)
    Case statement in the request handler that dispatches 'update_doc' calls to handleUpdateDoc and formats the output as JSON text.
    case 'update_doc': {
      const result = await handleUpdateDoc((args || {}) as any);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
Behavior3/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 adds behavioral context like 'validates references' and 'only sends changed fields', which is helpful but insufficient. It does not disclose error handling, permissions, or return behavior.

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 a single sentence with no wasted words, but could be structured more clearly (e.g., bullet points). It is concise yet efficient.

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 the tool has a nested parameter and no output schema, the description should explain return values or side effects. It does not. While the description covers essential update behavior, it lacks documentation of what the tool returns or error conditions.

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%, so the schema already defines all parameters. The description merely lists the fields again, adding no new meaning beyond what the schema provides. Baseline 3 is appropriate.

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 updates an existing document and specifies the fields (title, text, folder), distinguishing it from create_doc and delete_doc. The verb 'update' is specific and the resource 'existing document' is unambiguous.

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

Usage Guidelines4/5

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

The description implies usage for modifying an existing document, but does not explicitly mention when not to use it (e.g., if the document doesn't exist) nor alternatives like update_task. However, sibling tool names make resource differentiation clear.

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/standardbeagle/dart-query'

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