GetChartImgLink
Generate chart images by providing Quick Chart API parameters in JSON format. Create and retrieve chart visualization links for data representation.
Instructions
To draw chart and get chart image link by parameters, and parameter grammar follows Quick Chart API (quickchart.io).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| json | No | quick chart api's (quickchart.io) parameters and format is JSON object. The object does not include any functions, only values. |
Implementation Reference
- src/tools/agent/getChartImgLink.ts:12-36 (handler)Core handler function implementing the logic to generate a QuickChart image link from the provided JSON chart configuration.export default async function getChartImgLink( agent: Client, json: any, ) { try { let jsonStr = '{}'; try { jsonStr = JSON.stringify(json || '{}'); } catch (e) { console.error(e); } if (jsonStr && (jsonStr?.includes('{') || jsonStr?.includes(',') || jsonStr?.includes('['))) { jsonStr = bestEffortForJson(jsonStr); jsonStr = encodeURIComponent(jsonStr); // check need to encodeURIComponent } const response = `${quickChartUrl}?c=${jsonStr || ''}`; return response; } catch (error: any) { throw new Error(`getChartImgLink failed: ${error.message}`); } }
- Wrapper handler for the GetChartImgLink MCP tool that extracts input, calls the core getChartImgLink function, handles errors, and returns a standardized response.handler: async (agent: Client, input: Record<string, any>) => { try { const { json } = input || {}; const response = await getChartImgLink(agent, json); return { status: "success", message: response, }; } catch (error: any) { // Handle specific error types if (error.response) { const { status, data } = error.response; if (status === 429) { return { status: "error", message: "Rate limit exceeded. Please try again later.", }; } return { status: "error", message: `error: ${data.error?.message || error.message}`, }; } return { status: "error", message: `Failed to get information: ${error.message}`, }; } },
- Zod schema defining the input structure for the GetChartImgLink tool: a JSON object for QuickChart parameters.schema: z.object({ json: z.any().describe("quick chart api's (quickchart.io) parameters and format is JSON object. The object does not include any functions, only values."), }),
- src/actions/index.ts:6-8 (registration)Registers the GetChartImgLink ActionTool in the ACTIONS map, which is used by the MCP server to expose tools.const ACTIONS: any = { [EnumAction.GET_CHART_IMG_LINK]: getChartImgLink, }
- src/constants/index.ts:8-9 (registration)Defines the string name 'GetChartImgLink' for the tool in EnumAction.'GET_CHART_IMG_LINK' = 'GetChartImgLink', 'INSTALL_QUICK_CHART' = 'InstallQuickChart',