Skip to main content
Glama
scmdr

SourceSync.ai MCP Server

by scmdr

updateDocuments

Updates metadata for documents matching specified filter criteria to maintain accurate and organized document information in the knowledge management platform.

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 implementation for 'updateDocuments'. Processes parameters, creates SourceSync client, prepares filter and data, and calls client.updateDocuments wrapped in safeApiCall.
    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: {},
              },
            },
          })
        })
      },
  • src/index.ts:407-476 (registration)
    Registration of the 'updateDocuments' tool using McpServer.tool() with 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 parameters for the updateDocuments tool.
    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.updateDocuments method that makes the PATCH /v1/documents API call to update 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>()
    }
  • TypeScript type definitions for SourceSyncUpdateDocumentsRequest and SourceSyncUpdateDocumentsResponse.
    export type SourceSyncUpdateDocumentsRequest = {
      namespaceId: string
      filterConfig: SourceSyncDocumentFilterConfig
      data: {
        metadata: Record<string, string>
        $metadata: {
          $set?: Record<string, string | string[]>
          $append?: Record<string, string[]>
          $remove?: Record<string, string[]>
        }
      }
    }
    
    export type SourceSyncUpdateDocumentsResponse = SourceSyncApiResponse<{
      itemsUpdated: number
      documents: SourceSyncDocument[]
    }>
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 the tool updates metadata but doesn't explain critical behaviors: whether this is a destructive operation (e.g., overwrites or merges metadata), what permissions are required, how errors are handled, or the response format. For a mutation tool with complex parameters, this lack of transparency is a significant gap.

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, making it easy to parse quickly. However, it could be more structured by explicitly mentioning key parameters or outcomes, but it earns high marks for brevity.

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 complexity (5 parameters with nested objects, no annotations, no output schema, and 0% schema coverage), the description is inadequate. It doesn't explain the update mechanism (e.g., partial vs. full updates), error conditions, or what happens to unmatched documents. For a tool that modifies data based on filters, more context is needed to ensure correct usage.

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%, meaning none of the 5 parameters are documented in the schema. The description only vaguely references 'specified filter criteria' and 'metadata,' without explaining what parameters like 'namespaceId,' 'tenantId,' or the nested 'data' and 'filterConfig' objects do. It fails to compensate for the schema's lack of descriptions, leaving key semantics unclear.

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 distinguish this tool from sibling tools like 'updateConnection' or 'updateNamespace,' nor does it clarify what 'metadata' entails beyond the schema. The purpose is understandable but lacks specificity about the scope of updates compared to alternatives.

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, such as needing existing documents or connections, or compare it to sibling tools like 'resyncDocuments' or 'deleteDocuments.' Without explicit when-to-use or when-not-to-use instructions, the agent must infer usage from the name and schema alone.

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

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