{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://medgauge.org/schemas/0.1.0/tool.schema.json",
  "title": "tool",
  "description": "A tool, skill, plugin or MCP server in the tool registry: protocol, medical scope, side effects, conformance testing and licence.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^(sk|pl|tl|mcp)-[a-z0-9-]+$"
    },
    "kind": {
      "type": "string",
      "enum": [
        "skill",
        "plugin",
        "tool",
        "mcp"
      ]
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "summary_zh": {
      "type": "string",
      "minLength": 1
    },
    "summary_en": {
      "type": "string"
    },
    "spec": {
      "type": "object",
      "properties": {
        "protocol": {
          "type": "string",
          "enum": [
            "mcp",
            "agent-skills",
            "function",
            "plugin"
          ]
        },
        "protocol_version": {
          "type": "string"
        },
        "transport": {
          "type": "string",
          "enum": [
            "stdio",
            "http"
          ]
        },
        "tools_exposed": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "input_schema_hash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              },
              "output_schema_hash": {
                "type": "string",
                "pattern": "^sha256:[0-9a-f]{64}$"
              }
            },
            "required": [
              "name",
              "input_schema_hash"
            ],
            "additionalProperties": false
          }
        },
        "resources_exposed": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "input_schema": {
          "type": "object"
        },
        "output_schema": {
          "type": "object"
        }
      },
      "required": [
        "protocol"
      ],
      "additionalProperties": false
    },
    "source": {
      "type": "object",
      "properties": {
        "repo": {
          "type": "string",
          "format": "uri"
        },
        "commit": {
          "type": "string",
          "pattern": "^[0-9a-f]{7,40}$"
        },
        "package": {
          "type": "string"
        },
        "visibility": {
          "type": "string",
          "enum": [
            "public",
            "private"
          ],
          "description": "private = source held in the private grading repository; repo/commit omitted"
        }
      },
      "required": [
        "visibility"
      ],
      "additionalProperties": false
    },
    "medical_scope": {
      "type": "object",
      "properties": {
        "standards": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "data_origin": {
          "type": "string",
          "enum": [
            "synthetic",
            "public_licensed",
            "institutional_deidentified",
            "none"
          ]
        },
        "phi_risk": {
          "type": "string",
          "enum": [
            "none",
            "low",
            "medium",
            "high"
          ]
        }
      },
      "required": [
        "standards",
        "data_origin",
        "phi_risk"
      ],
      "additionalProperties": false
    },
    "capabilities_served": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[ABCDEX]\\.\\d+(\\.\\d+)?$"
      }
    },
    "conformance": {
      "type": "object",
      "properties": {
        "schema_valid": {
          "type": "boolean"
        },
        "smoke_test": {
          "type": "string",
          "enum": [
            "pass",
            "fail",
            "not_run"
          ]
        },
        "tested_on": {
          "type": "string",
          "format": "date"
        },
        "tested_with_harness": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "skills_ref_validate": {
          "type": "boolean"
        }
      },
      "required": [
        "schema_valid",
        "smoke_test"
      ],
      "additionalProperties": false
    },
    "safety": {
      "type": "object",
      "properties": {
        "side_effects": {
          "type": "string",
          "enum": [
            "none",
            "writes",
            "external_calls"
          ]
        },
        "requires_credentials": {
          "type": "boolean"
        }
      },
      "required": [
        "side_effects",
        "requires_credentials"
      ],
      "additionalProperties": false
    },
    "license": {
      "type": "string",
      "minLength": 1
    },
    "maintainer": {
      "type": "object",
      "properties": {
        "org": {
          "type": "string",
          "minLength": 1
        },
        "contact": {
          "type": "string"
        },
        "url": {
          "type": "string"
        }
      },
      "required": [
        "org"
      ],
      "additionalProperties": false
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "proposed",
        "experimental",
        "deprecated",
        "retired",
        "planned"
      ]
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "File path registry/tools/<id>/<version>.yaml; immutable once published"
    }
  },
  "required": [
    "id",
    "kind",
    "name",
    "summary_en",
    "spec",
    "source",
    "medical_scope",
    "conformance",
    "safety",
    "license",
    "maintainer",
    "status",
    "version"
  ]
}
