Add comprehensive schema validation and type system to MCPSchema gem - also add the gem

Note

I know it looks like a lot of code. But, according to coverage, only 443 lines are actually executable code. The rest is documentation, comments, tests and gem boilerplate.

What does this MR do and why?

Creates MCPSchema gem and adds comprehensive schema validation and type system to it

This release (v1.0.0) introduces a complete type system with JSON Schema validation for the MCPGraphQL DSL, including:

  • Boolean, String, Number, and Enum schema types with validation
  • Collections - Array & Object with both parameter and block-based syntax
  • Property management helpers for schema composition
  • Global configuration system for MCP tool settings
  • Comprehensive test coverage for all new components
  • Integration tests for complete schema definition workflows

The gem now provides robust input validation and type safety for Model Context Protocol tool definitions in GitLab's MCP server.

References

Usage

    class ComprehensiveTool
      include MCPSchema::DSL::Base

      mcp_tool_name :comprehensive_tool
      mcp_description "A tool demonstrating all schema types"

      mcp_input_schema do
        # String types
        String :name, required: true, description: "User name"
        URI :website, description: "Website URL"
        Email :contact, required: true, description: "Contact email"
        Date :birthday, description: "Birth date"
        DateTime :created_at, required: true, description: "Creation timestamp"

        # Number types
        Number :score, minimum: 0, maximum: 100, description: "Score value"
        Integer :count, required: true, minimum: 1, description: "Item count"

        # Boolean types
        Boolean :active, required: true, description: "Whether item is active"
        Boolean :featured, description: "Whether item is featured", default: false

        # Enum types
        Enum :status, enum: %w[draft published archived], required: true, description: "Publication status"
        Enum :priority, enum: %w[low medium high], enum_names: %w[Low Medium High],
                        description: "Task priority"
                        
        # Array types
        Array :tags, items: { type: "string" }, required: true, description: "List of tags"

        Array :matrix, description: "2D matrix of numbers" do
          Array :row do
            Number :value
          end
        end

        # Object types
        Object :project, required: "true", description: "Project" do
          String :title, required: true, description: "Project title"
          URI :repository, description: "Git repository URL"
          Date :start_date, required: true
          Date :end_date
          Boolean :completed, default: false
        end
      end

      mcp_output_schema do
        String :result_id, required: true, description: "Unique result identifier"
        Boolean :success, required: true, description: "Whether operation succeeded"
        Enum :result_type, enum: %w[created updated deleted], description: "Type of operation performed"
        String :message, description: "Human readable result message"
      end

      mcp_annotations do
        audience "user", "assistant"
        last_modified "2023-12-01T10:30:00Z"
        priority 0.9
      end
    end
{
  "name": "comprehensive_tool",
  "description": "A tool demonstrating all schema types",
  "inputSchema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "description": "User name"
      },
      "website": {
        "type": "string",
        "format": "uri",
        "description": "Website URL"
      },
      "contact": {
        "type": "string",
        "format": "email",
        "description": "Contact email"
      },
      "birthday": {
        "type": "string",
        "format": "date",
        "description": "Birth date"
      },
      "created_at": {
        "type": "string",
        "format": "date-time",
        "description": "Creation timestamp"
      },
      "score": {
        "type": "number",
        "minimum": 0,
        "maximum": 100,
        "description": "Score value"
      },
      "count": {
        "type": "integer",
        "minimum": 1,
        "description": "Item count"
      },
      "active": {
        "type": "boolean",
        "description": "Whether item is active"
      },
      "featured": {
        "type": "boolean",
        "description": "Whether item is featured",
        "default": false
      },
      "status": {
        "type": "string",
        "enum": ["draft", "published", "archived"],
        "description": "Publication status"
      },
      "priority": {
        "type": "string",
        "enum": ["low", "medium", "high"],
        "enumNames": ["Low", "Medium", "High"],
        "description": "Task priority"
      },
      "tags": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "List of tags"
      },
      "matrix": {
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "number"
          }
        },
        "description": "2D matrix of numbers"
      },
      "project": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "description": "Project title"
          },
          "repository": {
            "type": "string",
            "format": "uri",
            "description": "Git repository URL"
          },
          "start_date": {
            "type": "string",
            "format": "date"
          },
          "end_date": {
            "type": "string",
            "format": "date"
          },
          "completed": {
            "type": "boolean",
            "default": false
          }
        },
        "required": ["title", "start_date"],
        "description": "Project"
      }
    },
    "required": ["name", "contact", "created_at", "count", "active", "status", "tags", "project"]
  },
  "outputSchema": {
    "type": "object",
    "properties": {
      "result_id": {
        "type": "string",
        "description": "Unique result identifier"
      },
      "success": {
        "type": "boolean",
        "description": "Whether operation succeeded"
      },
      "result_type": {
        "type": "string",
        "enum": ["created", "updated", "deleted"],
        "description": "Type of operation performed"
      },
      "message": {
        "type": "string",
        "description": "Human readable result message"
      }
    },
    "required": ["result_id", "success"]
  },
  "annotations": {
    "audience": ["user", "assistant"],
    "lastModified": "2023-12-01T10:30:00Z",
    "priority": 0.9
  }
}

How to set up and validate locally

It is a gem build as part of the monolith. No need for any extra setup except fro bundle install and integration if we decide to go this direction.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Armin Pašalić

Merge request reports

Loading