{
  "openapi": "3.1.1",
  "info": {
    "title": "Contract Bridge Score Calculator API",
    "version": "1.0.0",
    "summary": "Bridge score of one contract: duplicate points, rubber entries above and below the line, IMPs.",
    "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://playcardsbridgescore.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Bridge score of one contract: duplicate points, rubber entries above and below the line, IMPs.",
        "description": "Scores one Contract Bridge deal by the scoring tables of the Laws of Duplicate Bridge: points for the tricks bid and made, overtricks, the bonus for making a doubled or redoubled contract, slam bonuses and the penalties for undertricks, not vulnerable or vulnerable, doubled or redoubled. Duplicate scoring adds the part-score or game bonus; rubber scoring splits the result into the points below the line (towards game, with your existing part score) and above it, with honours. Enter the other table’s score to get the IMP difference. The Playcards app scores every deal with the same engine.\n\nMethodology:\n- Tricks bid and made: Clubs and Diamonds 20 each, Hearts and Spades 30, no trumps 40 for the first and 30 for the others; doubled × 2, redoubled × 4. A game needs 100 of these points.\n- Overtricks: the trick value undoubled; doubled 100 (not vulnerable) or 200 (vulnerable) each, redoubled twice that. Making a doubled contract scores 50, redoubled 100. Small slam 500 / 750, grand slam 1000 / 1500.\n- Undertricks: undoubled 50 / 100 each; doubled not vulnerable 100 for the first, 200 for the second and third, 300 for each further one; doubled vulnerable 200 for the first and 300 for each further one; redoubled twice the doubled penalty.\n- Duplicate adds 50 for a part score, 300 for a game not vulnerable, 500 vulnerable; honours do not count. Rubber bridge enters the trick score below the line (game at 100, with the part score you already have) and everything else above it, honours included (four trump honours in one hand 100, five 150, four Aces at no trumps 150). IMPs follow the WBF scale (20–40 = 1 … 4000+ = 24).",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "playcards_bridge_score",
        "x-owner-app": "playcards",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlaycardsBridgeScoreInput"
              },
              "examples": {
                "example1": {
                  "summary": "4♠ made with an overtrick, not vulnerable",
                  "value": {
                    "level": 4,
                    "strain": "S",
                    "tricks": 11
                  }
                },
                "example2": {
                  "summary": "3NT doubled, two down, vulnerable",
                  "value": {
                    "level": 3,
                    "strain": "N",
                    "doubled": "1",
                    "vulnerable": true,
                    "tricks": 7
                  }
                },
                "example3": {
                  "summary": "6♥ doubled making 13 (rubber, honours)",
                  "value": {
                    "level": 6,
                    "strain": "H",
                    "doubled": "1",
                    "tricks": 13,
                    "scoring": "rubber",
                    "honours": "four"
                  }
                },
                "example4": {
                  "summary": "2♠+2 against 4♠ at the other table (IMPs)",
                  "value": {
                    "level": 2,
                    "strain": "S",
                    "tricks": 10,
                    "otherTable": "420"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlaycardsBridgeScoreResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "PlaycardsBridgeScoreInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "level": {
            "title": "Contract level",
            "description": "Odd tricks bid: 1 (seven tricks) to 7 (all thirteen).",
            "type": "integer",
            "minimum": 1,
            "maximum": 7,
            "default": 4
          },
          "strain": {
            "title": "Trumps",
            "type": "string",
            "enum": [
              "C",
              "D",
              "H",
              "S",
              "N"
            ],
            "default": "S"
          },
          "doubled": {
            "title": "Doubled",
            "type": "string",
            "enum": [
              "0",
              "1",
              "2"
            ],
            "default": "0"
          },
          "vulnerable": {
            "title": "Declarer’s side vulnerable",
            "type": "boolean",
            "default": false
          },
          "tricks": {
            "title": "Tricks won by declarer’s side",
            "type": "integer",
            "minimum": 0,
            "maximum": 13,
            "default": 10
          },
          "scoring": {
            "title": "Scoring",
            "type": "string",
            "enum": [
              "duplicate",
              "rubber"
            ],
            "default": "duplicate"
          },
          "partScore": {
            "title": "Part score already below the line (rubber)",
            "description": "Points the declarer’s side already has towards the current game.",
            "type": "integer",
            "minimum": 0,
            "maximum": 90,
            "default": 0
          },
          "honours": {
            "title": "Honours in one hand (rubber)",
            "type": "string",
            "enum": [
              "none",
              "four",
              "five",
              "aces"
            ],
            "default": "none"
          },
          "honoursSide": {
            "title": "Honours held by",
            "type": "string",
            "enum": [
              "declarer",
              "defenders"
            ],
            "default": "declarer"
          },
          "otherTable": {
            "title": "Other table’s score for the same side (optional)",
            "description": "With a score from the other table the tool converts the difference to IMPs.",
            "type": "string",
            "maxLength": 6,
            "default": ""
          }
        },
        "required": []
      },
      "PlaycardsBridgeScoreResult": {
        "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": [
              "contract",
              "made",
              "overtricks",
              "undertricks",
              "trickScore",
              "overtrickScore",
              "insult",
              "slamBonus",
              "undertrickPenalty",
              "gameBonus",
              "duplicateScore",
              "belowLine",
              "aboveLine",
              "gameCompleted",
              "honours",
              "imps"
            ],
            "properties": {
              "contract": {
                "type": "string"
              },
              "made": {
                "type": "boolean"
              },
              "overtricks": {
                "type": "integer"
              },
              "undertricks": {
                "type": "integer"
              },
              "trickScore": {
                "type": "integer",
                "description": "Points for the tricks bid and made (below the line in rubber bridge)."
              },
              "overtrickScore": {
                "type": "integer"
              },
              "insult": {
                "type": "integer",
                "description": "50 for making a doubled contract, 100 redoubled."
              },
              "slamBonus": {
                "type": "integer"
              },
              "undertrickPenalty": {
                "type": "integer",
                "description": "Points for the defenders when the contract fails."
              },
              "gameBonus": {
                "type": "integer",
                "description": "Duplicate: 50 part score, 300 game not vulnerable, 500 game vulnerable (0 when defeated)."
              },
              "duplicateScore": {
                "type": "integer",
                "description": "Duplicate score for the declarer’s side (negative = the defenders score)."
              },
              "belowLine": {
                "type": "integer"
              },
              "aboveLine": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "declarer",
                  "defenders"
                ],
                "properties": {
                  "declarer": {
                    "type": "integer"
                  },
                  "defenders": {
                    "type": "integer"
                  }
                }
              },
              "gameCompleted": {
                "type": "boolean",
                "description": "Rubber: the part score plus this contract reaches 100 below the line."
              },
              "honours": {
                "type": "integer"
              },
              "imps": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "IMPs for the declarer’s side against the other table (null without a comparison)."
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}