{
  "openapi": "3.1.1",
  "info": {
    "title": "Unix Permission Calculator API",
    "version": "1.0.0",
    "summary": "chmod calculator: octal ↔ rwx, setuid/sticky, u+x style changes, umask and ls -l.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://unixpermissioncalculator.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "chmod calculator: octal ↔ rwx, setuid/sticky, u+x style changes, umask and ls -l.",
        "description": "Converts Unix file modes between octal (755, 4755), symbolic (rwxr-xr-x) and ls -l strings, explains what owner, group and others may do, applies chmod expressions such as u+x,g-w,o=r or a+X to a base mode exactly like GNU chmod, and computes default file and directory modes from a umask.\n\nMethodology:\n- A mode has 12 bits: setuid (4000), setgid (2000), sticky (1000), then read (4), write (2) and execute (1) for owner, group and others. ls shows setuid/setgid as s in the execute position (S if execute is off) and the sticky bit as t (T).\n- chmod expressions follow GNU coreutils: clauses are separated by commas; who is any of u, g, o, a; operators + - =; permissions r w x X s t or a class to copy (g=u). X adds execute only for directories or when some execute bit is already set. s only affects u and g; t only affects o/a.\n- Without a who letter (e.g. +x), the bits masked by the umask are not changed, as in GNU chmod. For directories, GNU keeps setuid/setgid when you use = without s or a numeric mode of up to four digits; a fifth leading zero (00755) clears them.\n- umask: new files are created with 666 & ~umask and directories with 777 & ~umask (programs may request fewer bits).",
        "tags": [
          "developer"
        ],
        "x-mcp-tool": "unix_permission_calculator",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UnixPermissionCalculatorInput"
              },
              "examples": {
                "example1": {
                  "summary": "755 explained",
                  "value": {
                    "mode": "755"
                  }
                },
                "example2": {
                  "summary": "Apply u+x,g-w,o=r to 664",
                  "value": {
                    "mode": "664",
                    "chmod": "u+x,g-w,o=r"
                  }
                },
                "example3": {
                  "summary": "Parse ls -l \"drwxrwsr-t\" and umask 027",
                  "value": {
                    "mode": "drwxrwsr-t",
                    "umask": "027"
                  }
                },
                "example4": {
                  "summary": "a+X on a file without execute bits, then +t",
                  "value": {
                    "mode": "rw-r-----",
                    "chmod": "a+X,o+t"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnixPermissionCalculatorResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "UnixPermissionCalculatorInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "Mode",
            "description": "Octal (644, 0755, 4755), symbolic (rwxr-xr-x) or an ls -l string (drwxr-sr-x, -rw-r--r--@).",
            "type": "string",
            "maxLength": 200
          },
          "chmod": {
            "title": "chmod expression to apply (optional)",
            "description": "Symbolic clauses (u+x, go-w, a=rX, g=u, u+s, +t) or a numeric mode, applied to the mode above.",
            "type": "string",
            "maxLength": 200
          },
          "isDirectory": {
            "title": "It is a directory",
            "description": "Affects X, the meaning of r/w/x and GNU's handling of setuid/setgid on directories. ls -l strings starting with d set this automatically.",
            "type": "boolean",
            "default": false
          },
          "umask": {
            "title": "umask (optional)",
            "description": "Shows the default modes for new files (666 & ~umask) and directories (777 & ~umask).",
            "type": "string",
            "maxLength": 5
          }
        },
        "required": [
          "mode"
        ]
      },
      "UnixPermissionCalculatorResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "input",
              "inputFormat",
              "isDirectory",
              "fileType",
              "octal",
              "symbolic",
              "lsString",
              "special",
              "chmod",
              "umask"
            ],
            "properties": {
              "input": {
                "type": "string"
              },
              "inputFormat": {
                "type": "string",
                "enum": [
                  "octal",
                  "symbolic",
                  "ls"
                ]
              },
              "isDirectory": {
                "type": "boolean"
              },
              "fileType": {
                "type": "string"
              },
              "octal": {
                "type": "string",
                "description": "Final mode (after chmod, if given) as 4-digit octal."
              },
              "symbolic": {
                "type": "string"
              },
              "lsString": {
                "type": "string"
              },
              "special": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "setuid",
                  "setgid",
                  "sticky"
                ],
                "properties": {
                  "setuid": {
                    "type": "boolean"
                  },
                  "setgid": {
                    "type": "boolean"
                  },
                  "sticky": {
                    "type": "boolean"
                  }
                }
              },
              "chmod": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "expression",
                  "baseOctal",
                  "resultOctal",
                  "steps",
                  "command"
                ],
                "properties": {
                  "expression": {
                    "type": "string"
                  },
                  "baseOctal": {
                    "type": "string"
                  },
                  "resultOctal": {
                    "type": "string"
                  },
                  "command": {
                    "type": "string"
                  },
                  "steps": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "clause",
                        "before",
                        "after"
                      ],
                      "properties": {
                        "clause": {
                          "type": "string"
                        },
                        "before": {
                          "type": "string"
                        },
                        "after": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              },
              "umask": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "required": [
                  "umask",
                  "fileDefault",
                  "directoryDefault"
                ],
                "properties": {
                  "umask": {
                    "type": "string"
                  },
                  "fileDefault": {
                    "type": "string"
                  },
                  "directoryDefault": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}