Skip to main content
The Query API MCP server gives AI agents (Claude, Cursor, VS Code) secure access to consented user data. Instead of making direct HTTP calls, AI tools use the Model Context Protocol with session-based credentials.
Different from Docs MCP: This server queries user data. For documentation search, see Docs MCP Setup.

Architecture

The MCP server is a thin wrapper around Query API sync endpoints:
FeatureMCP ServerDirect HTTP
ProtocolMCP (JSON-RPC over HTTP)REST API
CredentialsSession-based (provide once)Per-request (Bearer token)
Tool DiscoveryBuilt-in (tools/list)OpenAPI spec
Ship with MCPNative supportManual implementation
Best ForAI agents, IDE pluginsServer-to-server, custom apps

Prerequisites

The Control Room account with API credentials
At least one user with granted consent
Don’t have credentials? Sign up here.

MCP Server URL

https://mcp.emergedata.ai/mcp
Authentication: Session-based credentials passed via URL parameters during initialization.

Setup by Tool

Add MCP Server

claude mcp add emerge-query "https://mcp.emergedata.ai/mcp?auth_token=YOUR_TOKEN&uid=YOUR_UID"

Verify Connection

claude mcp list
You should see:
emerge-query: https://mcp.emergedata.ai/mcp (connected)

Usage

Now you can query user data:
claude "Get search history for psub_c3d4e5f6789012345678901234abcdef from the last week"
Claude Code will:
  1. Call the get_search_data tool
  2. Apply date range filters
  3. Return formatted results

Verify Connection

After configuration, test the health endpoint:
curl https://mcp.emergedata.ai/mcp/health

# Expected response
{
  "status": "ok",
  "service": "mcp-server",
  "version": "1.0.0",
  "protocol": "streamable-http"
}

Session Credentials

The MCP server uses session-based credentials — provide them once on connection, and all tool calls use them automatically.
CredentialWhat it isFormatExample
auth_tokenBase64-encoded JWT from The Control RoomStarts with eyJ... (long string)eyJhbGciOiJSUzI1NiIs...
uidConsented user identifier from consent callbackTypically starts with psub_psub_c3d4e5f6789012345678901234abcdef
Don’t mix these up! A common mistake is swapping auth_token and uid. The auth_token is always a long JWT string starting with eyJ. The uid is a shorter identifier, typically starting with psub_.
You can override session credentials for individual tool calls by passing auth_token and uid as tool parameters.

Security Best Practices

Never commit credentials to git repositories
Use environment variables in configuration files
Rotate API tokens regularly via The Control Room
Use unique uid per user (don’t share across users)

Available Tools

The MCP server exposes 5 tools that map 1:1 to Query API sync endpoints:
MCP ToolQuery API EndpointData Type
get_search_data/v1/sync/get_searchSearch history
get_youtube_data/v1/sync/get_youtubeYouTube watch history
get_browsing_data/v1/sync/get_browsingWeb browsing
get_ads_data/v1/sync/get_adsAd interactions
get_receipts_data/v1/sync/get_receiptsPurchase receipts
See MCP Query Tools for detailed parameter and response documentation.

Response Format

All tools return the same structure:
{
  "success": true,
  "count": 10,
  "has_more": true,
  "next_cursor": "eyJsYXN0X2V2ZW50X2lkIjoxMjM0NX0=",
  "applied_ingested_end": "2024-01-15T10:30:00Z",
  "data": [
    // ... event objects
  ]
}

Pagination

Use cursor-based pagination for large datasets:
let cursor = null;
let allData = [];

do {
  const result = await use_mcp_tool({
    tool: "get_search_data",
    arguments: {
      begin: "2024-01-01T00:00:00Z",
      limit: 1000,
      cursor: cursor
    }
  });

  allData.push(...result.data);
  cursor = result.next_cursor;
} while (result.has_more);
See Pagination Guide for best practices.

Error Handling

When a tool call fails, it returns:
{
  "isError": true,
  "content": [
    {
      "type": "text",
      "text": "Detailed error message"
    }
  ]
}
Common errors:
  • 401 Unauthorized: Invalid or missing credentials
  • 400 Bad Request: Invalid parameters (e.g., malformed timestamp)
  • 500 Internal Server Error: Query API or database error

Example Queries

"Get search history for psub_c3d4e5f6789012345678901234abcdef from the last 7 days filtered by Shopping category"
The AI agent will:
  1. Parse your natural language query
  2. Select the appropriate MCP tool
  3. Apply filters and parameters
  4. Return formatted results

Troubleshooting

Cause: Invalid or missing credentialsSolutions:
  • Verify auth_token is correct from The Control Room
  • Check that user has granted consent (callback status=success)
  • Ensure credentials are in the connection URL
  • Try refreshing/rotating your API token
Cause: No data available for querySolutions:
  • Data export may still be processing (watch for data.ready/data.failed webhooks or poll GET /export/status/{uid} until provider data_ready: true)
  • User may not have data for the requested type
  • Check time filters (begin/end) aren’t excluding all data
  • Verify category filter isn’t too restrictive
Cause: Cannot reach MCP serverSolutions:
  • Verify MCP server URL is exactly https://mcp.emergedata.ai/mcp
  • Check firewall/network settings allow HTTPS outbound
  • Test health endpoint: curl https://mcp.emergedata.ai/mcp/health
  • Contact support if server appears down
Cause: MCP connection not establishedSolutions:
  • Restart your AI tool after adding configuration
  • Verify config file is in the correct location
  • Check file permissions (must be readable)
  • Review AI tool logs for MCP connection errors

Rate Limits

The MCP server inherits rate limits from the Query API:
  • Requests: 100 requests per minute per auth token
  • Data: 10,000 events per request (recommended: 1000)
  • Concurrent: 10 simultaneous connections per organization
Exceeding limits returns HTTP 429 errors. Contact support for higher limits.

Source Code

The MCP server is open-source:

Next Steps

Tool Reference

Detailed documentation for all 5 tools

Query Guide

Learn about sync vs async queries

Examples

See AI workflow examples

Webhooks

Track consent and data export lifecycle changes