Skip to main content
The Query API MCP server provides 5 tools for querying consented user data. Each tool maps 1:1 to a Query API sync endpoint.
Tools use session credentials by default (provided during connection). You can override per-tool by passing auth_token and uid parameters.

Tool: get_search_data

Retrieve user search history (Google searches).

Parameters

ParameterTypeRequiredDescription
auth_tokenstringNo*Base64-encoded JWT (starts with eyJ...). Not the user ID.
uidstringNo*Consented user ID (typically starts with psub_). Not the auth token.
beginstringNoStart time filter (ISO 8601)
endstringNoEnd time filter (ISO 8601)
ingested_beginstringNoIngestion start (for delta queries)
ingested_endstringNoIngestion end (for delta queries)
categorystringNoFilter by category (e.g., “/Shopping”)
cursorstringNoPagination cursor from previous response
limitnumberNoMax results per request (default 100, max 1000)
Either provide in tool call or use session credentials from connection

Response Format

{
  "success": true,
  "count": 2,
  "has_more": true,
  "next_cursor": "eyJsYXN0X2V2ZW50X2lkIjoxMjM0NX0=",
  "applied_ingested_end": "2024-01-15T10:30:00Z",
  "data": [
    {
      "event_id": 12345,
      "user_id": "psub_e5f6789012345678901234abcdef0123",
      "query": "best restaurants nearby",
      "title": "best restaurants nearby - Google Search",
      "url": "https://www.google.com/search?q=best+restaurants+nearby",
      "timestamp": "2024-01-15T10:30:00Z",
      "category": "/Food/Restaurants",
      "intent": "find",
      "brands": ["Google"],
      "ingested_at": "2024-01-15T11:00:00Z"
    },
    {
      "event_id": 12346,
      "user_id": "psub_e5f6789012345678901234abcdef0123",
      "query": "laptop deals",
      "title": "laptop deals - Google Search",
      "url": "https://www.google.com/search?q=laptop+deals",
      "timestamp": "2024-01-15T14:20:00Z",
      "category": "/Shopping/Electronics",
      "intent": "buy",
      "brands": ["Google"],
      "ingested_at": "2024-01-15T14:25:00Z"
    }
  ]
}

Example Usage

"Get search history from January 1-15, 2024, filtered by Shopping category"

Tool: get_youtube_data

Retrieve user YouTube watch history and interactions.

Parameters

ParameterTypeRequiredDescription
auth_tokenstringNo*Base64-encoded JWT (starts with eyJ...). Not the user ID.
uidstringNo*Consented user ID (typically starts with psub_). Not the auth token.
beginstringNoStart time filter (ISO 8601)
endstringNoEnd time filter (ISO 8601)
ingested_beginstringNoIngestion start (for delta queries)
ingested_endstringNoIngestion end (for delta queries)
categorystringNoFilter by category (e.g., “/Music”)
cursorstringNoPagination cursor
limitnumberNoMax results per request
Either provide in tool call or use session credentials from connection

Response Format

{
  "success": true,
  "count": 1,
  "has_more": false,
  "next_cursor": null,
  "applied_ingested_end": "2024-01-15T10:30:00Z",
  "data": [
    {
      "event_id": 67890,
      "user_id": "psub_e5f6789012345678901234abcdef0123",
      "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
      "title": "Example Video Title",
      "timestamp": "2024-01-15T10:30:00Z",
      "category": "/Entertainment/Music",
      "brands": ["YouTube"],
      "ingested_at": "2024-01-15T11:00:00Z"
    }
  ]
}

Example Usage

"Show me YouTube videos watched in the last 3 days"

Tool: get_browsing_data

Retrieve user web browsing history (Chrome).

Parameters

ParameterTypeRequiredDescription
auth_tokenstringNo*Base64-encoded JWT (starts with eyJ...). Not the user ID.
uidstringNo*Consented user ID (typically starts with psub_). Not the auth token.
beginstringNoStart time filter (ISO 8601)
endstringNoEnd time filter (ISO 8601)
ingested_beginstringNoIngestion start (for delta queries)
ingested_endstringNoIngestion end (for delta queries)
categorystringNoFilter by category (e.g., “/Shopping”)
cursorstringNoPagination cursor
limitnumberNoMax results per request
Either provide in tool call or use session credentials from connection

Response Format

{
  "success": true,
  "count": 1,
  "has_more": true,
  "next_cursor": "eyJsYXN0X2lkIjogNjc4OX0=",
  "applied_ingested_end": "2024-01-15T10:30:00Z",
  "data": [
    {
      "event_id": 45678,
      "user_id": "psub_e5f6789012345678901234abcdef0123",
      "url": "https://example.com/product",
      "title": "Product Page - Example Store",
      "timestamp": "2024-01-15T10:30:00Z",
      "category": "/Shopping",
      "page_category": "/Shopping/Electronics",
      "brands": ["Example Store"],
      "ingested_at": "2024-01-15T11:00:00Z"
    }
  ]
}

Example Usage

"Find browsing history related to cooking recipes from last month"

