search_khk
Search Turkish Decree Laws (KHKs) by keyword with Boolean operators, wildcards, and date filters. Retrieve KHK number, title, and official gazette information.
Instructions
Search for Turkish Decree Laws (Kanun Hükmünde Kararname / KHK) in titles and content.
IMPORTANT: Search is keyword-based, NOT by KHK number. Use descriptive Turkish terms. KHKs were abolished after the 2017 constitutional referendum (last issued 2018). Previously enacted KHKs remain in force unless repealed.
Query Syntax: Simple keyword, AND, OR, NOT, +required, (grouping), "exact phrase"
Example queries:
"sağlık AND düzenleme" - Health-related KHKs
"anayasa" - Constitutional KHKs
Leave empty with dates (e.g., 2010-2018) to list all KHKs from a period
Returns: KHK number, title, dates, Official Gazette info.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aranacak_ifade | No | Search query with Boolean operators and wildcards. Examples: "değişiklik" (simple), "sağlık AND düzenleme" (AND), "bakanlık OR kurum" (OR), "kanun NOT yürürlük" (NOT), "değişiklik*" (wildcard), "güvenlik sistemi" (exact phrase with quotes). Leave empty to list all KHKs in date range. | |
| tam_cumle | No | If True, searches for exact phrase match. If False (default), searches for any word match with Boolean operators. | |
| baslangic_tarihi | No | Start year for filtering results (format: YYYY, e.g., '2010'). Use with bitis_tarihi to define a date range. | |
| bitis_tarihi | No | End year for filtering results (format: YYYY, e.g., '2018'). Use with baslangic_tarihi to define a date range. | |
| page_number | No | Page number of results to retrieve (starts from 1) | |
| aranacak_yer | No | Where to search: 1=Title only, 2=Content only, 3=Both title and content (default) | |
| page_size | No | Number of results per page (1-100, default: 25) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documents | Yes | ||
| total_results | Yes | ||
| current_page | Yes | ||
| page_size | Yes | ||
| total_pages | Yes | ||
| query_used | Yes | ||
| error_message | No |
Implementation Reference
- mevzuat_mcp_server.py:1162-1243 (handler)The main handler function for the 'search_khk' tool. It searches for Turkish Decree Laws (Kanun Hükmünde Kararname / KHK) by constructing a MevzuatSearchRequestNew with mevzuat_tur='KHK' and delegating to mevzuat_client.search_documents(). Registered via @app.tool() decorator.
@app.tool() async def search_khk( aranacak_ifade: Optional[str] = Field( None, description='Search query with Boolean operators and wildcards. Examples: "değişiklik" (simple), "sağlık AND düzenleme" (AND), "bakanlık OR kurum" (OR), "kanun NOT yürürlük" (NOT), "değişiklik*" (wildcard), "güvenlik sistemi" (exact phrase with quotes). Leave empty to list all KHKs in date range.' ), tam_cumle: bool = Field( False, description="If True, searches for exact phrase match. If False (default), searches for any word match with Boolean operators." ), baslangic_tarihi: Optional[str] = Field( None, description="Start year for filtering results (format: YYYY, e.g., '2010'). Use with bitis_tarihi to define a date range." ), bitis_tarihi: Optional[str] = Field( None, description="End year for filtering results (format: YYYY, e.g., '2018'). Use with baslangic_tarihi to define a date range." ), page_number: int = Field( 1, ge=1, description="Page number of results to retrieve (starts from 1)" ), aranacak_yer: int = Field( 3, ge=1, le=3, description="Where to search: 1=Title only, 2=Content only, 3=Both title and content (default)" ), page_size: int = Field( 25, ge=1, le=100, description="Number of results per page (1-100, default: 25)" ) ) -> MevzuatSearchResultNew: """ Search for Turkish Decree Laws (Kanun Hükmünde Kararname / KHK) in titles and content. IMPORTANT: Search is keyword-based, NOT by KHK number. Use descriptive Turkish terms. KHKs were abolished after the 2017 constitutional referendum (last issued 2018). Previously enacted KHKs remain in force unless repealed. Query Syntax: Simple keyword, AND, OR, NOT, +required, (grouping), "exact phrase" Example queries: - "sağlık AND düzenleme" - Health-related KHKs - "anayasa" - Constitutional KHKs - Leave empty with dates (e.g., 2010-2018) to list all KHKs from a period Returns: KHK number, title, dates, Official Gazette info. """ logger.info(f"Tool 'search_khk' called: '{aranacak_ifade}', dates: {baslangic_tarihi}-{bitis_tarihi}") try: search_req = MevzuatSearchRequestNew( mevzuat_tur="KHK", aranacak_ifade=aranacak_ifade or "", aranacak_yer=aranacak_yer, tam_cumle=tam_cumle, mevzuat_no=None, baslangic_tarihi=baslangic_tarihi, bitis_tarihi=bitis_tarihi, page_number=page_number, page_size=page_size ) result = await mevzuat_client.search_documents(search_req) logger.info(f"Found {result.total_results} KHKs") return result except Exception as e: logger.exception("Error in tool 'search_khk'") return MevzuatSearchResultNew( documents=[], total_results=0, current_page=page_number, page_size=page_size, total_pages=0, query_used={"error": str(e)}, error_message=f"An unexpected error occurred: {str(e)}" ) - mevzuat_mcp_server.py:1162-1162 (registration)Registration of the 'search_khk' tool via the FastMCP @app.tool() decorator on the async function below.
@app.tool() - mevzuat_models.py:32-84 (schema)Input schema used by search_khk. MevzuatSearchRequestNew defines the request parameters including mevzuat_tur (set to 'KHK'), aranacak_ifade, tam_cumle, date filters, pagination, and search location.
class MevzuatSearchRequestNew(BaseModel): """Request model for searching legislation on mevzuat.gov.tr""" mevzuat_tur: MevzuatTurLiteral = Field( "Kanun", description="Type of legislation. Currently only 'Kanun' (laws) are fully supported for content extraction." ) aranacak_ifade: Optional[str] = Field( None, description="Search term or phrase to look for in legislation" ) aranacak_yer: int = Field( 3, ge=1, le=3, description="Where to search: 1=Title only, 2=Article titles, 3=Full text (default)" ) tam_cumle: bool = Field( False, description="Exact phrase match (true) or any word match (false, default)" ) mevzuat_no: Optional[str] = Field( None, description="Specific legislation number to search for" ) baslangic_tarihi: Optional[str] = Field( None, description="Start date for filtering (format: DD.MM.YYYY)" ) bitis_tarihi: Optional[str] = Field( None, description="End date for filtering (format: DD.MM.YYYY)" ) page_number: int = Field( 1, ge=1, description="Page number of results" ) page_size: int = Field( 10, ge=1, le=100, description="Number of results per page" ) - mevzuat_models.py:107-117 (schema)Output schema returned by search_khk. Contains the list of matching documents, pagination info, and optional error message.
class MevzuatSearchResultNew(BaseModel): """Model for search results from mevzuat.gov.tr""" documents: List[MevzuatDocumentNew] total_results: int current_page: int page_size: int total_pages: int query_used: Dict[str, Any] error_message: Optional[str] = None