@mcpfn/datafn 0.1.8 → 0.1.10
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/README.md +8 -0
- package/dist/index.cjs +36 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +36 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -42,6 +42,14 @@ const server = createMcpFnServer({
|
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
Mutation tools need the function form of `clientId`, returning a value per
|
|
46
|
+
credential: DataFn keys idempotency records by namespace, client ID and the
|
|
47
|
+
model-supplied `mutationId`, so with one fixed string two users could share
|
|
48
|
+
records. A fixed string is accepted for read-only exposure, or with
|
|
49
|
+
`allowSharedClientId: true`. List filters accept scalar values only; `object`
|
|
50
|
+
and `array` fields are left out of the default filters and refused in an
|
|
51
|
+
explicit `filterFields`.
|
|
52
|
+
|
|
45
53
|
This adapter is appropriate for bounded data operations. Domain workflows with additional authorization, auditing, asset grants, or version-resolution semantics should remain explicit McpFn tools.
|
|
46
54
|
|
|
47
55
|
## Exposure reference
|
package/dist/index.cjs
CHANGED
|
@@ -106,6 +106,13 @@ function fieldSchema(field) {
|
|
|
106
106
|
}
|
|
107
107
|
return base;
|
|
108
108
|
}
|
|
109
|
+
function scalarFilterSchema(field) {
|
|
110
|
+
const schema = fieldSchema(field);
|
|
111
|
+
const types = (Array.isArray(schema.type) ? schema.type : [schema.type]).filter((type) => type !== "object" && type !== "array");
|
|
112
|
+
if (!types.some((type) => type !== "null")) return void 0;
|
|
113
|
+
const { items: _items, additionalProperties: _additional, ...rest } = schema;
|
|
114
|
+
return { ...rest, type: types.length === 1 ? types[0] : types };
|
|
115
|
+
}
|
|
109
116
|
function capabilitiesFor(schema, resource) {
|
|
110
117
|
return (0, import_core.getCapabilityFields)(
|
|
111
118
|
(0, import_core.resolveCapabilities)(schema.capabilities, resource.capabilities)
|
|
@@ -227,6 +234,25 @@ function createDatafnMcpRegistry(options) {
|
|
|
227
234
|
throw new import_core2.McpFnValidationError("DataFn clientId must be a non-empty string");
|
|
228
235
|
}
|
|
229
236
|
assertUniqueToolNames(registry, options.expose, prefix);
|
|
237
|
+
if (typeof options.clientId === "string" && options.allowSharedClientId !== true && Object.values(options.expose).some((exposure) => exposure.create || exposure.update || exposure.delete)) {
|
|
238
|
+
throw new import_core2.McpFnValidationError(
|
|
239
|
+
"DataFn mutation tools need a per-credential clientId resolver; a fixed string shares idempotency records between users (set allowSharedClientId to accept it)"
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
for (const [resourceName, exposure] of Object.entries(options.expose)) {
|
|
243
|
+
const list = operationOptions(exposure.list, true);
|
|
244
|
+
const resource = schema.resources.find((candidate) => candidate.name === resourceName);
|
|
245
|
+
if (!list?.filterFields || !resource) continue;
|
|
246
|
+
const schemaFields = fieldMaps(schema, resource).schemaFields;
|
|
247
|
+
for (const field of list.filterFields) {
|
|
248
|
+
const definition = schemaFields.get(field);
|
|
249
|
+
if (field !== "id" && definition && !scalarFilterSchema(definition)) {
|
|
250
|
+
throw new import_core2.McpFnValidationError(
|
|
251
|
+
`DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
230
256
|
for (const resourceName of Object.keys(options.expose).sort()) {
|
|
231
257
|
const exposure = options.expose[resourceName];
|
|
232
258
|
const resource = schema.resources.find((candidate) => candidate.name === resourceName);
|
|
@@ -244,12 +270,16 @@ function createDatafnMcpRegistry(options) {
|
|
|
244
270
|
validateFieldList(`DataFn resource ${resourceName} filterFields`, filterFields);
|
|
245
271
|
validateFieldList(`DataFn resource ${resourceName} sortFields`, sortFields);
|
|
246
272
|
validateReadFields(schema, resource, [...filterFields, ...sortFields]);
|
|
247
|
-
const filterProperties =
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
273
|
+
const filterProperties = {};
|
|
274
|
+
for (const field of filterFields) {
|
|
275
|
+
const filter = field === "id" ? { type: "string" } : scalarFilterSchema(maps.schemaFields.get(field));
|
|
276
|
+
if (filter) filterProperties[field] = filter;
|
|
277
|
+
else if (list.filterFields) {
|
|
278
|
+
throw new import_core2.McpFnValidationError(
|
|
279
|
+
`DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
253
283
|
const maxLimit = list.maxLimit ?? 100;
|
|
254
284
|
validateLimit(`DataFn resource ${resourceName} maxLimit`, maxLimit);
|
|
255
285
|
const defaultLimit = list.defaultLimit ?? Math.min(50, maxLimit);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/adapter.ts"],"sourcesContent":["export * from \"./adapter.js\";\nexport * from \"./types.js\";\n","import {\n getCapabilityFields,\n resolveCapabilities,\n type DatafnFieldSchema,\n type DatafnResourceSchema,\n type DatafnSchema,\n} from \"@datafn/core\";\nimport {\n McpFnRegistry,\n McpFnValidationError,\n structuredResult,\n type McpFnJsonSchema,\n type McpFnToolDefinition,\n} from \"@mcpfn/core\";\n\nimport type {\n CreateDatafnMcpRegistryOptions,\n DatafnListToolOptions,\n DatafnReadToolOptions,\n DatafnResourceExposure,\n DatafnWriteToolOptions,\n} from \"./types.js\";\n\ntype Operation = \"list\" | \"get\" | \"create\" | \"update\" | \"delete\";\n\nfunction validateFieldList(label: string, fields: string[]): void {\n if (\n fields.length === 0 ||\n new Set(fields).size !== fields.length ||\n fields.some((field) => typeof field !== \"string\" || !field)\n ) {\n throw new McpFnValidationError(`${label} must be a non-empty, unique field list`);\n }\n}\n\nfunction validateLimit(label: string, value: number): void {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new McpFnValidationError(`${label} must be a positive safe integer`);\n }\n}\n\nasync function resolveClientId<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n context: TMcpContext,\n): Promise<string> {\n const clientId = typeof options.clientId === \"string\"\n ? options.clientId\n : await options.clientId(context);\n if (typeof clientId !== \"string\" || !clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must resolve to a non-empty string\");\n }\n return clientId;\n}\n\nfunction safeSegment(value: string): string {\n let segment = \"\";\n let needsSeparator = false;\n for (const character of value) {\n const code = character.charCodeAt(0);\n const allowed =\n (code >= 48 && code <= 57) ||\n (code >= 65 && code <= 90) ||\n (code >= 97 && code <= 122) ||\n character === \"_\" || character === \".\" || character === \"-\";\n if (allowed) {\n if (needsSeparator && segment) segment += \"_\";\n segment += character;\n needsSeparator = false;\n } else {\n needsSeparator = true;\n }\n }\n let start = 0;\n let end = segment.length;\n while (start < end && segment[start] === \"_\") start += 1;\n while (end > start && segment[end - 1] === \"_\") end -= 1;\n return segment.slice(start, end);\n}\n\nfunction resourceDefaults(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n if (resource.permissions !== undefined || resource.defaultPermissions === false) {\n return undefined;\n }\n return schema.defaultPermissions;\n}\n\nfunction fieldSchema(field: DatafnFieldSchema): McpFnJsonSchema {\n const base: McpFnJsonSchema = (() => {\n switch (field.type) {\n case \"number\": return { type: \"number\" };\n case \"boolean\": return { type: \"boolean\" };\n case \"array\": return { type: \"array\", items: {} };\n case \"object\": return { type: \"object\", additionalProperties: true };\n case \"json\": return { type: [\"string\", \"number\", \"boolean\", \"object\", \"array\"] };\n case \"date\": return { type: [\"string\", \"number\"], format: \"date-time\" };\n case \"file\": return { type: \"string\" };\n default: return { type: \"string\" };\n }\n })();\n if (field.enum) base.enum = field.enum;\n if (field.min !== undefined) base.minimum = field.min;\n if (field.max !== undefined) base.maximum = field.max;\n if (field.minLength !== undefined) base.minLength = field.minLength;\n if (field.maxLength !== undefined) base.maxLength = field.maxLength;\n if (field.pattern !== undefined) base.pattern = field.pattern;\n if (field.nullable) {\n const currentTypes = Array.isArray(base.type) ? base.type : [base.type];\n base.type = [...new Set([...currentTypes, \"null\"])];\n if (Array.isArray(base.enum) && !base.enum.includes(null)) {\n base.enum = [...base.enum, null];\n }\n }\n return base;\n}\n\nfunction capabilitiesFor(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n return getCapabilityFields(\n resolveCapabilities(schema.capabilities as never, resource.capabilities as never) as never,\n );\n}\n\nfunction fieldMaps(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n const schemaFields = new Map(resource.fields.map((field) => [field.name, field]));\n for (const field of capabilitiesFor(schema, resource)) {\n schemaFields.set(field.name, field as DatafnFieldSchema);\n }\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n const defaultFields = [\"id\", ...resource.fields.map((field) => field.name)];\n const readable = new Set([\n \"id\",\n ...(resource.permissions?.read?.fields ??\n (readDefault === \"allResourceFields\" ? defaultFields : [])),\n ]);\n for (const field of capabilitiesFor(schema, resource)) readable.add(field.name);\n const writable = new Set(\n resource.permissions?.write?.fields ??\n (writeDefault === \"allResourceFields\" ? defaultFields : []),\n );\n return { schemaFields, readable, writable };\n}\n\nfunction validateReadFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n if (!resource.permissions?.read && readDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no read policy and cannot be exposed`,\n );\n }\n const { schemaFields, readable } = fieldMaps(schema, resource);\n for (const field of fields) {\n if (field !== \"id\" && !schemaFields.has(field)) {\n throw new McpFnValidationError(\n `Unknown exposed field ${resource.name}.${field}`,\n );\n }\n if (!readable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not readable by DataFn policy`,\n );\n }\n }\n}\n\nfunction validateWriteFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no write policy and cannot expose mutations`,\n );\n }\n const { schemaFields, writable } = fieldMaps(schema, resource);\n for (const field of fields) {\n const definition = schemaFields.get(field);\n if (!definition) {\n throw new McpFnValidationError(`Unknown write field ${resource.name}.${field}`);\n }\n if (definition.readonly || !writable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not writable by DataFn policy`,\n );\n }\n }\n}\n\nfunction operationOptions<T>(value: boolean | T | undefined, enabledByDefault: boolean): T | undefined {\n if (value === false) return undefined;\n if (value === true) return {} as T;\n if (value === undefined) return enabledByDefault ? ({} as T) : undefined;\n return value;\n}\n\nfunction outputSchema() {\n return {\n type: \"object\" as const,\n properties: {\n resource: { type: \"string\" },\n operation: { type: \"string\" },\n result: {},\n },\n required: [\"resource\", \"operation\", \"result\"],\n additionalProperties: false,\n };\n}\n\nfunction defaultName(prefix: string, resource: string, operation: Operation): string {\n return [prefix, safeSegment(resource), operation].filter(Boolean).join(\"_\");\n}\n\nfunction assertUniqueToolNames<TMcpContext>(\n registry: McpFnRegistry<TMcpContext>,\n expose: Record<string, DatafnResourceExposure>,\n prefix: string,\n): void {\n const owners = new Map<string, string>();\n for (const resourceName of Object.keys(expose).sort()) {\n const exposure = expose[resourceName]!;\n const operations: Array<[Operation, DatafnReadToolOptions | DatafnWriteToolOptions | undefined]> = [\n [\"list\", operationOptions<DatafnListToolOptions>(exposure.list, true)],\n [\"get\", operationOptions<DatafnReadToolOptions>(exposure.get, true)],\n [\"create\", exposure.create || undefined],\n [\"update\", exposure.update || undefined],\n [\"delete\", operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(exposure.delete, false)],\n ];\n for (const [operation, config] of operations) {\n if (!config) continue;\n const name = config.name ?? defaultName(prefix, resourceName, operation);\n const owner = `${resourceName}.${operation}`;\n const existing = owners.get(name);\n if (existing || registry.has(name)) {\n throw new McpFnValidationError(\n `DataFn tool name collision for ${name}: ${existing ?? \"existing registry tool\"} and ${owner}`,\n );\n }\n owners.set(name, owner);\n }\n }\n}\n\nexport function createDatafnMcpRegistry<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n): McpFnRegistry<TMcpContext> {\n const registry = options.registry ?? new McpFnRegistry<TMcpContext>();\n const schema = options.executor.schema;\n const prefix = safeSegment(options.toolPrefix ?? \"datafn\");\n if (typeof options.clientId === \"string\" && !options.clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must be a non-empty string\");\n }\n assertUniqueToolNames(registry, options.expose, prefix);\n\n for (const resourceName of Object.keys(options.expose).sort()) {\n const exposure = options.expose[resourceName]!;\n const resource = schema.resources.find((candidate) => candidate.name === resourceName);\n if (!resource) {\n throw new McpFnValidationError(`Unknown DataFn resource: ${resourceName}`);\n }\n const list = operationOptions<DatafnListToolOptions>(exposure.list, true);\n const get = operationOptions<DatafnReadToolOptions>(exposure.get, true);\n validateFieldList(`DataFn resource ${resourceName} projection`, exposure.fields);\n if (list || get) validateReadFields(schema, resource, exposure.fields);\n const maps = fieldMaps(schema, resource);\n\n if (list) {\n const filterFields = list.filterFields ?? exposure.fields;\n const sortFields = list.sortFields ?? [\"id\"];\n validateFieldList(`DataFn resource ${resourceName} filterFields`, filterFields);\n validateFieldList(`DataFn resource ${resourceName} sortFields`, sortFields);\n validateReadFields(schema, resource, [...filterFields, ...sortFields]);\n const filterProperties = Object.fromEntries(\n filterFields.map((field) => [\n field,\n field === \"id\" ? { type: \"string\" } : fieldSchema(maps.schemaFields.get(field)!),\n ]),\n );\n const maxLimit = list.maxLimit ?? 100;\n validateLimit(`DataFn resource ${resourceName} maxLimit`, maxLimit);\n const defaultLimit = list.defaultLimit ?? Math.min(50, maxLimit);\n validateLimit(`DataFn resource ${resourceName} defaultLimit`, defaultLimit);\n if (defaultLimit > maxLimit) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} defaultLimit cannot exceed maxLimit`,\n );\n }\n const definition: McpFnToolDefinition<TMcpContext> = {\n name: list.name ?? defaultName(prefix, resourceName, \"list\"),\n description:\n list.description ?? `List ${resourceName} records visible to the authenticated DataFn context.`,\n inputSchema: {\n type: \"object\",\n properties: {\n filters: {\n type: \"object\",\n properties: filterProperties,\n additionalProperties: false,\n },\n sort: {\n type: \"array\",\n items: {\n type: \"string\",\n enum: sortFields.flatMap((field) => [`${field}:asc`, `${field}:desc`]),\n },\n maxItems: Math.max(1, sortFields.length),\n },\n cursor: { type: \"object\", additionalProperties: true },\n limit: { type: \"integer\", minimum: 1, maximum: maxLimit },\n },\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"list\" } },\n handler: async (args, context) => {\n const requestedSort = args.sort as string[] | undefined;\n const querySort = requestedSort?.length\n ? [\n ...requestedSort.filter((term) => !term.startsWith(\"id:\")),\n requestedSort.find((term) => term.startsWith(\"id:\")) ?? \"id:asc\",\n ]\n : undefined;\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n ...(args.filters ? { filters: args.filters } : {}),\n ...(querySort ? { sort: querySort } : {}),\n ...(args.cursor ? { cursor: args.cursor } : {}),\n limit: Math.min(Number(args.limit ?? defaultLimit), maxLimit),\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"list\", result });\n },\n };\n registry.register(definition);\n }\n\n if (get) {\n registry.register({\n name: get.name ?? defaultName(prefix, resourceName, \"get\"),\n description: get.description ?? `Get one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\", minLength: 1 } },\n required: [\"id\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"get\" } },\n handler: async ({ id }, context) => {\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n filters: { id },\n limit: 1,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"get\", result });\n },\n });\n }\n\n const registerWrite = (\n operation: \"create\" | \"update\",\n config: DatafnWriteToolOptions,\n ) => {\n validateFieldList(\n `DataFn resource ${resourceName} ${operation} fields`,\n config.fields,\n );\n validateWriteFields(schema, resource, config.fields);\n const requiredCreateFields = [...maps.schemaFields.values()]\n .filter((field) =>\n field.name !== \"id\" &&\n field.required &&\n field.default === undefined &&\n !field.readonly)\n .map((field) => field.name)\n .sort();\n if (operation === \"create\") {\n const missingRequiredFields = requiredCreateFields.filter(\n (field) => !config.fields.includes(field),\n );\n if (missingRequiredFields.length) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} create fields omit required writable fields: ${missingRequiredFields.join(\", \")}`,\n );\n }\n }\n const properties = Object.fromEntries(\n config.fields.map((field) => [field, fieldSchema(maps.schemaFields.get(field)!)]),\n );\n const recordRequired = operation === \"create\"\n ? requiredCreateFields\n : [];\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, operation),\n description: config.description ?? `${operation === \"create\" ? \"Create\" : \"Update\"} one ${resourceName} record.`,\n inputSchema: {\n type: \"object\",\n properties: {\n ...(operation === \"create\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n ...(operation === \"update\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n mutationId: { type: \"string\", minLength: 1 },\n record: {\n type: \"object\",\n properties,\n ...(recordRequired.length ? { required: recordRequired } : {}),\n additionalProperties: false,\n },\n },\n required: [\"mutationId\", \"record\", ...(operation === \"update\" ? [\"id\"] : [])],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation } },\n handler: async (args, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: operation === \"create\" ? \"insert\" : \"merge\",\n clientId,\n mutationId: args.mutationId,\n ...(args.id ? { id: args.id } : {}),\n record: args.record,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation, result });\n },\n });\n };\n\n if (exposure.create) registerWrite(\"create\", exposure.create);\n if (exposure.update) registerWrite(\"update\", exposure.update);\n const remove = operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(\n exposure.delete,\n false,\n );\n if (remove) {\n const config = remove;\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} has no write policy and cannot expose delete`,\n );\n }\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, \"delete\"),\n description: config.description ?? `Delete one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", minLength: 1 },\n mutationId: { type: \"string\", minLength: 1 },\n },\n required: [\"id\", \"mutationId\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"delete\" } },\n handler: async ({ id, mutationId }, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: \"delete\",\n clientId,\n mutationId,\n id,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resour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AS,OAAO,SAAS,OAAO;AAAA,cAChC,WAAW;AAAA,cACX;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YACA,MAAM,QAAQ,QAAQ,OAAO;AAAA,UAC/B;AACA,qBAAO,+BAAiB,EAAE,UAAU,cAAc,WAAW,UAAU,OAAO,CAAC;AAAA,QACjF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":["import_core"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/adapter.ts"],"sourcesContent":["export * from \"./adapter.js\";\nexport * from \"./types.js\";\n","import {\n getCapabilityFields,\n resolveCapabilities,\n type DatafnFieldSchema,\n type DatafnResourceSchema,\n type DatafnSchema,\n} from \"@datafn/core\";\nimport {\n McpFnRegistry,\n McpFnValidationError,\n structuredResult,\n type McpFnJsonSchema,\n type McpFnToolDefinition,\n} from \"@mcpfn/core\";\n\nimport type {\n CreateDatafnMcpRegistryOptions,\n DatafnListToolOptions,\n DatafnReadToolOptions,\n DatafnResourceExposure,\n DatafnWriteToolOptions,\n} from \"./types.js\";\n\ntype Operation = \"list\" | \"get\" | \"create\" | \"update\" | \"delete\";\n\nfunction validateFieldList(label: string, fields: string[]): void {\n if (\n fields.length === 0 ||\n new Set(fields).size !== fields.length ||\n fields.some((field) => typeof field !== \"string\" || !field)\n ) {\n throw new McpFnValidationError(`${label} must be a non-empty, unique field list`);\n }\n}\n\nfunction validateLimit(label: string, value: number): void {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new McpFnValidationError(`${label} must be a positive safe integer`);\n }\n}\n\nasync function resolveClientId<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n context: TMcpContext,\n): Promise<string> {\n const clientId = typeof options.clientId === \"string\"\n ? options.clientId\n : await options.clientId(context);\n if (typeof clientId !== \"string\" || !clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must resolve to a non-empty string\");\n }\n return clientId;\n}\n\nfunction safeSegment(value: string): string {\n let segment = \"\";\n let needsSeparator = false;\n for (const character of value) {\n const code = character.charCodeAt(0);\n const allowed =\n (code >= 48 && code <= 57) ||\n (code >= 65 && code <= 90) ||\n (code >= 97 && code <= 122) ||\n character === \"_\" || character === \".\" || character === \"-\";\n if (allowed) {\n if (needsSeparator && segment) segment += \"_\";\n segment += character;\n needsSeparator = false;\n } else {\n needsSeparator = true;\n }\n }\n let start = 0;\n let end = segment.length;\n while (start < end && segment[start] === \"_\") start += 1;\n while (end > start && segment[end - 1] === \"_\") end -= 1;\n return segment.slice(start, end);\n}\n\nfunction resourceDefaults(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n if (resource.permissions !== undefined || resource.defaultPermissions === false) {\n return undefined;\n }\n return schema.defaultPermissions;\n}\n\nfunction fieldSchema(field: DatafnFieldSchema): McpFnJsonSchema {\n const base: McpFnJsonSchema = (() => {\n switch (field.type) {\n case \"number\": return { type: \"number\" };\n case \"boolean\": return { type: \"boolean\" };\n case \"array\": return { type: \"array\", items: {} };\n case \"object\": return { type: \"object\", additionalProperties: true };\n case \"json\": return { type: [\"string\", \"number\", \"boolean\", \"object\", \"array\"] };\n case \"date\": return { type: [\"string\", \"number\"], format: \"date-time\" };\n case \"file\": return { type: \"string\" };\n default: return { type: \"string\" };\n }\n })();\n if (field.enum) base.enum = field.enum;\n if (field.min !== undefined) base.minimum = field.min;\n if (field.max !== undefined) base.maximum = field.max;\n if (field.minLength !== undefined) base.minLength = field.minLength;\n if (field.maxLength !== undefined) base.maxLength = field.maxLength;\n if (field.pattern !== undefined) base.pattern = field.pattern;\n if (field.nullable) {\n const currentTypes = Array.isArray(base.type) ? base.type : [base.type];\n base.type = [...new Set([...currentTypes, \"null\"])];\n if (Array.isArray(base.enum) && !base.enum.includes(null)) {\n base.enum = [...base.enum, null];\n }\n }\n return base;\n}\n\nfunction scalarFilterSchema(field: DatafnFieldSchema): McpFnJsonSchema | undefined {\n const schema = fieldSchema(field);\n const types = (Array.isArray(schema.type) ? schema.type : [schema.type])\n .filter((type) => type !== \"object\" && type !== \"array\");\n if (!types.some((type) => type !== \"null\")) return undefined;\n const { items: _items, additionalProperties: _additional, ...rest } = schema;\n return { ...rest, type: types.length === 1 ? types[0] : types };\n}\n\nfunction capabilitiesFor(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n return getCapabilityFields(\n resolveCapabilities(schema.capabilities as never, resource.capabilities as never) as never,\n );\n}\n\nfunction fieldMaps(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n const schemaFields = new Map(resource.fields.map((field) => [field.name, field]));\n for (const field of capabilitiesFor(schema, resource)) {\n schemaFields.set(field.name, field as DatafnFieldSchema);\n }\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n const defaultFields = [\"id\", ...resource.fields.map((field) => field.name)];\n const readable = new Set([\n \"id\",\n ...(resource.permissions?.read?.fields ??\n (readDefault === \"allResourceFields\" ? defaultFields : [])),\n ]);\n for (const field of capabilitiesFor(schema, resource)) readable.add(field.name);\n const writable = new Set(\n resource.permissions?.write?.fields ??\n (writeDefault === \"allResourceFields\" ? defaultFields : []),\n );\n return { schemaFields, readable, writable };\n}\n\nfunction validateReadFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n if (!resource.permissions?.read && readDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no read policy and cannot be exposed`,\n );\n }\n const { schemaFields, readable } = fieldMaps(schema, resource);\n for (const field of fields) {\n if (field !== \"id\" && !schemaFields.has(field)) {\n throw new McpFnValidationError(\n `Unknown exposed field ${resource.name}.${field}`,\n );\n }\n if (!readable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not readable by DataFn policy`,\n );\n }\n }\n}\n\nfunction validateWriteFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no write policy and cannot expose mutations`,\n );\n }\n const { schemaFields, writable } = fieldMaps(schema, resource);\n for (const field of fields) {\n const definition = schemaFields.get(field);\n if (!definition) {\n throw new McpFnValidationError(`Unknown write field ${resource.name}.${field}`);\n }\n if (definition.readonly || !writable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not writable by DataFn policy`,\n );\n }\n }\n}\n\nfunction operationOptions<T>(value: boolean | T | undefined, enabledByDefault: boolean): T | undefined {\n if (value === false) return undefined;\n if (value === true) return {} as T;\n if (value === undefined) return enabledByDefault ? ({} as T) : undefined;\n return value;\n}\n\nfunction outputSchema() {\n return {\n type: \"object\" as const,\n properties: {\n resource: { type: \"string\" },\n operation: { type: \"string\" },\n result: {},\n },\n required: [\"resource\", \"operation\", \"result\"],\n additionalProperties: false,\n };\n}\n\nfunction defaultName(prefix: string, resource: string, operation: Operation): string {\n return [prefix, safeSegment(resource), operation].filter(Boolean).join(\"_\");\n}\n\nfunction assertUniqueToolNames<TMcpContext>(\n registry: McpFnRegistry<TMcpContext>,\n expose: Record<string, DatafnResourceExposure>,\n prefix: string,\n): void {\n const owners = new Map<string, string>();\n for (const resourceName of Object.keys(expose).sort()) {\n const exposure = expose[resourceName]!;\n const operations: Array<[Operation, DatafnReadToolOptions | DatafnWriteToolOptions | undefined]> = [\n [\"list\", operationOptions<DatafnListToolOptions>(exposure.list, true)],\n [\"get\", operationOptions<DatafnReadToolOptions>(exposure.get, true)],\n [\"create\", exposure.create || undefined],\n [\"update\", exposure.update || undefined],\n [\"delete\", operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(exposure.delete, false)],\n ];\n for (const [operation, config] of operations) {\n if (!config) continue;\n const name = config.name ?? defaultName(prefix, resourceName, operation);\n const owner = `${resourceName}.${operation}`;\n const existing = owners.get(name);\n if (existing || registry.has(name)) {\n throw new McpFnValidationError(\n `DataFn tool name collision for ${name}: ${existing ?? \"existing registry tool\"} and ${owner}`,\n );\n }\n owners.set(name, owner);\n }\n }\n}\n\nexport function createDatafnMcpRegistry<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n): McpFnRegistry<TMcpContext> {\n const registry = options.registry ?? new McpFnRegistry<TMcpContext>();\n const schema = options.executor.schema;\n const prefix = safeSegment(options.toolPrefix ?? \"datafn\");\n if (typeof options.clientId === \"string\" && !options.clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must be a non-empty string\");\n }\n assertUniqueToolNames(registry, options.expose, prefix);\n if (\n typeof options.clientId === \"string\" &&\n options.allowSharedClientId !== true &&\n Object.values(options.expose).some((exposure) => exposure.create || exposure.update || exposure.delete)\n ) {\n throw new McpFnValidationError(\n \"DataFn mutation tools need a per-credential clientId resolver; a fixed string shares idempotency records between users (set allowSharedClientId to accept it)\",\n );\n }\n\n // Refuse non-scalar filters before registering any tool, so this check\n // never leaves a supplied registry partly populated. (The registration\n // loop's other validation errors, which predate it, can still stop part-way.)\n for (const [resourceName, exposure] of Object.entries(options.expose)) {\n const list = operationOptions<DatafnListToolOptions>(exposure.list, true);\n const resource = schema.resources.find((candidate) => candidate.name === resourceName);\n if (!list?.filterFields || !resource) continue;\n const schemaFields = fieldMaps(schema, resource).schemaFields;\n for (const field of list.filterFields) {\n const definition = schemaFields.get(field);\n if (field !== \"id\" && definition && !scalarFilterSchema(definition)) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`,\n );\n }\n }\n }\n\n for (const resourceName of Object.keys(options.expose).sort()) {\n const exposure = options.expose[resourceName]!;\n const resource = schema.resources.find((candidate) => candidate.name === resourceName);\n if (!resource) {\n throw new McpFnValidationError(`Unknown DataFn resource: ${resourceName}`);\n }\n const list = operationOptions<DatafnListToolOptions>(exposure.list, true);\n const get = operationOptions<DatafnReadToolOptions>(exposure.get, true);\n validateFieldList(`DataFn resource ${resourceName} projection`, exposure.fields);\n if (list || get) validateReadFields(schema, resource, exposure.fields);\n const maps = fieldMaps(schema, resource);\n\n if (list) {\n const filterFields = list.filterFields ?? exposure.fields;\n const sortFields = list.sortFields ?? [\"id\"];\n validateFieldList(`DataFn resource ${resourceName} filterFields`, filterFields);\n validateFieldList(`DataFn resource ${resourceName} sortFields`, sortFields);\n validateReadFields(schema, resource, [...filterFields, ...sortFields]);\n // Filters take scalar values only: DataFn reads an object as an\n // operator expression, which the model should not choose.\n const filterProperties: Record<string, McpFnJsonSchema> = {};\n for (const field of filterFields) {\n const filter = field === \"id\" ? { type: \"string\" } : scalarFilterSchema(maps.schemaFields.get(field)!);\n if (filter) filterProperties[field] = filter;\n else if (list.filterFields) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`,\n );\n }\n }\n const maxLimit = list.maxLimit ?? 100;\n validateLimit(`DataFn resource ${resourceName} maxLimit`, maxLimit);\n const defaultLimit = list.defaultLimit ?? Math.min(50, maxLimit);\n validateLimit(`DataFn resource ${resourceName} defaultLimit`, defaultLimit);\n if (defaultLimit > maxLimit) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} defaultLimit cannot exceed maxLimit`,\n );\n }\n const definition: McpFnToolDefinition<TMcpContext> = {\n name: list.name ?? defaultName(prefix, resourceName, \"list\"),\n description:\n list.description ?? `List ${resourceName} records visible to the authenticated DataFn context.`,\n inputSchema: {\n type: \"object\",\n properties: {\n filters: {\n type: \"object\",\n properties: filterProperties,\n additionalProperties: false,\n },\n sort: {\n type: \"array\",\n items: {\n type: \"string\",\n enum: sortFields.flatMap((field) => [`${field}:asc`, `${field}:desc`]),\n },\n maxItems: Math.max(1, sortFields.length),\n },\n cursor: { type: \"object\", additionalProperties: true },\n limit: { type: \"integer\", minimum: 1, maximum: maxLimit },\n },\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"list\" } },\n handler: async (args, context) => {\n const requestedSort = args.sort as string[] | undefined;\n const querySort = requestedSort?.length\n ? [\n ...requestedSort.filter((term) => !term.startsWith(\"id:\")),\n requestedSort.find((term) => term.startsWith(\"id:\")) ?? \"id:asc\",\n ]\n : undefined;\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n ...(args.filters ? { filters: args.filters } : {}),\n ...(querySort ? { sort: querySort } : {}),\n ...(args.cursor ? { cursor: args.cursor } : {}),\n limit: Math.min(Number(args.limit ?? defaultLimit), maxLimit),\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"list\", result });\n },\n };\n registry.register(definition);\n }\n\n if (get) {\n registry.register({\n name: get.name ?? defaultName(prefix, resourceName, \"get\"),\n description: get.description ?? `Get one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\", minLength: 1 } },\n required: [\"id\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"get\" } },\n handler: async ({ id }, context) => {\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n filters: { id },\n limit: 1,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"get\", result });\n },\n });\n }\n\n const registerWrite = (\n operation: \"create\" | \"update\",\n config: DatafnWriteToolOptions,\n ) => {\n validateFieldList(\n `DataFn resource ${resourceName} ${operation} fields`,\n config.fields,\n );\n validateWriteFields(schema, resource, config.fields);\n const requiredCreateFields = [...maps.schemaFields.values()]\n .filter((field) =>\n field.name !== \"id\" &&\n field.required &&\n field.default === undefined &&\n !field.readonly)\n .map((field) => field.name)\n .sort();\n if (operation === \"create\") {\n const missingRequiredFields = requiredCreateFields.filter(\n (field) => !config.fields.includes(field),\n );\n if (missingRequiredFields.length) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} create fields omit required writable fields: ${missingRequiredFields.join(\", \")}`,\n );\n }\n }\n const properties = Object.fromEntries(\n config.fields.map((field) => [field, fieldSchema(maps.schemaFields.get(field)!)]),\n );\n const recordRequired = operation === \"create\"\n ? requiredCreateFields\n : [];\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, operation),\n description: config.description ?? `${operation === \"create\" ? \"Create\" : \"Update\"} one ${resourceName} record.`,\n inputSchema: {\n type: \"object\",\n properties: {\n ...(operation === \"create\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n ...(operation === \"update\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n mutationId: { type: \"string\", minLength: 1 },\n record: {\n type: \"object\",\n properties,\n ...(recordRequired.length ? { required: recordRequired } : {}),\n additionalProperties: false,\n },\n },\n required: [\"mutationId\", \"record\", ...(operation === \"update\" ? [\"id\"] : [])],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation } },\n handler: async (args, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: operation === \"create\" ? \"insert\" : \"merge\",\n clientId,\n mutationId: args.mutationId,\n ...(args.id ? { id: args.id } : {}),\n record: args.record,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation, result });\n },\n });\n };\n\n if (exposure.create) registerWrite(\"create\", exposure.create);\n if (exposure.update) registerWrite(\"update\", exposure.update);\n const remove = operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(\n exposure.delete,\n false,\n );\n if (remove) {\n const config = remove;\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} has no write policy and cannot expose delete`,\n );\n }\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, \"delete\"),\n description: config.description ?? `Delete one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", minLength: 1 },\n mutationId: { type: \"string\", minLength: 1 },\n },\n required: [\"id\", \"mutationId\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"delete\" } },\n handler: async ({ id, mutationId }, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: \"delete\",\n clientId,\n mutationId,\n id,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"delete\", result });\n },\n });\n }\n }\n\n return registry;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAMO;AACP,IAAAA,eAMO;AAYP,SAAS,kBAAkB,OAAe,QAAwB;AAChE,MACE,OAAO,WAAW,KAClB,IAAI,IAAI,MAAM,EAAE,SAAS,OAAO,UAChC,OAAO,KAAK,CAAC,UAAU,OAAO,UAAU,YAAY,CAAC,KAAK,GAC1D;AACA,UAAM,IAAI,kCAAqB,GAAG,KAAK,yCAAyC;AAAA,EAClF;AACF;AAEA,SAAS,cAAc,OAAe,OAAqB;AACzD,MAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG;AAC7C,UAAM,IAAI,kCAAqB,GAAG,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eAAS,SAAS;AAAA,QAChB,MAAM,OAAO,QAAQ,YAAY,QAAQ,cAAc,QAAQ;AAAA,QAC/D,aAAa,OAAO,eAAe,cAAc,YAAY;AAAA,QAC7D,aAAa;AAAA,UACX,MAAM;AAAA,UACN,YAAY;AAAA,YACV,IAAI,EAAE,MAAM,UAAU,WAAW,EAAE;AAAA,YACnC,YAAY,EAAE,MAAM,UAAU,WAAW,EAAE;AAAA,UAC7C;AAAA,UACA,UAAU,CAAC,MAAM,YAAY;AAAA,UAC7B,sBAAsB;AAAA,QACxB;AAAA,QACA,cAAc,aAAa;AAAA,QAC3B,aAAa;AAAA,UACX,cAAc;AAAA,UACd,iBAAiB;AAAA,UACjB,gBAAgB;AAAA,UAChB,eAAe;AAAA,QACjB;AAAA,QACA,UAAU,EAAE,gBAAgB,EAAE,UAAU,cAAc,WAAW,SAAS,EAAE;AAAA,QAC5E,SAAS,OAAO,EAAE,IAAI,WAAW,GAAG,YAAY;AAC9C,gBAAM,WAAW,MAAM,gBAAgB,SAAS,OAAO;AACvD,gBAAM,SAAS,MAAM,QAAQ,SAAS;AAAA,YACpC;AAAA,cACE,UAAU;AAAA,cACV,SAAS,OAAO,SAAS,OAAO;AAAA,cAChC,WAAW;AAAA,cACX;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YACA,MAAM,QAAQ,QAAQ,OAAO;AAAA,UAC/B;AACA,qBAAO,+BAAiB,EAAE,UAAU,cAAc,WAAW,UAAU,OAAO,CAAC;AAAA,QACjF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":["import_core"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -35,8 +35,17 @@ interface CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext> {
|
|
|
35
35
|
expose: Record<string, DatafnResourceExposure>;
|
|
36
36
|
/** Resolve trusted DataFn context from server-derived MCP context. */
|
|
37
37
|
context: (context: TMcpContext) => TDatafnContext | Promise<TDatafnContext>;
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Client ID used with DataFn idempotency records, which are keyed by
|
|
40
|
+
* namespace, client ID and the model-supplied mutationId. Use the function
|
|
41
|
+
* form and return a per-credential value: with one fixed string, two users
|
|
42
|
+
* in a namespace share idempotency records, so one can receive the other's
|
|
43
|
+
* cached mutation result. A string is accepted for read-only exposure, and
|
|
44
|
+
* with mutations only when allowSharedClientId is true.
|
|
45
|
+
*/
|
|
39
46
|
clientId: string | ((context: TMcpContext) => string | Promise<string>);
|
|
47
|
+
/** Accept a fixed string clientId when mutation tools are exposed. */
|
|
48
|
+
allowSharedClientId?: boolean;
|
|
40
49
|
registry?: McpFnRegistry<TMcpContext>;
|
|
41
50
|
toolPrefix?: string;
|
|
42
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -35,8 +35,17 @@ interface CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext> {
|
|
|
35
35
|
expose: Record<string, DatafnResourceExposure>;
|
|
36
36
|
/** Resolve trusted DataFn context from server-derived MCP context. */
|
|
37
37
|
context: (context: TMcpContext) => TDatafnContext | Promise<TDatafnContext>;
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Client ID used with DataFn idempotency records, which are keyed by
|
|
40
|
+
* namespace, client ID and the model-supplied mutationId. Use the function
|
|
41
|
+
* form and return a per-credential value: with one fixed string, two users
|
|
42
|
+
* in a namespace share idempotency records, so one can receive the other's
|
|
43
|
+
* cached mutation result. A string is accepted for read-only exposure, and
|
|
44
|
+
* with mutations only when allowSharedClientId is true.
|
|
45
|
+
*/
|
|
39
46
|
clientId: string | ((context: TMcpContext) => string | Promise<string>);
|
|
47
|
+
/** Accept a fixed string clientId when mutation tools are exposed. */
|
|
48
|
+
allowSharedClientId?: boolean;
|
|
40
49
|
registry?: McpFnRegistry<TMcpContext>;
|
|
41
50
|
toolPrefix?: string;
|
|
42
51
|
}
|
package/dist/index.js
CHANGED
|
@@ -87,6 +87,13 @@ function fieldSchema(field) {
|
|
|
87
87
|
}
|
|
88
88
|
return base;
|
|
89
89
|
}
|
|
90
|
+
function scalarFilterSchema(field) {
|
|
91
|
+
const schema = fieldSchema(field);
|
|
92
|
+
const types = (Array.isArray(schema.type) ? schema.type : [schema.type]).filter((type) => type !== "object" && type !== "array");
|
|
93
|
+
if (!types.some((type) => type !== "null")) return void 0;
|
|
94
|
+
const { items: _items, additionalProperties: _additional, ...rest } = schema;
|
|
95
|
+
return { ...rest, type: types.length === 1 ? types[0] : types };
|
|
96
|
+
}
|
|
90
97
|
function capabilitiesFor(schema, resource) {
|
|
91
98
|
return getCapabilityFields(
|
|
92
99
|
resolveCapabilities(schema.capabilities, resource.capabilities)
|
|
@@ -208,6 +215,25 @@ function createDatafnMcpRegistry(options) {
|
|
|
208
215
|
throw new McpFnValidationError("DataFn clientId must be a non-empty string");
|
|
209
216
|
}
|
|
210
217
|
assertUniqueToolNames(registry, options.expose, prefix);
|
|
218
|
+
if (typeof options.clientId === "string" && options.allowSharedClientId !== true && Object.values(options.expose).some((exposure) => exposure.create || exposure.update || exposure.delete)) {
|
|
219
|
+
throw new McpFnValidationError(
|
|
220
|
+
"DataFn mutation tools need a per-credential clientId resolver; a fixed string shares idempotency records between users (set allowSharedClientId to accept it)"
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
for (const [resourceName, exposure] of Object.entries(options.expose)) {
|
|
224
|
+
const list = operationOptions(exposure.list, true);
|
|
225
|
+
const resource = schema.resources.find((candidate) => candidate.name === resourceName);
|
|
226
|
+
if (!list?.filterFields || !resource) continue;
|
|
227
|
+
const schemaFields = fieldMaps(schema, resource).schemaFields;
|
|
228
|
+
for (const field of list.filterFields) {
|
|
229
|
+
const definition = schemaFields.get(field);
|
|
230
|
+
if (field !== "id" && definition && !scalarFilterSchema(definition)) {
|
|
231
|
+
throw new McpFnValidationError(
|
|
232
|
+
`DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
211
237
|
for (const resourceName of Object.keys(options.expose).sort()) {
|
|
212
238
|
const exposure = options.expose[resourceName];
|
|
213
239
|
const resource = schema.resources.find((candidate) => candidate.name === resourceName);
|
|
@@ -225,12 +251,16 @@ function createDatafnMcpRegistry(options) {
|
|
|
225
251
|
validateFieldList(`DataFn resource ${resourceName} filterFields`, filterFields);
|
|
226
252
|
validateFieldList(`DataFn resource ${resourceName} sortFields`, sortFields);
|
|
227
253
|
validateReadFields(schema, resource, [...filterFields, ...sortFields]);
|
|
228
|
-
const filterProperties =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
254
|
+
const filterProperties = {};
|
|
255
|
+
for (const field of filterFields) {
|
|
256
|
+
const filter = field === "id" ? { type: "string" } : scalarFilterSchema(maps.schemaFields.get(field));
|
|
257
|
+
if (filter) filterProperties[field] = filter;
|
|
258
|
+
else if (list.filterFields) {
|
|
259
|
+
throw new McpFnValidationError(
|
|
260
|
+
`DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
234
264
|
const maxLimit = list.maxLimit ?? 100;
|
|
235
265
|
validateLimit(`DataFn resource ${resourceName} maxLimit`, maxLimit);
|
|
236
266
|
const defaultLimit = list.defaultLimit ?? Math.min(50, maxLimit);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import {\n getCapabilityFields,\n resolveCapabilities,\n type DatafnFieldSchema,\n type DatafnResourceSchema,\n type DatafnSchema,\n} from \"@datafn/core\";\nimport {\n McpFnRegistry,\n McpFnValidationError,\n structuredResult,\n type McpFnJsonSchema,\n type McpFnToolDefinition,\n} from \"@mcpfn/core\";\n\nimport type {\n CreateDatafnMcpRegistryOptions,\n DatafnListToolOptions,\n DatafnReadToolOptions,\n DatafnResourceExposure,\n DatafnWriteToolOptions,\n} from \"./types.js\";\n\ntype Operation = \"list\" | \"get\" | \"create\" | \"update\" | \"delete\";\n\nfunction validateFieldList(label: string, fields: string[]): void {\n if (\n fields.length === 0 ||\n new Set(fields).size !== fields.length ||\n fields.some((field) => typeof field !== \"string\" || !field)\n ) {\n throw new McpFnValidationError(`${label} must be a non-empty, unique field list`);\n }\n}\n\nfunction validateLimit(label: string, value: number): void {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new McpFnValidationError(`${label} must be a positive safe integer`);\n }\n}\n\nasync function resolveClientId<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n context: TMcpContext,\n): Promise<string> {\n const clientId = typeof options.clientId === \"string\"\n ? options.clientId\n : await options.clientId(context);\n if (typeof clientId !== \"string\" || !clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must resolve to a non-empty string\");\n }\n return clientId;\n}\n\nfunction safeSegment(value: string): string {\n let segment = \"\";\n let needsSeparator = false;\n for (const character of value) {\n const code = character.charCodeAt(0);\n const allowed =\n (code >= 48 && code <= 57) ||\n (code >= 65 && code <= 90) ||\n (code >= 97 && code <= 122) ||\n character === \"_\" || character === \".\" || character === \"-\";\n if (allowed) {\n if (needsSeparator && segment) segment += \"_\";\n segment += character;\n needsSeparator = false;\n } else {\n needsSeparator = true;\n }\n }\n let start = 0;\n let end = segment.length;\n while (start < end && segment[start] === \"_\") start += 1;\n while (end > start && segment[end - 1] === \"_\") end -= 1;\n return segment.slice(start, end);\n}\n\nfunction resourceDefaults(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n if (resource.permissions !== undefined || resource.defaultPermissions === false) {\n return undefined;\n }\n return schema.defaultPermissions;\n}\n\nfunction fieldSchema(field: DatafnFieldSchema): McpFnJsonSchema {\n const base: McpFnJsonSchema = (() => {\n switch (field.type) {\n case \"number\": return { type: \"number\" };\n case \"boolean\": return { type: \"boolean\" };\n case \"array\": return { type: \"array\", items: {} };\n case \"object\": return { type: \"object\", additionalProperties: true };\n case \"json\": return { type: [\"string\", \"number\", \"boolean\", \"object\", \"array\"] };\n case \"date\": return { type: [\"string\", \"number\"], format: \"date-time\" };\n case \"file\": return { type: \"string\" };\n default: return { type: \"string\" };\n }\n })();\n if (field.enum) base.enum = field.enum;\n if (field.min !== undefined) base.minimum = field.min;\n if (field.max !== undefined) base.maximum = field.max;\n if (field.minLength !== undefined) base.minLength = field.minLength;\n if (field.maxLength !== undefined) base.maxLength = field.maxLength;\n if (field.pattern !== undefined) base.pattern = field.pattern;\n if (field.nullable) {\n const currentTypes = Array.isArray(base.type) ? base.type : [base.type];\n base.type = [...new Set([...currentTypes, \"null\"])];\n if (Array.isArray(base.enum) && !base.enum.includes(null)) {\n base.enum = [...base.enum, null];\n }\n }\n return base;\n}\n\nfunction capabilitiesFor(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n return getCapabilityFields(\n resolveCapabilities(schema.capabilities as never, resource.capabilities as never) as never,\n );\n}\n\nfunction fieldMaps(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n const schemaFields = new Map(resource.fields.map((field) => [field.name, field]));\n for (const field of capabilitiesFor(schema, resource)) {\n schemaFields.set(field.name, field as DatafnFieldSchema);\n }\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n const defaultFields = [\"id\", ...resource.fields.map((field) => field.name)];\n const readable = new Set([\n \"id\",\n ...(resource.permissions?.read?.fields ??\n (readDefault === \"allResourceFields\" ? defaultFields : [])),\n ]);\n for (const field of capabilitiesFor(schema, resource)) readable.add(field.name);\n const writable = new Set(\n resource.permissions?.write?.fields ??\n (writeDefault === \"allResourceFields\" ? defaultFields : []),\n );\n return { schemaFields, readable, writable };\n}\n\nfunction validateReadFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n if (!resource.permissions?.read && readDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no read policy and cannot be exposed`,\n );\n }\n const { schemaFields, readable } = fieldMaps(schema, resource);\n for (const field of fields) {\n if (field !== \"id\" && !schemaFields.has(field)) {\n throw new McpFnValidationError(\n `Unknown exposed field ${resource.name}.${field}`,\n );\n }\n if (!readable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not readable by DataFn policy`,\n );\n }\n }\n}\n\nfunction validateWriteFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no write policy and cannot expose mutations`,\n );\n }\n const { schemaFields, writable } = fieldMaps(schema, resource);\n for (const field of fields) {\n const definition = schemaFields.get(field);\n if (!definition) {\n throw new McpFnValidationError(`Unknown write field ${resource.name}.${field}`);\n }\n if (definition.readonly || !writable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not writable by DataFn policy`,\n );\n }\n }\n}\n\nfunction operationOptions<T>(value: boolean | T | undefined, enabledByDefault: boolean): T | undefined {\n if (value === false) return undefined;\n if (value === true) return {} as T;\n if (value === undefined) return enabledByDefault ? ({} as T) : undefined;\n return value;\n}\n\nfunction outputSchema() {\n return {\n type: \"object\" as const,\n properties: {\n resource: { type: \"string\" },\n operation: { type: \"string\" },\n result: {},\n },\n required: [\"resource\", \"operation\", \"result\"],\n additionalProperties: false,\n };\n}\n\nfunction defaultName(prefix: string, resource: string, operation: Operation): string {\n return [prefix, safeSegment(resource), operation].filter(Boolean).join(\"_\");\n}\n\nfunction assertUniqueToolNames<TMcpContext>(\n registry: McpFnRegistry<TMcpContext>,\n expose: Record<string, DatafnResourceExposure>,\n prefix: string,\n): void {\n const owners = new Map<string, string>();\n for (const resourceName of Object.keys(expose).sort()) {\n const exposure = expose[resourceName]!;\n const operations: Array<[Operation, DatafnReadToolOptions | DatafnWriteToolOptions | undefined]> = [\n [\"list\", operationOptions<DatafnListToolOptions>(exposure.list, true)],\n [\"get\", operationOptions<DatafnReadToolOptions>(exposure.get, true)],\n [\"create\", exposure.create || undefined],\n [\"update\", exposure.update || undefined],\n [\"delete\", operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(exposure.delete, false)],\n ];\n for (const [operation, config] of operations) {\n if (!config) continue;\n const name = config.name ?? defaultName(prefix, resourceName, operation);\n const owner = `${resourceName}.${operation}`;\n const existing = owners.get(name);\n if (existing || registry.has(name)) {\n throw new McpFnValidationError(\n `DataFn tool name collision for ${name}: ${existing ?? \"existing registry tool\"} and ${owner}`,\n );\n }\n owners.set(name, owner);\n }\n }\n}\n\nexport function createDatafnMcpRegistry<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n): McpFnRegistry<TMcpContext> {\n const registry = options.registry ?? new McpFnRegistry<TMcpContext>();\n const schema = options.executor.schema;\n const prefix = safeSegment(options.toolPrefix ?? \"datafn\");\n if (typeof options.clientId === \"string\" && !options.clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must be a non-empty string\");\n }\n assertUniqueToolNames(registry, options.expose, prefix);\n\n for (const resourceName of Object.keys(options.expose).sort()) {\n const exposure = options.expose[resourceName]!;\n const resource = schema.resources.find((candidate) => candidate.name === resourceName);\n if (!resource) {\n throw new McpFnValidationError(`Unknown DataFn resource: ${resourceName}`);\n }\n const list = operationOptions<DatafnListToolOptions>(exposure.list, true);\n const get = operationOptions<DatafnReadToolOptions>(exposure.get, true);\n validateFieldList(`DataFn resource ${resourceName} projection`, exposure.fields);\n if (list || get) validateReadFields(schema, resource, exposure.fields);\n const maps = fieldMaps(schema, resource);\n\n if (list) {\n const filterFields = list.filterFields ?? exposure.fields;\n const sortFields = list.sortFields ?? [\"id\"];\n validateFieldList(`DataFn resource ${resourceName} filterFields`, filterFields);\n validateFieldList(`DataFn resource ${resourceName} sortFields`, sortFields);\n validateReadFields(schema, resource, [...filterFields, ...sortFields]);\n const filterProperties = Object.fromEntries(\n filterFields.map((field) => [\n field,\n field === \"id\" ? { type: \"string\" } : fieldSchema(maps.schemaFields.get(field)!),\n ]),\n );\n const maxLimit = list.maxLimit ?? 100;\n validateLimit(`DataFn resource ${resourceName} maxLimit`, maxLimit);\n const defaultLimit = list.defaultLimit ?? Math.min(50, maxLimit);\n validateLimit(`DataFn resource ${resourceName} defaultLimit`, defaultLimit);\n if (defaultLimit > maxLimit) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} defaultLimit cannot exceed maxLimit`,\n );\n }\n const definition: McpFnToolDefinition<TMcpContext> = {\n name: list.name ?? defaultName(prefix, resourceName, \"list\"),\n description:\n list.description ?? `List ${resourceName} records visible to the authenticated DataFn context.`,\n inputSchema: {\n type: \"object\",\n properties: {\n filters: {\n type: \"object\",\n properties: filterProperties,\n additionalProperties: false,\n },\n sort: {\n type: \"array\",\n items: {\n type: \"string\",\n enum: sortFields.flatMap((field) => [`${field}:asc`, `${field}:desc`]),\n },\n maxItems: Math.max(1, sortFields.length),\n },\n cursor: { type: \"object\", additionalProperties: true },\n limit: { type: \"integer\", minimum: 1, maximum: maxLimit },\n },\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"list\" } },\n handler: async (args, context) => {\n const requestedSort = args.sort as string[] | undefined;\n const querySort = requestedSort?.length\n ? [\n ...requestedSort.filter((term) => !term.startsWith(\"id:\")),\n requestedSort.find((term) => term.startsWith(\"id:\")) ?? \"id:asc\",\n ]\n : undefined;\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n ...(args.filters ? { filters: args.filters } : {}),\n ...(querySort ? { sort: querySort } : {}),\n ...(args.cursor ? { cursor: args.cursor } : {}),\n limit: Math.min(Number(args.limit ?? defaultLimit), maxLimit),\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"list\", result });\n },\n };\n registry.register(definition);\n }\n\n if (get) {\n registry.register({\n name: get.name ?? defaultName(prefix, resourceName, \"get\"),\n description: get.description ?? `Get one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\", minLength: 1 } },\n required: [\"id\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"get\" } },\n handler: async ({ id }, context) => {\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n filters: { id },\n limit: 1,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"get\", result });\n },\n });\n }\n\n const registerWrite = (\n operation: \"create\" | \"update\",\n config: DatafnWriteToolOptions,\n ) => {\n validateFieldList(\n `DataFn resource ${resourceName} ${operation} fields`,\n config.fields,\n );\n validateWriteFields(schema, resource, config.fields);\n const requiredCreateFields = [...maps.schemaFields.values()]\n .filter((field) =>\n field.name !== \"id\" &&\n field.required &&\n field.default === undefined &&\n !field.readonly)\n .map((field) => field.name)\n .sort();\n if (operation === \"create\") {\n const missingRequiredFields = requiredCreateFields.filter(\n (field) => !config.fields.includes(field),\n );\n if (missingRequiredFields.length) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} create fields omit required writable fields: ${missingRequiredFields.join(\", \")}`,\n );\n }\n }\n const properties = Object.fromEntries(\n config.fields.map((field) => [field, fieldSchema(maps.schemaFields.get(field)!)]),\n );\n const recordRequired = operation === \"create\"\n ? requiredCreateFields\n : [];\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, operation),\n description: config.description ?? `${operation === \"create\" ? \"Create\" : \"Update\"} one ${resourceName} record.`,\n inputSchema: {\n type: \"object\",\n properties: {\n ...(operation === \"create\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n ...(operation === \"update\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n mutationId: { type: \"string\", minLength: 1 },\n record: {\n type: \"object\",\n properties,\n ...(recordRequired.length ? { required: recordRequired } : {}),\n additionalProperties: false,\n },\n },\n required: [\"mutationId\", \"record\", ...(operation === \"update\" ? [\"id\"] : [])],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation } },\n handler: async (args, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: operation === \"create\" ? \"insert\" : \"merge\",\n clientId,\n mutationId: args.mutationId,\n ...(args.id ? { id: args.id } : {}),\n record: args.record,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation, result });\n },\n });\n };\n\n if (exposure.create) registerWrite(\"create\", exposure.create);\n if (exposure.update) registerWrite(\"update\", exposure.update);\n const remove = operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(\n exposure.delete,\n false,\n );\n if (remove) {\n const config = remove;\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} has no write policy and cannot expose delete`,\n );\n }\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, \"delete\"),\n description: config.description ?? `Delete one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", minLength: 1 },\n mutationId: { type: \"string\", minLength: 1 },\n },\n required: [\"id\", \"mutationId\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"delete\" } },\n handler: async ({ id, mutationId }, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: \"delete\",\n clientId,\n mutationId,\n id,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"delete\", result });\n },\n });\n }\n }\n\n return registry;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAYP,SAAS,kBAAkB,OAAe,QAAwB;AAChE,MACE,OAAO,WAAW,KAClB,IAAI,IAAI,MAAM,EAAE,SAAS,OAAO,UAChC,OAAO,KAAK,CAAC,UAAU,OAAO,UAAU,YAAY,CAAC,KAAK,GAC1D;AACA,UAAM,IAAI,qBAAqB,GAAG,KAAK,yCAAyC;AAAA,EAClF;AACF;AAEA,SAAS,cAAc,OAAe,OAAqB;AACzD,MAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAAG;AAC7C,UAAM,IAAI,qBAAqB,GAAG,KAAK,kCAAkC;AAAA,EAC3E;AACF;AAEA,eAAe,gBACb,SACA,SACiB;AACjB,QAAM,WAAW,OAAO,QAAQ,aAAa,WACzC,QAAQ,WACR,MAAM,QAAQ,SAAS,OAAO;AAClC,MAAI,OAAO,aAAa,YAAY,CAAC,SAAS,KAAK,GAAG;AACpD,UAAM,IAAI,qBAAqB,oDAAoD;AAAA,EACrF;AACA,SAAO;AACT;AAEA,SAAS,YAAY,OAAuB;AAC1C,MAAI,UAAU;AACd,MAAI,iBAAiB;AACrB,aAAW,aAAa,OAAO;AAC7B,UAAM,OAAO,UAAU,WAAW,CAAC;AACnC,UAAM,UACH,QAAQ,MAAM,Q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Ac;AAAA,UACd,iBAAiB;AAAA,UACjB,gBAAgB;AAAA,UAChB,eAAe;AAAA,QACjB;AAAA,QACA,UAAU,EAAE,gBAAgB,EAAE,UAAU,cAAc,WAAW,SAAS,EAAE;AAAA,QAC5E,SAAS,OAAO,EAAE,IAAI,WAAW,GAAG,YAAY;AAC9C,gBAAM,WAAW,MAAM,gBAAgB,SAAS,OAAO;AACvD,gBAAM,SAAS,MAAM,QAAQ,SAAS;AAAA,YACpC;AAAA,cACE,UAAU;AAAA,cACV,SAAS,OAAO,SAAS,OAAO;AAAA,cAChC,WAAW;AAAA,cACX;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YACA,MAAM,QAAQ,QAAQ,OAAO;AAAA,UAC/B;AACA,iBAAO,iBAAiB,EAAE,UAAU,cAAc,WAAW,UAAU,OAAO,CAAC;AAAA,QACjF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import {\n getCapabilityFields,\n resolveCapabilities,\n type DatafnFieldSchema,\n type DatafnResourceSchema,\n type DatafnSchema,\n} from \"@datafn/core\";\nimport {\n McpFnRegistry,\n McpFnValidationError,\n structuredResult,\n type McpFnJsonSchema,\n type McpFnToolDefinition,\n} from \"@mcpfn/core\";\n\nimport type {\n CreateDatafnMcpRegistryOptions,\n DatafnListToolOptions,\n DatafnReadToolOptions,\n DatafnResourceExposure,\n DatafnWriteToolOptions,\n} from \"./types.js\";\n\ntype Operation = \"list\" | \"get\" | \"create\" | \"update\" | \"delete\";\n\nfunction validateFieldList(label: string, fields: string[]): void {\n if (\n fields.length === 0 ||\n new Set(fields).size !== fields.length ||\n fields.some((field) => typeof field !== \"string\" || !field)\n ) {\n throw new McpFnValidationError(`${label} must be a non-empty, unique field list`);\n }\n}\n\nfunction validateLimit(label: string, value: number): void {\n if (!Number.isSafeInteger(value) || value < 1) {\n throw new McpFnValidationError(`${label} must be a positive safe integer`);\n }\n}\n\nasync function resolveClientId<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n context: TMcpContext,\n): Promise<string> {\n const clientId = typeof options.clientId === \"string\"\n ? options.clientId\n : await options.clientId(context);\n if (typeof clientId !== \"string\" || !clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must resolve to a non-empty string\");\n }\n return clientId;\n}\n\nfunction safeSegment(value: string): string {\n let segment = \"\";\n let needsSeparator = false;\n for (const character of value) {\n const code = character.charCodeAt(0);\n const allowed =\n (code >= 48 && code <= 57) ||\n (code >= 65 && code <= 90) ||\n (code >= 97 && code <= 122) ||\n character === \"_\" || character === \".\" || character === \"-\";\n if (allowed) {\n if (needsSeparator && segment) segment += \"_\";\n segment += character;\n needsSeparator = false;\n } else {\n needsSeparator = true;\n }\n }\n let start = 0;\n let end = segment.length;\n while (start < end && segment[start] === \"_\") start += 1;\n while (end > start && segment[end - 1] === \"_\") end -= 1;\n return segment.slice(start, end);\n}\n\nfunction resourceDefaults(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n if (resource.permissions !== undefined || resource.defaultPermissions === false) {\n return undefined;\n }\n return schema.defaultPermissions;\n}\n\nfunction fieldSchema(field: DatafnFieldSchema): McpFnJsonSchema {\n const base: McpFnJsonSchema = (() => {\n switch (field.type) {\n case \"number\": return { type: \"number\" };\n case \"boolean\": return { type: \"boolean\" };\n case \"array\": return { type: \"array\", items: {} };\n case \"object\": return { type: \"object\", additionalProperties: true };\n case \"json\": return { type: [\"string\", \"number\", \"boolean\", \"object\", \"array\"] };\n case \"date\": return { type: [\"string\", \"number\"], format: \"date-time\" };\n case \"file\": return { type: \"string\" };\n default: return { type: \"string\" };\n }\n })();\n if (field.enum) base.enum = field.enum;\n if (field.min !== undefined) base.minimum = field.min;\n if (field.max !== undefined) base.maximum = field.max;\n if (field.minLength !== undefined) base.minLength = field.minLength;\n if (field.maxLength !== undefined) base.maxLength = field.maxLength;\n if (field.pattern !== undefined) base.pattern = field.pattern;\n if (field.nullable) {\n const currentTypes = Array.isArray(base.type) ? base.type : [base.type];\n base.type = [...new Set([...currentTypes, \"null\"])];\n if (Array.isArray(base.enum) && !base.enum.includes(null)) {\n base.enum = [...base.enum, null];\n }\n }\n return base;\n}\n\nfunction scalarFilterSchema(field: DatafnFieldSchema): McpFnJsonSchema | undefined {\n const schema = fieldSchema(field);\n const types = (Array.isArray(schema.type) ? schema.type : [schema.type])\n .filter((type) => type !== \"object\" && type !== \"array\");\n if (!types.some((type) => type !== \"null\")) return undefined;\n const { items: _items, additionalProperties: _additional, ...rest } = schema;\n return { ...rest, type: types.length === 1 ? types[0] : types };\n}\n\nfunction capabilitiesFor(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n return getCapabilityFields(\n resolveCapabilities(schema.capabilities as never, resource.capabilities as never) as never,\n );\n}\n\nfunction fieldMaps(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n) {\n const schemaFields = new Map(resource.fields.map((field) => [field.name, field]));\n for (const field of capabilitiesFor(schema, resource)) {\n schemaFields.set(field.name, field as DatafnFieldSchema);\n }\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n const defaultFields = [\"id\", ...resource.fields.map((field) => field.name)];\n const readable = new Set([\n \"id\",\n ...(resource.permissions?.read?.fields ??\n (readDefault === \"allResourceFields\" ? defaultFields : [])),\n ]);\n for (const field of capabilitiesFor(schema, resource)) readable.add(field.name);\n const writable = new Set(\n resource.permissions?.write?.fields ??\n (writeDefault === \"allResourceFields\" ? defaultFields : []),\n );\n return { schemaFields, readable, writable };\n}\n\nfunction validateReadFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const readDefault = typeof defaults === \"string\" ? defaults : defaults?.read;\n if (!resource.permissions?.read && readDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no read policy and cannot be exposed`,\n );\n }\n const { schemaFields, readable } = fieldMaps(schema, resource);\n for (const field of fields) {\n if (field !== \"id\" && !schemaFields.has(field)) {\n throw new McpFnValidationError(\n `Unknown exposed field ${resource.name}.${field}`,\n );\n }\n if (!readable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not readable by DataFn policy`,\n );\n }\n }\n}\n\nfunction validateWriteFields(\n schema: DatafnSchema,\n resource: DatafnResourceSchema,\n fields: string[],\n): void {\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resource.name} has no write policy and cannot expose mutations`,\n );\n }\n const { schemaFields, writable } = fieldMaps(schema, resource);\n for (const field of fields) {\n const definition = schemaFields.get(field);\n if (!definition) {\n throw new McpFnValidationError(`Unknown write field ${resource.name}.${field}`);\n }\n if (definition.readonly || !writable.has(field)) {\n throw new McpFnValidationError(\n `Field ${resource.name}.${field} is not writable by DataFn policy`,\n );\n }\n }\n}\n\nfunction operationOptions<T>(value: boolean | T | undefined, enabledByDefault: boolean): T | undefined {\n if (value === false) return undefined;\n if (value === true) return {} as T;\n if (value === undefined) return enabledByDefault ? ({} as T) : undefined;\n return value;\n}\n\nfunction outputSchema() {\n return {\n type: \"object\" as const,\n properties: {\n resource: { type: \"string\" },\n operation: { type: \"string\" },\n result: {},\n },\n required: [\"resource\", \"operation\", \"result\"],\n additionalProperties: false,\n };\n}\n\nfunction defaultName(prefix: string, resource: string, operation: Operation): string {\n return [prefix, safeSegment(resource), operation].filter(Boolean).join(\"_\");\n}\n\nfunction assertUniqueToolNames<TMcpContext>(\n registry: McpFnRegistry<TMcpContext>,\n expose: Record<string, DatafnResourceExposure>,\n prefix: string,\n): void {\n const owners = new Map<string, string>();\n for (const resourceName of Object.keys(expose).sort()) {\n const exposure = expose[resourceName]!;\n const operations: Array<[Operation, DatafnReadToolOptions | DatafnWriteToolOptions | undefined]> = [\n [\"list\", operationOptions<DatafnListToolOptions>(exposure.list, true)],\n [\"get\", operationOptions<DatafnReadToolOptions>(exposure.get, true)],\n [\"create\", exposure.create || undefined],\n [\"update\", exposure.update || undefined],\n [\"delete\", operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(exposure.delete, false)],\n ];\n for (const [operation, config] of operations) {\n if (!config) continue;\n const name = config.name ?? defaultName(prefix, resourceName, operation);\n const owner = `${resourceName}.${operation}`;\n const existing = owners.get(name);\n if (existing || registry.has(name)) {\n throw new McpFnValidationError(\n `DataFn tool name collision for ${name}: ${existing ?? \"existing registry tool\"} and ${owner}`,\n );\n }\n owners.set(name, owner);\n }\n }\n}\n\nexport function createDatafnMcpRegistry<TMcpContext, TDatafnContext>(\n options: CreateDatafnMcpRegistryOptions<TMcpContext, TDatafnContext>,\n): McpFnRegistry<TMcpContext> {\n const registry = options.registry ?? new McpFnRegistry<TMcpContext>();\n const schema = options.executor.schema;\n const prefix = safeSegment(options.toolPrefix ?? \"datafn\");\n if (typeof options.clientId === \"string\" && !options.clientId.trim()) {\n throw new McpFnValidationError(\"DataFn clientId must be a non-empty string\");\n }\n assertUniqueToolNames(registry, options.expose, prefix);\n if (\n typeof options.clientId === \"string\" &&\n options.allowSharedClientId !== true &&\n Object.values(options.expose).some((exposure) => exposure.create || exposure.update || exposure.delete)\n ) {\n throw new McpFnValidationError(\n \"DataFn mutation tools need a per-credential clientId resolver; a fixed string shares idempotency records between users (set allowSharedClientId to accept it)\",\n );\n }\n\n // Refuse non-scalar filters before registering any tool, so this check\n // never leaves a supplied registry partly populated. (The registration\n // loop's other validation errors, which predate it, can still stop part-way.)\n for (const [resourceName, exposure] of Object.entries(options.expose)) {\n const list = operationOptions<DatafnListToolOptions>(exposure.list, true);\n const resource = schema.resources.find((candidate) => candidate.name === resourceName);\n if (!list?.filterFields || !resource) continue;\n const schemaFields = fieldMaps(schema, resource).schemaFields;\n for (const field of list.filterFields) {\n const definition = schemaFields.get(field);\n if (field !== \"id\" && definition && !scalarFilterSchema(definition)) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`,\n );\n }\n }\n }\n\n for (const resourceName of Object.keys(options.expose).sort()) {\n const exposure = options.expose[resourceName]!;\n const resource = schema.resources.find((candidate) => candidate.name === resourceName);\n if (!resource) {\n throw new McpFnValidationError(`Unknown DataFn resource: ${resourceName}`);\n }\n const list = operationOptions<DatafnListToolOptions>(exposure.list, true);\n const get = operationOptions<DatafnReadToolOptions>(exposure.get, true);\n validateFieldList(`DataFn resource ${resourceName} projection`, exposure.fields);\n if (list || get) validateReadFields(schema, resource, exposure.fields);\n const maps = fieldMaps(schema, resource);\n\n if (list) {\n const filterFields = list.filterFields ?? exposure.fields;\n const sortFields = list.sortFields ?? [\"id\"];\n validateFieldList(`DataFn resource ${resourceName} filterFields`, filterFields);\n validateFieldList(`DataFn resource ${resourceName} sortFields`, sortFields);\n validateReadFields(schema, resource, [...filterFields, ...sortFields]);\n // Filters take scalar values only: DataFn reads an object as an\n // operator expression, which the model should not choose.\n const filterProperties: Record<string, McpFnJsonSchema> = {};\n for (const field of filterFields) {\n const filter = field === \"id\" ? { type: \"string\" } : scalarFilterSchema(maps.schemaFields.get(field)!);\n if (filter) filterProperties[field] = filter;\n else if (list.filterFields) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} cannot filter on non-scalar field ${field}`,\n );\n }\n }\n const maxLimit = list.maxLimit ?? 100;\n validateLimit(`DataFn resource ${resourceName} maxLimit`, maxLimit);\n const defaultLimit = list.defaultLimit ?? Math.min(50, maxLimit);\n validateLimit(`DataFn resource ${resourceName} defaultLimit`, defaultLimit);\n if (defaultLimit > maxLimit) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} defaultLimit cannot exceed maxLimit`,\n );\n }\n const definition: McpFnToolDefinition<TMcpContext> = {\n name: list.name ?? defaultName(prefix, resourceName, \"list\"),\n description:\n list.description ?? `List ${resourceName} records visible to the authenticated DataFn context.`,\n inputSchema: {\n type: \"object\",\n properties: {\n filters: {\n type: \"object\",\n properties: filterProperties,\n additionalProperties: false,\n },\n sort: {\n type: \"array\",\n items: {\n type: \"string\",\n enum: sortFields.flatMap((field) => [`${field}:asc`, `${field}:desc`]),\n },\n maxItems: Math.max(1, sortFields.length),\n },\n cursor: { type: \"object\", additionalProperties: true },\n limit: { type: \"integer\", minimum: 1, maximum: maxLimit },\n },\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"list\" } },\n handler: async (args, context) => {\n const requestedSort = args.sort as string[] | undefined;\n const querySort = requestedSort?.length\n ? [\n ...requestedSort.filter((term) => !term.startsWith(\"id:\")),\n requestedSort.find((term) => term.startsWith(\"id:\")) ?? \"id:asc\",\n ]\n : undefined;\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n ...(args.filters ? { filters: args.filters } : {}),\n ...(querySort ? { sort: querySort } : {}),\n ...(args.cursor ? { cursor: args.cursor } : {}),\n limit: Math.min(Number(args.limit ?? defaultLimit), maxLimit),\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"list\", result });\n },\n };\n registry.register(definition);\n }\n\n if (get) {\n registry.register({\n name: get.name ?? defaultName(prefix, resourceName, \"get\"),\n description: get.description ?? `Get one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\", minLength: 1 } },\n required: [\"id\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"get\" } },\n handler: async ({ id }, context) => {\n const result = await options.executor.query(\n {\n resource: resourceName,\n version: String(resource.version),\n select: exposure.fields,\n filters: { id },\n limit: 1,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"get\", result });\n },\n });\n }\n\n const registerWrite = (\n operation: \"create\" | \"update\",\n config: DatafnWriteToolOptions,\n ) => {\n validateFieldList(\n `DataFn resource ${resourceName} ${operation} fields`,\n config.fields,\n );\n validateWriteFields(schema, resource, config.fields);\n const requiredCreateFields = [...maps.schemaFields.values()]\n .filter((field) =>\n field.name !== \"id\" &&\n field.required &&\n field.default === undefined &&\n !field.readonly)\n .map((field) => field.name)\n .sort();\n if (operation === \"create\") {\n const missingRequiredFields = requiredCreateFields.filter(\n (field) => !config.fields.includes(field),\n );\n if (missingRequiredFields.length) {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} create fields omit required writable fields: ${missingRequiredFields.join(\", \")}`,\n );\n }\n }\n const properties = Object.fromEntries(\n config.fields.map((field) => [field, fieldSchema(maps.schemaFields.get(field)!)]),\n );\n const recordRequired = operation === \"create\"\n ? requiredCreateFields\n : [];\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, operation),\n description: config.description ?? `${operation === \"create\" ? \"Create\" : \"Update\"} one ${resourceName} record.`,\n inputSchema: {\n type: \"object\",\n properties: {\n ...(operation === \"create\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n ...(operation === \"update\" ? { id: { type: \"string\", minLength: 1 } } : {}),\n mutationId: { type: \"string\", minLength: 1 },\n record: {\n type: \"object\",\n properties,\n ...(recordRequired.length ? { required: recordRequired } : {}),\n additionalProperties: false,\n },\n },\n required: [\"mutationId\", \"record\", ...(operation === \"update\" ? [\"id\"] : [])],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation } },\n handler: async (args, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: operation === \"create\" ? \"insert\" : \"merge\",\n clientId,\n mutationId: args.mutationId,\n ...(args.id ? { id: args.id } : {}),\n record: args.record,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation, result });\n },\n });\n };\n\n if (exposure.create) registerWrite(\"create\", exposure.create);\n if (exposure.update) registerWrite(\"update\", exposure.update);\n const remove = operationOptions<Omit<DatafnWriteToolOptions, \"fields\">>(\n exposure.delete,\n false,\n );\n if (remove) {\n const config = remove;\n const defaults = resourceDefaults(schema, resource);\n const writeDefault = typeof defaults === \"string\" ? defaults : defaults?.write;\n if (!resource.permissions?.write && writeDefault !== \"allResourceFields\") {\n throw new McpFnValidationError(\n `DataFn resource ${resourceName} has no write policy and cannot expose delete`,\n );\n }\n registry.register({\n name: config.name ?? defaultName(prefix, resourceName, \"delete\"),\n description: config.description ?? `Delete one ${resourceName} record by ID.`,\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", minLength: 1 },\n mutationId: { type: \"string\", minLength: 1 },\n },\n required: [\"id\", \"mutationId\"],\n additionalProperties: false,\n },\n outputSchema: outputSchema(),\n annotations: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n metadata: { \"mcpfn/datafn\": { resource: resourceName, operation: \"delete\" } },\n handler: async ({ id, mutationId }, context) => {\n const clientId = await resolveClientId(options, context);\n const result = await options.executor.mutate(\n {\n resource: resourceName,\n version: String(resource.version),\n operation: \"delete\",\n clientId,\n mutationId,\n id,\n },\n await options.context(context),\n );\n return structuredResult({ resource: resourceName, operation: \"delete\", result });\n },\n });\n }\n }\n\n return registry;\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAYP,SAAS,kBAAkB,OAAe,QAAwB;AAChE,MACE,OAAO,WAAW,KAClB,IAAI,IAAI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AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpfn/datafn",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Explicit, deny-by-default DataFn resource exposure for McpFn",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@datafn/core": "0.1.0",
|
|
34
34
|
"@datafn/server": "0.1.1",
|
|
35
|
-
"@mcpfn/core": "0.0
|
|
35
|
+
"@mcpfn/core": "0.1.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@superfunctions/db": "0.2.0",
|
|
39
|
-
"@mcpfn/testing": "0.0.
|
|
39
|
+
"@mcpfn/testing": "0.0.11",
|
|
40
40
|
"@types/node": "^20.0.0",
|
|
41
41
|
"tsup": "^8.5.0",
|
|
42
42
|
"typescript": "^5.9.3",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
57
|
"sideEffects": false,
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "aed88d3853812b94dfde44b581545679dd629dc9"
|
|
59
59
|
}
|