Skip to main content
Glama

get_chemical_image

Generate chemical structure images from SMILES or other notations to visualize molecular compounds for research and documentation.

Instructions

Generate chemical structure image from SMILES or other structure notation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
structureYesSMILES string or other structure notation
heightNoImage height in pixels (default: 200)
widthNoImage width in pixels (default: 200)

Implementation Reference

  • The main handler function that validates input arguments, calls the SureChEMBL API endpoint '/service/chemical/image' with structure notation and dimensions, receives image as binary data, encodes it as base64 PNG data URI, and returns structured JSON response.
    private async handleGetChemicalImage(args: any) { if (!isValidImageArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid image arguments'); } try { const height = args.height || 200; const width = args.width || 200; const response = await this.apiClient.get('/service/chemical/image', { params: { structure: args.structure, height: height, width: width }, responseType: 'arraybuffer' }); // Convert binary data to base64 for JSON response const base64Image = Buffer.from(response.data).toString('base64'); return { content: [ { type: 'text', text: JSON.stringify({ structure: args.structure, image_data: `data:image/png;base64,${base64Image}`, dimensions: { width, height }, message: 'Chemical structure image generated successfully' }, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to generate chemical image: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
  • JSON schema defining input parameters for the tool: required 'structure' string (SMILES or notation), optional 'height' and 'width' numbers (50-1000).
    inputSchema: { type: 'object', properties: { structure: { type: 'string', description: 'SMILES string or other structure notation' }, height: { type: 'number', description: 'Image height in pixels (default: 200)', minimum: 50, maximum: 1000 }, width: { type: 'number', description: 'Image width in pixels (default: 200)', minimum: 50, maximum: 1000 }, }, required: ['structure'], },
  • src/index.ts:435-447 (registration)
    Full tool registration entry in the ListToolsRequestSchema handler's tools array, including name, description, and input schema.
    { name: 'get_chemical_image', description: 'Generate chemical structure image from SMILES or other structure notation', inputSchema: { type: 'object', properties: { structure: { type: 'string', description: 'SMILES string or other structure notation' }, height: { type: 'number', description: 'Image height in pixels (default: 200)', minimum: 50, maximum: 1000 }, width: { type: 'number', description: 'Image width in pixels (default: 200)', minimum: 50, maximum: 1000 }, }, required: ['structure'], }, },
  • src/index.ts:562-563 (registration)
    Switch case in CallToolRequestSchema handler that dispatches execution to the specific tool handler.
    case 'get_chemical_image': return await this.handleGetChemicalImage(args);
  • Type guard function validating tool input arguments matching the schema: non-empty structure string, optional height/width in 1-1000 range.
    const isValidImageArgs = ( args: any ): args is { structure: string; height?: number; width?: number } => { return ( typeof args === 'object' && args !== null && typeof args.structure === 'string' && args.structure.length > 0 && (args.height === undefined || (typeof args.height === 'number' && args.height > 0 && args.height <= 1000)) && (args.width === undefined || (typeof args.width === 'number' && args.width > 0 && args.width <= 1000)) ); };

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/Augmented-Nature/SureChEMBL-MCP-Server'

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