Skip to main content
Glama
paulsham

Wiki Analytics Specification MCP Server

by paulsham

validate_event_payload

Check analytics event payloads against specifications to identify errors, warnings, and valid fields for proper tracking implementation.

Instructions

Validate a tracking implementation payload against the event spec. Returns errors, warnings, and valid fields.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
event_nameYesName of the event to validate against
payloadYesThe payload object to validate

Implementation Reference

  • The main handler function for the 'validate_event_payload' tool. It retrieves the event spec, expands properties, validates provided payload fields against expected types and constraints, identifies unknown/missing fields, and returns validation results including errors, warnings, and valid fields.
    handler: async (args) => {
      const event = eventsMap.get(args.event_name);
      if (!event) {
        throw new NotFoundError('Event', args.event_name);
      }
    
      const expanded = getExpandedProperties(event);
      const errors = [];
      const warnings = [];
      const validFields = [];
    
      // Collect all expected properties
      const expectedProps = new Map();
      for (const group of expanded.property_groups) {
        for (const prop of group.properties) {
          expectedProps.set(prop.name, prop);
        }
      }
      for (const prop of expanded.additional_properties) {
        expectedProps.set(prop.name, prop);
      }
    
      // Check provided fields
      for (const [key, value] of Object.entries(args.payload)) {
        const prop = expectedProps.get(key);
        if (!prop) {
          warnings.push({ field: key, issue: 'Unknown property not in spec' });
          continue;
        }
    
        // Remove from expected (field was provided, even if invalid)
        expectedProps.delete(key);
    
        // Type validation
        const actualType = Array.isArray(value) ? 'array' : typeof value;
        const expectedType = prop.type === 'timestamp' ? 'string' : prop.type;
    
        if (expectedType !== actualType && expectedType !== 'unknown') {
          errors.push({
            field: key,
            issue: 'Type mismatch',
            expected: prop.type,
            got: actualType
          });
          continue;
        }
    
        // Constraint validation
        if (prop.constraints && prop.constraints !== '-') {
          if (prop.constraints.startsWith('enum:')) {
            const allowedValues = prop.constraints.substring(5).split(',').map(s => s.trim());
            if (!allowedValues.includes(value)) {
              errors.push({
                field: key,
                issue: 'Invalid enum value',
                expected: allowedValues,
                got: value
              });
              continue;
            }
          } else if (prop.constraints.startsWith('regex:')) {
            const pattern = prop.constraints.substring(6).trim();
            try {
              const regex = new RegExp(pattern);
              if (!regex.test(value)) {
                errors.push({
                  field: key,
                  issue: 'Regex validation failed',
                  expected: pattern,
                  got: value
                });
                continue;
              }
            } catch (e) {
              // Invalid regex pattern in spec
            }
          }
        }
    
        validFields.push(key);
      }
    
      // Check for missing properties
      for (const [name] of expectedProps) {
        warnings.push({ field: name, issue: 'Missing property' });
      }
    
      return {
        valid: errors.length === 0,
        errors,
        warnings,
        valid_fields: validFields
      };
    }
  • The input schema defining the expected arguments: event_name (string) and payload (object).
    inputSchema: {
      type: 'object',
      properties: {
        event_name: {
          type: 'string',
          description: 'Name of the event to validate against'
        },
        payload: {
          type: 'object',
          description: 'The payload object to validate'
        }
      },
      required: ['event_name', 'payload']
    },
  • The tool object definition for 'validate_event_payload' within the exported 'tools' object, which is used by the MCP server to register and dispatch tool calls.
    validate_event_payload: {
      description: 'Validate a tracking implementation payload against the event spec. Returns errors, warnings, and valid fields.',
      inputSchema: {
        type: 'object',
        properties: {
          event_name: {
            type: 'string',
            description: 'Name of the event to validate against'
          },
          payload: {
            type: 'object',
            description: 'The payload object to validate'
          }
        },
        required: ['event_name', 'payload']
      },
      handler: async (args) => {
        const event = eventsMap.get(args.event_name);
        if (!event) {
          throw new NotFoundError('Event', args.event_name);
        }
    
        const expanded = getExpandedProperties(event);
        const errors = [];
        const warnings = [];
        const validFields = [];
    
        // Collect all expected properties
        const expectedProps = new Map();
        for (const group of expanded.property_groups) {
          for (const prop of group.properties) {
            expectedProps.set(prop.name, prop);
          }
        }
        for (const prop of expanded.additional_properties) {
          expectedProps.set(prop.name, prop);
        }
    
        // Check provided fields
        for (const [key, value] of Object.entries(args.payload)) {
          const prop = expectedProps.get(key);
          if (!prop) {
            warnings.push({ field: key, issue: 'Unknown property not in spec' });
            continue;
          }
    
          // Remove from expected (field was provided, even if invalid)
          expectedProps.delete(key);
    
          // Type validation
          const actualType = Array.isArray(value) ? 'array' : typeof value;
          const expectedType = prop.type === 'timestamp' ? 'string' : prop.type;
    
          if (expectedType !== actualType && expectedType !== 'unknown') {
            errors.push({
              field: key,
              issue: 'Type mismatch',
              expected: prop.type,
              got: actualType
            });
            continue;
          }
    
          // Constraint validation
          if (prop.constraints && prop.constraints !== '-') {
            if (prop.constraints.startsWith('enum:')) {
              const allowedValues = prop.constraints.substring(5).split(',').map(s => s.trim());
              if (!allowedValues.includes(value)) {
                errors.push({
                  field: key,
                  issue: 'Invalid enum value',
                  expected: allowedValues,
                  got: value
                });
                continue;
              }
            } else if (prop.constraints.startsWith('regex:')) {
              const pattern = prop.constraints.substring(6).trim();
              try {
                const regex = new RegExp(pattern);
                if (!regex.test(value)) {
                  errors.push({
                    field: key,
                    issue: 'Regex validation failed',
                    expected: pattern,
                    got: value
                  });
                  continue;
                }
              } catch (e) {
                // Invalid regex pattern in spec
              }
            }
          }
    
          validFields.push(key);
        }
    
        // Check for missing properties
        for (const [name] of expectedProps) {
          warnings.push({ field: name, issue: 'Missing property' });
        }
    
        return {
          valid: errors.length === 0,
          errors,
          warnings,
          valid_fields: validFields
        };
      }
    },
  • The generic MCP CallToolRequestSchema handler that dispatches to the specific tool handler based on name, effectively registering all tools from the imported 'tools' object including 'validate_event_payload'.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
      const tool = tools[name];
    
      if (!tool) {
        throw new Error(`Unknown tool: ${name}`);
      }
    
      const result = await tool.handler(args || {});
    
      // Prepend outdated warning if present
      let responseText = JSON.stringify(result, null, 2);
      if (outdatedWarning) {
        responseText = `⚠️  Warning: ${outdatedWarning}\n\n${responseText}`;
      }
    
      return {
        content: [
          {
            type: 'text',
            text: responseText
          }
        ]
      };
    });
