Skip to main content
Glama

get_card_image

Retrieve Yu-Gi-Oh! card images by providing the card ID using the ygocdb-mcp server. Input the card ID to fetch and display the corresponding card image.

Instructions

通过卡牌ID获取游戏王卡牌的图片

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes游戏王卡牌ID,可以使用search_cards工具搜索

Implementation Reference

  • The core handler function that fetches the card image from the CDN URL, handles errors, converts the image to base64, and returns it embedded in the tool response.
    async function handleGetCardImage(id: string, config?: z.infer<typeof configSchema>) { const url = `https://cdn.233.momobako.com/ygopro/pics/${encodeURIComponent(id)}.jpg`; try { const response = await fetch(url); // 处理错误响应 if (!response.ok) { return { content: [ { type: "text", text: `获取卡牌图片失败: HTTP 错误 ${response.status}: ${response.statusText}` } ], isError: true }; } // 处理成功响应 - 读取图片数据 const buffer = await response.arrayBuffer(); const base64Data = Buffer.from(buffer).toString('base64'); const contentType = response.headers.get('content-type') || 'image/jpeg'; // 返回图像内容 return { content: [ { type: "text", text: `卡牌图片 (ID: ${id})` }, { type: "image", data: base64Data, mimeType: contentType } ], isError: false }; } catch (error) { // 捕获所有其他错误(网络错误、解析错误等) return { content: [ { type: "text", text: `获取卡牌图片失败: ${(error as Error).message}` } ], isError: true }; } }
  • Defines the tool schema with name, description, input schema (requires 'id' string), and annotations.
    const GET_CARD_IMAGE_TOOL: Tool = { name: "get_card_image", description: "通过卡牌ID获取游戏王卡牌的图片", inputSchema: { type: "object", properties: { id: { type: "string", description: "游戏王卡牌ID,可以使用search_cards工具搜索" } }, required: ["id"] }, annotations: { title: "通过ID获取游戏王卡牌图片", readOnlyHint: true, openWorldHint: true } };
  • index.ts:276-278 (registration)
    Registers the listTools handler which returns the array of tools including get_card_image.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: YGOCDB_TOOLS }));
  • index.ts:293-296 (registration)
    In the CallToolRequestSchema handler's switch statement, registers/dispatches the 'get_card_image' tool call to the handler function.
    case "get_card_image": { const { id } = args as { id: string }; return await handleGetCardImage(id, config); }
  • index.ts:136-140 (registration)
    Includes the get_card_image tool in the YGOCDB_TOOLS constant array used for tool listing.
    const YGOCDB_TOOLS = [ SEARCH_CARDS_TOOL, GET_CARD_BY_ID_TOOL, GET_CARD_IMAGE_TOOL ] as const;

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/ygocdb-mcp'

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