Skip to main content
Glama
Augmented-Nature

PubChem MCP Server

search_similar_compounds

Find chemically similar compounds in PubChem using Tanimoto similarity. Input a SMILES string, set a similarity threshold, and retrieve relevant results for chemical analysis.

Instructions

Find chemically similar compounds using Tanimoto similarity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_recordsNoMaximum number of results (1-10000, default: 100)
smilesYesSMILES string of the query molecule
thresholdNoSimilarity threshold (0-100, default: 90)

Implementation Reference

  • The main handler function that validates input using isValidSmilesArgs, performs POST request to PubChem similarity endpoint with SMILES, threshold, and maxRecords, and returns the JSON response.
    private async handleSearchSimilarCompounds(args: any) {
      if (!isValidSmilesArgs(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid similarity search arguments');
      }
    
      try {
        const threshold = args.threshold || 90;
        const maxRecords = args.max_records || 100;
    
        const response = await this.apiClient.post('/compound/similarity/smiles/JSON', {
          smiles: args.smiles,
          Threshold: threshold,
          MaxRecords: maxRecords,
        });
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(response.data, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to search similar compounds: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • Input schema definition for the search_similar_compounds tool, specifying required SMILES and optional threshold/max_records parameters.
    inputSchema: {
      type: 'object',
      properties: {
        smiles: { type: 'string', description: 'SMILES string of the query molecule' },
        threshold: { type: 'number', description: 'Similarity threshold (0-100, default: 90)', minimum: 0, maximum: 100 },
        max_records: { type: 'number', description: 'Maximum number of results (1-10000, default: 100)', minimum: 1, maximum: 10000 },
      },
      required: ['smiles'],
    },
  • src/index.ts:754-755 (registration)
    Switch case in the main CallToolRequestSchema handler that routes calls to search_similar_compounds to the specific handler function.
    case 'search_similar_compounds':
      return await this.handleSearchSimilarCompounds(args);
  • src/index.ts:441-453 (registration)
    Tool registration in the ListToolsRequestSchema response, including name, description, and input schema.
    {
      name: 'search_similar_compounds',
      description: 'Find chemically similar compounds using Tanimoto similarity',
      inputSchema: {
        type: 'object',
        properties: {
          smiles: { type: 'string', description: 'SMILES string of the query molecule' },
          threshold: { type: 'number', description: 'Similarity threshold (0-100, default: 90)', minimum: 0, maximum: 100 },
          max_records: { type: 'number', description: 'Maximum number of results (1-10000, default: 100)', minimum: 1, maximum: 10000 },
        },
        required: ['smiles'],
      },
    },
  • Type guard function used to validate inputs for SMILES-based searches, including similarity search.
    const isValidSmilesArgs = (
      args: any
    ): args is { smiles: string; threshold?: number; max_records?: number } => {
      return (
        typeof args === 'object' &&
        args !== null &&
        typeof args.smiles === 'string' &&
        args.smiles.length > 0 &&
        (args.threshold === undefined || (typeof args.threshold === 'number' && args.threshold >= 0 && args.threshold <= 100)) &&
        (args.max_records === undefined || (typeof args.max_records === 'number' && args.max_records > 0 && args.max_records <= 10000))
      );
    };

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/PubChem-MCP-Server'

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