Skip to main content
Glama
miyamamoto

JVLink MCP Server

by miyamamoto

generate_sql_from_natural_language

Convert natural language questions about Japanese horse racing data into SQL queries for analysis without manual coding.

Instructions

自然言語からSQLクエリを動的生成

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

Returns:
    生成されたSQLクエリと説明

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_textYes

Implementation Reference

  • The `generate_sql_from_natural_language` function serves as the MCP tool handler. It takes a natural language query as input, retrieves schema information, constructs a prompt for an LLM to generate a safe SQL query based on the JVLink database structure, and returns the prompt and metadata.
    def generate_sql_from_natural_language(query_text: str) -> dict:
        """自然言語からSQLクエリを動的生成
    
        Args:
            query_text: 自然言語のクエリ
                例: "過去3年で東京競馬場の芝1600mで1番人気だった馬の成績を教えて"
                例: "ディープインパクト産駒の距離別成績を集計して"
    
        Returns:
            生成されたSQLクエリと説明
        """
        # スキーマ情報を取得
        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
        }

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