Skip to main content
Glama
Jij-Inc

Jij MCP Server

Official
by Jij-Inc

jm_check

Validate code compliance with JijModeling rules to ensure proper implementation and identify potential issues.

Instructions

Check the code for JijModeling rules.

Args:
    code (str): The code to check.

Returns:
    dict: The result of the check.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes

Implementation Reference

  • Registration of the 'jm_check' MCP tool. Thin handler that invokes the core checker function from jm_checker.
    @mcp.tool()
    def jm_check(code: str) -> dict:
        """
        Check the code for JijModeling rules.
    
        Args:
            code (str): The code to check.
    
        Returns:
            dict: The result of the check.
        """
        return jijmodeling_check(code)
  • Core handler logic for jm_check: detects 'for' loops (forbidden in JijModeling), executes code in PythonREPL to catch errors, returns diagnostic dict.
    def jijmodeling_check(code_string: str) -> dict:
        """
        Pythonコード文字列をJijModelingのルールに従ってチェックする関数
    
        Args:
            code_string (str): 解析対象のPythonコード文字列
    
        Returns:
            dict: チェック結果を含む辞書
        """
        # for文の検出
        for_loop_detected = detect_for_loop(code_string)
        if for_loop_detected:
            return {
                "for_loop_detected": True,
                "message": _jm_for_statement_check,
            }
    
        # PythonREPLを使用してコードを実行し、エラーをキャッチ
        result = PythonREPL.run(code_string)
    
        if result["status"] == "error":
            return {
                "for_loop_detected": False,
                "message": _jm_for_statement_check,
                "error": result["error"],
            }
    
        return {
            "for_loop_detected": False,
            "message": "No for loop detected and no errors found.",
        }
  • Helper function to detect 'for' loops using AST parsing (primary) or regex (fallback).
    def detect_for_loop(code_string):
        """
        Pythonコード文字列からfor文の存在を検出する関数
    
        Args:
            code_string (str): 解析対象のPythonコード文字列
    
        Returns:
            bool: for文が存在する場合はTrue、存在しない場合はFalse
        """
        # 方法1: ASTを使用した解析(構文的に正しいコードの場合)
        try:
            tree = ast.parse(code_string)
            for node in ast.walk(tree):
                if isinstance(node, ast.For):
                    return True
        except SyntaxError:
            # 構文エラーがある場合は正規表現による検出に進む
            pass
    
        # 方法2: 正規表現を使用した解析(ASTが適用できない場合のバックアップ)
        # for文の正規表現パターン: 'for'の後にスペースまたはタブ、その後に変数名、'in'が続く形式
        pattern = r"\bfor\s+[a-zA-Z_][a-zA-Z0-9_]*\s+in\b"
    
        if re.search(pattern, code_string):
            return True
    
        return False
  • Helper string containing guidance and examples on avoiding Python 'for' loops in JijModeling using jm.Element and jm.sum.
    _jm_for_statement_check = """In JijModeling, you cannot use Python loops directly. Instead, you should use the Element objects.
    
    # How to write summation in JijModeling without Python loops.
    
    The wrong code:
    ```python
    objective = 0
    for l in range(n_l):
        for t in range(n_t):
            for p in range(n_p):
                for q in range(n_p):
                    if p != q:
                        objective += ChangeCost[p, q] * Switch[p, q, l, t]
    ```
    
    The correct code:
    ```
    l = jm.Element("l", belongs_to=range(0, n_l))
    t = jm.Element("t", belongs_to=range(0, n_t))
    p = jm.Element("p", belongs_to=range(0, n_p))
    q = jm.Element("q", belongs_to=range(0, n_p))
    objective = jm.sum([l, t, p, (q, p != q)], ChangeCost[p, q] * Switch[p, q, l, t])
    ```
    
    # How to write forall in JijModeling without Python loops.
    
    The wrong code:
    ```python
    for l in range(n_l):
        for t in range(n_t):
            problem += jm.Constraint(
                "SingleProductPerLine",
                jm.sum([X[p, l, t] for p in range(n_p)]) <= 1,
                forall=[]
            )
    ```
    
    The correct code:
    ```python
    l = jm.Element("l", belongs_to=range(0, n_l))
    t = jm.Element("t", belongs_to=range(0, n_t))
    p = jm.Element("p", belongs_to=range(0, n_p))
    problem += jm.Constraint(
        "SingleProductPerLine",
        jm.sum(p, X[p, l, t]) <= 1,
        forall=[l, t]
    )
    ```
    """
  • Input schema: code (str). Output: dict with keys like 'for_loop_detected', 'message', optional 'error'.
    def jm_check(code: str) -> dict:
        """
        Check the code for JijModeling rules.
    
        Args:
            code (str): The code to check.
    
        Returns:
            dict: The result of the check.
        """
        return jijmodeling_check(code)
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool checks code and returns a dict result, but it does not describe what the check entails (e.g., syntax validation, rule compliance, error types), potential side effects, or any constraints like rate limits or authentication needs. This leaves significant gaps in understanding the tool's behavior.

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 concise and well-structured, with a clear purpose statement followed by Args and Returns sections. It avoids unnecessary words and is front-loaded with the main function. However, it could be slightly more informative without sacrificing brevity, such as hinting at what the check involves.

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

Completeness2/5

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

Given the complexity of code checking, lack of annotations, no output schema, and minimal parameter details, the description is incomplete. It does not explain what the result dict contains, potential error cases, or how to interpret outputs. This inadequacy makes it hard for an agent to use the tool effectively without additional context.

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

Parameters3/5

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

The description adds minimal semantics beyond the input schema. It specifies that 'code' is a string representing the code to check, which aligns with the schema's type. However, with 0% schema description coverage, it does not compensate by detailing format, examples, or constraints (e.g., code language, length). The baseline is 3 due to the single parameter, but it lacks enrichment.

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: 'Check the code for JijModeling rules.' It specifies the verb ('check') and resource ('code for JijModeling rules'), making it understandable. However, it does not explicitly differentiate from sibling tools like 'learn_jijmodeling' or 'qiskit_code_static_check', which might involve similar checking or learning functions, so it misses full sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It lacks context such as when to check JijModeling code, what scenarios it applies to, or how it differs from siblings like 'learn_jijmodeling' or other code-checking tools. This absence of usage instructions leaves the agent without clear direction.

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/Jij-Inc/Jij-MCP-Server'

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