Skip to main content
Glama
saidsurucu

Yargı MCP

by saidsurucu

get_emsal_document_markdown

Read-onlyIdempotent

Retrieve full text of Turkish legal precedent decisions in clean Markdown format for legal research and analysis.

Instructions

Use this when retrieving full text of an Emsal precedent decision. Returns clean Markdown format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that implements the core logic of fetching an Emsal decision document by ID from the API, processing the HTML response, converting it to Markdown, and returning it in the expected format. This is the exact implementation of the tool's main functionality.
    async def get_decision_document_as_markdown(self, id: str) -> EmsalDocumentMarkdown:
        """
        Retrieves a specific Emsal decision by ID and returns its content as Markdown.
        Assumes Emsal /getDokuman endpoint returns JSON with HTML content in the 'data' field.
        """
        document_api_url = f"{self.DOCUMENT_ENDPOINT}?id={id}"
        source_url = f"{self.BASE_URL}{document_api_url}"
        logger.info(f"EmsalApiClient: Fetching Emsal document for Markdown (ID: {id}) from {source_url}")
    
        try:
            response = await self.http_client.get(document_api_url)
            response.raise_for_status()
            
            # Emsal /getDokuman returns JSON with HTML in 'data' field (confirmed by user example)
            response_json = response.json()
            html_content_from_api = response_json.get("data")
    
            if not isinstance(html_content_from_api, str) or not html_content_from_api.strip():
                logger.warning(f"EmsalApiClient: Received empty or non-string HTML in 'data' field for Emsal ID {id}.")
                return EmsalDocumentMarkdown(id=id, markdown_content=None, source_url=source_url)
    
            markdown_content = self._clean_html_and_convert_to_markdown_emsal(html_content_from_api)
    
            return EmsalDocumentMarkdown(
                id=id,
                markdown_content=markdown_content,
                source_url=source_url
            )
        except httpx.RequestError as e:
            logger.error(f"EmsalApiClient: HTTP error fetching Emsal document (ID: {id}): {e}")
            raise
        except ValueError as e: 
            logger.error(f"EmsalApiClient: ValueError processing Emsal document response (ID: {id}): {e}")
            raise
        except Exception as e:
            logger.error(f"EmsalApiClient: General error processing Emsal document (ID: {id}): {e}")
            raise
  • Pydantic schema/model defining the input/output structure for the Emsal document markdown response, including id, markdown_content, and source_url.
    class EmsalDocumentMarkdown(BaseModel):
        """Model for an Emsal decision document, containing only Markdown content."""
        id: str
        markdown_content: str = Field("", description="The decision content (Karar İçeriği) converted to Markdown.")
        source_url: HttpUrl
  • Helper function that cleans the HTML content received from the Emsal API and converts it to Markdown using MarkItDown library. Called by the main handler.
    def _clean_html_and_convert_to_markdown_emsal(self, html_content_from_api_data_field: str) -> Optional[str]:
        """
        Cleans HTML (from Emsal API 'data' field containing HTML string)
        and converts it to Markdown using MarkItDown.
        This assumes Emsal /getDokuman response is JSON with HTML in "data" field,
        similar to Yargitay and the last Emsal /getDokuman example.
        """
        if not html_content_from_api_data_field:
            return None
    
        # Basic HTML unescaping and fixing common escaped characters
        # Based on user's original fix_html_content in app/routers/emsal.py
        content = html.unescape(html_content_from_api_data_field)
        content = content.replace('\\"', '"')
        content = content.replace('\\r\\n', '\n')
        content = content.replace('\\n', '\n')
        content = content.replace('\\t', '\t')
        
        # The HTML string from "data" field starts with "<html><head>..."
        html_input_for_markdown = content 
    
        markdown_text = None
        try:
            # Convert HTML string to bytes and create BytesIO stream
            html_bytes = html_input_for_markdown.encode('utf-8')
            html_stream = io.BytesIO(html_bytes)
            
            # Pass BytesIO stream to MarkItDown to avoid temp file creation
            md_converter = MarkItDown()
            conversion_result = md_converter.convert(html_stream)
            markdown_text = conversion_result.text_content
            logger.info("EmsalApiClient: HTML to Markdown conversion successful.")
        except Exception as e:
            logger.error(f"EmsalApiClient: Error during MarkItDown HTML to Markdown conversion for Emsal: {e}")
        
        return markdown_text
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and idempotentHint=true, so the agent knows this is a safe, repeatable read operation. The description adds value by specifying the return format ('clean Markdown format'), which isn't covered by annotations. However, it doesn't provide additional behavioral context like rate limits, authentication needs, or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just two sentences that directly state the tool's purpose and output format. Every word earns its place, and it's front-loaded with the primary use case, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (one parameter, read-only/idempotent annotations, output schema exists), the description is reasonably complete. It covers the core purpose and output format, and the output schema will handle return value details. However, it could benefit from more explicit differentiation from sibling search tools to fully guide usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has one parameter 'id' with 0% description coverage, so the schema provides no semantic information. The description doesn't explicitly mention parameters, but it implies the 'id' is needed to retrieve a specific document. Since there's only one parameter and its purpose is reasonably inferred from context, this compensates adequately for the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: retrieving full text of an Emsal precedent decision and returning it in clean Markdown format. It specifies both the action ('retrieving') and resource ('Emsal precedent decision'), but doesn't explicitly differentiate from sibling tools like 'search_emsal_detailed_decisions' or other document retrieval tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides some usage guidance with 'Use this when retrieving full text of an Emsal precedent decision,' which implies this is for full document retrieval rather than search. However, it doesn't explicitly state when NOT to use it or mention alternatives like the search tools among siblings, leaving some ambiguity about tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/saidsurucu/yargi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server