@ekwo-ai/mcp
Version:
MCP server for Ekwo OS: let an AI agent work on the books, under the user's own row level security.
45 lines • 2.19 kB
TypeScript
/**
* The direct-Postgres backend.
*
* For a self-hosted installation where PostgREST is not in front of the
* database, and for the tests, which run the real schema in Postgres compiled
* to WebAssembly. It is the second route, not the privileged one: every call
* runs inside a transaction that sets `request.jwt.claims` and switches to
* the `authenticated` role, so row level security binds exactly as it does
* over the API. A connection that could bypass the policies would make this
* server a way round them, which is the one thing it must never be.
*
* The driver is behind `SqlClient` — thirty lines with nothing to decide — so
* the tests plug PGlite in and never load a network driver.
*/
import { type AgentSession } from './backend.js';
import { type SocleBackend } from '@ekwo-ai/core';
/** A Postgres connection, reduced to what this server needs. */
export interface SqlClient {
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
exec(sql: string): Promise<void>;
transaction<T>(fn: (tx: SqlClient) => Promise<T>): Promise<T>;
close(): Promise<void>;
}
export interface SqlBackendOptions {
/**
* The user this server acts for. Required: without it there is no
* `auth.uid()`, every policy fails closed, and the useful-looking
* alternative — running as the owner — is the one that must not exist.
*/
userId: string;
/** Extra JWT claims, if an installation reads more than `sub` and `role`. */
claims?: Record<string, unknown>;
/**
* Marks every transaction as an agent's (`ekwo.agent`, with the session's
* choice of `review` or `autopilot` if it made one, and `ekwo.agent_session`),
* which the database reads to hold a posting to the company's
* `agent_posting`. The MCP server sets it; a script acting for a person does
* not.
*/
agent?: AgentSession | undefined;
}
export declare function sqlBackend(db: SqlClient, options: SqlBackendOptions): SocleBackend;
/** Opens a connection with the `postgres` driver. */
export declare function connect(connectionString: string): Promise<SqlClient>;
//# sourceMappingURL=sql.d.ts.map