Agent Interaction with the MCP Server
An agent interacts with the Ocient MCP Server in this sequence:- The agent connects to the server and requests the tool list. The server returns
execute_statementand all discovered tools, system tools and user-defined tools, with their MCP names (such asshow_tables), argument schemas, and descriptions. - The agent passes the tool definitions to the LLM together with the user request.
- The LLM selects a tool and provides the arguments. The agent invokes the tool through the MCP session.
- The server executes the tool in the Ocient System and returns the result, which the agent passes back to the LLM.
- The loop repeats until the LLM produces a final answer.
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
Add the Agent Loop
To turn the connection into an agent, pass the tool definitions fromlist_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_statementtool 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.queriesandsys.completed_queriessystem 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 TOOLSQL 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
TOOLSETclause of theCREATE MCP TOOLSQL 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 TOOLSQL 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.

