Skip to main content
You can build your own AI agent that uses the MCP Server as its data layer. An AI agent combines a large language model (LLM) with a set of tools in a loop: the model decides which tool to invoke, your agent code executes the tool, and the model uses the result to decide the next step. The Ocient MCP Server supplies the tools, so your agent can explore schemas, execute SQL statements, and invoke the custom tools that you define in the database — without any database-specific code.

Agent Interaction with the MCP Server

An agent interacts with the Ocient MCP Server in this sequence:
  1. The agent connects to the server and requests the tool list. The server returns execute_statement and all discovered tools, system tools and user-defined tools, with their MCP names (such as show_tables), argument schemas, and descriptions.
  2. The agent passes the tool definitions to the LLM together with the user request.
  3. The LLM selects a tool and provides the arguments. The agent invokes the tool through the MCP session.
  4. The server executes the tool in the Ocient System and returns the result, which the agent passes back to the LLM.
  5. The loop repeats until the LLM produces a final answer.
Because the database stores the tool definitions, the tool descriptions in the sys.mcp_tools system catalog table act as prompts for the LLM. Clear, specific tool descriptions improve how reliably the model selects and uses your tools.

Connect to the Server from Python

This example uses the MCP SDK to launch a local server with the Stdio transport, list the available tools, and execute a SQL statement.
Python
To connect to a remote server instead, use the Streamable HTTP client from the same SDK and pass your API key as a Bearer token. For deployment details, see Deployment Models.

Add the Agent Loop

To turn the connection into an agent, pass the tool definitions from list_tools to your LLM provider as its available tools, and execute each tool invocation that the model requests through session.call_tool. Most LLM provider SDKs and agent frameworks accept MCP tool definitions directly or with a thin conversion layer, and many agent frameworks manage this loop for you when you register an MCP server as a tool source. Follow these practices in the loop:
  • Return tool errors to the model. The execute_statement tool returns Ocient error messages as descriptive tool errors, and the messages are descriptive enough for the model to correct its SQL statement and retry.
  • Bound the loop with a maximum number of tool invocations to prevent runaway execution.
  • Log each tool invocation and its SQL text for auditing. Agent-driven queries also appear in the sys.queries and sys.completed_queries system catalog tables.

Design a Governed Tool Surface

The most reliable agents work with a small set of purpose-built tools instead of open-ended SQL. Use these techniques to shape what your agent can do.
  • Create task-specific tools — Encapsulate approved queries as user-defined MCP tools with the CREATE MCP TOOL SQL statement. The agent invokes the tools by name with typed arguments, which removes whole categories of SQL generation errors. For the complete syntax, see Model Context Protocol Tools.
  • Group tools into toolsets — Assign related tools to a toolset with the TOOLSET clause of the CREATE MCP TOOL SQL statement so that agents can work with a coherent set of capabilities, for example, a geospatial analysis toolset or a reporting toolset.
  • Scope privileges — Connect the agent with a dedicated database user that has only the privileges the agent requires. Revoke the EXECUTE privilege on tools that the agent must not use. The CALL MCP TOOL SQL statement executes with the privileges of the caller, so the database enforces your access control on every invocation. For the MCP tool privileges, see Data Control Language (DCL) Statement Reference.
  • Control query priority — Assign a service class to the agent user to manage the workload impact of agent-driven queries. For details, see Workload Management and Service Classes.
Ocient MCP Server Data Analytics Workflow Using the Ocient MCP Server Model Context Protocol Tools Data Control Language (DCL) Statement Reference
Last modified on September 9, 2026