Skip to main content
Glama
yangjeep

Searchspring Integration Assistant

by yangjeep

searchspring_code_validator

Validate Searchspring implementation code to identify errors and ensure proper integration with e-commerce platforms.

Instructions

Validate and troubleshoot Searchspring implementation code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesJavaScript/HTML code to validate
codeTypeYesType of Searchspring implementation being validated
platformNoE-commerce platform (optional)
issueNoSpecific issue or error message you're experiencing (optional)

Implementation Reference

  • Core handler function implementing the searchspring_code_validator tool. Performs comprehensive static code analysis for Searchspring API implementations, validates endpoints, required parameters, tracking calls, platform compatibility (Shopify, BigCommerce, etc.), error handling, and provides actionable feedback including troubleshooting for specific issues.
      async validateCode(params: CodeValidationParams) {
        const { code, codeType, platform, issue } = params;
        const siteId = this.getSiteIdOrExample();
    
        const validationResults: string[] = [];
        const warnings: string[] = [];
        const suggestions: string[] = [];
    
        // Common validation checks
        if (codeType === "tracking" || codeType === "beacon") {
          // Check for IntelliSuggest script inclusion
          if (!code.includes("cdn.searchspring.net/intellisuggest") && !code.includes("is.min.js")) {
            validationResults.push("❌ Missing IntelliSuggest script: <script src='//cdn.searchspring.net/intellisuggest/is.min.js'></script>");
          } else {
            validationResults.push("✅ IntelliSuggest script inclusion detected");
          }
    
          // Check for ss.track usage
          if (!code.includes("ss.track")) {
            validationResults.push("❌ No tracking calls found (ss.track.product.view, ss.track.cart.add, ss.track.purchase.buy)");
          } else {
            validationResults.push("✅ Tracking calls detected");
          }
    
          // Check for typeof ss check
          if (!code.includes("typeof ss")) {
            warnings.push("⚠️  Consider adding safety check: if (typeof ss != 'undefined')");
          }
    
          // Check for required tracking fields
          if (code.includes("ss.track.product") && !code.includes("sku")) {
            validationResults.push("❌ Product tracking missing required 'sku' field");
          }
    
          if (code.includes("ss.track.cart") && (!code.includes("sku") || !code.includes("quantity"))) {
            validationResults.push("❌ Cart tracking missing required 'sku' and/or 'quantity' fields");
          }
    
          if (code.includes("ss.track.purchase") && (!code.includes("sku") || !code.includes("quantity"))) {
            validationResults.push("❌ Purchase tracking missing required 'sku' and/or 'quantity' fields");
          }
        }
    
        if (codeType === "search" || codeType === "autocomplete" || codeType === "suggest" || codeType === "trending" || codeType === "finder" || codeType === "recommendations") {
          // Check for API endpoint
          if (!code.includes(".a.searchspring.io")) {
            validationResults.push("❌ Missing Searchspring API endpoint (should include .a.searchspring.io)");
          } else {
            validationResults.push("✅ Searchspring API endpoint detected");
          }
    
          // Check for required parameters
          if (!code.includes("siteId")) {
            validationResults.push("❌ Missing required 'siteId' parameter");
          } else {
            validationResults.push("✅ siteId parameter detected");
          }
    
          if (!code.includes("userId") && !code.includes("sessionId")) {
            warnings.push("⚠️  Missing tracking parameters (userId, sessionId) - these are required for analytics");
          }
    
          // API-specific validations
          if (codeType === "search" && !code.includes("q=")) {
            validationResults.push("❌ Search API missing query parameter 'q'");
          }
    
          if (codeType === "autocomplete" && !code.includes("debounce")) {
            warnings.push("⚠️  Consider implementing debouncing for autocomplete to reduce API calls");
          }
    
          if (codeType === "recommendations" && !code.includes("pageLoadId")) {
            warnings.push("⚠️  Recommendations work better with pageLoadId parameter");
          }
    
          // Check for error handling
          if (!code.includes(".catch") && !code.includes("try")) {
            warnings.push("⚠️  No error handling detected - consider adding .catch() or try/catch");
          }
        }
    
        if (codeType === "beacon") {
          // Check for beacon endpoint
          if (!code.includes("beacon.searchspring.io")) {
            validationResults.push("❌ Missing Beacon API endpoint (should be beacon.searchspring.io)");
          } else {
            validationResults.push("✅ Beacon API endpoint detected");
          }
    
          // Check for POST method
          if (!code.includes("POST")) {
            validationResults.push("❌ Beacon API requires POST method");
          }
    
          // Check for required beacon fields
          if (!code.includes("type")) {
            validationResults.push("❌ Beacon tracking missing required 'type' field");
          }
        }
    
        if (codeType === "bulk-index") {
          // Check for bulk index endpoint
          if (!code.includes("index-api.searchspring.net")) {
            validationResults.push("❌ Missing Bulk Index API endpoint (should be index-api.searchspring.net)");
          } else {
            validationResults.push("✅ Bulk Index API endpoint detected");
          }
    
          // Check for secret key
          if (!code.includes("secretKey")) {
            validationResults.push("❌ Bulk Index API requires 'secretKey' parameter");
          }
    
          // Check for products array
          if (!code.includes("products")) {
            validationResults.push("❌ Bulk Index API missing 'products' array");
          }
        }
    
        // Platform-specific checks
        if (platform === "shopify") {
          if (codeType === "tracking" && !code.includes("{{")) {
            warnings.push("⚠️  No Liquid template variables detected - make sure you're using Shopify's template syntax");
          }
    
          if (code.includes("product.variants.first.sku") && !code.includes("product.selected_or_first_available_variant.sku")) {
            suggestions.push("💡 Consider using product.selected_or_first_available_variant.sku for better variant handling");
          }
    
          // Check for modern Shopify checkout extensibility
          if (codeType === "tracking" && code.includes("ss.track.purchase.buy") && code.includes("order.line_items")) {
            warnings.push("⚠️  IMPORTANT: For Shopify stores with checkout extensibility, sales tracking must use Web Pixel apps instead of thank you page code");
            suggestions.push("💡 Modern Shopify: Contact Searchspring support for Web Pixel app setup (https://help.searchspring.net/hc/en-us/articles/24882106349467)");
          }
        }
    
        if (platform === "bigcommerce") {
          if (codeType === "tracking" && !code.includes("{{#") && !code.includes("{{")) {
            warnings.push("⚠️  No Handlebars template syntax detected - make sure you're using BigCommerce's Stencil template syntax");
          }
    
          if (code.includes("product.sku") && !code.includes("{{product.sku}}")) {
            suggestions.push("💡 Use {{product.sku}} for BigCommerce Stencil template syntax");
          }
        }
    
        if (platform === "magento2") {
          if (codeType === "tracking" && !code.includes("<?=")) {
            warnings.push("⚠️  No PHP template syntax detected - make sure you're using Magento's .phtml syntax");
          }
    
          if (code.includes("$_product") && !code.includes("escapeHtml")) {
            suggestions.push("💡 Use $block->escapeHtml() for proper data escaping in Magento 2");
          }
        }
    
        // Issue-specific troubleshooting
        let troubleshooting = "";
        if (issue) {
          troubleshooting = `
    
    Troubleshooting for: "${issue}"
    `;
    
          if (issue.toLowerCase().includes("not working") || issue.toLowerCase().includes("not tracking")) {
            troubleshooting += `Common causes:
    - IntelliSuggest script not loaded or blocked by ad blockers
    - Script placed in wrong location (should be in <head> or before tracking calls)
    - Missing _isuid cookie (check browser dev tools > Application > Cookies)
    - SKU values don't match Searchspring indexed product SKU field
    - Browser console errors preventing script execution
    - SHOPIFY SPECIFIC: Modern Shopify stores with checkout extensibility require Web Pixel apps for sales tracking
    `;
          }
    
          if (issue.toLowerCase().includes("undefined") || issue.toLowerCase().includes("is not defined")) {
            troubleshooting += `Script loading issue:
    - Ensure IntelliSuggest script loads before your tracking code
    - Remove async/defer attributes from the IntelliSuggest script tag
    - Check browser console for script loading errors
    `;
          }
    
          if (issue.toLowerCase().includes("shopify") && issue.toLowerCase().includes("sales")) {
            troubleshooting += `Shopify sales tracking issues:
    - Modern Shopify (checkout extensibility): Use Web Pixel apps instead of thank you page
    - Traditional Shopify: Add code to order-status-url template
    - Contact Searchspring support for Web Pixel app setup
    - Verify _isuid cookie is being set correctly
    - Documentation: https://help.searchspring.net/hc/en-us/articles/24882106349467
    `;
          }
    
          if (issue.toLowerCase().includes("search") || issue.toLowerCase().includes("results")) {
            troubleshooting += `API integration issues:
    - Verify siteId is correct: ${siteId}
    - Check CORS settings if calling from browser
    - Ensure all required parameters are included
    - Check network tab for API response errors
    `;
          }
        }
    
        const summary = `Code Validation Results for ${codeType.toUpperCase()} implementation${platform ? ` on ${platform.toUpperCase()}` : ''}
    
    ${validationResults.join('\n')}
    
    ${warnings.length > 0 ? `Warnings:\n${warnings.join('\n')}\n` : ''}${suggestions.length > 0 ? `Suggestions:\n${suggestions.join('\n')}\n` : ''}${troubleshooting}
    For additional support:
    - Documentation: https://docs.searchspring.com/
    - Support: https://help.searchspring.net/
    - Implementation guides: https://help.searchspring.net/hc/en-us/sections/201185149`;
    
        return {
          content: [
            {
              type: "text",
              text: summary,
            },
          ],
        };
      }
  • src/index.ts:99-127 (registration)
    Tool registration definition including name, description, and complete inputSchema for validation parameters (code, codeType, platform, issue). Added to the tools array returned by ListToolsRequest.
      {
        name: "searchspring_code_validator",
        description: "Validate and troubleshoot Searchspring implementation code",
        inputSchema: {
          type: "object",
          properties: {
            code: {
              type: "string",
              description: "JavaScript/HTML code to validate",
            },
            codeType: {
              type: "string",
              enum: ["search", "autocomplete", "suggest", "trending", "recommendations", "finder", "beacon", "bulk-index", "tracking"],
              description: "Type of Searchspring implementation being validated",
            },
            platform: {
              type: "string",
              enum: ["shopify", "bigcommerce", "magento2", "custom", "other"],
              description: "E-commerce platform (optional)",
            },
            issue: {
              type: "string",
              description: "Specific issue or error message you're experiencing (optional)",
            },
          },
          required: ["code", "codeType"],
        },
      },
    ];
  • MCP CallToolRequest handler dispatch that routes calls to the searchspring_code_validator tool to the underlying SearchspringClient.validateCode method.
    case "searchspring_code_validator":
      return await searchspringClient.validateCode(args as any);
  • TypeScript interface defining the input parameters for code validation, mirroring the tool's inputSchema for type safety.
    export interface CodeValidationParams {
      code: string;
      codeType: "search" | "autocomplete" | "suggest" | "trending" | "recommendations" | "finder" | "beacon" | "bulk-index" | "tracking";
      platform?: "shopify" | "bigcommerce" | "magento1" | "magento2" | "miva" | "commercev3" | "3dcart" | "volusion" | "custom" | "other";
      issue?: string;
    }
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 the tool validates and troubleshoots code, implying it performs analysis and returns diagnostic information, but doesn't describe the output format, error handling, or any limitations (e.g., rate limits, supported code complexity). For a validation tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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's front-loaded with the core functionality ('Validate and troubleshoot'), making it immediately clear. Every word earns its place, and there's no redundancy or fluff.

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

Completeness3/5

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

Given the tool's moderate complexity (4 parameters, validation/troubleshooting function) and no output schema, the description is minimally adequate but incomplete. It lacks details on output format, error cases, or behavioral traits, which are important for a validation tool. However, the schema provides good parameter documentation, partially compensating for the description's brevity.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional semantic context about parameters beyond what's in the schema (e.g., it doesn't explain how 'codeType' influences validation or what 'platform' affects). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't detract either.

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 tool's purpose as 'Validate and troubleshoot Searchspring implementation code', specifying the action (validate/troubleshoot) and resource (Searchspring implementation code). It distinguishes from sibling tools like 'searchspring_code_generator' (which creates code) and 'searchspring_api_guide' (which provides documentation), though it doesn't explicitly contrast with them in the description text.

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 the sibling tools (searchspring_api_guide, searchspring_code_generator, searchspring_parameter_guide) or specify scenarios where validation/troubleshooting is appropriate versus generating code or consulting guides. Usage is implied but not explicitly stated.

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/yangjeep/playground-searchspring-api-assist-mcp'

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