UNPKG

@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.

63 lines • 3.32 kB
/** * The recommended backend: PostgREST, with the user's own session. * * Supabase already turns the schema into a REST API with an OpenAPI * description, and row level security decides what each request may see. So * this server holds no privileges of its own: it signs in as the person using * it — or is handed their access token — and everything it can do afterwards * is what that person can do. There is no service_role path here, on purpose. * A server that could read every company would turn "an AI keeps my books" * into "an AI holds the keys to everybody's books". * * `@supabase/supabase-js` does two things this package deliberately does not * hand-write: the password grant with its token refresh, and the query string * PostgREST expects. Both are the part that cannot be tested here — no test * talks to a Supabase project — and a library that is known to work is worth * more than code of ours that is merely untested. */ import { type SocleBackend } from '@ekwo-ai/core'; import { type AgentSession } from './backend.js'; export interface PostgrestBackendOptions { supabaseUrl: string; anonKey: string; /** A session already in hand. Otherwise sign in with the two below. */ accessToken?: string | undefined; email?: string | undefined; password?: string | undefined; /** * A key of Ekwo OS — what `create_api_key()` issues — instead of a person. * * It travels in `X-Ekwo-Api-Key` and the core's `db_pre_request` hook * presents it at the top of every request's transaction (decision 0062), so * the caller is on the key's company with the key's capabilities and * nothing else. Such a request carries **no `Authorization`**: PostgREST * decides the role from that header before any function of the core runs, * and the hook is what moves the request off `anon`. */ apiKey?: string | undefined; /** The `fetch` every request goes through. A host or a test may hand its own. */ fetch?: typeof globalThis.fetch | undefined; /** * Marks every request as an agent's, in `X-Ekwo-Agent` — with the session's * choice of `review` or `autopilot` if it made one — and names the session * in `X-Ekwo-Agent-Session`. The database reads them 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; } /** The header the core's pre-request hook reads a key out of. */ export declare const API_KEY_HEADER = "X-Ekwo-Api-Key"; /** The header that says a request is an agent's (`agent_call()`), and its session's choice. */ export declare const AGENT_HEADER = "X-Ekwo-Agent"; /** The header that names the session of an agent, for the audit trail. */ export declare const AGENT_SESSION_HEADER = "X-Ekwo-Agent-Session"; /** * Signs in, or takes the token it was given, and returns the backend. * * With an email and a password the client keeps the session in memory and * refreshes it on its own; nothing is written to disk, so a long-running * server outlives the first hour without a credential cache existing. */ export declare function postgrestBackend(options: PostgrestBackendOptions): Promise<SocleBackend>; //# sourceMappingURL=postgrest.d.ts.map