Skip to main content
Glama

mcp_get_documents

Retrieve documents from a CosmosDB container using optional filters, partition keys, and limit settings. Streamline data queries for efficient analysis and extraction.

Instructions

Get documents from a container with optional filters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idYesThe ID of the container to query
filter_conditionsNoOptional filter conditions as key-value pairs
limitNoMaximum number of documents to return
partition_keyNoOptional partition key to filter by

Implementation Reference

  • The core handler function implementing the mcp_get_documents tool. It queries a CosmosDB container for documents using optional filters, partition key, and limit.
    export const mcp_get_documents = async (args: { container_id: string; limit?: number; partition_key?: string; filter_conditions?: Record<string, any>; }): Promise<ToolResult<DocumentInfo[]>> => { const { container_id, limit = 100, partition_key, filter_conditions } = args; console.log('Executing mcp_get_documents with:', args); try { const container = getContainer(container_id); // Build query let query = `SELECT * FROM c`; const parameters: Array<{ name: string; value: any }> = []; // Add filter conditions if (filter_conditions && Object.keys(filter_conditions).length > 0) { const whereClauses = Object.entries(filter_conditions).map(([key, value], index) => { const paramName = `@param${index}`; parameters.push({ name: paramName, value }); return `c.${key} = ${paramName}`; }); query += ` WHERE ${whereClauses.join(' AND ')}`; } // Add limit query = `SELECT TOP ${limit} * FROM (${query})`; const querySpec = { query, parameters }; // Query options const options: any = { maxItemCount: limit }; if (partition_key) { options.partitionKey = partition_key; } const { resources: documents } = await container.items.query(querySpec, options).fetchAll(); return { success: true, data: documents }; } catch (error: any) { console.error(`Error in mcp_get_documents for container ${container_id}: ${error.message}`); return { success: false, error: error.message }; } };
  • The input schema definition for the mcp_get_documents tool, defining parameters like container_id, limit, partition_key, and filter_conditions.
    { name: "mcp_get_documents", description: "Get documents from a container with optional filters", inputSchema: { type: "object", properties: { container_id: { type: "string", description: "The ID of the container to query" }, limit: { type: "number", description: "Maximum number of documents to return", default: 100 }, partition_key: { type: "string", description: "Optional partition key to filter by" }, filter_conditions: { type: "object", description: "Optional filter conditions as key-value pairs" } }, required: ["container_id"] } },
  • src/server.ts:106-107 (registration)
    Registration in the server dispatch switch statement, mapping the tool name to its handler execution.
    case 'mcp_get_documents': result = await toolHandlers.mcp_get_documents(input as any);
  • Re-export of the mcp_get_documents handler from dataOperations.js, making it available for import in mcp-server.ts.
    export { mcp_execute_query, mcp_get_documents, mcp_get_document_by_id, mcp_analyze_schema } from './dataOperations.js';
  • src/mcp-server.ts:2-2 (registration)
    Re-export of all tools from tools/index.js, used by server.ts as toolHandlers.
    export * from './tools/index.js';

Other Tools

Related 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/hendrickcastro/MCPCosmosDB'

If you have feedback or need assistance with the MCP directory API, please join our Discord server