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[] }>

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