Skip to main content
Glama
hendrickcastro

MCP CosmosDB

mcp_analyze_schema

Analyze document schemas in Azure CosmosDB containers to understand data structure and types by sampling documents.

Instructions

Analyze the schema of documents in a container to understand data structure and types

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
container_idYesThe ID of the container to analyze
sample_sizeNoNumber of documents to sample for analysis

Implementation Reference

  • Main handler function implementing the schema analysis logic by sampling documents, analyzing properties recursively, and computing statistics.
    export const mcp_analyze_schema = async (args: { 
      container_id: string; 
      sample_size?: number; 
    }): Promise<ToolResult<SchemaAnalysis>> => {
      const { container_id, sample_size = 1000 } = args;
      console.log('Executing mcp_analyze_schema with:', args);
    
      try {
        const container = getContainer(container_id);
    
        // Get sample documents
        const query = `SELECT TOP ${sample_size} * FROM c`;
        const { resources: documents } = await container.items.query(query).fetchAll();
    
        if (documents.length === 0) {
          return { success: true, data: { sampleSize: 0, commonProperties: [], dataTypes: {}, nestedStructures: [] } };
        }
    
        // Analyze properties
        const propertyStats: Record<string, { count: number; types: Set<string>; nullCount: number; examples: any[] }> = {};
        const dataTypeCounts: Record<string, number> = {};
    
        documents.forEach(doc => {
          analyzeObject(doc, '', propertyStats, dataTypeCounts);
        });
    
        // Convert to results
        const commonProperties: PropertyAnalysis[] = Object.entries(propertyStats)
          .map(([name, stats]) => ({
            name,
            type: Array.from(stats.types).join(' | '),
            frequency: stats.count / documents.length,
            nullCount: stats.nullCount,
            examples: stats.examples.slice(0, 5)
          }))
          .sort((a, b) => b.frequency - a.frequency)
          .slice(0, 50); // Top 50 properties
    
        const schemaAnalysis: SchemaAnalysis = {
          sampleSize: documents.length,
          commonProperties,
          dataTypes: dataTypeCounts,
          nestedStructures: [] // Could be implemented for deeper analysis
        };
    
        return { success: true, data: schemaAnalysis };
      } catch (error: any) {
        console.error(`Error in mcp_analyze_schema for container ${container_id}: ${error.message}`);
        return { success: false, error: error.message };
      }
    };
  • Input JSON schema definition for the mcp_analyze_schema tool, defining parameters container_id (required) and sample_size (optional).
    {
      name: "mcp_analyze_schema",
      description: "Analyze the schema of documents in a container to understand data structure and types",
      inputSchema: {
        type: "object",
        properties: {
          container_id: {
            type: "string",
            description: "The ID of the container to analyze"
          },
          sample_size: {
            type: "number",
            description: "Number of documents to sample for analysis",
            default: 100
          }
        },
        required: ["container_id"]
      }
    }
  • Re-export of the mcp_analyze_schema handler from dataOperations.js, making it available for import as toolHandlers.
    export {
      mcp_execute_query,
      mcp_get_documents,
      mcp_get_document_by_id,
      mcp_analyze_schema
    } from './dataOperations.js';
  • src/server.ts:112-113 (registration)
    Dispatch case in server request handler that calls the mcp_analyze_schema tool handler.
    case 'mcp_analyze_schema':
        result = await toolHandlers.mcp_analyze_schema(input as any);
  • Recursive helper function to analyze object properties, track types, frequencies, and examples across sampled documents.
    function analyzeObject(obj: any, prefix: string, propertyStats: Record<string, any>, dataTypeCounts: Record<string, number>, maxDepth = 3): void {
      if (maxDepth <= 0 || obj === null || obj === undefined) return;
    
      Object.entries(obj).forEach(([key, value]) => {
        const propName = prefix ? `${prefix}.${key}` : key;
        const valueType = getValueType(value);
    
        // Update data type counts
        dataTypeCounts[valueType] = (dataTypeCounts[valueType] || 0) + 1;
    
        // Update property stats
        if (!propertyStats[propName]) {
          propertyStats[propName] = { count: 0, types: new Set(), nullCount: 0, examples: [] };
        }
    
        propertyStats[propName].count++;
        propertyStats[propName].types.add(valueType);
    
        if (value === null || value === undefined) {
          propertyStats[propName].nullCount++;
        } else if (propertyStats[propName].examples.length < 5) {
          propertyStats[propName].examples.push(value);
        }
    
        // Recurse for objects
        if (valueType === 'object' && value !== null) {
          analyzeObject(value, propName, propertyStats, dataTypeCounts, maxDepth - 1);
        }
      });
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool analyzes schema but doesn't describe key behaviors: whether it's read-only or mutates data, what the output format looks like (e.g., summary statistics, type mappings), if it has rate limits, or if it requires specific permissions. For a tool with no annotations, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action and resource, making it easy to parse. Every part of the sentence contributes to understanding the tool's function.

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 complexity of schema analysis, lack of annotations, and no output schema, the description is incomplete. It doesn't explain what the analysis entails (e.g., inferring types, detecting patterns), the format of results, or any limitations (e.g., sampling bias). For a tool that likely returns structured insights, this leaves critical gaps for an agent.

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

Parameters3/5

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

The input schema has 100% description coverage, with clear documentation for both parameters (container_id and sample_size). The description adds no additional parameter semantics beyond what the schema provides, such as explaining how sampling affects accuracy or what constitutes a valid container_id. With high schema coverage, the baseline score of 3 is appropriate.

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 tool's purpose: 'Analyze the schema of documents in a container to understand data structure and types.' It specifies the verb ('analyze'), resource ('schema of documents in a container'), and outcome ('understand data structure and types'). However, it doesn't explicitly differentiate from siblings like mcp_container_stats or mcp_execute_query, which might also provide structural insights.

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. It doesn't mention prerequisites, such as needing an existing container, or compare it to siblings like mcp_container_info or mcp_execute_query for similar tasks. This leaves the agent without context for tool selection.

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

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