Skip to main content
Glama

android-mcp-toolkit

convert-svg-to-android-drawable

Convert SVG markup or files into Android VectorDrawable XML for Android development, with options to write to disk and customize precision, colors, and formatting.

Instructions

Convert SVG markup or files into Android VectorDrawable XML quickly, optionally writing to disk.

Input Schema

NameRequiredDescriptionDefault
svgNoInline SVG markup to convert
svgPathNoPath to an SVG file to read
outputPathNoOptional output path for generated VectorDrawable XML
floatPrecisionNoDecimal precision when serializing coordinates
fillBlackNoForce fill color black when missing
xmlTagNoInclude XML declaration
tintNoAndroid tint color (e.g. #FF000000)
cacheNoReuse cached result for identical inputs within this process

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "cache": { "default": true, "description": "Reuse cached result for identical inputs within this process", "type": "boolean" }, "fillBlack": { "default": false, "description": "Force fill color black when missing", "type": "boolean" }, "floatPrecision": { "default": 2, "description": "Decimal precision when serializing coordinates", "maximum": 6, "minimum": 0, "type": "integer" }, "outputPath": { "description": "Optional output path for generated VectorDrawable XML", "minLength": 1, "type": "string" }, "svg": { "description": "Inline SVG markup to convert", "minLength": 1, "type": "string" }, "svgPath": { "description": "Path to an SVG file to read", "minLength": 1, "type": "string" }, "tint": { "description": "Android tint color (e.g. #FF000000)", "minLength": 1, "type": "string" }, "xmlTag": { "default": false, "description": "Include XML declaration", "type": "boolean" } }, "type": "object" }

Implementation Reference

  • Registers the 'convert-svg-to-android-drawable' tool with the MCP server, specifying title, description, and input schema.
    server.registerTool( 'convert-svg-to-android-drawable', { title: 'SVG to VectorDrawable', description: 'Convert SVG markup or files into Android VectorDrawable XML quickly, optionally writing to disk.', inputSchema: convertInputSchema },
  • The handler function that loads SVG, applies caching, calls the svg2vectordrawable converter, handles output file writing if specified, logs timing, and returns the XML content.
    async (params, extra) => { const svgCode = await loadSvg(params); const options = { floatPrecision: params.floatPrecision, fillBlack: params.fillBlack, xmlTag: params.xmlTag, tint: params.tint }; const cacheKey = makeCacheKey(svgCode, options); const startTime = process.hrtime.bigint(); let xml = null; if (params.cache) { xml = getCached(cacheKey); } if (!xml) { xml = await svg2vectordrawable(svgCode, options); if (!xml || typeof xml !== 'string') { throw new Error('Conversion did not produce XML'); } setCache(cacheKey, xml); } const savedPath = await maybeWriteOutput(params.outputPath, xml); const elapsedMs = Number(process.hrtime.bigint() - startTime) / 1_000_000; if (extra && typeof extra.sessionId === 'string') { server .sendLoggingMessage( { level: 'info', data: `Converted SVG in ${elapsedMs.toFixed(2)}ms` + (savedPath ? ` (saved to ${savedPath})` : '') }, extra.sessionId ) .catch(() => { /* best-effort logging */ }); } const content = []; if (savedPath) { content.push({ type: 'text', text: `Saved VectorDrawable to ${savedPath}` }); } content.push({ type: 'text', text: xml }); return { content }; }
  • Zod schema defining the input parameters for the tool, including SVG source, output options, precision, caching, etc.
    const convertInputSchema = z .object({ svg: z.string().min(1).describe('Inline SVG markup to convert').optional(), svgPath: z.string().min(1).describe('Path to an SVG file to read').optional(), outputPath: z .string() .min(1) .describe('Optional output path for generated VectorDrawable XML') .optional(), floatPrecision: z .number() .int() .min(0) .max(6) .default(2) .describe('Decimal precision when serializing coordinates'), fillBlack: z.boolean().default(false).describe('Force fill color black when missing'), xmlTag: z.boolean().default(false).describe('Include XML declaration'), tint: z.string().min(1).optional().describe('Android tint color (e.g. #FF000000)'), cache: z .boolean() .default(true) .describe('Reuse cached result for identical inputs within this process') }) .refine(data => data.svg || data.svgPath, { message: 'Provide either svg or svgPath' });
  • src/index.js:20-20 (registration)
    Calls the registerSvgTool function to register the SVG conversion tool with the main MCP server instance.
    registerSvgTool(server);
  • Helper functions for loading SVG from inline or file path, and optionally writing the output XML to a file.
    async function loadSvg(params) { if (params.svg) return params.svg; const resolvedPath = path.resolve(params.svgPath); return fs.readFile(resolvedPath, 'utf8'); } async function maybeWriteOutput(outputPath, xml) { if (!outputPath) return null; const resolvedPath = path.resolve(outputPath); await fs.mkdir(path.dirname(resolvedPath), { recursive: true }); await fs.writeFile(resolvedPath, xml, 'utf8'); return resolvedPath; }

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/Nam0101/android-mcp-toolkit'

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