Skip to main content
Glama
scmdr

SourceSync.ai MCP Server

by scmdr

updateDocuments

Modify metadata for documents in SourceSync.ai by specifying filter criteria, enabling precise updates to document attributes and properties.

Instructions

Updates metadata for documents that match the specified filter criteria.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYes
documentsYes
filterConfigYes
namespaceIdNo
tenantIdNo

Implementation Reference

  • MCP tool registration and handler function for 'updateDocuments'. Processes parameters, constructs filterConfig with enum conversions, prepares update data including metadata merging from documents list, creates SourceSync client, and calls the underlying API client's updateDocuments method.
    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 input schema for the updateDocuments tool, defining parameters like namespaceId, list of documents with IDs and metadata, tenantId, filterConfig, and data with metadata update operations ($set, $append, $remove).
    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 method that performs the actual API call to PATCH /v1/documents, adding namespaceId to the request body and using the provided filterConfig and data.
    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>() }
  • FilterConfigSchema referenced in UpdateDocumentsSchema for specifying which documents to update based on various criteria.
    export const FilterConfigSchema = z.object({ documentIds: z.array(z.string()).optional(), documentExternalIds: z.array(z.string()).optional(), documentConnectionIds: z.array(z.string()).optional(), documentTypes: z .array( z.enum([ 'TEXT', 'URL', 'FILE', 'NOTION_DOCUMENT', 'GOOGLE_DRIVE_DOCUMENT', 'DROPBOX_DOCUMENT', 'ONEDRIVE_DOCUMENT', 'BOX_DOCUMENT', 'SHAREPOINT_DOCUMENT', ]), ) .optional(), documentIngestionSources: z .array( z.enum([ 'TEXT', 'URLS_LIST', 'SITEMAP', 'WEBSITE', 'LOCAL_FILE', 'NOTION', 'GOOGLE_DRIVE', 'DROPBOX', 'ONEDRIVE', 'BOX', 'SHAREPOINT', ]), ) .optional(), documentIngestionStatuses: z .array( z.enum([ 'BACKLOG', 'QUEUED', 'QUEUED_FOR_RESYNC', 'PROCESSING', 'SUCCESS', 'FAILED', 'CANCELLED', ]), ) .optional(), metadata: z.record(z.string()).optional(), }) export const FetchDocumentsSchema = z.object({ namespaceId: namespaceIdSchema.optional(), documentIds: z.array(z.string()).optional(), pagination: PaginationSchema.optional(), tenantId: tenantIdSchema, filterConfig: FilterConfigSchema, includeConfig: z .object({ documents: z.boolean().optional(), stats: z.boolean().optional(), statsBySource: z.boolean().optional(), statsByStatus: z.boolean().optional(), rawFileUrl: z.boolean().optional(), parsedTextFileUrl: z.boolean().optional(), }) .optional(), }) 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(), }), })

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