mcpdata Request an invite

Answers / Connect your AI

How do I use the same data from Python and from my AI?

Recipe verified on Ran on the public demo (read-only)
Short answer

Point both at the same instance: your AI over MCP, Python with the cdb client and the same address. They read the same tables, so the number in your notebook and the number in the AI's answer are the same number.

Steps

  1. Connect your assistant to the public demo. It's a read-only instance with 10 million synthetic orders, so you can try this before you have your own. In Claude Code:
    claude mcp add --transport http mcpdata-demo https://demo.mcpdata.org/mcp --header "Authorization: Bearer cdb_live_PkVoldus8qcE-hqffjajNZzQwiA7rTHMoR4RLSAxsCE"

    The key is public on purpose: it can only read the demo's sample data. For Claude Desktop, Cursor and other apps, see Connect your AI.

  2. From Python. Install the client (pip install https://demo.mcpdata.org/help/download/cdb-0.3.4-py3-none-any.whl), set CDB_API_KEY to the demo key, then:
    import cdb
    s = cdb.Session("https://demo.mcpdata.org")
    df = s.execute_sql("SELECT region, SUM(revenue) AS revenue FROM Demo.Orders "
                       "WHERE order_year = 2025 GROUP BY region ORDER BY region").to_dataframe()
    print(df.to_string(index=False))
  3. Ask your question. Give your AI this prompt:
    Using mcpdata, total revenue per region in Demo.Orders for 2025.
What your AI does: the tool call it makes for this prompt, and what came back
query(table_name="Demo.Orders", filters=[{"column": "order_year", "op": "eq", "value": 2025}], group_by=["region"], agg=[{"func": "sum", "column": "revenue", "alias": "revenue"}], sort=[{"column": "region", "desc": false}]) → 3 rows
Output of the steps above, from the last run
region      revenue
Americas 8.644176e+08
    APAC 4.138674e+08
    EMEA 7.822569e+08
What you should get · the recipe's real result from its last run
regionrevenue
Americas864,417,603
APAC413,867,443
EMEA782,256,894

Synthetic data: the demo's orders are generated, not real customers.

The assistant needs mcpdata connected (step 1) to run the query.

Why this works

Exports copied between tools drift apart. One database with two ways in (MCP for the assistant; Python, JDBC or the workbench for you) keeps one version of the truth. The Python code below and the AI's call return identical totals.

Related questions