Skip to main content
Glama

Validate AsyncAPI Spec

validate_asyncapi_spec

Validate raw AsyncAPI documents in YAML or JSON format to detect specification errors.

Instructions

Validate raw AsyncAPI YAML or JSON content and return validation errors if the spec is invalid.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
specYesRaw AsyncAPI document content as YAML or JSON.

Implementation Reference

  • The main handler function that validates an AsyncAPI spec string using @asyncapi/parser and returns validation errors, warnings, and counts.
    export const validateAsyncApiSpec = async (spec: string): Promise<AsyncApiValidationResult> => {
        const diagnostics = await parser.validate(spec);
        const issues = diagnostics.map(diagnosticToIssue);
        const errors = issues.filter(issue => issue.severity === 'error');
        const warnings = issues.filter(issue => issue.severity === 'warning' || issue.severity === 'info' || issue.severity === 'hint');
    
        return {
            valid: errors.length === 0,
            errorCount: errors.length,
            warningCount: warnings.length,
            errors,
            warnings,
        };
    };
  • Type definition for a single validation issue (message, path, code, severity, line, character).
    export type AsyncApiValidationIssue = {
        message: string;
        path?: string;
        code?: string | number;
        severity: 'error' | 'warning' | 'info' | 'hint' | 'unknown';
        line?: number;
        character?: number;
    };
  • Type definition for the validation result (valid, errorCount, warningCount, errors, warnings).
    export type AsyncApiValidationResult = {
        valid: boolean;
        errorCount: number;
        warningCount: number;
        errors: AsyncApiValidationIssue[];
        warnings: AsyncApiValidationIssue[];
    };
  • src/tools.ts:118-142 (registration)
    Tool registration at the MCP server level – connects the tool name 'validate_asyncapi_spec' to its input schema and handler callback.
    mcpServer.registerTool(
        'validate_asyncapi_spec',
        {
            title: 'Validate AsyncAPI Spec',
            description: 'Validate raw AsyncAPI YAML or JSON content and return validation errors if the spec is invalid.',
            inputSchema: z.object({
                spec: z.string().min(1).describe('Raw AsyncAPI document content as YAML or JSON.'),
            }),
        },
        async ({ spec }) => {
            try {
                const validation = await validateAsyncApiSpec(spec);
    
                return {
                    content: [{ type: 'text', text: JSON.stringify(validation, null, 2) }],
                    structuredContent: validation,
                };
            } catch (error) {
                return {
                    isError: true,
                    content: [{ type: 'text', text: formatUnknownError(error) }],
                };
            }
        }
    );
  • Helper functions: severityLabel maps DiagnosticSeverity to a label string, pathToString converts diagnostic path to dot-notation, diagnosticToIssue transforms a Diagnostic into an AsyncApiValidationIssue.
    const severityLabel = (severity: Diagnostic['severity']): AsyncApiValidationIssue['severity'] => {
        switch (severity) {
            case DiagnosticSeverity.Error:
                return 'error';
            case DiagnosticSeverity.Warning:
                return 'warning';
            case DiagnosticSeverity.Information:
                return 'info';
            case DiagnosticSeverity.Hint:
                return 'hint';
            default:
                return 'unknown';
        }
    };
    
    const pathToString = (path: Diagnostic['path']): string | undefined => {
        if (!Array.isArray(path) || path.length === 0) {
            return undefined;
        }
    
        return path.map(segment => String(segment)).join('.');
    };
    
    const diagnosticToIssue = (diagnostic: Diagnostic): AsyncApiValidationIssue => {
        const start = diagnostic.range?.start;
    
        return {
            message: diagnostic.message,
            path: pathToString(diagnostic.path),
            code: diagnostic.code,
            severity: severityLabel(diagnostic.severity),
            line: typeof start?.line === 'number' ? start.line + 1 : undefined,
            character: typeof start?.character === 'number' ? start.character + 1 : undefined,
        };
    };
Behavior2/5

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

No annotations provided, so description carries full burden. It mentions returning errors for invalid specs but does not clarify behavior for valid specs (e.g., empty list vs success message). No mention of permissions, side effects, or performance.

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?

Single sentence, direct and complete. No unnecessary words.

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?

For a simple validation tool with one parameter and no output schema, the description covers the basic purpose and input. However, it lacks explicit mention of the return format (e.g., list of errors) which would improve completeness.

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?

Schema description coverage is 100% (single parameter 'spec' described as 'Raw AsyncAPI document content as YAML or JSON.'). Description adds no extra parameter info beyond the schema, so baseline 3 is appropriate.

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

Purpose5/5

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

Description clearly states verb 'validate', resource 'AsyncAPI YAML or JSON content', and outcome 'return validation errors'. Clearly distinguishes from sibling tools that handle metadata, sections, versions, and search.

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?

No guidance on when to use this tool versus alternatives like get_asyncapi_spec_metadata or search_asyncapi_spec. The description does not specify prerequisites or contexts where validation is appropriate.

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/Souvikns/asyncapi-mcp'

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