Skip to main content
Glama
pholex

Qinglong MCP Server

by pholex

run_task

Execute scheduled tasks in Qinglong Panel and retrieve execution logs by providing a task ID, with synchronous operation that waits up to 30 seconds for completion.

Instructions

执行任务并等待完成,返回执行日志(最多等待30秒)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
task_idYes任务 ID

Implementation Reference

  • Handler for the 'run_task' tool: starts the specified task via Qinglong API, polls status every 5s for up to 30s until completion, then returns the execution log. Times out with suggestion to use get_task_logs.
    elif tool_name == "run_task":
        task_id = arguments.get("task_id")
        headers = {"Authorization": f"Bearer {token}"}
        
        try:
            url = f"{QINGLONG_URL}/open/crons/run"
            resp = requests.put(url, headers=headers, json=[task_id], timeout=10)
            result = resp.json()
            if result.get("code") != 200:
                response = {
                    "jsonrpc": "2.0",
                    "id": request["id"],
                    "error": {"code": -32603, "message": f"启动任务失败: {result}"}
                }
                print(json.dumps(response), flush=True)
                continue
        except Exception as e:
            response = {
                "jsonrpc": "2.0",
                "id": request["id"],
                "error": {"code": -32603, "message": f"启动任务失败: {str(e)}"}
            }
            print(json.dumps(response), flush=True)
            continue
        
        time.sleep(2)
        response = None
        task_started = False
        
        for _ in range(6):
            time.sleep(5)
            try:
                status_url = f"{QINGLONG_URL}/open/crons/{task_id}"
                status_resp = requests.get(status_url, headers=headers, timeout=10)
                status_result = status_resp.json()
                
                if status_result.get("code") == 200:
                    cron = status_result["data"]
                    task_status = cron.get("status")
                    
                    # status: 0=运行中, 1=空闲
                    if task_status == 0:
                        task_started = True
                    elif task_status == 1 and task_started:
                        log_url = f"{QINGLONG_URL}/open/crons/{task_id}/log"
                        log_resp = requests.get(log_url, headers=headers, timeout=10)
                        log_result = log_resp.json()
                        
                        if log_result.get("code") == 200:
                            response = {
                                "jsonrpc": "2.0",
                                "id": request["id"],
                                "result": {"content": [{"type": "text", "text": log_result["data"]}]}
                            }
                        else:
                            response = {
                                "jsonrpc": "2.0",
                                "id": request["id"],
                                "error": {"code": -32603, "message": f"获取日志失败: {log_result}"}
                            }
                        break
            except Exception as e:
                response = {
                    "jsonrpc": "2.0",
                    "id": request["id"],
                    "error": {"code": -32603, "message": f"检查任务失败: {str(e)}"}
                }
                break
        
        if response is None:
            response = {
                "jsonrpc": "2.0",
                "id": request["id"],
                "result": {"content": [{"type": "text", "text": f"任务 {task_id} 超时(30秒),请使用 get_task_logs 查看日志"}]}
            }
  • Schema definition for the 'run_task' tool, specifying input as an object with required 'task_id' integer.
    {
        "name": "run_task",
        "description": "执行任务并等待完成,返回执行日志(最多等待30秒)",
        "inputSchema": {
            "type": "object",
            "properties": {
                "task_id": {"type": "integer", "description": "任务 ID"}
            },
            "required": ["task_id"]
        }
    },
  • server.py:77-156 (registration)
    Registration of all tools including 'run_task' in the tools/list MCP method response.
    response = {
        "jsonrpc": "2.0",
        "id": request["id"],
        "result": {
            "tools": [
                {
                    "name": "list_qinglong_tasks",
                    "description": "查询青龙面板中的所有定时任务列表",
                    "inputSchema": {
                        "type": "object",
                        "properties": {}
                    }
                },
                {
                    "name": "run_task",
                    "description": "执行任务并等待完成,返回执行日志(最多等待30秒)",
                    "inputSchema": {
                        "type": "object",
                        "properties": {
                            "task_id": {"type": "integer", "description": "任务 ID"}
                        },
                        "required": ["task_id"]
                    }
                },
                {
                    "name": "run_task_async",
                    "description": "异步启动任务,不等待执行完成",
                    "inputSchema": {
                        "type": "object",
                        "properties": {
                            "task_id": {"type": "integer", "description": "任务 ID"}
                        },
                        "required": ["task_id"]
                    }
                },
                {
                    "name": "get_task_logs",
                    "description": "获取青龙面板中指定任务的执行日志",
                    "inputSchema": {
                        "type": "object",
                        "properties": {
                            "task_id": {"type": "integer", "description": "任务 ID"}
                        },
                        "required": ["task_id"]
                    }
                },
                {
                    "name": "get_task_status",
                    "description": "获取青龙面板中指定任务的执行状态",
                    "inputSchema": {
                        "type": "object",
                        "properties": {
                            "task_id": {"type": "integer", "description": "任务 ID"}
                        },
                        "required": ["task_id"]
                    }
                },
                {
                    "name": "list_subscriptions",
                    "description": "查询青龙面板中的所有订阅列表",
                    "inputSchema": {
                        "type": "object",
                        "properties": {}
                    }
                },
                {
                    "name": "run_subscription",
                    "description": "运行指定的订阅",
                    "inputSchema": {
                        "type": "object",
                        "properties": {
                            "subscription_id": {"type": "integer", "description": "订阅 ID"}
                        },
                        "required": ["subscription_id"]
                    }
                }
            ]
        }
    }
    print(json.dumps(response), flush=True)
Behavior2/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool waits for completion (up to 30 seconds) and returns execution logs, which is useful. However, it lacks details on permissions needed, error handling, what happens if the task exceeds 30 seconds, or whether it's idempotent, which are critical for a mutation tool.

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 front-loaded, stating the core action and key constraint (30-second wait) in a single sentence. There's no wasted text, but it could be slightly more structured by separating the action from the behavioral details for clarity.

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 a task execution tool with no annotations and no output schema, the description is incomplete. It doesn't cover error cases, return format details beyond '执行日志', or interaction with sibling tools, leaving gaps for an AI agent to understand full behavior.

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 schema description coverage is 100%, with the parameter 'task_id' clearly documented as '任务 ID'. The description doesn't add any additional meaning beyond the schema, such as format examples or constraints, so it meets the baseline for high schema coverage without extra value.

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 action ('执行任务并等待完成') and the resource ('任务'), specifying that it runs a task and waits for completion. It distinguishes from sibling 'run_task_async' by explicitly mentioning synchronous waiting, but doesn't fully differentiate from other task-related tools like 'get_task_logs' or 'get_task_status' in terms of scope.

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 implies usage when you need to run a task and wait for its completion, with a 30-second timeout. However, it doesn't explicitly state when to use this vs. alternatives like 'run_task_async' (for asynchronous execution) or 'get_task_status' (for checking status without running), leaving some ambiguity in 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/pholex/qinglong-mcp-server'

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