Use Grok to Talk to Your Amazon Athena Data via CData Connect AI

Anusha M B
Anusha M B
Technical Marketing Engineer
Leverage the CData Connect AI Remote MCP Server to enable Grok AI to securely answer questions and take actions on your Amazon Athena data for you.

Grok AI is a large language model developed by xAI for real-time reasoning, tool invocation, and agentic workflows. It enables developers to build AI agents that can reason over live data, discover tools dynamically, and take intelligent actions.

CData Connect AI provides a secure cloud-to-cloud interface for integrating 350+ enterprise data sources with Grok AI. Using Connect AI, live Amazon Athena data is exposed through a remote MCP endpoint without replication, allowing Grok AI agents to securely query and analyze governed enterprise data in real time.

About Amazon Athena Data Integration

CData provides the easiest way to access and integrate live data from Amazon Athena. Customers use CData connectivity to:

  • Authenticate securely using a variety of methods, including IAM credentials, access keys, and Instance Profiles, catering to diverse security needs and simplifying the authentication process.
  • Streamline their setup and quickly resolve issue with detailed error messaging.
  • Enhance performance and minimize strain on client resources with server-side query execution.

Users frequently integrate Athena with analytics tools like Tableau, Power BI, and Excel for in-depth analytics from their preferred tools.

To learn more about unique Amazon Athena use cases with CData, check out our blog post: https://www.cdata.com/blog/amazon-athena-use-cases.


Getting Started


Step 1: Configure Amazon Athena in CData Connect AI

To enable Grok to query live Amazon Athena data, first create a Amazon Athena connection in CData Connect AI. This connection is exposed through the CData Remote MCP Server.

  1. Log into Connect AI, click Sources, and then click Add Connection.
  2. Select "Amazon Athena" from the Add Connection panel.
  3. Enter the required authentication properties.

    Authenticating to Amazon Athena

    To authorize Amazon Athena requests, provide the credentials for an administrator account or for an IAM user with custom permissions: Set AccessKey to the access key Id. Set SecretKey to the secret access key.

    Note: Though you can connect as the AWS account administrator, it is recommended to use IAM user credentials to access AWS services.

    Obtaining the Access Key

    To obtain the credentials for an IAM user, follow the steps below:

    1. Sign into the IAM console.
    2. In the navigation pane, select Users.
    3. To create or manage the access keys for a user, select the user and then select the Security Credentials tab.

    To obtain the credentials for your AWS root account, follow the steps below:

    1. Sign into the AWS Management console with the credentials for your root account.
    2. Select your account name or number and select My Security Credentials in the menu that is displayed.
    3. Click Continue to Security Credentials and expand the Access Keys section to manage or create root account access keys.

    Authenticating from an EC2 Instance

    If you are using the CData Data Provider for Amazon Athena 2018 from an EC2 Instance and have an IAM Role assigned to the instance, you can use the IAM Role to authenticate. To do so, set UseEC2Roles to true and leave AccessKey and SecretKey empty. The CData Data Provider for Amazon Athena 2018 will automatically obtain your IAM Role credentials and authenticate with them.

    Authenticating as an AWS Role

    In many situations it may be preferable to use an IAM role for authentication instead of the direct security credentials of an AWS root user. An AWS role may be used instead by specifying the RoleARN. This will cause the CData Data Provider for Amazon Athena 2018 to attempt to retrieve credentials for the specified role. If you are connecting to AWS (instead of already being connected such as on an EC2 instance), you must additionally specify the AccessKey and SecretKey of an IAM user to assume the role for. Roles may not be used when specifying the AccessKey and SecretKey of an AWS root user.

    Authenticating with MFA

    For users and roles that require Multi-factor Authentication, specify the MFASerialNumber and MFAToken connection properties. This will cause the CData Data Provider for Amazon Athena 2018 to submit the MFA credentials in a request to retrieve temporary authentication credentials. Note that the duration of the temporary credentials may be controlled via the TemporaryTokenDuration (default 3600 seconds).

    Connecting to Amazon Athena

    In addition to the AccessKey and SecretKey properties, specify Database, S3StagingDirectory and Region. Set Region to the region where your Amazon Athena data is hosted. Set S3StagingDirectory to a folder in S3 where you would like to store the results of queries.

    If Database is not set in the connection, the data provider connects to the default database set in Amazon Athena.

    Click Create & Test.
  4. Open the Permissions tab and configure user access.

Add a Personal Access Token

A Personal Access Token (PAT) authenticates MCP requests from Agno to CData Connect AI.

  1. Open Settings and navigate to Access Tokens.
  2. Click Create PAT.
  3. Save the generated token securely.

Step 2: Install required dependencies

Remote MCP Tools allow Grok to connect to external MCP (Model Context Protocol) servers, extending its capabilities with custom tools from third parties or your own implementations. Simply specify a server URL and optional configuration xAI manages the MCP server connection and interaction on your behalf.

Open the terminal and install the required dependencies for the MCP integration using pip.

	pip install xai-sdk==1.4.0

The xai-sdk (v1.4.0) enables Remote MCP tools, and python-dotenv is used to securely load environment variables.

	pip install python-dotenv

Step 3: Generate an xAI API key

  1. Create or login to xAI account
  2. Open xAI API console
  3. Navigate to API Keys
  4. Click on create API key

After generating an API key, user need to save it somewhere safe. Recommended option is to export it as an environment variable in your terminal or save it to a .env file.

Step 4: Connect to CData Connect AI

Initialize the Grok client and configure the MCP connection to CData Connect AI. The code below establishes a secure connection and sends a natural language query to your data source.

import os

from xai_sdk import Client
from xai_sdk.chat import user
from xai_sdk.tools import mcp

client = Client(api_key="Your_xAI-API_KEY")
chat = client.chat.create(
	model="grok-4-1-fast-non-reasoning",
	tools=[
		mcp(
			server_url="https://mcp.cloud.cdata.com/mcp",
			extra_headers={"Authorization": "Basic Username:PAT"} #Base64 Encoded Username:PAT
		)
		],
	include=["verbose_streaming"],
)

chat.append(user("List the top two catalogs for me please"))

is_thinking = True
for response, chunk in chat.stream():
	# View the server-side tool calls as they are being made in real-time
	for tool_call in chunk.tool_calls:
		print(f"
Calling tool: {tool_call.function.name} with arguments: {tool_call.function.arguments}")
	if response.usage.reasoning_tokens and is_thinking:
		print(f"
Thinking... ({response.usage.reasoning_tokens} tokens)", end="", flush=True)
	if chunk.content and is_thinking:
		print("

Final Response:")
		is_thinking = False
	if chunk.content and not is_thinking:
		print(chunk.content, end="", flush=True)

print("

Usage:")
print(response.usage)
print(response.server_side_tool_usage)
print("

Server Side Tool Calls:")
print(response.tool_calls)

This code initializes the Grok AI client, connects to CData Connect AI via MCP using Basic Authentication, and streams the response in real-time. The agent automatically discovers available tools, invokes them to query your live data, and displays both the tool calls and final results.

Run the script to see Grok query your connected data source.

Query Results

The output shows Grok invoking MCP tools through CData Connect AI and returning live data from your connected source.

User can now query live data using natural language through Grok AI.

Build agentic workflows with Grok and CData Connect AI

Combining Grok AI with CData Connect AI delivers AI-powered data access without pipelines or custom integrations. Start your free trial today to see how CData can empower Grok with live, secure access to 350+ external systems.

Ready to get started?

Learn more about CData Connect AI or sign up for free trial access:

Free Trial