Skip to main content
Glama

updateDocuments

Modify metadata for documents matching specific criteria to maintain organized knowledge bases in SourceSync.ai.

Instructions

Updates metadata for documents that match the specified filter criteria.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceIdNo
documentsYes
tenantIdNo
filterConfigYes
dataYes

Implementation Reference

  • MCP tool handler for 'updateDocuments': processes input params, creates SourceSync client, handles document IDs and metadata merging, converts enums, and invokes the API client's updateDocuments method wrapped in safeApiCall.
    async (params: any) => {
      return safeApiCall(async () => {
        const { namespaceId, documents, tenantId, filterConfig, data } = params
    
        // Create a client with the provided parameters
        const client = createClient({ namespaceId, tenantId })
    
        // Extract document IDs and add to filter if not already present
        if (documents && documents.length > 0 && !filterConfig.documentIds) {
          filterConfig.documentIds = documents.map((doc: any) => doc.documentId)
        }
    
        // Prepare metadata for update
        const metadata: Record<string, any> = {}
    
        if (documents) {
          documents.forEach((doc: any) => {
            if (doc.metadata) {
              // Combine all document metadata
              Object.assign(metadata, doc.metadata)
            }
          })
        }
    
        // Prepare the data object
        if (Object.keys(metadata).length > 0) {
          data.metadata = metadata
        }
    
        // Call the updateDocuments method with properly structured parameters
        return await client.updateDocuments({
          filterConfig: {
            ...filterConfig,
            // Convert string enum values to their SourceSync enum equivalents
            documentTypes: filterConfig.documentTypes?.map(
              (type: string) =>
                SourceSyncDocumentType[
                  type as keyof typeof SourceSyncDocumentType
                ],
            ),
            documentIngestionSources: filterConfig.documentIngestionSources?.map(
              (source: string) =>
                SourceSyncIngestionSource[
                  source as keyof typeof SourceSyncIngestionSource
                ],
            ),
            documentIngestionStatuses:
              filterConfig.documentIngestionStatuses?.map(
                (status: string) =>
                  SourceSyncIngestionStatus[
                    status as keyof typeof SourceSyncIngestionStatus
                  ],
              ),
          },
          data: {
            metadata: data?.metadata || {},
            $metadata: data?.$metadata || {
              $set: {},
              $append: {},
              $remove: {},
            },
          },
        })
      })
    },
  • src/index.ts:407-476 (registration)
    MCP server registration of the 'updateDocuments' tool, specifying name, description, input schema, and handler function.
    server.tool(
      'updateDocuments',
      'Updates metadata for documents that match the specified filter criteria.',
      UpdateDocumentsSchema.shape,
      async (params: any) => {
        return safeApiCall(async () => {
          const { namespaceId, documents, tenantId, filterConfig, data } = params
    
          // Create a client with the provided parameters
          const client = createClient({ namespaceId, tenantId })
    
          // Extract document IDs and add to filter if not already present
          if (documents && documents.length > 0 && !filterConfig.documentIds) {
            filterConfig.documentIds = documents.map((doc: any) => doc.documentId)
          }
    
          // Prepare metadata for update
          const metadata: Record<string, any> = {}
    
          if (documents) {
            documents.forEach((doc: any) => {
              if (doc.metadata) {
                // Combine all document metadata
                Object.assign(metadata, doc.metadata)
              }
            })
          }
    
          // Prepare the data object
          if (Object.keys(metadata).length > 0) {
            data.metadata = metadata
          }
    
          // Call the updateDocuments method with properly structured parameters
          return await client.updateDocuments({
            filterConfig: {
              ...filterConfig,
              // Convert string enum values to their SourceSync enum equivalents
              documentTypes: filterConfig.documentTypes?.map(
                (type: string) =>
                  SourceSyncDocumentType[
                    type as keyof typeof SourceSyncDocumentType
                  ],
              ),
              documentIngestionSources: filterConfig.documentIngestionSources?.map(
                (source: string) =>
                  SourceSyncIngestionSource[
                    source as keyof typeof SourceSyncIngestionSource
                  ],
              ),
              documentIngestionStatuses:
                filterConfig.documentIngestionStatuses?.map(
                  (status: string) =>
                    SourceSyncIngestionStatus[
                      status as keyof typeof SourceSyncIngestionStatus
                    ],
                ),
            },
            data: {
              metadata: data?.metadata || {},
              $metadata: data?.$metadata || {
                $set: {},
                $append: {},
                $remove: {},
              },
            },
          })
        })
      },
    )
  • Zod schema defining the input structure for the updateDocuments tool, including namespace, documents list, tenant, filter config, and update data.
    export const UpdateDocumentsSchema = z.object({
      namespaceId: namespaceIdSchema.optional(),
      documents: z.array(
        z.object({
          documentId: z.string(),
          metadata: z.record(z.string()).optional(),
        }),
      ),
      tenantId: tenantIdSchema,
      filterConfig: FilterConfigSchema,
      data: z.object({
        metadata: z.record(z.string()).optional(),
        $metadata: z
          .object({
            $set: z.record(z.union([z.string(), z.array(z.string())])).optional(),
            $append: z.record(z.array(z.string())).optional(),
            $remove: z.record(z.array(z.string())).optional(),
          })
          .optional(),
      }),
    })
  • SourceSyncApiClient's updateDocuments method: sends PATCH request to /v1/documents endpoint with filterConfig and data to update matching documents.
    public async updateDocuments({
      filterConfig,
      data,
    }: Omit<
      SourceSyncUpdateDocumentsRequest,
      'namespaceId'
    >): Promise<SourceSyncUpdateDocumentsResponse> {
      return this.client
        .url(`/v1/documents`)
        .json({
          namespaceId: this.namespaceId,
          filterConfig,
          data,
        } satisfies SourceSyncUpdateDocumentsRequest)
        .patch()
        .json<SourceSyncUpdateDocumentsResponse>()
    }
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 states this is an update operation, implying mutation, but doesn't clarify permissions required, whether changes are reversible, rate limits, or what happens to unmatched documents. For a mutation tool with zero annotation coverage, this is a significant gap in transparency, leaving the agent uncertain about side effects or constraints.

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, efficient sentence that front-loads the core action ('Updates metadata for documents'). There's no wasted verbiage or redundancy. However, it could be more structured by briefly hinting at key parameters or usage scenarios, but as-is, it's appropriately concise for its limited content.

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 with nested objects, 0% schema coverage, no output schema, and no annotations), the description is inadequate. It doesn't explain the update semantics (e.g., partial vs. full updates), error handling, or return values. For a mutation tool with rich input schema but poor documentation, this leaves critical gaps in understanding how to invoke it successfully.

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?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'filter criteria' and 'metadata,' which loosely map to 'filterConfig' and 'data' parameters, but doesn't explain the purpose of 'namespaceId,' 'tenantId,' or the complex nested structures in 'data' (e.g., '$metadata' with '$set,' '$append,' '$remove'). This adds minimal value beyond the schema, failing to clarify parameter roles or usage.

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

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Updates metadata for documents that match the specified filter criteria,' which provides a clear verb ('Updates') and resource ('metadata for documents'). However, it doesn't differentiate this tool from siblings like 'updateConnection' or 'updateNamespace,' nor does it specify what kind of metadata updates are possible (e.g., adding, removing, or modifying). The purpose is clear but lacks sibling distinction and specificity about the update operation.

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 offers no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing existing documents), exclusions (e.g., not for creating or deleting documents), or comparisons to siblings like 'deleteDocuments' or 'resyncDocuments.' Without such context, an agent might struggle to select this tool appropriately in a workflow.

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/sitegpt/sourcesyncai-mcp'

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