Skip to main content
Glama

search_cards

Read-only

Search Magic: The Gathering cards using advanced query strings with support for pagination, sorting, and deduplication. Retrieve card data efficiently for applications or workflows based on specific criteria like type, color, power, or text.

Instructions

通过查询字符串搜索卡牌,支持分页和排序。

查询语法示例:

  • t:creature c:r (红色生物)

  • pow>=5 or mv<2 (力量大于等于5或法术力值小于2)

  • o:"draw a card" -c:u (包含"抓一张牌"的非蓝色牌)

  • (t:instant or t:sorcery) mv<=3 (3费或以下的瞬间或法术)

分页参数:

  • page: 页码 (整数, 默认 1)

  • page_size: 每页数量 (整数, 默认 20, 最大 100)

排序参数:

  • order: 按字段排序,逗号分隔。前缀 - 表示降序 (例如: name, -mv, name,-rarity) 默认排序: name

其他参数:

  • unique: 去重方式 (id, oracle_id, illustration_id)

  • priority_chinese: 是否优先显示中文卡牌

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderNo排序字段 (例如: name, -mv, rarity)
pageNo页码 (默认 1)
page_sizeNo每页数量 (默认 20,最大 100)
priority_chineseNo是否优先显示中文卡牌 (默认 true)
qYes查询字符串,例如 't:creature c:r'、'pow>=5 or mv<2'、's:TDM -t:creature'
uniqueNo去重方式: id(不去重), oracle_id(按卡牌名去重), illustration_id(按插图去重)

Implementation Reference

  • The main handler function that implements the logic for the 'search_cards' tool by building the API query URL with parameters and fetching the response from the SBWSZ API.
    async function handleSearchCards(
      q: string, 
      page?: number, 
      pageSize?: number, 
      order?: string, 
      unique?: string, 
      priorityChinese?: boolean,
      config?: z.infer<typeof configSchema>
    ) {
      // 构建查询 URL
      let url = `${config?.apiUrl || BASE_URL}/result?q=${encodeURIComponent(q)}`;
      
      // 添加可选参数
      if (page !== undefined) url += `&page=${page}`;
      if (pageSize !== undefined) url += `&page_size=${pageSize}`;
      if (order !== undefined) url += `&order=${encodeURIComponent(order)}`;
      if (unique !== undefined) url += `&unique=${encodeURIComponent(unique)}`;
      if (priorityChinese !== undefined) url += `&priority_chinese=${priorityChinese}`;
      
      const response = await fetch(url);
      return handleSbwszResponse(response);
    }
  • Tool definition including name, detailed description, input schema with parameters (q, page, page_size, etc.), and annotations for the 'search_cards' tool.
    const SEARCH_CARDS_TOOL: Tool = {
      name: "search_cards",
      description:
        "通过查询字符串搜索卡牌,支持分页和排序。\n\n" +
        "**查询语法示例:**\n" +
        "- `t:creature c:r` (红色生物)\n" +
        "- `pow>=5 or mv<2` (力量大于等于5或法术力值小于2)\n" +
        "- `o:\"draw a card\" -c:u` (包含\"抓一张牌\"的非蓝色牌)\n" +
        "- `(t:instant or t:sorcery) mv<=3` (3费或以下的瞬间或法术)\n\n" +
        "**分页参数:**\n" +
        "- `page`: 页码 (整数, 默认 1)\n" +
        "- `page_size`: 每页数量 (整数, 默认 20, 最大 100)\n\n" +
        "**排序参数:**\n" +
        "- `order`: 按字段排序,逗号分隔。前缀 `-` 表示降序\n" +
        "  (例如: `name`, `-mv`, `name,-rarity`)\n" +
        "  默认排序: `name`\n\n" +
        "**其他参数:**\n" +
        "- `unique`: 去重方式 (id, oracle_id, illustration_id)\n" +
        "- `priority_chinese`: 是否优先显示中文卡牌",
      inputSchema: {
        type: "object",
        properties: {
          q: {
            type: "string",
            description: "查询字符串,例如 't:creature c:r'、'pow>=5 or mv<2'、's:TDM -t:creature'"
          },
          page: {
            type: "integer",
            description: "页码 (默认 1)"
          },
          page_size: {
            type: "integer",
            description: "每页数量 (默认 20,最大 100)"
          },
          order: {
            type: "string",
            description: "排序字段 (例如: name, -mv, rarity)"
          },
          unique: {
            type: "string",
            description: "去重方式: id(不去重), oracle_id(按卡牌名去重), illustration_id(按插图去重)"
          },
          priority_chinese: {
            type: "boolean",
            description: "是否优先显示中文卡牌 (默认 true)"
          }
        },
        required: ["q"]
      },
      annotations: {
        title: "通过查询字符串搜索卡牌",
        readOnlyHint: true,
        openWorldHint: true
      }
    };
  • index.ts:268-276 (registration)
    Array of all tools including SEARCH_CARDS_TOOL, used for listing available tools.
    // 返回我们的工具集
    const SBWSZ_TOOLS = [
      GET_CARD_BY_SET_AND_NUMBER_TOOL,
      SEARCH_CARDS_TOOL,
      GET_SETS_TOOL,
      GET_SET_TOOL,
      GET_SET_CARDS_TOOL,
      HZLS_TOOL
    ] as const;
  • index.ts:487-489 (registration)
    Registers the list of tools (including search_cards) for MCP ListTools requests.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: SBWSZ_TOOLS
    }));
  • Switch case dispatcher that extracts arguments and calls the search_cards handler function.
    case "search_cards": {
      const { q, page, page_size, order, unique, priority_chinese } = args as { 
        q: string; 
        page?: number; 
        page_size?: number; 
        order?: string; 
        unique?: string; 
        priority_chinese?: boolean 
      };
      return await handleSearchCards(q, page, page_size, order, unique, priority_chinese, config);
Behavior4/5

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

Annotations already provide readOnlyHint=true and openWorldHint=true, indicating safe read operations with open-ended queries. The description adds valuable behavioral context beyond annotations by specifying pagination limits (max 100 per page), default sorting ('name'), and priority for Chinese cards, which are not covered by annotations. No contradictions with annotations exist.

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

Conciseness5/5

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

The description is well-structured and appropriately sized, with clear sections for query syntax, pagination, sorting, and other parameters. Each sentence adds specific value (e.g., syntax examples, defaults, limits) without redundancy, making it efficient and easy to parse for an AI agent.

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 the tool's complexity (6 parameters, query-based search) and lack of output schema, the description is mostly complete, covering key behaviors like syntax, pagination, and sorting. However, it does not describe the return format (e.g., structure of card results) or error handling, leaving a minor gap for an agent to infer output details.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds some semantic context, such as query syntax examples and default values for pagination/sorting, but does not provide significant new information beyond what the schema describes (e.g., parameter meanings are already clear in schema). Baseline 3 is appropriate given high schema coverage.

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's purpose as searching cards via query strings with support for pagination and sorting. It specifies the exact action ('搜索卡牌') and resource ('卡牌'), distinguishing it from sibling tools like get_card_by_set_and_number (which fetches a specific card) or get_set_cards (which lists cards in a set without querying).

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

Usage Guidelines4/5

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

The description provides clear context for usage by detailing query syntax, pagination, and sorting, which implicitly guides when to use this tool for flexible searches. However, it does not explicitly state when to use alternatives like get_set_cards for set-specific listings or when not to use this tool (e.g., for simple lookups), missing explicit exclusions or named alternatives.

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

Related 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/lieyanqzu/sbwsz-mcp'

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