Skip to main content
Glama
Cappybara12

OpenXAI MCP Server

by Cappybara12

generate_explanation

Generate explanations for AI model predictions using methods like LIME, SHAP, or integrated gradients to understand how models make decisions.

Instructions

Generate explanations for model predictions using OpenXAI explainers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodYesExplanation method to use (lime, shap, integrated_gradients, etc.)
data_sampleYesJSON string of the input data sample to explain
model_infoYesInformation about the model being explained

Implementation Reference

  • The handler function that implements the core logic for the 'generate_explanation' tool. It validates the explanation method and returns a structured response with a Python code example for using OpenXAI's Explainer.
      async generateExplanation(method, dataSample, modelInfo) {
        const methods = ['lime', 'shap', 'integrated_gradients', 'gradcam', 'guided_backprop'];
        
        if (!methods.includes(method)) {
          throw new Error(`Method '${method}' not supported. Available methods: ${methods.join(', ')}`);
        }
    
        const codeExample = `
    # Example usage with OpenXAI:
    from openxai import Explainer
    from openxai import LoadModel
    from openxai.dataloader import ReturnLoaders
    
    # Load the model and data
    model = LoadModel(data_name='${modelInfo.data_name}', ml_model='${modelInfo.ml_model}', pretrained=True)
    trainloader, testloader = ReturnLoaders(data_name='${modelInfo.data_name}', download=True)
    
    # Initialize the explainer
    explainer = Explainer(method='${method}', model=model)
    
    # Generate explanations
    inputs, labels = next(iter(testloader))
    explanations = explainer.get_explanations(inputs)
    
    print(f"Explanation shape: {explanations.shape}")
    print(f"Explanation values: {explanations}")
    `;
    
        return {
          content: [
            {
              type: 'text',
              text: `Generated explanation using ${method.toUpperCase()}\n\n` +
                    `Method: ${method}\n` +
                    `Dataset: ${modelInfo.data_name}\n` +
                    `Model: ${modelInfo.ml_model}\n` +
                    `Data sample: ${dataSample}\n\n` +
                    `Python code example:\n\`\`\`python${codeExample}\`\`\``
            }
          ]
        };
      }
  • The input schema definition for the 'generate_explanation' tool, including properties for method, data_sample, and model_info, as returned in the list_tools response.
    {
      name: 'generate_explanation',
      description: 'Generate explanations for model predictions using OpenXAI explainers',
      inputSchema: {
        type: 'object',
        properties: {
          method: {
            type: 'string',
            description: 'Explanation method to use (lime, shap, integrated_gradients, etc.)',
            enum: ['lime', 'shap', 'integrated_gradients', 'gradcam', 'guided_backprop']
          },
          data_sample: {
            type: 'string',
            description: 'JSON string of the input data sample to explain'
          },
          model_info: {
            type: 'object',
            description: 'Information about the model being explained',
            properties: {
              data_name: { type: 'string' },
              ml_model: { type: 'string' }
            }
          }
        },
        required: ['method', 'data_sample', 'model_info']
      }
    },
  • index.js:270-272 (registration)
    The switch case in the CallToolRequestHandler that registers and dispatches calls to the generateExplanation handler for the 'generate_explanation' tool.
    case 'generate_explanation':
      return await this.generateExplanation(args.method, args.data_sample, args.model_info);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks critical behavioral details such as computational requirements, output format, error handling, or rate limits. This is inadequate for a tool that likely involves complex model interactions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of model explanation tasks, no annotations, and no output schema, the description is insufficient. It doesn't explain what the explanations look like, how they are returned, or any behavioral constraints, leaving significant gaps for effective tool use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting all three parameters and their purposes. The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline but doesn't enhance understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Generate explanations') and the resource ('model predictions using OpenXAI explainers'), making the purpose evident. However, it doesn't explicitly differentiate from sibling tools like 'evaluate_explanation' or 'list_explainers', which would require more specific scope definition to achieve a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, appropriate contexts, or comparisons to siblings like 'evaluate_explanation' or 'list_explainers', leaving the agent without usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/Cappybara12/mcpopenxAI'

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