Skip to main content

Overview

This guide demonstrates how to integrate Explorium’s MCP (Model Context Protocol) server with LangGraph to build intelligent AI agents that can access Explorium’s business data enrichment capabilities. LangGraph provides a framework for building stateful, multi-actor applications with LLMs, making it perfect for creating sophisticated business intelligence workflows.

Prerequisites

Before you begin, ensure you have:
  • Python 3.11 or higher
  • An Explorium API key
  • An Anthropic API key (or another LLM provider API key)
  • A Python environment (Databricks, Jupyter, or local)

Installation

Install the required packages using pip:
For Databricks environments, use the following commands in separate cells:
Then restart the Python kernel:

Quick Start

Here’s a minimal example to get you started:

Core Components

1. Required Imports

Start by importing all necessary libraries:

2. Define Configuration and State

Create the necessary data structures for your agent:

3. System Prompt

Define a system prompt that guides your agent’s behavior:

Complete Implementation

Here’s a full implementation of a LangGraph agent with Explorium MCP integration:

Running the Agent

Create a function to run your LangGraph agent:

Available Explorium Tools

The MCP integration provides access to the following Explorium tools:
  • match-business - Match and identify businesses
  • fetch-businesses - Retrieve business information
  • fetch-businesses-statistics - Get business statistics
  • fetch-businesses-events - Fetch business events
  • enrich-business - Enrich business data with additional attributes
  • match-prospects - Match prospect contacts
  • fetch-prospects - Retrieve prospect information
  • fetch-prospects-events - Fetch prospect events
  • fetch-prospects-statistics - Get prospect statistics
  • enrich-prospects - Enrich prospect data
  • autocomplete - Autocomplete suggestions for field values

Security Best Practices

Environment Variables

Store your API keys as environment variables:
Set environment variables before running:

Databricks Secrets

For Databricks environments, use the secrets management system:

Alternative LLM Providers

While this guide uses Anthropic’s Claude, you can use other LLM providers:

Advanced Features

Custom Tool Selection

Filter and select specific tools for your agent:

Custom Message Handling

Implement custom logic for different message types:

Error Handling

Implement comprehensive error handling:

Batch Processing

Process multiple queries efficiently:

Example Output

When running the agent with a query like “Find 10 product managers from Microsoft”, you’ll see:

Troubleshooting

Authentication Errors

Problem: AuthenticationError: Error code: 401 - invalid x-api-key Solution:
  1. Verify your Anthropic API key is valid and active
  2. Check the API key format (should start with sk-ant-api03-)
  3. Ensure you’re using a valid model name:
    • Claude: claude-3-5-sonnet-20241022, claude-3-opus-20240229
    • OpenAI: gpt-4, gpt-4-turbo

Connection Issues

Problem: Cannot connect to MCP server Solution:
  1. Verify your Explorium API key is correct
  2. Check the endpoint URL is exactly: https://mcp.explorium.ai/mcp
  3. Test your network connectivity
  4. Ensure firewall rules allow HTTPS connections

Tool Loading Issues

Problem: No tools loaded or tools not working Solution:
  1. Ensure you’re within an active MCP session context
  2. Check the langchain_mcp_adapters version is up to date:
  3. Verify the session is initialized before loading tools

API Reference

MCP Configuration

  • Endpoint: https://mcp.explorium.ai/mcp
  • Transport: Streamable HTTP
  • Authentication: API key in headers
  • Headers Format: {"api_key": "your-api-key"}

Support and Resources