Skip to main content
Glama

list_files

List result files for a task to see available outputs. Provide the task ID to get the file list.

Instructions

列出任务的结果文件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
task_idYes
serverNodefault

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler function that makes HTTP GET request to /api/v1/client/files/list/{task_id} to retrieve task file list, formats file info (id, filename, size, created_at), and returns structured result with error handling.
    def list_files(server_url, api_key, task_id):
        """
        获取任务文件列表
    
        Args:
            server_url: 服务端基础地址
            api_key: API 密钥
            task_id: 任务 ID
        """
        if not api_key:
            return {"error": "缺少 API Key,请先运行 register 进行注册"}
    
        if not task_id:
            return {"error": "缺少 task_id"}
    
        server_url = server_url.rstrip("/")
        url = f"{server_url}/api/v1/client/files/list/{task_id}"
    
        try:
            headers = {
                "Authorization": f"Bearer {api_key}"
            }
            req = urllib.request.Request(url, headers=headers, method="GET")
    
            with urllib.request.urlopen(req, timeout=30) as response:
                result = json.loads(response.read().decode("utf-8"))
                files = result if isinstance(result, list) else result.get("files", [])
    
                formatted = []
                for f in files:
                    formatted.append({
                        "file_id": f.get("id") or f.get("file_id"),
                        "filename": f.get("filename", ""),
                        "size": f.get("size", 0),
                        "created_at": f.get("created_at", "")
                    })
    
                return {
                    "content": f"任务 {task_id} 共有 {len(formatted)} 个文件",
                    "data": {
                        "task_id": task_id,
                        "files": formatted
                    }
  • MCP tool handler decorated with @mcp.tool() that lists task result files by calling the same API endpoint with server config and auth, returning a formatted string of file details.
    @mcp.tool()
    def list_files(task_id: str, server: str = "default") -> str:
        """列出任务的结果文件"""
        if not task_id:
            return "❌ 缺少必填参数: task_id"
    
        try:
            sc = get_server_config(server)
            api_key = require_api_key(server)
        except RuntimeError as e:
            return f"❌ {e}"
    
        server_url = strip_trailing_slash(sc.get("server_url", ""))
        url = f"{server_url}/api/v1/client/files/list/{quote(task_id, safe='')}"
    
        try:
            result = safe_request(
                "GET", url, headers={"Authorization": f"Bearer {api_key}"}
            )
        except OpenAaaSError as e:
            return f"❌ 获取文件列表失败: {e}"
    
        files = result if isinstance(result, list) else result.get("files", [])
        if not files:
            return f"任务 {task_id} 没有结果文件"
    
        lines = [f"任务 {task_id} 共有 {len(files)} 个结果文件:"]
        for i, f in enumerate(files):
            if not isinstance(f, dict):
                continue
            filename = f.get("filename") or f.get("name", "unnamed")
            file_id = f.get("id") or f.get("file_id", "")
            size = f.get("size")
            if size is None:
                size = f.get("file_size", "未知")
            lines.append(f"{i + 1}. {filename} (ID: {file_id}, 大小: {size})")
    
        return "\n".join(lines)
  • Registered as an MCP tool via the @mcp.tool() decorator on the list_files method.
    @mcp.tool()
    def list_files(task_id: str, server: str = "default") -> str:
Behavior2/5

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

No annotations are provided, so the description must convey behavioral traits. It only states that the tool lists files, implying read-only behavior, but omits details such as behavior on invalid task_id, pagination, sorting, or potential errors. The description is too minimal to be transparent.

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

Conciseness3/5

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

The description is very short (one phrase), which is concise, but it lacks structure and important details. While brevity is valued, it sacrifices clarity and completeness. It is minimally acceptable but not well-structured.

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 no annotations and the existence of an unrevealed output schema, the description is incomplete. It does not describe the return value, error conditions, or relationship to sibling tools like download_result. The tool requires more context for proper use.

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

Parameters1/5

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

Schema description coverage is 0%, and the description adds no meaning to the parameters. 'task_id' and 'server' are not explained; their semantics must be inferred from the names alone. The description fails to provide any additional context beyond the schema.

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 '列出任务的结果文件' (list result files of a task) clearly specifies the action 'list' and the resource 'result files of a task'. It is distinct from sibling tools like download_result or cancel_task, making the purpose unambiguous.

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?

No usage guidance is provided. The description does not indicate when to use this tool versus alternatives like discover or download_result, nor does it mention prerequisites or conditions (e.g., task must exist).

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/Wolido/OpenAaaS'

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