Skip to main content
Glama
scmdr

SourceSync.ai MCP Server

by scmdr

fetchDocuments

Retrieve documents from a namespace using filters for document types, sources, statuses, and metadata, with pagination and property selection options.

Instructions

Fetches documents from the namespace based on filter criteria. Supports pagination and including specific document properties.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceIdNo
documentIdsNo
paginationNo
tenantIdNo
filterConfigYes
includeConfigNo

Implementation Reference

  • src/index.ts:352-405 (registration)
    Registration of the 'fetchDocuments' MCP tool. Includes inline handler that processes input parameters, creates a SourceSync client, handles document ID filtering, converts string enums to proper enum values, and calls client.getDocuments() with pagination and include options.
    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 },
          })
        })
      },
    )
  • Zod schema definition for the fetchDocuments tool input parameters, including optional namespaceId, documentIds, pagination, required tenantId and filterConfig, and optional 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(),
    })
  • Helper function used by the fetchDocuments handler to instantiate the SourceSync client with provided or env-based credentials.
    function createClient({
      apiKey,
      namespaceId,
      tenantId,
    }: {
      apiKey?: string
      namespaceId?: string
      tenantId?: string
    }) {
      return sourcesync({
        apiKey: apiKey || process.env.SOURCESYNC_API_KEY || '',
        namespaceId: namespaceId || process.env.SOURCESYNC_NAMESPACE_ID || '',
        tenantId: tenantId || process.env.SOURCESYNC_TENANT_ID || '',
      })
    }
  • Helper function used by the fetchDocuments handler to wrap API calls, formatting successful results as MCP content and errors appropriately.
    async function safeApiCall<T>(apiCall: () => Promise<T>) {
      try {
        const result = await apiCall()
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(result),
            },
          ],
        }
      } catch (error: any) {
        // Preserve the original error structure from SourceSync
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(error),
            },
          ],
          isError: true,
        }
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions pagination and including specific properties, which is helpful, but fails to address critical aspects such as whether this is a read-only operation, potential rate limits, authentication requirements, error conditions, or what happens with large result sets. For a tool with 6 parameters and complex filtering, this is a significant gap in behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that covers the core functionality without unnecessary words. It's appropriately sized for the tool's complexity, though it could be more structured (e.g., separating key features). Every phrase earns its place by mentioning fetching, filtering, pagination, and property inclusion.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters with nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain the return format, error handling, or how parameters interact (e.g., 'namespaceId' vs. 'filterConfig'). For a data retrieval tool with rich filtering options, more context is needed to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning none of the 6 parameters are documented in the schema. The description only vaguely mentions 'filter criteria', 'pagination', and 'including specific document properties', which maps loosely to some parameters but doesn't explain their purpose, relationships (e.g., how 'documentIds' in the root differs from in 'filterConfig'), or usage. It adds minimal value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('fetches documents') and resource ('from the namespace'), and mentions filtering capabilities. However, it doesn't specifically differentiate this tool from sibling tools like 'semanticSearch' or 'hybridSearch' that might also retrieve documents, nor does it explain how it differs from 'listNamespaces' which might be related. The purpose is clear but lacks sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'semanticSearch', 'hybridSearch', or 'listNamespaces'. It mentions filtering and pagination but doesn't specify use cases, prerequisites, or exclusions. This leaves the agent with insufficient context to choose appropriately among sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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