Tool: get_ads_data

Retrieve user ad interactions (clicks and views).

Parameters

ParameterTypeRequiredDescription
auth_tokenstringNo*Base64-encoded JWT (starts with eyJ...). Not the user ID.
uidstringNo*Consented user ID (typically starts with psub_). Not the auth token.
beginstringNoStart time filter (ISO 8601)
endstringNoEnd time filter (ISO 8601)
ingested_beginstringNoIngestion start (for delta queries)
ingested_endstringNoIngestion end (for delta queries)
categorystringNoFilter by category
cursorstringNoPagination cursor
limitnumberNoMax results per request
Either provide in tool call or use session credentials from connection

Response Format

{
  "success": true,
  "count": 1,
  "has_more": false,
  "next_cursor": null,
  "applied_ingested_end": "2024-01-15T10:30:00Z",
  "data": [
    {
      "event_id": 23456,
      "user_id": "psub_e5f6789012345678901234abcdef0123",
      "url": "https://ads.example.com/click?id=abc123",
      "title": "Shop Electronics - Example Brand",
      "source_domain": "news.example.com",
      "landing_domain": "shop.examplebrand.com",
      "ad_network": "Google Ads",
      "timestamp": "2024-01-15T10:30:00Z",
      "category": "/Shopping/Electronics",
      "brands": ["Example Brand"],
      "ingested_at": "2024-01-15T11:00:00Z"
    }
  ]
}

Example Usage

"Show me ad interactions from the last week"

Tool: get_receipts_data

Retrieve user purchase receipts (email receipts).

Parameters

ParameterTypeRequiredDescription
auth_tokenstringNo*Base64-encoded JWT (starts with eyJ...). Not the user ID.
uidstringNo*Consented user ID (typically starts with psub_). Not the auth token.
beginstringNoStart time filter (ISO 8601)
endstringNoEnd time filter (ISO 8601)
ingested_beginstringNoIngestion start (for delta queries)
ingested_endstringNoIngestion end (for delta queries)
categorystringNoFilter by category
cursorstringNoPagination cursor
limitnumberNoMax results per request
Either provide in tool call or use session credentials from connection

Response Format

{
  "success": true,
  "count": 1,
  "has_more": false,
  "next_cursor": null,
  "applied_ingested_end": "2024-01-15T10:30:00Z",
  "data": [
    {
      "event_id": 98765,
      "user_id": "psub_e5f6789012345678901234abcdef0123",
      "retailer_name": "Example Store",
      "total_value": 49.99,
      "receipt_currency": "USD",
      "subject": "Purchase Receipt - Example Store",
      "timestamp": "2024-01-15T10:30:00Z",
      "category": "/Shopping/Retail",
      "brands": ["Example Store"],
      "items": [],
      "ingested_at": "2024-01-15T11:00:00Z"
    }
  ]
}

Example Usage

"Find all purchases over $100 from the last month"

Common Patterns

Pagination

All tools support cursor-based pagination for large datasets:
  1. Make initial request (no cursor parameter)
  2. Check response has_more field
  3. If true, use next_cursor in next request
  4. Repeat until has_more = false
let allData = [];
let cursor = null;

do {
  const result = await mcpTool.call('get_search_data', {
    begin: '2024-01-01T00:00:00Z',
    limit: 1000,
    cursor: cursor
  });

  allData.push(...result.data);
  cursor = result.next_cursor;
} while (result.has_more);

Delta Queries

Use ingested_begin/ingested_end to fetch only new data since last sync:
  1. Store last_sync_time after each sync
  2. Next sync: set ingested_begin = last_sync_time
  3. Update last_sync_time to response applied_ingested_end
  4. Repeat on subsequent syncs
This avoids re-fetching unchanged data.

Category Filtering

Categories use slash-delimited hierarchical paths:
  • /Shopping - All shopping data
  • /Shopping/Electronics - Electronics only
  • /Food/Restaurants - Restaurant searches/visits
Categories are assigned by Emerge’s classification system. Not all events have categories.

Error Handling

When a tool call fails, it returns an error structure:
{
  "isError": true,
  "content": [
    {
      "type": "text",
      "text": "Error: 401 Unauthorized - Invalid API token. Verify your auth_token is correct."
    }
  ]
}
Common error codes:
  • 401: Invalid credentials
  • 400: Invalid parameters (e.g., malformed timestamp)
  • 404: User not found (no consent)
  • 429: Rate limit exceeded
  • 500: Server error (retry with exponential backoff)

Best Practices

Use limit: 1000 for balanced performance and memory
Always check has_more for complete dataset retrieval
Use ingested_begin/end for incremental syncs
Apply category filters to reduce data volume
Handle errors gracefully with retry logic

Rate Limits

Per API token limits:
  • 100 requests/minute
  • 1000 requests/hour
Exceeding limits returns HTTP 429. Wait before retrying or contact support for higher limits.

Next Steps

Setup Guide

Configure AI tools to use these tools

Query API Reference

HTTP API equivalents

Examples

See workflow examples

MCP Query Setup

Architecture and configuration