Location: factory.ai/package.mcp/ObjAiMcpDatabase.py
Version: 8.0
Inherits from: ObjAiMcpBase
Database schema and calculation-SQL context provider for the AI layer.
ObjAiMcpDatabase is a data-context provider — it fetches live database
information (table DDL and SQL strings) so that AI prompts can be grounded in
the actual schema and data, rather than relying on static knowledge.
It does not route prompts to a language model. Use it in combination with
an LLM provider (e.g. ObjAiMcpOllama) via ObjAI.review_sql().
The Axion factory.ai/package.mcp/ layer is a Multi-Cloud Provider (MCP)
abstraction. Providers in this layer are loaded dynamically by ObjAI.mcp_factory().
ObjAiMcpDatabase is loaded as provider "database":
obj_factory = ai.mcp_factory("database")
db_ctx = obj_factory.ObjAiMcpDatabase(self.DB)
get_schema(table_names: list) -> strReturns SHOW CREATE TABLE DDL for each listed table, concatenated as a
formatted string. Uses the live database, so it reflects any ALTER TABLE
changes made after initial setup.
schema = db_ctx.get_schema(["def_calculations", "data_results"])
get_sql_samples(package: str, group_name: str = "", limit: int = 30) -> listFetches CalculationSql, PreSql, PostSql, SetSql, and Operation from
def_calculations for the given package (plus CORE and '' rows). Returns a
list of dicts with keys: name, group, sql, pre_sql, post_sql,
set_sql, operation.
samples = db_ctx.get_sql_samples("homechoice", group_name="scoring", limit=20)
prompt() / embed()Not implemented — return "" / []. This is a data-context provider only.
The primary intended use is through ObjAI.review_sql(), which orchestrates:
ObjAiMcpDatabaseObjAiMcpDatabaseObjAiMcpOllamaimport sys
sys.path += ["", "factory.core", "factory.ai"]
import ObjAI
ai = ObjAI.ObjAI(DB)
review = ai.review_sql(
package="homechoice",
group_name="scoring", # optional
model="mistral",
limit=30,
)
print(review)
get_schema() sanitises table names by stripping backticks and single-quotes
before embedding in the SHOW CREATE TABLE query.
get_sql_samples() escapes single-quotes in the package and group_name
parameters before embedding in the SQL. Table name substitution is not used
(query targets def_calculations directly). The LIMIT clause is cast to
int to prevent injection via that parameter.