Skip to main content
Glama
miyamamoto

JVLink MCP Server

by miyamamoto

get_sql_generation_prompt

Generates an LLM prompt to convert natural language questions into SQL queries for analyzing Japanese horse racing data. Use with keiba_data_search to run the SQL.

Instructions

自然言語クエリをSQLに変換するためのLLMプロンプトを生成

このツールはSQLを直接実行しません。LLMにSQLを生成させるためのプロンプトを返します。
生成されたSQLは keiba_data_search ツールで実行してください。

Args:
    query_text: 自然言語のクエリ
        例: "過去3年で東京競馬場の芝1600mで1番人気だった馬の成績を教えて"
        例: "ディープインパクト産駒の距離別成績を集計して"

Returns:
    LLM用プロンプトとスキーマ情報

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_textYes

Implementation Reference

  • The handler function that implements the 'get_sql_generation_prompt' tool. It builds an LLM prompt containing the database schema, track codes, grade codes, and the user's natural language query, then returns the prompt along with schema info for generating SQL.
    @mcp.tool()
    def get_sql_generation_prompt(query_text: str) -> dict:
        """自然言語クエリをSQLに変換するためのLLMプロンプトを生成
    
        このツールはSQLを直接実行しません。LLMにSQLを生成させるためのプロンプトを返します。
        生成されたSQLは keiba_data_search ツールで実行してください。
    
        Args:
            query_text: 自然言語のクエリ
                例: "過去3年で東京競馬場の芝1600mで1番人気だった馬の成績を教えて"
                例: "ディープインパクト産駒の距離別成績を集計して"
    
        Returns:
            LLM用プロンプトとスキーマ情報
        """
        # スキーマ情報を取得
        schema_info = get_schema_description()
    
        # プロンプトを構築
        prompt = f"""
    あなたはJVLink競馬データベースのSQLエキスパートです。
    以下のユーザーの自然言語クエリをSQLに変換してください。
    
    ### データベース構造:
    {json.dumps(schema_info, ensure_ascii=False, indent=2)}
    
    ### 競馬場コード:
    {json.dumps(TRACK_CODES, ensure_ascii=False)}
    
    ### グレードコード:
    {json.dumps(GRADE_CODES, ensure_ascii=False)}
    
    ### ユーザークエリ:
    {query_text}
    
    ### 要件:
    1. 読み取り専用のSELECT文のみ生成
    2. JOINが必要な場合は適切に使用
    3. WHERE句で適切にフィルタリング
    4. 日付フィルタは DATE() 関数を使用
    5. 集計が必要な場合はGROUP BYを使用
    
    ### 出力形式:
    {{
        "sql": "生成されたSQLクエリ",
        "explanation": "クエリの日本語説明",
        "tables_used": ["使用したテーブルのリスト"],
        "notes": "注意事項やヒント"
    }}
    """
    
        return {
            "prompt_for_llm": prompt,
            "hint": "このプロンプトをLLMに渡してSQLを生成してください",
            "schema_info": schema_info
        }
  • Tool registration via @mcp.tool() decorator on the get_sql_generation_prompt function.
    @mcp.tool()
  • The get_schema_description() helper function used by the tool to fetch database schema info (tables, track codes, grade codes, important notes) that gets embedded into the LLM prompt.
    def get_schema_description():
        return {
            "tables": ALL_TABLES,
            "track_codes": TRACK_CODES,
            "nar_track_codes": NAR_TRACK_CODES,
            "grade_codes": GRADE_CODES,
            "important_notes": [
                "NL_: 蓄積系(確定データ)、RT_: 速報系(当日データ)、TS_: 時系列オッズ",
                "_NAR サフィックス: NAR地方競馬テーブル(JRAと同構造)",
                "KakuteiJyuni(着順)とNinki(人気)はINTEGER型(1, 2, 3...)",
                "Umaban(馬番)とWakuban(枠番)もINTEGER型",
                "JyoCD(競馬場)はTEXT型: JRA='01'-'10', NAR='30'-'57'",
                "Odds, Time, HaronTimeL3, BaTaijyuはREAL型",
                "JRA馬マスタ: NL_UM、NAR馬マスタ: NL_UM_NAR(別テーブル)",
                "速報系(RT_)は当日のみ、過去データはNL_を使用",
                "JRA+NAR横断分析: UNION ALLでNL_SE + NL_SE_NARを結合",
            ],
        }
  • TRACK_CODES and GRADE_CODES constants imported by server.py and embedded into the prompt for SQL generation context.
    TRACK_CODES = {"01": "札幌", "02": "函館", "03": "福島", "04": "新潟", "05": "東京", "06": "中山", "07": "中京", "08": "京都", "09": "阪神", "10": "小倉"}
    
    NAR_TRACK_CODES = {
        "30": "門別", "31": "北見", "32": "岩見沢", "33": "帯広", "34": "旭川",
        "35": "盛岡", "36": "水沢", "37": "上山", "38": "三条", "39": "足利",
        "40": "宇都宮", "41": "高崎", "42": "浦和", "43": "船橋", "44": "大井",
        "45": "川崎", "46": "金沢", "47": "笠松", "48": "名古屋", "49": "園田",
        "50": "姫路", "51": "益田", "52": "福山", "53": "高知", "54": "佐賀",
        "55": "荒尾", "56": "中津", "57": "札幌(地)",
    }
Behavior3/5

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

No annotations are provided, so the description carries full burden. It states the tool returns a prompt and schema info, but does not disclose behavioral details like rate limits, authentication requirements, or error handling. It provides minimal transparency beyond the basic function.

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

Conciseness4/5

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

The description is well-structured with clear sections in Japanese and English, and front-loads the core purpose and usage. It is slightly verbose with examples but the examples are useful. Every sentence adds value.

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 only one parameter, no output schema, and no annotations, the description covers the essential aspects: what it does, what it returns, and how to use the result. It lacks detail about the exact return format but is sufficient for a tool that generates prompts for LLM consumption.

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?

Schema description coverage is 0%, but the description compensates by explaining the 'query_text' parameter with natural language examples. The description adds meaning beyond the bare schema type definition, helping the agent understand the format and scope of input.

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

Purpose5/5

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

The description clearly states the tool generates LLM prompts for converting natural language to SQL, and explicitly distinguishes itself from direct SQL execution tools like keiba_data_search, which is listed as a sibling. The verb 'generate' and resource 'LLM prompt for SQL' are specific and unambiguous.

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

Usage Guidelines5/5

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

The description provides explicit guidance: 'このツールはSQLを直接実行しません' (this tool does not execute SQL) and '生成されたSQLは keiba_data_search ツールで実行してください' (execute the generated SQL using keiba_data_search). This tells the agent when to use this tool and what alternative to use for execution.

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/miyamamoto/jvlink-mcp-server'

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