@telepath-computer/autofile 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +74 -2
- package/dist/blobs.d.ts +34 -0
- package/dist/blobs.js +295 -0
- package/dist/blobs.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +180 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.js +258 -0
- package/dist/config.js.map +1 -0
- package/dist/http.d.ts +10 -0
- package/dist/http.js +152 -0
- package/dist/http.js.map +1 -0
- package/dist/json.d.ts +9 -0
- package/dist/json.js +3 -0
- package/dist/json.js.map +1 -0
- package/dist/schema.d.ts +25 -0
- package/dist/schema.js +235 -0
- package/dist/schema.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +237 -0
- package/dist/server.js.map +1 -0
- package/dist/store.d.ts +132 -0
- package/dist/store.js +1381 -0
- package/dist/store.js.map +1 -0
- package/dist/watch.d.ts +20 -0
- package/dist/watch.js +313 -0
- package/dist/watch.js.map +1 -0
- package/package.json +46 -4
package/dist/schema.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers and checks Autofile's JSON Schemas with the explicitly selected
|
|
3
|
+
* 2020-12 dialect. The registry is process-global, so schemas are addressed by
|
|
4
|
+
* content and compiled once even when several store instances read them.
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import "@hyperjump/json-schema/formats";
|
|
8
|
+
import { InvalidSchemaError, registerSchema, setMetaSchemaOutputFormat, setShouldValidateFormat, unregisterSchema, validate, } from "@hyperjump/json-schema/draft-2020-12";
|
|
9
|
+
import { addFormat, setFormatHandler } from "@hyperjump/json-schema/experimental";
|
|
10
|
+
import { annotate } from "@hyperjump/json-schema/annotations/experimental";
|
|
11
|
+
import { annotatedWith, annotation, value as instanceValue, } from "@hyperjump/json-schema/annotated-instance/experimental";
|
|
12
|
+
import { JSE } from "@hyperjump/json-schema-errors";
|
|
13
|
+
import { isBlobInput } from "./blobs.js";
|
|
14
|
+
const DIALECT = "https://json-schema.org/draft/2020-12/schema";
|
|
15
|
+
const FORMAT_KEYWORD = "https://json-schema.org/keyword/draft-2020-12/format";
|
|
16
|
+
const BLOB_FORMAT = "https://autofile.dev/formats/blob";
|
|
17
|
+
const knownFormats = new Set([
|
|
18
|
+
"date-time",
|
|
19
|
+
"date",
|
|
20
|
+
"time",
|
|
21
|
+
"duration",
|
|
22
|
+
"email",
|
|
23
|
+
"idn-email",
|
|
24
|
+
"hostname",
|
|
25
|
+
"idn-hostname",
|
|
26
|
+
"ipv4",
|
|
27
|
+
"ipv6",
|
|
28
|
+
"uri",
|
|
29
|
+
"uri-reference",
|
|
30
|
+
"iri",
|
|
31
|
+
"iri-reference",
|
|
32
|
+
"uuid",
|
|
33
|
+
"uri-template",
|
|
34
|
+
"json-pointer",
|
|
35
|
+
"relative-json-pointer",
|
|
36
|
+
"regex",
|
|
37
|
+
"blob",
|
|
38
|
+
]);
|
|
39
|
+
const schemaMapKeywords = ["$defs", "properties", "patternProperties", "dependentSchemas"];
|
|
40
|
+
const schemaArrayKeywords = ["allOf", "anyOf", "oneOf", "prefixItems"];
|
|
41
|
+
const schemaKeywords = [
|
|
42
|
+
"items",
|
|
43
|
+
"contains",
|
|
44
|
+
"additionalProperties",
|
|
45
|
+
"unevaluatedItems",
|
|
46
|
+
"unevaluatedProperties",
|
|
47
|
+
"propertyNames",
|
|
48
|
+
"if",
|
|
49
|
+
"then",
|
|
50
|
+
"else",
|
|
51
|
+
"not",
|
|
52
|
+
"contentSchema",
|
|
53
|
+
];
|
|
54
|
+
const preparedSchemas = new Map();
|
|
55
|
+
setShouldValidateFormat(true);
|
|
56
|
+
// json-schema-errors augments the package root's TypeScript declarations, but
|
|
57
|
+
// the draft-specific entry point does not expose that augmentation.
|
|
58
|
+
setMetaSchemaOutputFormat(JSE);
|
|
59
|
+
addFormat({
|
|
60
|
+
id: BLOB_FORMAT,
|
|
61
|
+
// JSON Schema formats ignore other instance types. Autofile's separate
|
|
62
|
+
// annotation check gives URI and blob values their stricter string rule.
|
|
63
|
+
handler: (value) => typeof value !== "string" || isBlobInput(value),
|
|
64
|
+
});
|
|
65
|
+
setFormatHandler(FORMAT_KEYWORD, "blob", BLOB_FORMAT);
|
|
66
|
+
/** Checks that a declaration schema is safe, valid 2020-12 JSON Schema. */
|
|
67
|
+
export async function prepareSchema(schema) {
|
|
68
|
+
const inspectionErrors = inspectSchema(schema);
|
|
69
|
+
if (inspectionErrors.length > 0)
|
|
70
|
+
throw new SchemaRefusal(inspectionErrors);
|
|
71
|
+
const serialized = JSON.stringify(schema);
|
|
72
|
+
const digest = createHash("sha256").update(serialized).digest("hex");
|
|
73
|
+
const schemaUri = `https://autofile.dev/schemas/${digest}`;
|
|
74
|
+
let prepared = preparedSchemas.get(schemaUri);
|
|
75
|
+
if (prepared === undefined) {
|
|
76
|
+
prepared = compileSchema(schema, schemaUri);
|
|
77
|
+
preparedSchemas.set(schemaUri, prepared);
|
|
78
|
+
prepared.catch(() => preparedSchemas.delete(schemaUri));
|
|
79
|
+
}
|
|
80
|
+
return prepared;
|
|
81
|
+
}
|
|
82
|
+
/** A user-correctable problem in a proposed schema declaration. */
|
|
83
|
+
export class SchemaRefusal extends Error {
|
|
84
|
+
messages;
|
|
85
|
+
constructor(messages) {
|
|
86
|
+
super(messages.join("; "));
|
|
87
|
+
this.name = "SchemaRefusal";
|
|
88
|
+
this.messages = messages;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function compileSchema(schema, schemaUri) {
|
|
92
|
+
let registered = false;
|
|
93
|
+
try {
|
|
94
|
+
registerSchema(schema, schemaUri, DIALECT);
|
|
95
|
+
registered = true;
|
|
96
|
+
const validator = await validate(schemaUri);
|
|
97
|
+
const annotator = await annotate(schemaUri);
|
|
98
|
+
return {
|
|
99
|
+
validate: (value) => validateValue(validator, annotator, value),
|
|
100
|
+
formatFields: (value, format) => findFormatFields(annotator, value, format),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (registered)
|
|
105
|
+
unregisterSchema(schemaUri);
|
|
106
|
+
if (error instanceof InvalidSchemaError) {
|
|
107
|
+
const output = error.output;
|
|
108
|
+
throw new SchemaRefusal(formatErrors(output.valid ? [] : output.errors, "schema"));
|
|
109
|
+
}
|
|
110
|
+
throw new SchemaRefusal([
|
|
111
|
+
error instanceof Error ? `schema: ${error.message}` : `schema: ${String(error)}`,
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function findFormatFields(annotator, value, format) {
|
|
116
|
+
const fields = [];
|
|
117
|
+
const annotated = annotator(value);
|
|
118
|
+
for (const node of annotatedWith(annotated, "format", DIALECT)) {
|
|
119
|
+
if (!annotation(node, "format", DIALECT).includes(format))
|
|
120
|
+
continue;
|
|
121
|
+
const pointer = node.pointer;
|
|
122
|
+
fields.push({
|
|
123
|
+
pointer,
|
|
124
|
+
location: formatInstancePointer(pointer),
|
|
125
|
+
value: instanceValue(node),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return fields;
|
|
129
|
+
}
|
|
130
|
+
async function validateValue(validator, annotator, value) {
|
|
131
|
+
const output = validator(value, {
|
|
132
|
+
outputFormat: JSE,
|
|
133
|
+
});
|
|
134
|
+
if (!output.valid)
|
|
135
|
+
return formatErrors(output.errors, "");
|
|
136
|
+
// JSON Schema deliberately ignores `format` for non-strings. Autofile's
|
|
137
|
+
// field model is stricter: anything annotated as a URI or blob is a string.
|
|
138
|
+
const annotated = annotator(value);
|
|
139
|
+
const errors = [];
|
|
140
|
+
for (const node of annotatedWith(annotated, "format", DIALECT)) {
|
|
141
|
+
const formats = annotation(node, "format", DIALECT);
|
|
142
|
+
if (formats.some((format) => format === "uri" || format === "blob")
|
|
143
|
+
&& typeof instanceValue(node) !== "string") {
|
|
144
|
+
const location = formatInstancePointer(node.pointer);
|
|
145
|
+
errors.push(location === "" ? "must be a string" : `${location}: must be a string`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return errors;
|
|
149
|
+
}
|
|
150
|
+
function inspectSchema(schema) {
|
|
151
|
+
const errors = [];
|
|
152
|
+
inspectSubschema(schema, "schema", errors, true, new WeakSet());
|
|
153
|
+
return errors;
|
|
154
|
+
}
|
|
155
|
+
function inspectSubschema(schema, location, errors, isRoot, inspected) {
|
|
156
|
+
if (!isObject(schema))
|
|
157
|
+
return;
|
|
158
|
+
if (inspected.has(schema))
|
|
159
|
+
return;
|
|
160
|
+
inspected.add(schema);
|
|
161
|
+
if (schema.$schema !== undefined) {
|
|
162
|
+
if (!isRoot)
|
|
163
|
+
errors.push(`${location}.$schema: is only allowed at the schema root`);
|
|
164
|
+
else if (schema.$schema !== DIALECT) {
|
|
165
|
+
errors.push(`${location}.$schema: must name ${DIALECT}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (typeof schema.format === "string" && !knownFormats.has(schema.format)) {
|
|
169
|
+
errors.push(`${location}.format: unknown format ${JSON.stringify(schema.format)}`);
|
|
170
|
+
}
|
|
171
|
+
for (const keyword of ["$ref", "$dynamicRef"]) {
|
|
172
|
+
const reference = schema[keyword];
|
|
173
|
+
if (typeof reference === "string"
|
|
174
|
+
&& reference !== ""
|
|
175
|
+
&& !reference.startsWith("#")) {
|
|
176
|
+
errors.push(`${location}.${keyword}: must point within this schema`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
for (const keyword of schemaMapKeywords) {
|
|
180
|
+
const schemas = schema[keyword];
|
|
181
|
+
if (!isObject(schemas))
|
|
182
|
+
continue;
|
|
183
|
+
for (const [name, subschema] of Object.entries(schemas)) {
|
|
184
|
+
inspectSubschema(subschema, `${location}.${keyword}.${name}`, errors, false, inspected);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const keyword of schemaArrayKeywords) {
|
|
188
|
+
const schemas = schema[keyword];
|
|
189
|
+
if (!Array.isArray(schemas))
|
|
190
|
+
continue;
|
|
191
|
+
schemas.forEach((subschema, index) => {
|
|
192
|
+
inspectSubschema(subschema, `${location}.${keyword}.${String(index)}`, errors, false, inspected);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
for (const keyword of schemaKeywords) {
|
|
196
|
+
if (schema[keyword] !== undefined) {
|
|
197
|
+
inspectSubschema(schema[keyword], `${location}.${keyword}`, errors, false, inspected);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function formatErrors(errors, prefix) {
|
|
202
|
+
return errors.map((error) => {
|
|
203
|
+
const location = formatInstanceLocation(error.instanceLocation);
|
|
204
|
+
const path = [prefix, location].filter((part) => part !== "").join(".");
|
|
205
|
+
const message = error.message.length === 0
|
|
206
|
+
? "does not match the schema"
|
|
207
|
+
: `${error.message[0]?.toLowerCase() ?? ""}${error.message.slice(1)}`;
|
|
208
|
+
return path === "" ? message : `${path}: ${message}`;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function formatInstanceLocation(location) {
|
|
212
|
+
const hash = location.indexOf("#");
|
|
213
|
+
const fragment = hash === -1 ? location : location.slice(hash + 1);
|
|
214
|
+
if (fragment === "" || fragment === "/")
|
|
215
|
+
return "";
|
|
216
|
+
const pointer = decodeURIComponent(fragment).replace(/^\//u, "");
|
|
217
|
+
return pointer
|
|
218
|
+
.split("/")
|
|
219
|
+
.map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"))
|
|
220
|
+
.join(".");
|
|
221
|
+
}
|
|
222
|
+
function formatInstancePointer(pointer) {
|
|
223
|
+
if (pointer === "")
|
|
224
|
+
return "";
|
|
225
|
+
const parts = pointer.slice(1).split("/");
|
|
226
|
+
if (parts.some((part) => part === ""))
|
|
227
|
+
return pointer;
|
|
228
|
+
return parts
|
|
229
|
+
.map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"))
|
|
230
|
+
.join(".");
|
|
231
|
+
}
|
|
232
|
+
function isObject(value) {
|
|
233
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,gCAAgC,CAAC;AACxC,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,yBAAyB,EACzB,uBAAuB,EACvB,gBAAgB,EAChB,QAAQ,GAET,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAkB,MAAM,iDAAiD,CAAC;AAC3F,OAAO,EACL,aAAa,EACb,UAAU,EACV,KAAK,IAAI,aAAa,GACvB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,GAAG,EAAoC,MAAM,+BAA+B,CAAC;AAEtF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,MAAM,OAAO,GAAG,8CAA8C,CAAC;AAC/D,MAAM,cAAc,GAAG,sDAAsD,CAAC;AAC9E,MAAM,WAAW,GAAG,mCAAmC,CAAC;AACxD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,WAAW;IACX,MAAM;IACN,MAAM;IACN,UAAU;IACV,OAAO;IACP,WAAW;IACX,UAAU;IACV,cAAc;IACd,MAAM;IACN,MAAM;IACN,KAAK;IACL,eAAe;IACf,KAAK;IACL,eAAe;IACf,MAAM;IACN,cAAc;IACd,cAAc;IACd,uBAAuB;IACvB,OAAO;IACP,MAAM;CACP,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,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AAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC/D,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,KAA4B;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds Autofile's transport-independent MCP server. The store owns all
|
|
3
|
+
* persistence semantics; this module only describes the protocol surface and
|
|
4
|
+
* translates plain store values into MCP results.
|
|
5
|
+
*/
|
|
6
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
7
|
+
import { type Store } from "./store.js";
|
|
8
|
+
/** Builds one MCP server around a store, without choosing its transport. */
|
|
9
|
+
export declare function buildServer(store: Store): Promise<McpServer>;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds Autofile's transport-independent MCP server. The store owns all
|
|
3
|
+
* persistence semantics; this module only describes the protocol surface and
|
|
4
|
+
* translates plain store values into MCP results.
|
|
5
|
+
*/
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import { fromJsonSchema, McpServer, ProtocolError, ProtocolErrorCode, ResourceNotFoundError, } from "@modelcontextprotocol/server";
|
|
8
|
+
import { isResourceUri, } from "./store.js";
|
|
9
|
+
const SERVER_DESCRIPTION = "Typed records that agents file and retrieve, kept as JSON files in a folder the user owns.";
|
|
10
|
+
const BASE_INSTRUCTIONS = "Autofile is where the user keeps durable information, as typed records. When information should outlive the current task, file it here. Call `list_types` to see the types and what belongs in each, and `get_type` for the schema of one. Search with `find_records` before creating a record, so the same thing is not filed twice. If no type fits, propose a new type to the user and create it only once they agree.";
|
|
11
|
+
const RESOURCE_PAGE_SIZE = 100;
|
|
12
|
+
const packageJson = createRequire(import.meta.url)("../package.json");
|
|
13
|
+
const findRecordsSchema = fromJsonSchema({
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
type: { type: "string", description: "The type to search." },
|
|
17
|
+
q: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Words that must all appear, ignoring case, in the string values of a record at any depth.",
|
|
20
|
+
},
|
|
21
|
+
where: {
|
|
22
|
+
type: "object",
|
|
23
|
+
description: "Fields to match by value using MongoDB query syntax. An array field matches when any item equals the value, and `null` also matches a missing field. Keys starting with `$`, and the keys `__proto__`, `constructor` and `prototype`, are not supported at any depth or in dotted paths.",
|
|
24
|
+
},
|
|
25
|
+
limit: {
|
|
26
|
+
type: "integer",
|
|
27
|
+
minimum: 1,
|
|
28
|
+
maximum: 200,
|
|
29
|
+
default: 50,
|
|
30
|
+
description: "The most results the page returns, counting records and entries in `errors`. From 1 to 200; defaults to 50.",
|
|
31
|
+
},
|
|
32
|
+
fields: {
|
|
33
|
+
type: "array",
|
|
34
|
+
items: { type: "string", minLength: 1 },
|
|
35
|
+
description: "Top-level fields to return in `value`. All fields are returned when absent; matching still uses the whole record.",
|
|
36
|
+
},
|
|
37
|
+
cursor: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "An opaque cursor returned by the previous page. The next page starts after the last record file that page read, even if that file was deleted.",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
required: ["type"],
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
});
|
|
45
|
+
const getRecordSchema = fromJsonSchema({
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: { uri: { type: "string", description: "The URI of the record." } },
|
|
48
|
+
required: ["uri"],
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
});
|
|
51
|
+
const createRecordSchema = fromJsonSchema({
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {
|
|
54
|
+
type: { type: "string", description: "The type of the record." },
|
|
55
|
+
key: {
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "The key of the new record: lowercase letters, digits and hyphens, starting with a letter or digit. Generated when absent.",
|
|
58
|
+
},
|
|
59
|
+
record: {
|
|
60
|
+
type: "object",
|
|
61
|
+
description: "The full record, which must match the schema of its type. A blob field may hold the absolute path of a local file or a `data:` URI with base64 contents; Autofile stores the file and puts its blob URI in the field.",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
required: ["type", "record"],
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
});
|
|
67
|
+
const updateRecordSchema = fromJsonSchema({
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
uri: { type: "string", description: "The URI of the record." },
|
|
71
|
+
patch: {
|
|
72
|
+
type: "object",
|
|
73
|
+
description: "A [JSON Merge Patch](https://www.rfc-editor.org/rfc/rfc7396): fields in the patch are set, a field set to `null` is removed, nested objects are merged, and arrays are replaced whole. A blob field may hold the absolute path of a local file or a `data:` URI with base64 contents; Autofile stores the file and puts its blob URI in the field.",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
required: ["uri", "patch"],
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
});
|
|
79
|
+
const deleteRecordSchema = fromJsonSchema({
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: { uri: { type: "string", description: "The URI of the record." } },
|
|
82
|
+
required: ["uri"],
|
|
83
|
+
additionalProperties: false,
|
|
84
|
+
});
|
|
85
|
+
const listTypesSchema = fromJsonSchema({
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {},
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
});
|
|
90
|
+
const getTypeSchema = fromJsonSchema({
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: { type: { type: "string", description: "The name of the type." } },
|
|
93
|
+
required: ["type"],
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
});
|
|
96
|
+
const createTypeSchema = fromJsonSchema({
|
|
97
|
+
type: "object",
|
|
98
|
+
properties: {
|
|
99
|
+
type: { type: "string", description: "The name of the type." },
|
|
100
|
+
description: { type: "string", description: "What belongs in the folder." },
|
|
101
|
+
schema: { type: "object", description: "The JSON Schema for records of the type." },
|
|
102
|
+
titleField: {
|
|
103
|
+
type: "string",
|
|
104
|
+
description: "A top-level field of the record whose string value is shown as its title.",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
required: ["type", "description", "schema"],
|
|
108
|
+
additionalProperties: false,
|
|
109
|
+
});
|
|
110
|
+
const updateTypeSchema = fromJsonSchema({
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
type: { type: "string", description: "The name of the type." },
|
|
114
|
+
description: { type: "string", description: "The new description." },
|
|
115
|
+
schema: { type: "object", description: "The new JSON Schema." },
|
|
116
|
+
titleField: {
|
|
117
|
+
type: ["string", "null"],
|
|
118
|
+
description: "The new title field; `null` removes it.",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
required: ["type"],
|
|
122
|
+
additionalProperties: false,
|
|
123
|
+
});
|
|
124
|
+
const deleteTypeSchema = fromJsonSchema({
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: { type: { type: "string", description: "The name of the type." } },
|
|
127
|
+
required: ["type"],
|
|
128
|
+
additionalProperties: false,
|
|
129
|
+
});
|
|
130
|
+
/** Builds one MCP server around a store, without choosing its transport. */
|
|
131
|
+
export async function buildServer(store) {
|
|
132
|
+
const { types } = await store.listTypes({});
|
|
133
|
+
const typeNames = types.map(({ type }) => type).sort();
|
|
134
|
+
const typeSummary = typeNames.length === 0 ? "none yet" : typeNames.join(", ");
|
|
135
|
+
const server = new McpServer({
|
|
136
|
+
name: "autofile",
|
|
137
|
+
version: packageJson.version,
|
|
138
|
+
description: SERVER_DESCRIPTION,
|
|
139
|
+
}, {
|
|
140
|
+
instructions: `${BASE_INSTRUCTIONS}\n\nTypes: ${typeSummary}. This list was taken when the session began; call \`list_types\` for types created since.`,
|
|
141
|
+
});
|
|
142
|
+
server.registerTool("find_records", {
|
|
143
|
+
description: "Searches the records of one type and returns matching records in URI order. It reads past nonmatching files until the page has `limit` results, reaches 64 KB of JSON, or no files remain; the size cap never prevents the first result. `fields` selects top-level fields to return, while matching uses the whole record. A schema-invalid record is listed in `errors` only when it matches the search; a file that cannot be read or parsed as JSON is always listed. Autofile is where the user keeps durable information.",
|
|
144
|
+
inputSchema: findRecordsSchema,
|
|
145
|
+
}, async (input) => toolResult(await store.findRecords(input)));
|
|
146
|
+
server.registerTool("get_record", {
|
|
147
|
+
description: "Returns one record by URI: its `uri`, `createdAt` and `updatedAt` times, and `value`. A record that does not match its type is still returned, with what must change in `error`.",
|
|
148
|
+
inputSchema: getRecordSchema,
|
|
149
|
+
}, async (input) => toolResult(await store.getRecord(input)));
|
|
150
|
+
server.registerTool("create_record", {
|
|
151
|
+
description: "Creates a record and returns its URI. `record` is the full record and must match the schema of its type, which `get_type` returns. `key` is optional and generated when absent. Autofile is where the user keeps durable information.",
|
|
152
|
+
inputSchema: createRecordSchema,
|
|
153
|
+
}, async (input, context) => toolResult(await store.createRecord(input, {
|
|
154
|
+
allowLocalPaths: context.http === undefined,
|
|
155
|
+
})));
|
|
156
|
+
server.registerTool("update_record", { description: "Changes a record and returns its URI.", inputSchema: updateRecordSchema }, async (input, context) => toolResult(await store.updateRecord(input, {
|
|
157
|
+
allowLocalPaths: context.http === undefined,
|
|
158
|
+
})));
|
|
159
|
+
server.registerTool("delete_record", {
|
|
160
|
+
description: "Deletes a record, removes the links to it from other records, and returns its URI.",
|
|
161
|
+
inputSchema: deleteRecordSchema,
|
|
162
|
+
}, async (input) => toolResult(await store.deleteRecord(input)));
|
|
163
|
+
server.registerTool("list_types", {
|
|
164
|
+
description: "Returns every type, ordered by name, with the URI of its declaration and its description.",
|
|
165
|
+
inputSchema: listTypesSchema,
|
|
166
|
+
}, async (input) => toolResult(await store.listTypes(input)));
|
|
167
|
+
server.registerTool("get_type", { description: "Returns the declaration of a type with its URI added.", inputSchema: getTypeSchema }, async (input) => toolResult(await store.getType(input)));
|
|
168
|
+
server.registerTool("create_type", { description: "Declares a type and returns the URI of its declaration.", inputSchema: createTypeSchema }, async (input) => toolResult(await store.createType(input)));
|
|
169
|
+
server.registerTool("update_type", {
|
|
170
|
+
description: "Replaces the description, schema or title field of a type, or any of them.",
|
|
171
|
+
inputSchema: updateTypeSchema,
|
|
172
|
+
}, async (input) => toolResult(await store.updateType(input)));
|
|
173
|
+
server.registerTool("delete_type", { description: "Deletes a type and returns its URI.", inputSchema: deleteTypeSchema }, async (input) => toolResult(await store.deleteType(input)));
|
|
174
|
+
// The high-level resource API returns every resource at once. These
|
|
175
|
+
// handlers stay at the low-level boundary where cursors remain explicit;
|
|
176
|
+
// the process-level watcher supplies the advertised change notices.
|
|
177
|
+
server.server.registerCapabilities({ resources: { subscribe: true, listChanged: true } });
|
|
178
|
+
server.server.setRequestHandler("resources/list", async (request) => {
|
|
179
|
+
const resources = await store.listResources();
|
|
180
|
+
const cursor = request.params?.cursor;
|
|
181
|
+
let start = 0;
|
|
182
|
+
if (cursor !== undefined) {
|
|
183
|
+
const previousUri = decodeCursor(cursor);
|
|
184
|
+
if (previousUri === undefined) {
|
|
185
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Invalid resource cursor");
|
|
186
|
+
}
|
|
187
|
+
const nextIndex = resources.findIndex(({ uri }) => uri > previousUri);
|
|
188
|
+
start = nextIndex < 0 ? resources.length : nextIndex;
|
|
189
|
+
}
|
|
190
|
+
const page = resources.slice(start, start + RESOURCE_PAGE_SIZE);
|
|
191
|
+
const last = page.at(-1);
|
|
192
|
+
return {
|
|
193
|
+
resources: page.map(({ lastModified, ...resource }) => ({
|
|
194
|
+
...resource,
|
|
195
|
+
...(lastModified === undefined ? {} : { annotations: { lastModified } }),
|
|
196
|
+
})),
|
|
197
|
+
...(last !== undefined && start + page.length < resources.length
|
|
198
|
+
? { nextCursor: encodeCursor(last.uri) }
|
|
199
|
+
: {}),
|
|
200
|
+
ttlMs: 0,
|
|
201
|
+
cacheScope: "private",
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
server.server.setRequestHandler("resources/read", async (request) => {
|
|
205
|
+
const contents = await store.readResource(request.params.uri);
|
|
206
|
+
if (contents === undefined)
|
|
207
|
+
throw new ResourceNotFoundError(request.params.uri);
|
|
208
|
+
return { contents: [contents], ttlMs: 0, cacheScope: "private" };
|
|
209
|
+
});
|
|
210
|
+
return server;
|
|
211
|
+
}
|
|
212
|
+
function toolResult(result) {
|
|
213
|
+
const body = result;
|
|
214
|
+
return {
|
|
215
|
+
content: [{ type: "text", text: JSON.stringify(body) }],
|
|
216
|
+
structuredContent: body,
|
|
217
|
+
...("errors" in body && !("uri" in body) && !("records" in body) ? { isError: true } : {}),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function encodeCursor(uri) {
|
|
221
|
+
return Buffer.from(uri, "utf8").toString("base64url");
|
|
222
|
+
}
|
|
223
|
+
function decodeCursor(cursor) {
|
|
224
|
+
if (!/^[A-Za-z0-9_-]+$/u.test(cursor))
|
|
225
|
+
return undefined;
|
|
226
|
+
const bytes = Buffer.from(cursor, "base64url");
|
|
227
|
+
if (bytes.toString("base64url") !== cursor)
|
|
228
|
+
return undefined;
|
|
229
|
+
try {
|
|
230
|
+
const uri = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
231
|
+
return isResourceUri(uri) ? uri : undefined;
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAC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,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpE,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads and writes Autofile's on-disk types and records, and exposes recognized
|
|
3
|
+
* records, declarations, and blobs as plain resource data. Each operation reads
|
|
4
|
+
* current files and keeps protocol-specific behavior outside the store.
|
|
5
|
+
*/
|
|
6
|
+
import type { JsonObject } from "./json.js";
|
|
7
|
+
export type { JsonObject, JsonPrimitive, JsonValue } from "./json.js";
|
|
8
|
+
export interface StoreError {
|
|
9
|
+
uri?: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Refusal {
|
|
13
|
+
errors: StoreError[];
|
|
14
|
+
}
|
|
15
|
+
export interface OpenStoreOptions {
|
|
16
|
+
dataFolder?: string;
|
|
17
|
+
writeLockPath?: string;
|
|
18
|
+
}
|
|
19
|
+
/** Transport-sensitive permissions for a record write. */
|
|
20
|
+
export interface RecordWriteOptions {
|
|
21
|
+
allowLocalPaths?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface Store {
|
|
24
|
+
findRecords(input: FindRecordsInput): Promise<FindRecordsResult | Refusal>;
|
|
25
|
+
getRecord(input: GetRecordInput): Promise<RecordResult | Refusal>;
|
|
26
|
+
createRecord(input: CreateRecordInput, options?: RecordWriteOptions): Promise<UriResult | Refusal>;
|
|
27
|
+
updateRecord(input: UpdateRecordInput, options?: RecordWriteOptions): Promise<UriResult | Refusal>;
|
|
28
|
+
deleteRecord(input: DeleteRecordInput): Promise<UriResult | Refusal>;
|
|
29
|
+
listTypes(input: Record<string, never>): Promise<ListTypesResult>;
|
|
30
|
+
getType(input: GetTypeInput): Promise<TypeResult | Refusal>;
|
|
31
|
+
createType(input: CreateTypeInput): Promise<UriResult | Refusal>;
|
|
32
|
+
updateType(input: UpdateTypeInput): Promise<UpdateTypeResult | Refusal>;
|
|
33
|
+
deleteType(input: DeleteTypeInput): Promise<UriResult | Refusal>;
|
|
34
|
+
listResources(): Promise<StoreResource[]>;
|
|
35
|
+
getResourceMetadata(uri: string): Promise<StoreResource | undefined>;
|
|
36
|
+
listResourceFolder(folder: string): Promise<StoreResource[]>;
|
|
37
|
+
listTypeResources(type: string): Promise<StoreResource[]>;
|
|
38
|
+
readResource(uri: string): Promise<StoreResourceContents | undefined>;
|
|
39
|
+
}
|
|
40
|
+
export interface FindRecordsInput {
|
|
41
|
+
type: string;
|
|
42
|
+
q?: string;
|
|
43
|
+
where?: JsonObject;
|
|
44
|
+
limit?: number;
|
|
45
|
+
fields?: string[];
|
|
46
|
+
cursor?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface GetRecordInput {
|
|
49
|
+
uri: string;
|
|
50
|
+
}
|
|
51
|
+
export interface CreateRecordInput {
|
|
52
|
+
type: string;
|
|
53
|
+
key?: string;
|
|
54
|
+
record: JsonObject;
|
|
55
|
+
}
|
|
56
|
+
export interface UpdateRecordInput {
|
|
57
|
+
uri: string;
|
|
58
|
+
patch: JsonObject;
|
|
59
|
+
}
|
|
60
|
+
export interface DeleteRecordInput {
|
|
61
|
+
uri: string;
|
|
62
|
+
}
|
|
63
|
+
export interface GetTypeInput {
|
|
64
|
+
type: string;
|
|
65
|
+
}
|
|
66
|
+
export interface CreateTypeInput {
|
|
67
|
+
type: string;
|
|
68
|
+
description: string;
|
|
69
|
+
schema: JsonObject;
|
|
70
|
+
titleField?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface UpdateTypeInput {
|
|
73
|
+
type: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
schema?: JsonObject;
|
|
76
|
+
titleField?: string | null;
|
|
77
|
+
}
|
|
78
|
+
export interface DeleteTypeInput {
|
|
79
|
+
type: string;
|
|
80
|
+
}
|
|
81
|
+
export interface UriResult {
|
|
82
|
+
uri: string;
|
|
83
|
+
}
|
|
84
|
+
export interface FindRecordsResult {
|
|
85
|
+
records: RecordResult[];
|
|
86
|
+
errors: StoreError[];
|
|
87
|
+
cursor?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface RecordResult extends UriResult {
|
|
90
|
+
createdAt: string;
|
|
91
|
+
updatedAt: string;
|
|
92
|
+
value: JsonObject;
|
|
93
|
+
error?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface TypeSummary extends UriResult {
|
|
96
|
+
type: string;
|
|
97
|
+
description: string;
|
|
98
|
+
}
|
|
99
|
+
export interface ListTypesResult {
|
|
100
|
+
types: TypeSummary[];
|
|
101
|
+
}
|
|
102
|
+
export interface TypeResult extends UriResult {
|
|
103
|
+
description: string;
|
|
104
|
+
schema: JsonObject;
|
|
105
|
+
titleField?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface UpdateTypeResult extends UriResult {
|
|
108
|
+
errors: StoreError[];
|
|
109
|
+
}
|
|
110
|
+
/** Plain metadata for one resource recognized in the data folder. */
|
|
111
|
+
export interface StoreResource extends UriResult {
|
|
112
|
+
name: string;
|
|
113
|
+
mimeType: string;
|
|
114
|
+
title?: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
size?: number;
|
|
117
|
+
lastModified?: string;
|
|
118
|
+
}
|
|
119
|
+
/** Exact contents of a recognized text or binary resource. */
|
|
120
|
+
export type StoreResourceContents = {
|
|
121
|
+
uri: string;
|
|
122
|
+
mimeType: string;
|
|
123
|
+
text: string;
|
|
124
|
+
} | {
|
|
125
|
+
uri: string;
|
|
126
|
+
mimeType: string;
|
|
127
|
+
blob: string;
|
|
128
|
+
};
|
|
129
|
+
/** Opens a store, creating its data folder when it does not exist. */
|
|
130
|
+
export declare function openStore(options?: OpenStoreOptions): Promise<Store>;
|
|
131
|
+
/** Returns whether a string is the canonical URI of an Autofile resource. */
|
|
132
|
+
export declare function isResourceUri(uri: string): boolean;
|