@telepath-computer/autofile 0.0.0-stage → 0.4.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 +88 -2
- package/dist/blobs.d.ts +21 -0
- package/dist/blobs.js +159 -0
- package/dist/blobs.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +186 -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 +157 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +11 -0
- package/dist/json.js +82 -0
- package/dist/json.js.map +1 -0
- package/dist/mcp-resources.d.ts +31 -0
- package/dist/mcp-resources.js +111 -0
- package/dist/mcp-resources.js.map +1 -0
- package/dist/mcp-tools.d.ts +113 -0
- package/dist/mcp-tools.js +89 -0
- package/dist/mcp-tools.js.map +1 -0
- package/dist/mcp-upload.d.ts +16 -0
- package/dist/mcp-upload.js +81 -0
- package/dist/mcp-upload.js.map +1 -0
- package/dist/mcp-watch.d.ts +18 -0
- package/dist/mcp-watch.js +165 -0
- package/dist/mcp-watch.js.map +1 -0
- package/dist/schema.d.ts +25 -0
- package/dist/schema.js +241 -0
- package/dist/schema.js.map +1 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +257 -0
- package/dist/server.js.map +1 -0
- package/dist/store.d.ts +112 -0
- package/dist/store.js +1389 -0
- package/dist/store.js.map +1 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +195 -0
- package/dist/watch.js.map +1 -0
- package/package.json +52 -4
package/dist/config.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/** Reads, validates, and writes Autofile's process-wide settings. */
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
const DEFAULT_HTTP_HOST = "127.0.0.1";
|
|
6
|
+
const DEFAULT_HTTP_PORT = 7319;
|
|
7
|
+
const settingNames = ["storage", "http.host", "http.port", "http.origins"];
|
|
8
|
+
function getAutofileHome() {
|
|
9
|
+
return resolve(process.env.AUTOFILE_HOME ?? join(homedir(), ".autofile"));
|
|
10
|
+
}
|
|
11
|
+
/** Returns whether a command argument names one of Autofile's settings. */
|
|
12
|
+
export function isSettingName(value) {
|
|
13
|
+
return settingNames.includes(value);
|
|
14
|
+
}
|
|
15
|
+
/** Returns the path shared stores use to serialize writes between processes. */
|
|
16
|
+
export function getWriteLockPath() {
|
|
17
|
+
return join(getAutofileHome(), "write.lock");
|
|
18
|
+
}
|
|
19
|
+
async function readConfig() {
|
|
20
|
+
const configPath = join(getAutofileHome(), "config.json");
|
|
21
|
+
let text;
|
|
22
|
+
try {
|
|
23
|
+
text = await readFile(configPath, "utf8");
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
27
|
+
return {};
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
let value;
|
|
31
|
+
try {
|
|
32
|
+
value = JSON.parse(text);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throw new Error(`${configPath}: invalid JSON`);
|
|
36
|
+
}
|
|
37
|
+
if (!isObject(value))
|
|
38
|
+
throw new Error(`${configPath}: must contain a JSON object`);
|
|
39
|
+
const storage = "storage" in value ? value.storage : undefined;
|
|
40
|
+
if (storage !== undefined && typeof storage !== "string") {
|
|
41
|
+
throw new Error(`${configPath}: storage must be a string`);
|
|
42
|
+
}
|
|
43
|
+
const httpValue = "http" in value ? value.http : undefined;
|
|
44
|
+
if (httpValue !== undefined && !isObject(httpValue)) {
|
|
45
|
+
throw new Error(`${configPath}: http must be a JSON object`);
|
|
46
|
+
}
|
|
47
|
+
const host = httpValue === undefined || !("host" in httpValue) ? undefined : httpValue.host;
|
|
48
|
+
if (host !== undefined && (typeof host !== "string" || host.length === 0)) {
|
|
49
|
+
throw new Error(`${configPath}: http.host must be a non-empty string`);
|
|
50
|
+
}
|
|
51
|
+
const port = httpValue === undefined || !("port" in httpValue) ? undefined : httpValue.port;
|
|
52
|
+
if (port !== undefined && !isPort(port)) {
|
|
53
|
+
throw new Error(`${configPath}: http.port must be an integer from 1 to 65535`);
|
|
54
|
+
}
|
|
55
|
+
const originsValue = httpValue === undefined || !("origins" in httpValue)
|
|
56
|
+
? undefined
|
|
57
|
+
: httpValue.origins;
|
|
58
|
+
let origins;
|
|
59
|
+
if (originsValue !== undefined && !Array.isArray(originsValue)) {
|
|
60
|
+
throw new Error(`${configPath}: http.origins must contain only http or https origins without paths`);
|
|
61
|
+
}
|
|
62
|
+
if (originsValue !== undefined) {
|
|
63
|
+
origins = [];
|
|
64
|
+
for (const origin of originsValue) {
|
|
65
|
+
const normalized = typeof origin === "string" ? normalizeHttpOrigin(origin) : undefined;
|
|
66
|
+
if (normalized === undefined) {
|
|
67
|
+
throw new Error(`${configPath}: http.origins must contain only http or https origins without paths`);
|
|
68
|
+
}
|
|
69
|
+
origins.push(normalized);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
...(storage === undefined ? {} : { storage }),
|
|
74
|
+
...(host === undefined && port === undefined && origins === undefined
|
|
75
|
+
? {}
|
|
76
|
+
: {
|
|
77
|
+
http: {
|
|
78
|
+
...(host === undefined ? {} : { host }),
|
|
79
|
+
...(port === undefined ? {} : { port }),
|
|
80
|
+
...(origins === undefined ? {} : { origins }),
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async function writeConfig(config) {
|
|
86
|
+
const autofileHome = getAutofileHome();
|
|
87
|
+
await mkdir(autofileHome, { recursive: true });
|
|
88
|
+
await writeFile(join(autofileHome, "config.json"), `${JSON.stringify(canonicalConfig(config), null, 2)}\n`, "utf8");
|
|
89
|
+
}
|
|
90
|
+
/** Returns every effective setting, applying defaults to settings that are absent. */
|
|
91
|
+
export async function getSettings() {
|
|
92
|
+
const config = await readConfig();
|
|
93
|
+
return {
|
|
94
|
+
storage: config.storage ?? join(getAutofileHome(), "data"),
|
|
95
|
+
http: {
|
|
96
|
+
host: config.http?.host ?? DEFAULT_HTTP_HOST,
|
|
97
|
+
port: config.http?.port ?? DEFAULT_HTTP_PORT,
|
|
98
|
+
origins: [...(config.http?.origins ?? [])],
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Returns the configured data folder, or the default folder when unset. */
|
|
103
|
+
export async function getStorage() {
|
|
104
|
+
return (await getSettings()).storage;
|
|
105
|
+
}
|
|
106
|
+
/** Returns a setting as the lines its CLI `get` command prints. */
|
|
107
|
+
export async function getSetting(name) {
|
|
108
|
+
const settings = await getSettings();
|
|
109
|
+
switch (name) {
|
|
110
|
+
case "storage": return [settings.storage];
|
|
111
|
+
case "http.host": return [settings.http.host];
|
|
112
|
+
case "http.port": return [String(settings.http.port)];
|
|
113
|
+
case "http.origins": return settings.http.origins;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Validates and stores one setting while preserving every other setting. */
|
|
117
|
+
export async function setSetting(name, values) {
|
|
118
|
+
const config = await readConfig();
|
|
119
|
+
switch (name) {
|
|
120
|
+
case "storage": {
|
|
121
|
+
const [folder] = values;
|
|
122
|
+
if (values.length !== 1 || folder === undefined || folder === "") {
|
|
123
|
+
throw new Error("storage must be a non-empty folder");
|
|
124
|
+
}
|
|
125
|
+
config.storage = resolveStorage(folder);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "http.host": {
|
|
129
|
+
const [host] = values;
|
|
130
|
+
if (values.length !== 1 || host === undefined || host === "") {
|
|
131
|
+
throw new Error("http.host must be a non-empty string");
|
|
132
|
+
}
|
|
133
|
+
config.http = { ...config.http, host };
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
case "http.port": {
|
|
137
|
+
const [value] = values;
|
|
138
|
+
if (values.length !== 1 || value === undefined) {
|
|
139
|
+
throw new Error("http.port must be an integer from 1 to 65535");
|
|
140
|
+
}
|
|
141
|
+
config.http = { ...config.http, port: parsePort(value) };
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case "http.origins": {
|
|
145
|
+
if (values.length === 0) {
|
|
146
|
+
throw new Error("http.origins must contain at least one origin");
|
|
147
|
+
}
|
|
148
|
+
config.http = { ...config.http, origins: values.map(parseOrigin) };
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
await writeConfig(config);
|
|
153
|
+
}
|
|
154
|
+
/** Removes one setting so its default applies, preserving its siblings. */
|
|
155
|
+
export async function unsetSetting(name) {
|
|
156
|
+
const config = await readConfig();
|
|
157
|
+
let changed = false;
|
|
158
|
+
if (name === "storage") {
|
|
159
|
+
changed = config.storage !== undefined;
|
|
160
|
+
delete config.storage;
|
|
161
|
+
}
|
|
162
|
+
else if (config.http !== undefined) {
|
|
163
|
+
const key = name.slice("http.".length);
|
|
164
|
+
changed = config.http[key] !== undefined;
|
|
165
|
+
delete config.http[key];
|
|
166
|
+
if (Object.keys(config.http).length === 0)
|
|
167
|
+
delete config.http;
|
|
168
|
+
}
|
|
169
|
+
if (changed)
|
|
170
|
+
await writeConfig(config);
|
|
171
|
+
}
|
|
172
|
+
/** Parses a CLI port value and rejects anything outside the TCP port range. */
|
|
173
|
+
export function parsePort(value) {
|
|
174
|
+
if (!/^\d+$/u.test(value)) {
|
|
175
|
+
throw new Error("http.port must be an integer from 1 to 65535");
|
|
176
|
+
}
|
|
177
|
+
const port = Number(value);
|
|
178
|
+
if (!isPort(port))
|
|
179
|
+
throw new Error("http.port must be an integer from 1 to 65535");
|
|
180
|
+
return port;
|
|
181
|
+
}
|
|
182
|
+
function resolveStorage(folder) {
|
|
183
|
+
if (folder === "~")
|
|
184
|
+
return homedir();
|
|
185
|
+
return folder.startsWith("~/") ? resolve(homedir(), folder.slice(2)) : resolve(folder);
|
|
186
|
+
}
|
|
187
|
+
function parseOrigin(value) {
|
|
188
|
+
const origin = normalizeHttpOrigin(value);
|
|
189
|
+
if (origin === undefined) {
|
|
190
|
+
throw new Error("http.origins must contain only http or https origins without paths");
|
|
191
|
+
}
|
|
192
|
+
return origin;
|
|
193
|
+
}
|
|
194
|
+
/** Returns the URL-normalized form of a strict HTTP origin, or undefined when invalid. */
|
|
195
|
+
export function normalizeHttpOrigin(value) {
|
|
196
|
+
const match = /^https?:\/\/(.+)$/iu.exec(value);
|
|
197
|
+
if (match === null)
|
|
198
|
+
return undefined;
|
|
199
|
+
const authority = match[1];
|
|
200
|
+
if (authority === undefined
|
|
201
|
+
|| authority.trim() !== authority
|
|
202
|
+
|| /[\s/\\?#@]/u.test(authority)) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
if (authority.startsWith("[")) {
|
|
206
|
+
const closingBracket = authority.indexOf("]");
|
|
207
|
+
if (closingBracket <= 1
|
|
208
|
+
|| (authority.slice(closingBracket + 1) !== ""
|
|
209
|
+
&& !/^:\d+$/u.test(authority.slice(closingBracket + 1)))) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
const firstColon = authority.indexOf(":");
|
|
215
|
+
if (firstColon !== -1
|
|
216
|
+
&& (firstColon !== authority.lastIndexOf(":")
|
|
217
|
+
|| !/^\d+$/u.test(authority.slice(firstColon + 1)))) {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const url = new URL(value);
|
|
223
|
+
if ((url.protocol !== "http:" && url.protocol !== "https:")
|
|
224
|
+
|| url.hostname === ""
|
|
225
|
+
|| url.username !== ""
|
|
226
|
+
|| url.password !== "") {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
return url.origin;
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function isPort(value) {
|
|
236
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 65_535;
|
|
237
|
+
}
|
|
238
|
+
function canonicalConfig(config) {
|
|
239
|
+
const host = config.http?.host;
|
|
240
|
+
const port = config.http?.port;
|
|
241
|
+
const origins = config.http?.origins;
|
|
242
|
+
return {
|
|
243
|
+
...(config.storage === undefined ? {} : { storage: config.storage }),
|
|
244
|
+
...(host === undefined && port === undefined && origins === undefined
|
|
245
|
+
? {}
|
|
246
|
+
: {
|
|
247
|
+
http: {
|
|
248
|
+
...(host === undefined ? {} : { host }),
|
|
249
|
+
...(port === undefined ? {} : { port }),
|
|
250
|
+
...(origins === undefined ? {} : { origins }),
|
|
251
|
+
},
|
|
252
|
+
}),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function isObject(value) {
|
|
256
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAErE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,iBAAiB,GAAG,WAAW,CAAC;AACtC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,CAAU,CAAC;AAwBpF,SAAS,eAAe;IACtB,OAAO,OAAO,CAAC,OAAO,C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HttpSettings } from "./config.js";
|
|
3
|
+
import type { Autofile } from "./index.js";
|
|
4
|
+
export interface RunningHttpServer {
|
|
5
|
+
endpoint: URL;
|
|
6
|
+
closed: Promise<void>;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/** Starts one modern-only Streamable HTTP endpoint around a process-shared store. */
|
|
10
|
+
export declare function startHttpServer(store: Autofile, settings: HttpSettings, onError: (error: Error) => void): Promise<RunningHttpServer>;
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/** Mounts Autofile's transport-independent MCP server on Node's HTTP server. */
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { toNodeHandler } from "@modelcontextprotocol/node";
|
|
4
|
+
import { createMcpHandler } from "@modelcontextprotocol/server";
|
|
5
|
+
import { normalizeHttpOrigin } from "./config.js";
|
|
6
|
+
import { buildServer } from "./server.js";
|
|
7
|
+
import { watchResources } from "./mcp-watch.js";
|
|
8
|
+
const MAX_REQUEST_BODY_BYTES = 64 * 1024 * 1024;
|
|
9
|
+
const CORS_ALLOW_HEADERS = "Content-Type, MCP-Protocol-Version, Mcp-Method, Mcp-Name";
|
|
10
|
+
/** Starts one modern-only Streamable HTTP endpoint around a process-shared store. */
|
|
11
|
+
export async function startHttpServer(store, settings, onError) {
|
|
12
|
+
const handler = createMcpHandler(() => buildServer(store), {
|
|
13
|
+
legacy: "reject",
|
|
14
|
+
maxRequestBodySize: MAX_REQUEST_BODY_BYTES,
|
|
15
|
+
onerror: onError,
|
|
16
|
+
});
|
|
17
|
+
const watcher = await watchResources(store, (batch) => {
|
|
18
|
+
const uris = new Set(batch.changes.map(({ uri }) => uri));
|
|
19
|
+
for (const uri of uris) {
|
|
20
|
+
handler.notify.resourceUpdated(uri);
|
|
21
|
+
}
|
|
22
|
+
if (batch.listChanged)
|
|
23
|
+
handler.notify.resourcesChanged();
|
|
24
|
+
}, onError).catch(async (error) => {
|
|
25
|
+
await Promise.all([store.close(), handler.close()]);
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
28
|
+
const serveMcp = toNodeHandler(handler, { maxRequestBodySize: MAX_REQUEST_BODY_BYTES });
|
|
29
|
+
const allowedOrigins = new Set(settings.origins);
|
|
30
|
+
const allowedHosts = new Set([
|
|
31
|
+
"localhost",
|
|
32
|
+
"127.0.0.1",
|
|
33
|
+
"[::1]",
|
|
34
|
+
...settings.origins.map((origin) => new URL(origin).hostname.toLowerCase()),
|
|
35
|
+
]);
|
|
36
|
+
const httpServer = createServer((request, response) => {
|
|
37
|
+
void routeRequest(request, response, allowedOrigins, allowedHosts, serveMcp);
|
|
38
|
+
});
|
|
39
|
+
const closed = new Promise((resolveClosed) => httpServer.once("close", resolveClosed));
|
|
40
|
+
try {
|
|
41
|
+
await new Promise((resolveListening, reject) => {
|
|
42
|
+
const onError = (error) => reject(error);
|
|
43
|
+
httpServer.once("error", onError);
|
|
44
|
+
httpServer.listen(settings.port, settings.host, () => {
|
|
45
|
+
httpServer.off("error", onError);
|
|
46
|
+
resolveListening();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
await Promise.all([watcher.close(), handler.close()]);
|
|
52
|
+
await store.close();
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
const endpoint = new URL(`http://${urlHost(settings.host)}:${settings.port}/mcp`);
|
|
56
|
+
let closing;
|
|
57
|
+
return {
|
|
58
|
+
endpoint,
|
|
59
|
+
closed,
|
|
60
|
+
close() {
|
|
61
|
+
closing ??= closeHttpServer();
|
|
62
|
+
return closing;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
async function closeHttpServer() {
|
|
66
|
+
httpServer.close();
|
|
67
|
+
httpServer.closeAllConnections();
|
|
68
|
+
await Promise.all([watcher.close(), handler.close(), closed]);
|
|
69
|
+
await store.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function routeRequest(request, response, allowedOrigins, allowedHosts, serveMcp) {
|
|
73
|
+
if (!isAllowedHost(request.headers.host, allowedHosts)) {
|
|
74
|
+
refuse(response, 403, "Forbidden\n");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const origin = request.headers.origin;
|
|
78
|
+
if (origin !== undefined && !isAllowedOrigin(origin, allowedOrigins)) {
|
|
79
|
+
refuse(response, 403, "Forbidden\n");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (requestPath(request) !== "/mcp") {
|
|
83
|
+
refuse(response, 404, "Not Found\n");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (origin !== undefined)
|
|
87
|
+
setCorsHeaders(response, origin);
|
|
88
|
+
if (request.method === "OPTIONS") {
|
|
89
|
+
response.setHeader("Connection", "close");
|
|
90
|
+
response.writeHead(204, {
|
|
91
|
+
"Access-Control-Allow-Methods": "POST, OPTIONS",
|
|
92
|
+
"Access-Control-Allow-Headers": CORS_ALLOW_HEADERS,
|
|
93
|
+
}).end();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
await serveMcp(request, response);
|
|
97
|
+
}
|
|
98
|
+
function requestPath(request) {
|
|
99
|
+
try {
|
|
100
|
+
return new URL(request.url ?? "", "http://autofile.local").pathname;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function isAllowedOrigin(origin, allowedOrigins) {
|
|
107
|
+
const normalized = normalizeHttpOrigin(origin);
|
|
108
|
+
if (normalized === undefined)
|
|
109
|
+
return false;
|
|
110
|
+
const hostname = new URL(normalized).hostname.toLowerCase();
|
|
111
|
+
return hostname === "localhost"
|
|
112
|
+
|| hostname === "127.0.0.1"
|
|
113
|
+
|| hostname === "[::1]"
|
|
114
|
+
|| allowedOrigins.has(normalized);
|
|
115
|
+
}
|
|
116
|
+
function isAllowedHost(host, allowedHosts) {
|
|
117
|
+
const hostname = host === undefined ? undefined : hostHeaderName(host);
|
|
118
|
+
return hostname !== undefined && allowedHosts.has(hostname);
|
|
119
|
+
}
|
|
120
|
+
function hostHeaderName(host) {
|
|
121
|
+
if (host === "" || host.trim() !== host || /[\s/\\?#@,]/u.test(host))
|
|
122
|
+
return undefined;
|
|
123
|
+
if (host.startsWith("[")) {
|
|
124
|
+
const closingBracket = host.indexOf("]");
|
|
125
|
+
if (closingBracket <= 1
|
|
126
|
+
|| (host.slice(closingBracket + 1) !== ""
|
|
127
|
+
&& !/^:\d+$/u.test(host.slice(closingBracket + 1)))) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const firstColon = host.indexOf(":");
|
|
133
|
+
if (firstColon !== -1
|
|
134
|
+
&& (firstColon !== host.lastIndexOf(":")
|
|
135
|
+
|| !/^\d+$/u.test(host.slice(firstColon + 1)))) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
return new URL(`http://${host}`).hostname.toLowerCase();
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function refuse(response, status, body) {
|
|
147
|
+
response.setHeader("Connection", "close");
|
|
148
|
+
response.writeHead(status).end(body);
|
|
149
|
+
}
|
|
150
|
+
function setCorsHeaders(response, origin) {
|
|
151
|
+
response.setHeader("Access-Control-Allow-Origin", origin);
|
|
152
|
+
response.setHeader("Vary", "Origin");
|
|
153
|
+
}
|
|
154
|
+
function urlHost(host) {
|
|
155
|
+
return host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAEhF,OAAO,EAAE,YAAY,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IAAI,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,QAAwB,EAAE,MAAc,EAAE,IAAY;IACpE,QAAQ,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,cAAc,CAAC,QAAwB,EAAE,MAAc;IAC9D,QAAQ,CAAC,SAAS,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAC;IAC1D,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The embedding interface. Importing it starts no server or watcher. */
|
|
2
|
+
export { Autofile, AutofileError } from "./store.js";
|
|
3
|
+
export type { AutofileProblem, AutofileRecord, ChangeEvent, RecordQuery, RecordQueryResult, TypeChanges, TypeDeclaration, TypeDefinition, WatchOptions, } from "./store.js";
|
|
4
|
+
export type { JsonObject, JsonPrimitive, JsonValue } from "./json.js";
|
|
5
|
+
export type { FormatField, PreparedSchema } from "./schema.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Shared JSON types and lossless input checks at the store boundary. */
|
|
2
|
+
/** A scalar JSON value. */
|
|
3
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
4
|
+
/** Any value representable in JSON. */
|
|
5
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
6
|
+
/** A JSON object with string keys. */
|
|
7
|
+
export interface JsonObject {
|
|
8
|
+
[key: string]: JsonValue;
|
|
9
|
+
}
|
|
10
|
+
/** Returns why an input is not a plain JSON object, without calling getters or toJSON. */
|
|
11
|
+
export declare function jsonObjectProblem(value: unknown): string | undefined;
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Shared JSON types and lossless input checks at the store boundary. */
|
|
2
|
+
import { isProxy } from "node:util/types";
|
|
3
|
+
const isRawJson = JSON.isRawJSON;
|
|
4
|
+
/** Returns why an input is not a plain JSON object, without calling getters or toJSON. */
|
|
5
|
+
export function jsonObjectProblem(value) {
|
|
6
|
+
if (isProxy(value))
|
|
7
|
+
return "JSON proxies are not supported";
|
|
8
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
9
|
+
return "must be a JSON object";
|
|
10
|
+
}
|
|
11
|
+
return jsonValueProblem(value, "", new Set());
|
|
12
|
+
}
|
|
13
|
+
function jsonValueProblem(value, path, ancestors) {
|
|
14
|
+
const location = `JSON value at ${JSON.stringify(path || "/")}`;
|
|
15
|
+
if (isProxy(value))
|
|
16
|
+
return `${location}: proxies are not supported`;
|
|
17
|
+
if (isRawJson?.(value))
|
|
18
|
+
return `${location}: raw JSON fragments are not supported`;
|
|
19
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
20
|
+
return undefined;
|
|
21
|
+
if (typeof value === "number") {
|
|
22
|
+
return Number.isFinite(value) && !Object.is(value, -0)
|
|
23
|
+
? undefined
|
|
24
|
+
: `${location}: must be a finite number other than negative zero`;
|
|
25
|
+
}
|
|
26
|
+
if (typeof value !== "object")
|
|
27
|
+
return `${location}: ${typeof value} is not supported`;
|
|
28
|
+
const isArray = Array.isArray(value);
|
|
29
|
+
const prototype = Object.getPrototypeOf(value);
|
|
30
|
+
if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {
|
|
31
|
+
return `${location}: must be a plain object or ordinary array`;
|
|
32
|
+
}
|
|
33
|
+
// Built-in prototypes can carry serialization hooks too. Check descriptors so
|
|
34
|
+
// the JSON snapshot cannot invoke an inherited getter or rewrite the value.
|
|
35
|
+
if (!Object.hasOwn(value, "toJSON")) {
|
|
36
|
+
for (let parent = prototype; parent !== null; parent = Object.getPrototypeOf(parent)) {
|
|
37
|
+
const descriptor = Object.getOwnPropertyDescriptor(parent, "toJSON");
|
|
38
|
+
if (descriptor === undefined)
|
|
39
|
+
continue;
|
|
40
|
+
if (!("value" in descriptor) || typeof descriptor.value === "function") {
|
|
41
|
+
return `${location}: inherited JSON serialization hooks are not supported`;
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (ancestors.has(value))
|
|
47
|
+
return `${location}: circular references are not supported`;
|
|
48
|
+
const keys = Reflect.ownKeys(value);
|
|
49
|
+
// Arrays serialize only their numbered elements. Inspect descriptors rather
|
|
50
|
+
// than reading properties so getters and toJSON can never change the input.
|
|
51
|
+
const length = isArray ? Object.getOwnPropertyDescriptor(value, "length").value : undefined;
|
|
52
|
+
if (length !== undefined && keys.length !== length + 1) {
|
|
53
|
+
return `${location}: arrays must be dense and have no extra properties`;
|
|
54
|
+
}
|
|
55
|
+
ancestors.add(value);
|
|
56
|
+
try {
|
|
57
|
+
for (const key of keys) {
|
|
58
|
+
if (typeof key === "symbol")
|
|
59
|
+
return `${location}: symbol properties are not supported`;
|
|
60
|
+
if (length !== undefined) {
|
|
61
|
+
if (key === "length")
|
|
62
|
+
continue;
|
|
63
|
+
if (!/^(?:0|[1-9]\d*)$/u.test(key) || Number(key) >= length) {
|
|
64
|
+
return `${location}: arrays must have no extra properties`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
68
|
+
if (!("value" in descriptor) || !descriptor.enumerable) {
|
|
69
|
+
return `${location}: properties must be enumerable data properties`;
|
|
70
|
+
}
|
|
71
|
+
const childPath = `${path}/${key.replaceAll("~", "~0").replaceAll("/", "~1")}`;
|
|
72
|
+
const problem = jsonValueProblem(descriptor.value, childPath, ancestors);
|
|
73
|
+
if (problem !== undefined)
|
|
74
|
+
return problem;
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
ancestors.delete(value);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=json.js.map
|
package/dist/json.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,SAAS,GAAI,IAA2D,CAAC,SAAS,CAAC;AAWzF,0FAA0F;AAC1F,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,gCAAgC,CAAC;IAC5D,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,uBAAuB,CAAC;IACjC,CAAC;IACD,OAAO,gBAAgB,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc,EAAE,IAAY,EAAE,SAAsB;IAC5E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GAAG,QAAQ,wCAAwC,CAAC;gBAC7D,CAAC;YACH,CAAC;YACD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAE,CAAC;YAChE,IAAI,CAAC,CAAC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;gBACvD,OAAO,GAAG,QAAQ,iDAAiD,CAAC;YACtE,CAAC;YACD,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YAC/E,MAAM,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;YACzE,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC;QAC5C,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;YAAS,CAAC;QACT,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Derives MCP resources from public Autofile records and type declarations. */
|
|
2
|
+
import { type Autofile } from "./index.js";
|
|
3
|
+
/** The public information used in an MCP resource listing. */
|
|
4
|
+
export interface StoreResource {
|
|
5
|
+
uri: string;
|
|
6
|
+
name: string;
|
|
7
|
+
mimeType: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
}
|
|
11
|
+
/** The text or binary contents of one resource. */
|
|
12
|
+
export type StoreResourceContents = {
|
|
13
|
+
uri: string;
|
|
14
|
+
mimeType: string;
|
|
15
|
+
text: string;
|
|
16
|
+
} | {
|
|
17
|
+
uri: string;
|
|
18
|
+
mimeType: string;
|
|
19
|
+
blob: string;
|
|
20
|
+
};
|
|
21
|
+
/** Resource operations shared by the MCP server and its notification adapter. */
|
|
22
|
+
export interface Resources {
|
|
23
|
+
listResources(): Promise<StoreResource[]>;
|
|
24
|
+
getResourceMetadata(uri: string): Promise<StoreResource | undefined>;
|
|
25
|
+
listTypeResources(type: string): Promise<StoreResource[]>;
|
|
26
|
+
readResource(uri: string): Promise<StoreResourceContents | undefined>;
|
|
27
|
+
}
|
|
28
|
+
/** Builds resource operations using only the public library interface. */
|
|
29
|
+
export declare function buildResources(autofile: Autofile): Resources;
|
|
30
|
+
/** Checks addresses that can occur in an MCP resource-list cursor. */
|
|
31
|
+
export declare function isResourceUri(uri: string): boolean;
|