Behavior3/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 validates a payload and returns errors, warnings, and valid fields, which covers the basic operation and output. However, it lacks details on error handling, validation rules, performance implications, or any side effects, leaving gaps in transparency for a validation tool.

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 concise and front-loaded, consisting of a single sentence that directly states the tool's function and output. There is no wasted text, but it could be slightly improved by structuring usage hints or examples without sacrificing brevity.

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

Completeness3/5

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

Given the tool's complexity (validation with two parameters, no output schema, and no annotations), the description is minimally adequate. It explains what the tool does and its output, but lacks details on error types, validation scope, or integration with sibling tools. Without an output schema, more information on return values would be beneficial, but it meets the basic threshold.

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 ('event_name' and 'payload'). The description adds no additional semantic details beyond what the schema provides, such as format examples or validation criteria. According to the rules, with high schema coverage, the baseline is 3, which is appropriate here.

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: 'Validate a tracking implementation payload against the event spec.' It specifies the verb (validate) and resource (payload against event spec), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'get_event_implementation' or 'search_events', which might also involve event-related operations, so it doesn't reach the highest score.

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, context, or exclusions, nor does it reference sibling tools like 'get_event_implementation' or 'search_events' for comparison. This leaves the agent without clear usage instructions.

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/paulsham/wiki-mcp-analytics-test-1.1.0'

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