Integrating LlamaIndex with SingleStore Data via CData Connect AI
LlamaIndex is a data framework for building LLM applications — agents, RAG pipelines, and structured workflows that reason over external data. By integrating LlamaIndex with CData Connect AI through the built-in MCP Server, your agents can discover and query live SingleStore data as native tools without writing custom connectors.
CData Connect AI offers a secure, low-code environment to connect SingleStore and other data sources, removing the need for complex ETL and enabling seamless automation across business applications with live data.
This article outlines how to configure SingleStore connectivity in CData Connect AI, register the MCP server with LlamaIndex, and build a ReAct agent that queries SingleStore data in real time.
Prerequisites
- An account in CData Connect AI
- Python version 3.10 or higher, to install the LlamaIndex packages
- Generate and save an OpenAI API key
- Install Visual Studio Code in your system
Step 1: Configure SingleStore Connectivity for LlamaIndex
Before LlamaIndex can access SingleStore, a SingleStore connection must be created in CData Connect AI. This connection is then exposed to LlamaIndex through the remote MCP server.
- Log in to Connect AI, click Sources, and then click + Add Connection
- From the available data sources, choose SingleStore
-
Enter the necessary authentication properties to connect to SingleStore
The following connection properties are required in order to connect to data.
- Server: The host name or IP of the server hosting the SingleStore database.
- Port: The port of the server hosting the SingleStore database.
- Database (Optional): The default database to connect to when connecting to the SingleStore Server. If this is not set, tables from all databases will be returned.
Connect Using Standard Authentication
To authenticate using standard authentication, set the following:
- User: The user which will be used to authenticate with the SingleStore server.
- Password: The password which will be used to authenticate with the SingleStore server.
Connect Using Integrated Security
As an alternative to providing the standard username and password, you can set IntegratedSecurity to True to authenticate trusted users to the server via Windows Authentication.
Connect Using SSL Authentication
You can leverage SSL authentication to connect to SingleStore data via a secure session. Configure the following connection properties to connect to data:
- SSLClientCert: Set this to the name of the certificate store for the client certificate. Used in the case of 2-way SSL, where truststore and keystore are kept on both the client and server machines.
- SSLClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
- SSLClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
- SSLClientCertType: The certificate type of the client store.
- SSLServerCert: The certificate to be accepted from the server.
Connect Using SSH Authentication
Using SSH, you can securely login to a remote machine. To access SingleStore data via SSH, configure the following connection properties:
- SSHClientCert: Set this to the name of the certificate store for the client certificate.
- SSHClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
- SSHClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
- SSHClientCertType: The certificate type of the client store.
- SSHPassword: The password that you use to authenticate with the SSH server.
- SSHPort: The port used for SSH operations.
- SSHServer: The SSH authentication server you are trying to authenticate against.
- SSHServerFingerPrint: The SSH Server fingerprint used for verification of the host you are connecting to.
- SSHUser: Set this to the username that you use to authenticate with the SSH server.
- Click Save & Test
- Once authenticated, open the Permissions tab in the SingleStore connection and configure user-based permissions as required
Generate a Personal Access Token (PAT)
LlamaIndex authenticates to Connect AI using an account email and a Personal Access Token (PAT). Creating separate PATs for each integration is recommended to maintain access control granularity.
- In Connect AI, select the Gear icon in the top-right to open Settings
- Under Access Tokens, select Create PAT
- Provide a descriptive name for the token and select Create
- Copy the token and store it securely. The PAT will only be visible during creation
With the SingleStore connection configured and a PAT generated, LlamaIndex is prepared to connect to SingleStore data through the CData MCP server.
Step 2: Connect to the MCP server in LlamaIndex
To connect LlamaIndex with CData Connect AI Remote MCP Server and use OpenAI for reasoning, configure your MCP server endpoint and authentication in a
config.pyfile. These values let LlamaIndex’s MCP tool spec call the MCP server tools, while OpenAI handles the natural language reasoning.
- Create a folder for the LlamaIndex MCP project
- Create two Python files within the folder:
config.py
andllamaindex_agent.py
- In
config.py
, define your MCP server URL and your Base64-encoded CData Connect AI email and PAT (obtained in the prerequisites):class Config: MCP_BASE_URL = "https://mcp.cloud.cdata.com/mcp" # MCP Server URL MCP_AUTH = "base64encoded(EMAIL:PAT)" # Base64 encoded Connect AI Email:PATNote: You can create the base64 encoded version of MCP_AUTH using any Base64 encoding tool.
- In
llamaindex_agent.py
, wire up the MCP tool spec and a ReAct agent:""" Integrates a LlamaIndex ReAct agent with the CData Connect AI MCP server. The script discovers MCP tools, wraps them as LlamaIndex tools, and runs an agent loop driven by OpenAI for reasoning. """ import asyncio from llama_index.tools.mcp import BasicMCPClient, McpToolSpec from llama_index.core.agent.workflow import ReActAgent from llama_index.llms.openai import OpenAI from config import Config async def main(): # Initialize the MCP client pointed at Connect AI mcp_client = BasicMCPClient( Config.MCP_BASE_URL, headers={"Authorization": f"Basic {Config.MCP_AUTH}"}, ) # Discover tools the MCP server exposes (getCatalogs, queryData, etc.) tool_spec = McpToolSpec(client=mcp_client) tools = await tool_spec.to_tool_list_async() print("Discovered MCP tools:", [t.metadata.name for t in tools]) # Configure the LLM that drives the ReAct loop llm = OpenAI( model="gpt-4o", temperature=0.2, api_key="YOUR_OPENAI_API_KEY", # https://platform.openai.com/ ) # Build the agent with the MCP-backed tools agent = ReActAgent(tools=tools, llm=llm) user_prompt = "How many tables are available in SingleStore1?" # Change as needed print(f" User prompt: {user_prompt}") response = await agent.run(user_prompt) print("Agent final response:", response) if __name__ == "__main__": asyncio.run(main())
Step 3: Install the LlamaIndex packages
Since this workflow uses LlamaIndex together with the CData Connect AI MCP server and OpenAI for reasoning, install the required Python packages.
Run the following command in your project terminal:
pip install llama-index llama-index-tools-mcp llama-index-llms-openai
Step 4: Prompt SingleStore using LlamaIndex (via the MCP server)
- When the installation finishes, run
python llamaindex_agent.py
to execute the script - The script connects to the MCP server and discovers the CData Connect AI MCP tools available for querying your connected data
- Supply a prompt (e.g., "How many tables are available in SingleStore?")
- The agent reasons over the available tools, calls
queryData
against SingleStore, and responds with the result
Get CData Connect AI
To get live data access to hundreds of SaaS, Big Data, and NoSQL sources directly from your cloud applications, try CData Connect AI today!