Skip to main content
Glama
raoulbia-ai

MCP Server for Intercom

search_conversations_by_customer

Retrieve customer-specific conversation history by email or ID, with optional date ranges and keyword filters. Use for analyzing past interactions with precision in Intercom support tickets.

Instructions

Searches for conversations by customer email or ID with optional date filtering.

Required: customerIdentifier (email/ID) Optional: startDate, endDate (DD/MM/YYYY format) Optional: keywords (array of terms to filter by)

Use when looking for conversation history with a specific customer.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
customerIdentifierYesCustomer email or ID to search for
endDateNoOptional end date in DD/MM/YYYY format (e.g., '21/01/2025')
keywordsNoOptional keywords to filter conversations by content
startDateNoOptional start date in DD/MM/YYYY format (e.g., '15/01/2025')

Implementation Reference

  • Core handler function that executes the tool: validates input with schema, fetches conversations via IntercomService.getConversationsByCustomer, formats and returns MCP-compliant response or error.
    async handleSearchConversationsByCustomer(args: unknown) {
        try {
            console.error("Handling search_conversations_by_customer request");
            
            // Validate and parse arguments
            const validatedArgs = SearchConversationsByCustomerSchema.parse(args);
            
            const customerIdentifier = validatedArgs.customerIdentifier;
            const startDateStr = validatedArgs.startDate;
            const endDateStr = validatedArgs.endDate;
            const keywords = validatedArgs.keywords;
            
            // Create Intercom service and retrieve conversations
            const intercomService = new IntercomService(this.API_BASE_URL, this.authToken);
            const conversations = await intercomService.getConversationsByCustomer(
                customerIdentifier,
                startDateStr,
                endDateStr,
                keywords
            );
            
            console.error(`Retrieved ${conversations.length} conversations for customer: ${customerIdentifier}`);
            
            return this.formatResponse(conversations);
        } catch (error) {
            console.error('Error handling search_conversations_by_customer:', error);
            
            // Enhanced error message for validation errors
            if (error instanceof Error && error.message.includes("customerIdentifier")) {
                return this.formatErrorResponse(error, 
                    `${error.message}\n\nPlease provide a valid customer email or ID, and optional dates in DD/MM/YYYY format (e.g., 15/01/2025)`
                );
            }
            
            return this.formatErrorResponse(error);
        }
    }
  • Zod schema defining and validating tool inputs: required customerIdentifier, optional startDate/endDate/keywords with date transformation and validation.
    export const SearchConversationsByCustomerSchema = z.object({
        // Required customer identifier parameter
        customerIdentifier: z.string({
            required_error: "customerIdentifier is required (email or ID)"
        }),
        
        // Optional date range parameters in DD/MM/YYYY format
        startDate: z.string().optional().refine(val => !val || /^\d{2}\/\d{2}\/\d{4}$/.test(val), {
            message: "startDate must be in DD/MM/YYYY format (e.g., 15/01/2025)"
        }),
        
        endDate: z.string().optional().refine(val => !val || /^\d{2}\/\d{2}\/\d{4}$/.test(val), {
            message: "endDate must be in DD/MM/YYYY format (e.g., 21/01/2025)"
        }),
        
        // Optional keywords array for filtering conversations
        keywords: z.array(z.string()).optional().describe("Array of keywords to filter conversations by content")
    }).transform(data => {
        console.error("Raw arguments received:", JSON.stringify(data));
        
        try {
            // Convert DD/MM/YYYY to ISO strings if provided
            if (data.startDate) {
                data.startDate = validateAndTransformDate(data.startDate, true);
            }
            
            if (data.endDate) {
                data.endDate = validateAndTransformDate(data.endDate, false);
            }
            
            // Validate date range if both dates are provided
            if (data.startDate && data.endDate) {
                validateDateRange(data.startDate, data.endDate);
            }
            
        } catch (e) {
            // Throw error to be caught by the handler
            console.error(`Error processing date parameters: ${e}`);
            throw new Error(`${e instanceof Error ? e.message : 'Invalid date format'} - Please provide dates in DD/MM/YYYY format (e.g., 15/01/2025)`);
        }
        
        console.error("Final parameters:", JSON.stringify(data));
        return data;
    });
  • src/index.ts:25-50 (registration)
    Tool registration in MCP server capabilities, specifying name, description, and input parameters schema.
    search_conversations_by_customer: {
        description: "Searches for conversations by customer email or ID with optional date filtering.",
        parameters: {
            type: "object",
            required: ["customerIdentifier"],
            properties: {
                customerIdentifier: {
                    type: "string",
                    description: "Customer email or ID to search for"
                },
                startDate: {
                    type: "string",
                    description: "Optional start date in DD/MM/YYYY format (e.g., '15/01/2025')"
                },
                endDate: {
                    type: "string",
                    description: "Optional end date in DD/MM/YYYY format (e.g., '21/01/2025')"
                },
                keywords: {
                    type: "array",
                    items: { type: "string" },
                    description: "Optional keywords to filter conversations by content"
                }
            }
        }
    },
  • Dispatcher in call_tool request handler that routes requests for this tool to the specific ToolHandlers method.
    case "search_conversations_by_customer":
        console.error("Handling search_conversations_by_customer request");
        return await toolHandlers.handleSearchConversationsByCustomer(args);
  • Tool metadata provided in list_tools response, including detailed description and input schema.
                        name: "search_conversations_by_customer",
                        description: `Searches for conversations by customer email or ID with optional date filtering.
    
    Required: customerIdentifier (email/ID)
    Optional: startDate, endDate (DD/MM/YYYY format)
    Optional: keywords (array of terms to filter by)
    
    Use when looking for conversation history with a specific customer.`,
                        inputSchema: {
                            type: "object",
                            required: ["customerIdentifier"],
                            properties: {
                                customerIdentifier: {
                                    type: "string",
                                    description: "Customer email or ID to search for"
                                },
                                startDate: {
                                    type: "string",
                                    description: "Optional start date in DD/MM/YYYY format (e.g., '15/01/2025')"
                                },
                                endDate: {
                                    type: "string",
                                    description: "Optional end date in DD/MM/YYYY format (e.g., '21/01/2025')"
                                },
                                keywords: {
                                    type: "array",
                                    items: { type: "string" },
                                    description: "Optional keywords to filter conversations by content"
                                }
                            }
                        },
                    },
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions optional date filtering and keywords, but lacks critical behavioral details like whether this is a read-only operation, what permissions are needed, how results are returned (e.g., pagination), or error handling. For a search tool with no annotation coverage, this is a significant gap.

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?

Perfectly concise and well-structured: first sentence states purpose, bullet points clarify parameters, and final sentence provides usage guidance. Every sentence earns its place with zero waste, and information is front-loaded appropriately.

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 no annotations and no output schema, the description is incomplete for a search tool. It covers purpose and parameters well, but misses behavioral aspects like result format, pagination, or error cases. However, it's adequate for basic usage, so it meets the minimum viable threshold.

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 minimal value by restating that customerIdentifier is required and dates/keywords are optional, but doesn't provide additional context beyond what's in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose5/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 with a specific verb ('searches') and resource ('conversations'), and distinguishes it from siblings by specifying it searches by customer email/ID rather than listing all conversations or searching tickets. The title being null doesn't affect this clarity.

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

Usage Guidelines5/5

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

Explicitly states when to use this tool ('Use when looking for conversation history with a specific customer'), which differentiates it from sibling tools like list_conversations (general listing) and search_tickets_by_customer (ticket-focused). No when-not guidance, but the context is clear enough for full credit.

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

Related 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/raoulbia-ai/mcp-server-for-intercom'

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