SQL Stored Procedures As Tools
Purpose
Much enterprise logic lives in stored procedures. This area turns them into API definitions, and from there into governed tools, without an HTTP wrapper written by hand: the platform discovers the procedures, drafts their descriptions with your language model, lets you review and confirm them, and calls them directly at runtime.
Supported engines: SQL Server (including Azure SQL), PostgreSQL, MySQL and MariaDB, and Oracle.
Once imported, a stored-procedure API is an ordinary API definition: mappings, enrichment, toolsets, policies, credential bindings and audit work exactly as they do for an OpenAPI import.
The Steps At A Glance
- Create a database target system for the database the procedures run on, with a login (Database target systems).
- In API Onboarding, choose Import, pick SQL stored procedures as the contract family, and discover the procedures, from a script or from the live database. The import wizard's steps are Source, Procedures, Draft, Review and Import.
- Select the procedures to import, then choose Draft with LLM or Import without a draft.
- Review each procedure, edit what needs it, and confirm whether it modifies data and is idempotent.
- Import them as a new API definition, or as a new version of an existing one.
- Create a mapping and publish a toolset as usual, binding the tools to the database target system.
Discovering Procedures
From a script
Upload a .sql script containing the CREATE PROCEDURE / CREATE FUNCTION statements and choose the engine it is
written for. The script is parsed, never executed. It may contain anything else: other statements are skipped.
| Engine | Statements are separated by | Also read from the script |
|---|---|---|
| SQL Server | lines holding only GO |
CREATE TYPE … AS TABLE (for table-valued parameters) and alias types |
| PostgreSQL | ; outside $$ bodies |
CREATE TYPE … AS ENUM, domains, COMMENT ON FUNCTION, SET search_path |
| MySQL / MariaDB | ;, or the delimiter set by DELIMITER |
USE, COMMENT '…' |
| Oracle | lines holding only / |
package specifications and their TYPE … INDEX BY declarations, ALTER SESSION SET CURRENT_SCHEMA |
A comment block immediately above a CREATE statement is taken as the procedure's existing description. A script for
MySQL or Oracle must say which schema its routines live in (a USE or ALTER SESSION SET CURRENT_SCHEMA statement, or
qualified names); otherwise its procedures are blocked, because they could not be called.
Up to 4 MB of script and 500 procedures are read.
From the live database
Enter the engine, a connection template without credentials (host, port, database and any attributes such as
Encrypt=True, see Entering A SQL Connection), and the user name and password of a login that can see the
procedures, then Discover procedures. The user name and password are used for this one discovery and never
saved. Every host the template
names must be in the tenant's outbound allowlist.
Discovery reads only the database's catalog, in a read-only transaction where the engine has one, and never calls a procedure. It lists only the procedures the login may execute: discover with the login the tools will use to see exactly what they will be able to call. Up to 500 procedures are listed.
What the live catalog adds over a script:
- SQL Server describes the columns of a procedure's first result set. Later result sets, and procedures whose shape depends on dynamic SQL, are proposed by the draft or declared by you during review.
- PostgreSQL distinguishes overloads of the same function, reads enum labels and domains, and treats
IMMUTABLEandSTABLEfunctions as read-only (the engine forbids them to write). - MySQL and MariaDB never describe result sets: the draft proposes them.
- Oracle reads package members, overloads, associative arrays and
REF CURSORresults from the current schema.
Import sessions
Each discovery becomes an import session that holds the procedures until you import them. A session keeps the
procedures' text only so the draft can read it, purges it on import, and expires after 24 hours by default
(APIONBOARDING__SQLPROCEDURES__SESSIONTIMETOLIVE). You can leave and come back to a session, or delete it: the wizard's first step lists them under Earlier import
sessions, each with Open and Delete.
Supported Types
Every parameter and result column is mapped to one of a fixed set of value types, which is what callers send and receive in JSON:
| Value type | JSON | Notes |
|---|---|---|
| String | string | the declared length is enforced |
| Integer | number | the database type's range is enforced |
| Decimal | string | exact digits; never rounded, so no JSON client loses precision |
| Float | number | |
| Boolean | boolean | |
| Date, Time, DateTime | string (ISO-8601) | a DateTime carries no offset |
| DateTimeOffset | string (ISO-8601 with offset) | |
| Uuid | string | |
| Binary | string (base64) | |
| Json | JSON value | inlined, not quoted |
| Xml | string | |
| Array | array | PostgreSQL arrays and Oracle associative arrays, one dimension, of simple values |
| Table | array of objects | SQL Server table-valued parameters |
A type outside the support matrix blocks the procedure: the warning names the parameter or column and its database type, and the procedure can be neither drafted nor imported. Among them:
- SQL Server:
sql_variant,geography,geometry,hierarchyid, CLR types,CURSORoutput parameters. - PostgreSQL: composite types as parameters or inside a result set,
money,interval, ranges, geometric types,hstore, multi-dimensional arrays, unnamed arguments,VARIADIC. - MySQL / MariaDB:
SET, spatial types,BIT(n)wider than one bit. - Oracle: object types,
VARRAY, nested tables,RECORD/%ROWTYPE,XMLType,LONG,BFILE,ROWIDparameters, associative arrays as outputs, andBOOLEANbefore Oracle Database 23ai.
Drafting With The Language Model
Select the procedures to import and choose Draft with LLM. The tenant's model for mapping enrichment (or the profile you pick) drafts, for each procedure:
- a one-line summary and a functional description: what it does for the caller, what it changes, its preconditions and notable failures, and how its result sets relate;
- a description of each parameter, result set, column and return value;
- the result sets the catalog could not describe, as the union of every column each can return;
- whether it modifies data and whether it is idempotent, each with a confidence and a one-line rationale.
An existing description (SQL Server MS_Description, PostgreSQL COMMENT, MySQL COMMENT, a script's header comment)
is refined, not contradicted. The model is told never to invent behaviour it cannot see and never to copy literals from
the procedure's text; descriptions it cannot ground are left empty. Procedure text is never written to a log.
Drafting runs in the background and its progress is shown live. A procedure whose draft fails keeps its existing descriptions; drafting never repeats a procedure it has already drafted. You can also choose Import without a draft. Drafting spend appears in the LLM Usage Dashboard as Stored-procedure drafts.
Reviewing And Confirming
Review each procedure before importing it:
- Edit the summary, the description and every parameter, result-set and column description. Descriptions that are missing, or that only repeat a name, are highlighted.
- Types, directions and nullability come from the database and cannot be changed; where the draft disagrees, a warning says so.
- For result sets the draft proposed, set which are always returned, and which columns are always present and nullable. A set or column returned only on some paths is optional in the tool's response schema.
- Check the columns of a proposed result set. The draft reads them from the procedure's text, so behind dynamic
SQL or
SELECT *it can miss columns, and a name in aWHEREclause can be mistaken for an output column. A column the procedure never returns stays empty in every response. Column names are matched regardless of case. - Confirm the classification. Modifies data and Idempotent are proposed with their confidence and rationale. When nothing reliable proposes a value, the safe one is used: modifies data on, idempotent off. A read-only procedure is always idempotent. Changing either flag confirms it; Confirm classification confirms the selected procedures as they stand.
Every selected procedure must be confirmed, and none may be blocked, before the import is enabled.
The flags describe; they do not enforce. They become the tool's MCP annotations (read-only, destructive, idempotent) that AI clients use to decide how carefully to call it. The runtime never retries a stored-procedure call, whatever the flags say, and a procedure marked read-only runs in a read-only transaction where the engine has one (PostgreSQL, MySQL, Oracle) only as a second line of defence. The login's database permissions are the real boundary: use a least-privilege login per database target system.
Importing
Import the confirmed procedures as a new API definition (give it a name) or as a new version of an existing one
(choose it, give the version a label, and decide whether it becomes current). The session is then closed and the
procedures' text purged. The imported operations appear on the API's Operations tab in API Onboarding with method EXEC, their classification and
their parameters' value types.
Calling A Stored-Procedure Tool
Bind the tool to the database target system, as you would bind an HTTP tool to its target system. A tool bound to the wrong kind of target system cannot be published.
Each call runs in its own transaction: committed when the procedure succeeds, rolled back when it fails, is cancelled or passes a result limit. The response is one object holding:
- one array per result set, under its reviewed name;
outputParameters, the values of OUT and INOUT parameters;returnValue, a function's value (or a SQL Server procedure'sRETURNstatus);rowsAffected, where the engine reports it.
Result limits
Every call is limited in the rows it may return over all its result sets, the size of any single value, and the number
of result sets. The runtime's ceilings apply to every call (RUNTIME__DOWNSTREAM__MAXRESULTROWS,
MAXRESULTFIELDBYTES, MAXRESULTSETS; see
Configuration reference); a database target system can set
lower ones, and the lower value applies. Passing a limit fails the call — nothing is truncated:
| Limit | Error code |
|---|---|
| Rows | downstream_result_row_limit_exceeded |
| Size of one value | downstream_result_field_limit_exceeded |
| Result sets | downstream_result_set_limit_exceeded |
Paging
A mapping can offer callers offset and limit over a procedure's first result set, for a procedure that does not
modify data and returns rows. Use it when the procedure has no paging parameters of its own. Paging is off until you
turn it on: on the mapping's endpoint, switch on Offer paging in the Paging group. Offset and limit can be renamed
and described like any field, for example to pageSize, which also avoids a clash with a parameter of the same name.
| Caller sends | Allowed values | Effect |
|---|---|---|
offset |
a whole number, 0 or more | Rows of the first result set to skip. 0 when omitted. |
limit |
a whole number from 1 up to the call's row limit | The most rows to return. The row limit when omitted. |
Both are integers in the tool's schema. A value written as a string of digits, such as "10", is accepted too, since
models often send numbers that way. Anything else, such as "-1" or "1.5", is refused with invalid_argument.
Once paging is on, every call is paged: a call that sends neither returns the first page, up to the row limit.
The response therefore always carries a $pagingInfo object, as the tool's output schema describes it, and a
result larger than the row limit returns its first page instead of failing. The leading $ marks the object as
the platform's, not a result set:
| Field | Meaning |
|---|---|
resultsOffset |
The rows skipped: the offset asked for, 0 when none was. |
resultsLimit |
The most rows the page could hold: the limit asked for, or the row limit. |
resultsTotal |
The rows the first result set held in total, over every page. |
resultsHasMore |
true when more rows follow; ask for them with the offset increased by the limit. false on the last page. |
The procedure's other result sets, its output parameters and its return value are returned as usual. The descriptions the mapping proposes for these fields state the same allowed values, so an AI client can choose its arguments from them.
Paging is applied by the platform while it reads the rows, not by the database:
- The procedure runs in full on every page. Paging saves the rows sent to the caller, and the tokens they cost, not the database's work. Only the returned rows count toward the row limit, so a set larger than the limit can be paged through.
- Pages are stable only if the procedure returns its rows in a fixed order, and only while the data does not change between calls.
- A procedure that modifies data cannot be paged, because every page would run it again; a call that asks for a page of
one is refused with
invalid_argument.
An existing mapping offers the paging fields after its next enrichment run or its next mapping version.
Errors
A failed call answers a status and a {code, message} body. The message names the engine's error number, never the
database's own message text, which can quote data.
| Status | Code | Meaning |
|---|---|---|
| 400 | invalid_argument |
an argument was refused, before the call or by the database |
| 403 | permission_denied |
the login may not run it, or a read-only call tried to write |
| 403 | host_not_allowed |
the database host is not in the tenant's outbound allowlist |
| 404 | object_not_found |
the procedure, or an object it uses, does not exist |
| 409 | constraint_violation |
a key, foreign-key, check or not-null constraint refused the change |
| 504 | timeout |
the call ran past its command timeout |
| 502 | unsupported_value |
a returned value cannot be represented (for example a number too wide to carry exactly) |
| 502 | unavailable |
the database could not be reached or refused the login |
| 500 | procedure_error |
the procedure raised its own error |
Effects that survive a failure
A rolled-back call undoes what the transaction did. It cannot undo what the procedure committed on its own: a
PostgreSQL COMMIT inside a procedure, an Oracle autonomous transaction, writes to MySQL tables that are not
transactional, or anything sent outside the database. When such a call fails, the error means the call failed, not
that nothing happened.