get_mevzuat_gerekce
Fetch the legislative rationale (gerekçe) for Turkish laws, including purpose, committee reports, and article justifications, using a gerekce ID from search results.
Instructions
Retrieve the law rationale (gerekçe / kanun gerekçesi) from bedesten.adalet.gov.tr.
The gerekçe contains:
Purpose and reasoning behind the law (kanunun amacı ve gerekçesi)
Parliamentary committee reports (komisyon raporları)
Article-by-article justifications (madde gerekçeleri)
Only available for KANUN type legislation that has a published rationale. Not all laws have a gerekçe — check if gerekceId is present in search_mevzuat results.
Workflow: search_mevzuat → check gerekceId in results → get_mevzuat_gerekce(gerekceId)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gerekce_id | Yes | Gerekçe ID from search_mevzuat results (gerekceId field, e.g., '2049'). Only available for laws (KANUN) that have a published rationale. Check if gerekceId exists in search_mevzuat results before calling. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mevzuat_mcp_server.py:2211-2249 (handler)The 'get_mevzuat_gerekce' tool handler function. This is the FastMCP tool registered with @app.tool() decorator. It takes gerekce_id as input, calls bedesten_client.get_gerekce_content(), strips HTML from the result, and returns plain text rationale content.
@app.tool() async def get_mevzuat_gerekce( gerekce_id: str = Field( ..., description=( "Gerekçe ID from search_mevzuat results (gerekceId field, e.g., '2049'). " "Only available for laws (KANUN) that have a published rationale. " "Check if gerekceId exists in search_mevzuat results before calling." ), ), ) -> str: """ Retrieve the law rationale (gerekçe / kanun gerekçesi) from bedesten.adalet.gov.tr. The gerekçe contains: - Purpose and reasoning behind the law (kanunun amacı ve gerekçesi) - Parliamentary committee reports (komisyon raporları) - Article-by-article justifications (madde gerekçeleri) Only available for KANUN type legislation that has a published rationale. Not all laws have a gerekçe — check if gerekceId is present in search_mevzuat results. Workflow: search_mevzuat → check gerekceId in results → get_mevzuat_gerekce(gerekceId) """ try: result = await bedesten_client.get_gerekce_content(gerekce_id) if result.error_message: return f"Error fetching gerekçe: {result.error_message}" if not result.content: return f"Error: No gerekçe content found for gerekceId {gerekce_id}" plain = _strip_html(result.content) if not plain: return f"Error: Gerekçe content is empty for gerekceId {gerekce_id}" return plain except Exception as e: logger.exception("Error in get_mevzuat_gerekce") return f"An unexpected error occurred: {str(e)}" - mevzuat_mcp_server.py:2212-2234 (registration)The tool is registered via @app.tool() decorator on the get_mevzuat_gerekce async function. The schema/input definition is via Field() for the gerekce_id parameter.
async def get_mevzuat_gerekce( gerekce_id: str = Field( ..., description=( "Gerekçe ID from search_mevzuat results (gerekceId field, e.g., '2049'). " "Only available for laws (KANUN) that have a published rationale. " "Check if gerekceId exists in search_mevzuat results before calling." ), ), ) -> str: """ Retrieve the law rationale (gerekçe / kanun gerekçesi) from bedesten.adalet.gov.tr. The gerekçe contains: - Purpose and reasoning behind the law (kanunun amacı ve gerekçesi) - Parliamentary committee reports (komisyon raporları) - Article-by-article justifications (madde gerekçeleri) Only available for KANUN type legislation that has a published rationale. Not all laws have a gerekçe — check if gerekceId is present in search_mevzuat results. Workflow: search_mevzuat → check gerekceId in results → get_mevzuat_gerekce(gerekceId) """ - bedesten_client.py:325-360 (helper)The BedestenClient.get_gerekce_content() method that actually calls the bedesten.adalet.gov.tr API endpoint /getGerekceContent. It handles caching, base64 decoding, and returns BedGerekceContent.
async def get_gerekce_content( self, gerekce_id: str, ) -> BedGerekceContent: """Fetch law rationale content.""" cache_key = f"gerekce_{gerekce_id}" cached = self._get_cached(cache_key) if cached: return cached inner = {"gerekceId": gerekce_id} try: resp = await self._client.post("/getGerekceContent", json=_wrap(inner)) resp.raise_for_status() body = resp.json() meta = body.get("metadata", {}) if meta.get("FMTY") != "SUCCESS": return BedGerekceContent(error_message=meta.get("FMTE", "Unknown error")) data = body.get("data") or {} raw = data.get("content", "") mime = data.get("mimetype", data.get("mimeType", "text/html")) decoded = _decode_base64(raw) result = BedGerekceContent( gerekce_id=data.get("gerekceId"), mevzuat_id=data.get("mevzuatId"), content=decoded, mime_type=mime, ) self._put_cached(cache_key, result) return result except Exception as e: logger.exception("bedesten get_gerekce_content error") return BedGerekceContent(error_message=str(e)) - bedesten_models.py:80-86 (schema)The BedGerekceContent model defining the response schema with fields: gerekce_id, mevzuat_id, content (decoded HTML/text), mime_type, error_message.
class BedGerekceContent(BaseModel): """Law rationale (gerekçe) content.""" gerekce_id: Optional[str] = None mevzuat_id: Optional[str] = None content: str = "" # decoded HTML/text mime_type: Optional[str] = None error_message: Optional[str] = None - bedesten_models.py:34-48 (schema)The BedMevzuatDocument model includes gerekce_id field (line 41) which indicates whether a law has a published rationale that can be retrieved via get_mevzuat_gerekce.
class BedMevzuatDocument(BaseModel): """A legislation document from search results.""" mevzuat_id: str = Field(..., alias="mevzuatId") mevzuat_no: Any = Field(..., alias="mevzuatNo") # can be int or str mevzuat_adi: str = Field(..., alias="mevzuatAdi") mevzuat_tur: Optional[Any] = Field(None, alias="mevzuatTur") mevzuat_tertip: Optional[Any] = Field(None, alias="mevzuatTertip") gerekce_id: Optional[str] = Field(None, alias="gerekceId") ekler: Optional[List[str]] = None resmi_gazete_tarihi: Optional[str] = Field(None, alias="resmiGazeteTarihi") resmi_gazete_sayisi: Optional[str] = Field(None, alias="resmiGazeteSayisi") url: Optional[str] = None mukerrer: Optional[str] = None model_config = {"populate_by_name": True}