Skip to main content
Glama
Suixinlei

Tongyi Wanxiang MCP Server

by Suixinlei

wanx-t2i-image-generation-result

Fetch text-to-image generation results using Alibaba Cloud's Tongyi Wanxiang API. Designed for integration via TypeScript MCP server to process task IDs and retrieve visual outputs.

Instructions

获取阿里云万相文生图大模型的文生图结果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
task_idYes

Implementation Reference

  • The core handler function for the "wanx-t2i-image-generation-result" tool. It takes a task_id, polls the task status until completion using the helper pollTaskUntilDone, and returns the results as a text content block with JSON stringified output.
    async ({ task_id }) => { const result = await pollTaskUntilDone(task_id); return { content: [{ type: "text", text: JSON.stringify(result.output.results) }], }; }
  • Zod schema for the tool input parameters: requires a 'task_id' string.
    { task_id: z.string() },
  • src/index.ts:40-50 (registration)
    Registration of the MCP tool "wanx-t2i-image-generation-result" using McpServer.tool(), specifying name, Chinese description, input schema, and handler function.
    server.tool( "wanx-t2i-image-generation-result", "获取阿里云万相文生图大模型的文生图结果", { task_id: z.string() }, async ({ task_id }) => { const result = await pollTaskUntilDone(task_id); return { content: [{ type: "text", text: JSON.stringify(result.output.results) }], }; } );
  • Helper function that polls the Alibaba Cloud Wanxiang task status using getTaskStatus until it succeeds, fails, or times out. Directly called by the tool handler.
    export const pollTaskUntilDone = async (taskId: string) => { let retries = 0; while (retries < config.maxRetries) { const taskData = await getTaskStatus(taskId); const status = taskData.output.task_status; if (status === "SUCCEEDED" || status === "FAILED") { return taskData; } // 等待一段时间后再次查询 await new Promise((resolve) => setTimeout(resolve, config.pollingInterval)); retries++; } throw new Error("Task polling timeout"); };
  • Supporting helper that queries the task status from the API endpoint `/tasks/{taskId}` using axios and the configured API key. Called by pollTaskUntilDone.
    export const getTaskStatus = async (taskId: string) => { try { const apiKey = config.api.apiKey; if (!apiKey) { throw new Error("API key is not configured"); } const response = await axios.get(`${config.api.baseUrl}/tasks/${taskId}`, { headers: { Authorization: `Bearer ${apiKey}`, }, }); return response.data; } catch (error: any) { if (error.response) { throw new Error( error.response.data.message || "Failed to get task status" ); } throw error; } };

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/Suixinlei/tongyi-wanx-mcp-server'

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