fetchDocuments
Retrieve documents from a specified namespace using filter criteria, including document types, sources, and statuses. Supports pagination and optional property inclusion for efficient document management and organization.
Instructions
Fetches documents from the namespace based on filter criteria. Supports pagination and including specific document properties.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documentIds | No | ||
| filterConfig | Yes | ||
| includeConfig | No | ||
| namespaceId | No | ||
| pagination | No | ||
| tenantId | No |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"documentIds": {
"items": {
"type": "string"
},
"type": "array"
},
"filterConfig": {
"additionalProperties": false,
"properties": {
"documentConnectionIds": {
"items": {
"type": "string"
},
"type": "array"
},
"documentExternalIds": {
"items": {
"type": "string"
},
"type": "array"
},
"documentIds": {
"items": {
"type": "string"
},
"type": "array"
},
"documentIngestionSources": {
"items": {
"enum": [
"TEXT",
"URLS_LIST",
"SITEMAP",
"WEBSITE",
"LOCAL_FILE",
"NOTION",
"GOOGLE_DRIVE",
"DROPBOX",
"ONEDRIVE",
"BOX",
"SHAREPOINT"
],
"type": "string"
},
"type": "array"
},
"documentIngestionStatuses": {
"items": {
"enum": [
"BACKLOG",
"QUEUED",
"QUEUED_FOR_RESYNC",
"PROCESSING",
"SUCCESS",
"FAILED",
"CANCELLED"
],
"type": "string"
},
"type": "array"
},
"documentTypes": {
"items": {
"enum": [
"TEXT",
"URL",
"FILE",
"NOTION_DOCUMENT",
"GOOGLE_DRIVE_DOCUMENT",
"DROPBOX_DOCUMENT",
"ONEDRIVE_DOCUMENT",
"BOX_DOCUMENT",
"SHAREPOINT_DOCUMENT"
],
"type": "string"
},
"type": "array"
},
"metadata": {
"additionalProperties": {
"type": "string"
},
"type": "object"
}
},
"type": "object"
},
"includeConfig": {
"additionalProperties": false,
"properties": {
"documents": {
"type": "boolean"
},
"parsedTextFileUrl": {
"type": "boolean"
},
"rawFileUrl": {
"type": "boolean"
},
"stats": {
"type": "boolean"
},
"statsBySource": {
"type": "boolean"
},
"statsByStatus": {
"type": "boolean"
}
},
"type": "object"
},
"namespaceId": {
"type": "string"
},
"pagination": {
"additionalProperties": false,
"properties": {
"cursor": {
"type": "string"
},
"pageSize": {
"type": "number"
}
},
"type": "object"
},
"tenantId": {
"type": "string"
}
},
"required": [
"filterConfig"
],
"type": "object"
}
Implementation Reference
- src/index.ts:352-406 (handler)Handler implementation for the 'fetchDocuments' tool. It creates a SourceSync client and calls getDocuments with processed filterConfig, pagination, and includeConfig.server.tool( 'fetchDocuments', 'Fetches documents from the namespace based on filter criteria. Supports pagination and including specific document properties.', FetchDocumentsSchema.shape, async (params) => { return safeApiCall(async () => { const { namespaceId, tenantId, documentIds, pagination, filterConfig, includeConfig, } = params // Create a client with the provided parameters const client = createClient({ namespaceId, tenantId }) // Add documentIds to filterConfig if provided if (documentIds && documentIds.length > 0 && !filterConfig.documentIds) { filterConfig.documentIds = documentIds } // Call the getDocuments method with properly structured parameters return await client.getDocuments({ 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 ], ), }, pagination, includeConfig: includeConfig || { documents: true }, }) }) }, )
- src/schemas.ts:366-382 (schema)Zod schema defining the input parameters for the fetchDocuments tool, including namespaceId, documentIds, pagination, filterConfig, and includeConfig.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(), })
- src/index.ts:352-406 (registration)Registration of the 'fetchDocuments' tool using server.tool, associating the name, description, schema, and handler function.server.tool( 'fetchDocuments', 'Fetches documents from the namespace based on filter criteria. Supports pagination and including specific document properties.', FetchDocumentsSchema.shape, async (params) => { return safeApiCall(async () => { const { namespaceId, tenantId, documentIds, pagination, filterConfig, includeConfig, } = params // Create a client with the provided parameters const client = createClient({ namespaceId, tenantId }) // Add documentIds to filterConfig if provided if (documentIds && documentIds.length > 0 && !filterConfig.documentIds) { filterConfig.documentIds = documentIds } // Call the getDocuments method with properly structured parameters return await client.getDocuments({ 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 ], ), }, pagination, includeConfig: includeConfig || { documents: true }, }) }) }, )