deleteDocuments
Remove documents from knowledge bases using filter criteria like document type, source, or status to manage content organization.
Instructions
Permanently deletes documents that match the specified filter criteria.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespaceId | No | ||
| documentIds | No | ||
| tenantId | No | ||
| filterConfig | Yes |
Implementation Reference
- src/index.ts:479-521 (handler)MCP tool handler for 'deleteDocuments': creates SourceSync client, prepares filterConfig with enum conversions, and calls client.deleteDocuments to delete matching documents.'deleteDocuments', 'Permanently deletes documents that match the specified filter criteria.', DeleteDocumentsSchema.shape, async (params: any) => { return safeApiCall(async () => { const { namespaceId, documentIds, tenantId, filterConfig } = params // Create a client with the provided parameters const client = createClient({ namespaceId, tenantId }) // Add documentIds to filter if provided and not already in filter if (documentIds && documentIds.length > 0 && !filterConfig.documentIds) { filterConfig.documentIds = documentIds } // Call the deleteDocuments method with properly structured parameters return await client.deleteDocuments({ 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 ], ), }, }) }) },
- src/schemas.ts:406-411 (schema)Zod schema defining input parameters for the deleteDocuments tool, including optional namespaceId, documentIds, tenantId, and filterConfig.export const DeleteDocumentsSchema = z.object({ namespaceId: namespaceIdSchema.optional(), documentIds: z.array(z.string()).optional(), tenantId: tenantIdSchema, filterConfig: FilterConfigSchema, })
- src/index.ts:478-522 (registration)Registration of the 'deleteDocuments' MCP tool with name, description, input schema, and inline handler function.server.tool( 'deleteDocuments', 'Permanently deletes documents that match the specified filter criteria.', DeleteDocumentsSchema.shape, async (params: any) => { return safeApiCall(async () => { const { namespaceId, documentIds, tenantId, filterConfig } = params // Create a client with the provided parameters const client = createClient({ namespaceId, tenantId }) // Add documentIds to filter if provided and not already in filter if (documentIds && documentIds.length > 0 && !filterConfig.documentIds) { filterConfig.documentIds = documentIds } // Call the deleteDocuments method with properly structured parameters return await client.deleteDocuments({ 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 ], ), }, }) }) }, )
- src/sourcesync.ts:524-538 (helper)SourceSyncApiClient helper method that sends DELETE request to /v1/documents endpoint with namespaceId and filterConfig to delete matching documents.public async deleteDocuments({ filterConfig, }: Omit< SourceSyncDeleteDocumentsRequest, 'namespaceId' >): Promise<SourceSyncDeleteDocumentsResponse> { return this.client .url(`/v1/documents`) .json({ namespaceId: this.namespaceId, filterConfig, } satisfies SourceSyncDeleteDocumentsRequest) .delete() .json<SourceSyncDeleteDocumentsResponse>() }