@layers/amba-mcp 4.0.4 → 4.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto/collection-tools.d.ts +63 -0
- package/dist/auto/describe.d.ts +39 -0
- package/dist/auto/index.d.ts +56 -0
- package/dist/auto/schema-to-zod.d.ts +87 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1941 -129
- package/dist/lib/annotations.d.ts +0 -7
- package/dist/tools/event-catalog.d.ts +20 -0
- package/dist/tools/functions.d.ts +1 -1
- package/dist/tools/leagues.d.ts +1 -1
- package/dist/tools/monetization.d.ts +20 -0
- package/dist/tools/operations.d.ts +24 -0
- package/dist/tools/payments.d.ts +30 -0
- package/package.json +2 -2
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `registerCollectionToolsFor` — project ONE collection into a set of
|
|
3
|
+
* typed MCP tools and register them on a server.
|
|
4
|
+
*
|
|
5
|
+
* Phase 1 = admin scope. Each tool is a thin proxy over the EXISTING
|
|
6
|
+
* authoritative admin collection routes (`/v1/admin/projects/:p/
|
|
7
|
+
* collections/:name/...`) — we do NOT reimplement any query logic. The
|
|
8
|
+
* tool's value is the *projection*: typed per-column input + an SDK-grade
|
|
9
|
+
* description, generated from the live schema (`schema-to-zod.ts` +
|
|
10
|
+
* `describe.ts`).
|
|
11
|
+
*
|
|
12
|
+
* Tools generated (verbs that map to a real admin route):
|
|
13
|
+
* <ns>_<coll>_list → GET /collections/:name/rows?query=…
|
|
14
|
+
* <ns>_<coll>_get → GET /collections/:name/rows/:id
|
|
15
|
+
* <ns>_<coll>_find → GET /collections/:name/rows?query=… (typed where)
|
|
16
|
+
* <ns>_<coll>_insert → POST /collections/:name/rows
|
|
17
|
+
* <ns>_<coll>_update → PATCH /collections/:name/rows/:id
|
|
18
|
+
* <ns>_<coll>_delete → DELETE /collections/:name/rows/:id
|
|
19
|
+
* <ns>_<coll>_aggregate → POST /collections/:name/rows/aggregate
|
|
20
|
+
*
|
|
21
|
+
* `find_nearest` is intentionally Phase 2 (client scope + vector route).
|
|
22
|
+
*
|
|
23
|
+
* Auth: every tool goes through `registerTool` (the pat-as-argument
|
|
24
|
+
* helper), so the developer Bearer flows from the inbound request OR a
|
|
25
|
+
* per-call `pat` arg, exactly like the platform collection tools.
|
|
26
|
+
*/
|
|
27
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
28
|
+
import type { ApiClient } from '../api-client.js';
|
|
29
|
+
import { type ToolScope } from './describe.js';
|
|
30
|
+
import { type CollectionSchemaPayload } from './schema-to-zod.js';
|
|
31
|
+
/** Effective access policy resolved from the describe endpoint. */
|
|
32
|
+
export interface CollectionPolicy {
|
|
33
|
+
read_policy: 'owner' | 'public';
|
|
34
|
+
write_policy: 'owner' | 'authenticated';
|
|
35
|
+
}
|
|
36
|
+
export interface RegisterCollectionToolsOptions {
|
|
37
|
+
/** Project the collection belongs to. */
|
|
38
|
+
projectId: string;
|
|
39
|
+
/** Tool-name namespace (sanitized app slug or project id). */
|
|
40
|
+
namespace: string;
|
|
41
|
+
/** Collection name (customer-facing, no `coll_` prefix). */
|
|
42
|
+
collection: string;
|
|
43
|
+
/** The describe-endpoint schema payload. */
|
|
44
|
+
schema: CollectionSchemaPayload;
|
|
45
|
+
/** The collection's effective access policy. */
|
|
46
|
+
policy: CollectionPolicy;
|
|
47
|
+
/** Scope to generate for. Phase 1 ships `admin`. */
|
|
48
|
+
scope: ToolScope;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Tool-name fragment regex. MCP + `tool-naming.test.ts` require lowercase
|
|
52
|
+
* `_`-separated names. The namespace + collection are sanitized to that
|
|
53
|
+
* shape so a slug like "My App" or a collection like "MyRecipes" never
|
|
54
|
+
* produces an invalid tool name.
|
|
55
|
+
*/
|
|
56
|
+
export declare function sanitizeNameFragment(raw: string): string;
|
|
57
|
+
/** Build the `<ns>_<coll>_<verb>` tool name. */
|
|
58
|
+
export declare function collectionToolName(namespace: string, collection: string, verb: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Register the typed CRUD tools for a single collection on `server`,
|
|
61
|
+
* proxying to the existing admin routes via `apiClient`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function registerCollectionToolsFor(server: McpServer, apiClient: ApiClient, options: RegisterCollectionToolsOptions): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK-grade per-tool description generator for the auto-MCP wedge.
|
|
3
|
+
*
|
|
4
|
+
* The wedge is only worth shipping if the generated tools read like a
|
|
5
|
+
* hand-built typed client, not a thin `find_rows({collection, where})`
|
|
6
|
+
* wrapper (design doc §7). These descriptions are generated from the live
|
|
7
|
+
* column list + access policy so an agent never needs external docs:
|
|
8
|
+
* column names, types, nullability, the access policy in plain words, and
|
|
9
|
+
* a worked example per verb.
|
|
10
|
+
*
|
|
11
|
+
* Pure string builders — snapshot-friendly, no I/O. NO provider leakage:
|
|
12
|
+
* "collection", "row", "column", "function" only — never the underlying
|
|
13
|
+
* storage engine.
|
|
14
|
+
*/
|
|
15
|
+
import { type MappedCollection } from './schema-to-zod.js';
|
|
16
|
+
/** The verbs a collection projects into tools. */
|
|
17
|
+
export type CollectionVerb = 'list' | 'get' | 'find' | 'insert' | 'update' | 'delete' | 'aggregate' | 'find_nearest';
|
|
18
|
+
/** Access scope the tools were generated for. Phase 1 ships `admin`. */
|
|
19
|
+
export type ToolScope = 'admin' | 'client';
|
|
20
|
+
export interface DescribeContext {
|
|
21
|
+
/** Collection name (customer-facing, no `coll_` prefix). */
|
|
22
|
+
collection: string;
|
|
23
|
+
/** The mapped schema (column kinds, vector columns). */
|
|
24
|
+
mapped: MappedCollection;
|
|
25
|
+
/** Effective read policy from the collection's access policy. */
|
|
26
|
+
readPolicy: 'owner' | 'public';
|
|
27
|
+
/** Effective write policy from the collection's access policy. */
|
|
28
|
+
writePolicy: 'owner' | 'authenticated';
|
|
29
|
+
/** Scope the tool set was generated for. */
|
|
30
|
+
scope: ToolScope;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate the description string for a single collection tool.
|
|
34
|
+
*/
|
|
35
|
+
export declare function describeCollectionTool(verb: CollectionVerb, ctx: DescribeContext): string;
|
|
36
|
+
/** Description for the `<ns>_list_collections` meta tool. */
|
|
37
|
+
export declare function describeListCollections(namespace: string): string;
|
|
38
|
+
/** Description for the `<ns>_whoami` meta tool. */
|
|
39
|
+
export declare function describeWhoami(namespace: string): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-MCP wedge entry — `registerAutoMcpTools`.
|
|
3
|
+
*
|
|
4
|
+
* The per-tenant MCP surface: instead of Amba's own platform tools, this
|
|
5
|
+
* registers tools that ARE the customer's own collections, projected into
|
|
6
|
+
* typed per-collection tools (`<ns>_<coll>_list/get/find/insert/update/
|
|
7
|
+
* delete/aggregate`) plus two meta tools:
|
|
8
|
+
*
|
|
9
|
+
* - `<ns>_list_collections` — the index of exposed collections.
|
|
10
|
+
* - `<ns>_whoami` — which project + scope this surface serves.
|
|
11
|
+
*
|
|
12
|
+
* Generation is LIVE (design doc §2.3): on registration we list the
|
|
13
|
+
* project's collections and introspect each via the existing admin
|
|
14
|
+
* routes, then project them. Stateless-per-request (the handler builds a
|
|
15
|
+
* fresh server per HTTP request) makes this clean — no cache in Phase 1.
|
|
16
|
+
*
|
|
17
|
+
* Phase 1 = admin scope, collections only. Function tools, client scope,
|
|
18
|
+
* and the manifest cache are later phases.
|
|
19
|
+
*/
|
|
20
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
21
|
+
import type { ApiClient } from '../api-client.js';
|
|
22
|
+
import { type ToolScope } from './describe.js';
|
|
23
|
+
import { mapCollectionSchema, type CollectionSchemaPayload } from './schema-to-zod.js';
|
|
24
|
+
export interface RegisterAutoMcpOptions {
|
|
25
|
+
/** Project whose collections become the tool surface. */
|
|
26
|
+
projectId: string;
|
|
27
|
+
/** Scope to generate. Phase 1 ships `admin`. */
|
|
28
|
+
scope: ToolScope;
|
|
29
|
+
/**
|
|
30
|
+
* Tool-name namespace. Defaults to a sanitized project id. A future
|
|
31
|
+
* phase passes the project slug here so multiple connected apps don't
|
|
32
|
+
* collide.
|
|
33
|
+
*/
|
|
34
|
+
namespace?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register the auto-MCP tool surface for one project on `server`.
|
|
38
|
+
*
|
|
39
|
+
* Lists + introspects the project's collections (admin routes) and
|
|
40
|
+
* registers a typed tool set per collection, plus the two meta tools.
|
|
41
|
+
* Returns the names of the collections that were exposed plus `listOk`
|
|
42
|
+
* (false when the collection listing was incomplete — a paginated page
|
|
43
|
+
* failed — in which case typed tools are deliberately NOT registered so a
|
|
44
|
+
* truncated set never masquerades as the whole project).
|
|
45
|
+
*/
|
|
46
|
+
export declare function registerAutoMcpTools(server: McpServer, apiClient: ApiClient, options: RegisterAutoMcpOptions): Promise<{
|
|
47
|
+
namespace: string;
|
|
48
|
+
collections: string[];
|
|
49
|
+
listOk: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
export { registerCollectionToolsFor, collectionToolName, sanitizeNameFragment, } from './collection-tools.js';
|
|
52
|
+
export type { CollectionPolicy, RegisterCollectionToolsOptions } from './collection-tools.js';
|
|
53
|
+
export { mapCollectionSchema };
|
|
54
|
+
export type { CollectionSchemaPayload };
|
|
55
|
+
export { classifyColumn, SERVER_MANAGED_COLUMNS, type CollectionColumn, type ColumnKind, type MappedCollection, } from './schema-to-zod.js';
|
|
56
|
+
export { describeCollectionTool, describeListCollections, describeWhoami, type CollectionVerb, type DescribeContext, type ToolScope, } from './describe.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure mapper: a collection's live schema (the JSON returned by the
|
|
3
|
+
* `GET .../collections/:name` describe endpoint) → the zod raw shapes the
|
|
4
|
+
* auto-generated MCP tools register.
|
|
5
|
+
*
|
|
6
|
+
* Three derived shapes per collection (the auto-MCP wedge §2.2):
|
|
7
|
+
*
|
|
8
|
+
* - `insertShape` — the typed body of an `insert` tool. Server-managed
|
|
9
|
+
* columns (`id`, `user_id`, `created_at`, `updated_at`, `deleted_at`)
|
|
10
|
+
* are omitted (the route stamps them); a column is REQUIRED when it is
|
|
11
|
+
* NOT NULL and has no default, OPTIONAL otherwise.
|
|
12
|
+
* - `whereShape` — the typed `where` of a `find` tool: one optional key
|
|
13
|
+
* per non-vector column whose value is `value | { eq?, ne?, gt?, … }`
|
|
14
|
+
* typed to the column. This is the single highest-value projection —
|
|
15
|
+
* it makes the generated tool read like a hand-built typed client
|
|
16
|
+
* rather than a free-form `where: object` blob.
|
|
17
|
+
* - `updateShape` — the typed `set` of an `update` tool: every non
|
|
18
|
+
* server-managed column, all optional (merge-patch semantics).
|
|
19
|
+
*
|
|
20
|
+
* Plus `rowTypeHints` — a column→plain-English type label map the
|
|
21
|
+
* description generator (`describe.ts`) reads, and `vectorColumns` — the
|
|
22
|
+
* vector columns (excluded from row input; they drive `find_nearest`).
|
|
23
|
+
*
|
|
24
|
+
* The mapper is PURE (no I/O, no zod-runtime coupling beyond building the
|
|
25
|
+
* shape) so it unit-tests in isolation and so the same projection can run
|
|
26
|
+
* in the hosted server today and in the CLI / console later.
|
|
27
|
+
*/
|
|
28
|
+
import { z } from 'zod';
|
|
29
|
+
/** A single column as returned by the describe endpoint (`information_schema`). */
|
|
30
|
+
export interface CollectionColumn {
|
|
31
|
+
column_name: string;
|
|
32
|
+
/** e.g. `text`, `integer`, `ARRAY`. For arrays this is the literal `ARRAY`. */
|
|
33
|
+
data_type: string;
|
|
34
|
+
/** Underlying type, e.g. `text`, `int4`, `_text` (array element prefixed `_`). */
|
|
35
|
+
udt_name: string;
|
|
36
|
+
is_nullable: 'YES' | 'NO';
|
|
37
|
+
column_default: string | null;
|
|
38
|
+
}
|
|
39
|
+
/** The describe-endpoint `data` payload the mapper consumes. */
|
|
40
|
+
export interface CollectionSchemaPayload {
|
|
41
|
+
name: string;
|
|
42
|
+
columns: CollectionColumn[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Columns Amba manages on every collection. They are stamped by the
|
|
46
|
+
* route, never accepted as tool input, and so are omitted from the
|
|
47
|
+
* insert / update shapes. They ARE filterable (`where`) and selectable.
|
|
48
|
+
*/
|
|
49
|
+
export declare const SERVER_MANAGED_COLUMNS: ReadonlySet<string>;
|
|
50
|
+
/** Plain-English label for a column, used by the description generator. */
|
|
51
|
+
export type ColumnKind = 'text' | 'integer' | 'number' | 'boolean' | 'json' | 'uuid' | 'date' | 'timestamp' | 'vector' | 'text[]' | 'integer[]' | 'number[]' | 'boolean[]' | 'uuid[]' | 'unknown';
|
|
52
|
+
export interface MappedCollection {
|
|
53
|
+
/** zod raw shape for an `insert` tool body. */
|
|
54
|
+
insertShape: z.ZodRawShape;
|
|
55
|
+
/** zod raw shape for a `find` tool's `where` argument (one key per column). */
|
|
56
|
+
whereShape: z.ZodRawShape;
|
|
57
|
+
/** zod raw shape for an `update` tool's `set` argument. */
|
|
58
|
+
updateShape: z.ZodRawShape;
|
|
59
|
+
/** column → plain-English kind, for description generation. */
|
|
60
|
+
rowTypeHints: Record<string, ColumnKind>;
|
|
61
|
+
/** Names of vector columns (drive `find_nearest`, excluded from row input). */
|
|
62
|
+
vectorColumns: string[];
|
|
63
|
+
/** Whether the collection has at least one vector column. */
|
|
64
|
+
hasVector: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Classify a column into a coarse {@link ColumnKind}. Reads `data_type`
|
|
68
|
+
* first (the only reliable array signal — `data_type === 'ARRAY'`), then
|
|
69
|
+
* `udt_name`. Unknown types fall back to `unknown` (mapped to free JSON)
|
|
70
|
+
* rather than throwing, so a future column type never breaks generation.
|
|
71
|
+
*/
|
|
72
|
+
export declare function classifyColumn(column: CollectionColumn): ColumnKind;
|
|
73
|
+
export interface MapCollectionOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Admin scope: surface `user_id` as an OPTIONAL insert field so a
|
|
76
|
+
* developer can attribute a row to a specific app user (the admin row
|
|
77
|
+
* POST honors a `user_id` in the body). Other server-managed columns
|
|
78
|
+
* (`id`, `created_at`, …) stay stamped. Client scope leaves this off —
|
|
79
|
+
* the route derives `user_id` from the session.
|
|
80
|
+
*/
|
|
81
|
+
includeUserIdInInsert?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Project a collection schema into the zod raw shapes the auto-MCP tools
|
|
85
|
+
* register. Pure — same input always yields the same shapes.
|
|
86
|
+
*/
|
|
87
|
+
export declare function mapCollectionSchema(schema: CollectionSchemaPayload, options?: MapCollectionOptions): MappedCollection;
|
package/dist/index.d.ts
CHANGED
|
@@ -41,3 +41,5 @@ export declare function createApiClient(options: {
|
|
|
41
41
|
}): ApiClient;
|
|
42
42
|
export { ApiClient } from './api-client.js';
|
|
43
43
|
export type { ApiClientOptions } from './api-client.js';
|
|
44
|
+
export { registerAutoMcpTools, registerCollectionToolsFor, collectionToolName, sanitizeNameFragment, mapCollectionSchema, classifyColumn, describeCollectionTool, describeListCollections, describeWhoami, SERVER_MANAGED_COLUMNS, } from './auto/index.js';
|
|
45
|
+
export type { RegisterAutoMcpOptions, CollectionPolicy, RegisterCollectionToolsOptions, CollectionSchemaPayload, CollectionColumn, ColumnKind, MappedCollection, CollectionVerb, DescribeContext, ToolScope, } from './auto/index.js';
|