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
| Name | Required | Description | Default |
|---|---|---|---|
| namespaceId | No | ||
| documents | Yes | ||
| tenantId | No | ||
| filterConfig | Yes | ||
| data | Yes |
Implementation Reference
- src/index.ts:407-475 (handler)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: {}, }, }, }) }) }, )
- src/schemas.ts:384-404 (schema)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(), }), })
- src/sourcesync.ts:503-519 (helper)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>() }
- src/sourcesync.types.ts:621-638 (schema)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[] }>