@hiai-gg/docsmint 2.0.3 → 2.1.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/README.md +68 -3
- package/dist/backend/index.js +22540 -2807
- package/dist/backend-account-runtime-cleanup.js +2 -1
- package/dist/backend-api-key-facade.js +2 -1
- package/dist/backend-pipeline-cancellation.js +2 -1
- package/dist/client.d.ts +33 -7
- package/dist/client.js +55 -1
- package/dist/frontend/{HiAiEditor-DDpfdQEg.js → HiAiEditor-D6ad_auS.js} +2 -2
- package/dist/frontend/{SettingsDialog-DzlYW50I.js → SettingsDialog-B8Oswuqb.js} +4 -4
- package/dist/frontend/{Sidebar-rFiVen96.js → Sidebar-BV0IDqTS.js} +1 -1
- package/dist/frontend/api/settings.js +1 -1
- package/dist/frontend/app-shell.js +45 -36
- package/dist/frontend/{auth-client-CXR-7mIO.js → auth-client-C5EyWdAF.js} +416 -349
- package/dist/frontend/components/editor/compact-editor.js +1 -1
- package/dist/frontend/components/editor/document-editor.js +1 -1
- package/dist/frontend/components/settings.js +1 -1
- package/dist/frontend/components/sidebar.js +1 -1
- package/dist/frontend/{db-Dya0HRhS.js → db-CgTtukT4.js} +1 -1
- package/dist/frontend/{identity-BOA7Jejv.js → identity-CNhtuCJV.js} +1 -1
- package/dist/frontend/offline/identity.js +1 -1
- package/dist/frontend/{settings-BRcYFQa_.js → settings-CHx4wBwb.js} +1 -1
- package/dist/frontend-ssr/api/settings.js +1 -1
- package/dist/frontend-ssr/app-shell.js +2 -2
- package/dist/frontend-ssr/assets/{HiAiEditor-Bj6tiE97.js → HiAiEditor-Cj3B2Dt6.js} +2 -2
- package/dist/frontend-ssr/assets/{SettingsDialog-h4SFwpUa.js → SettingsDialog-DAT-Zxu0.js} +4 -4
- package/dist/frontend-ssr/assets/{Sidebar-BFBpsd3L.js → Sidebar-B_Ey6QNL.js} +1 -1
- package/dist/frontend-ssr/assets/{auth-client-BC4hSFKF.js → auth-client-CITU3xkE.js} +308 -227
- package/dist/frontend-ssr/assets/{db-C3rFdTZa.js → db-DxRzq-kx.js} +1 -1
- package/dist/frontend-ssr/assets/{identity-DNIo1bgc.js → identity-B7ngLQzZ.js} +1 -1
- package/dist/frontend-ssr/assets/{settings-DWCpfCPj.js → settings-BRxvn30Y.js} +1 -1
- package/dist/frontend-ssr/components/editor/compact-editor.js +1 -1
- package/dist/frontend-ssr/components/editor/document-editor.js +1 -1
- package/dist/frontend-ssr/components/settings.js +1 -1
- package/dist/frontend-ssr/components/sidebar.js +1 -1
- package/dist/frontend-ssr/offline/identity.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lifecycle-runtime.js +4 -1
- package/dist/mcp-cli.js +301 -22
- package/dist/mcp-server.d.ts +92 -23
- package/dist/mcp-server.js +469 -22
- package/dist/types.d.ts +68 -1
- package/package.json +2 -2
- package/packages/cli/src/index.ts +1 -1
- package/packages/db/src/schema.ts +3 -1
- package/server.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getSession } from "./auth-client-
|
|
1
|
+
import { n as getSession } from "./auth-client-CITU3xkE.js";
|
|
2
2
|
//#region src/lib/offline/identity.ts
|
|
3
3
|
var OWNER_ID_CACHE_KEY = "hiai-docs:offline-owner-id";
|
|
4
4
|
var OFFLINE_BINDING_KEY = "hiai-docs:offline-binding";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as HiAiEditor } from "../../assets/HiAiEditor-
|
|
1
|
+
import { t as HiAiEditor } from "../../assets/HiAiEditor-Cj3B2Dt6.js";
|
|
2
2
|
import "svelte/internal/server";
|
|
3
3
|
//#region src/lib/components/editor/CompactEditor.svelte
|
|
4
4
|
function CompactEditor($$renderer, $$props) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as HiAiEditor } from "../../assets/HiAiEditor-
|
|
1
|
+
import { t as HiAiEditor } from "../../assets/HiAiEditor-Cj3B2Dt6.js";
|
|
2
2
|
export { HiAiEditor as DocsmintDocumentEditorHost };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as SettingsDialog } from "../assets/SettingsDialog-
|
|
1
|
+
import { t as SettingsDialog } from "../assets/SettingsDialog-DAT-Zxu0.js";
|
|
2
2
|
export { SettingsDialog };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as Sidebar } from "../assets/Sidebar-
|
|
1
|
+
import { t as Sidebar } from "../assets/Sidebar-B_Ey6QNL.js";
|
|
2
2
|
export { Sidebar };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as resolveOfflineIdentity, i as offlineDbName, n as enableOfflineAccess, o as resolveOfflineIdentityResolution, r as offlineAccessEnabled, t as disableOfflineAccess } from "../assets/identity-
|
|
1
|
+
import { a as resolveOfflineIdentity, i as offlineDbName, n as enableOfflineAccess, o as resolveOfflineIdentityResolution, r as offlineAccessEnabled, t as disableOfflineAccess } from "../assets/identity-B7ngLQzZ.js";
|
|
2
2
|
export { disableOfflineAccess, enableOfflineAccess, offlineAccessEnabled, offlineDbName, resolveOfflineIdentity, resolveOfflineIdentityResolution };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { DocsClientConfig } from "./client.js";
|
|
2
|
-
export { DocsApiError, DocsClient, DocsNetworkError, DocsTimeoutError, isDocsApiError, } from "./client.js";
|
|
2
|
+
export { DocsApiError, DocsClient, normalizeDocsSearchResult, DocsNetworkError, DocsTimeoutError, isDocsApiError, } from "./client.js";
|
|
3
3
|
export type { AssertPurgeAllowed, ExportUserDataContext, LifecycleHostStep, LifecycleOperationKind, LifecycleOperationStatus, PurgeUserDataContext, PurgeUserDataResult, UserDataExportRecord, UserDataLifecycle, UserDataLifecycleAdapter, } from "./lifecycle.js";
|
|
4
4
|
export { configureUserDataLifecycle, createUserDataLifecycle, encodeUserDataExportNdjson, exportUserData, purgeUserData, } from "./lifecycle.js";
|
|
5
5
|
export type * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { DocsApiError, DocsClient, DocsNetworkError, DocsTimeoutError, isDocsApiError, } from "./client.js";
|
|
1
|
+
export { DocsApiError, DocsClient, normalizeDocsSearchResult, DocsNetworkError, DocsTimeoutError, isDocsApiError, } from "./client.js";
|
|
2
2
|
export { configureUserDataLifecycle, createUserDataLifecycle, encodeUserDataExportNdjson, exportUserData, purgeUserData, } from "./lifecycle.js";
|
|
3
3
|
export { createDocsmintWorkspaceAssertion, DOCSMINT_WORKSPACE_ASSERTION_CLOCK_SKEW_SECONDS, DOCSMINT_WORKSPACE_ASSERTION_TTL_SECONDS, DOCSMINT_WORKSPACE_CONTEXT_HEADER, verifyDocsmintWorkspaceAssertion, } from "./workspace.js";
|
|
@@ -37691,10 +37691,11 @@ var accounts = pgTable("accounts", {
|
|
|
37691
37691
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
37692
37692
|
userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
37693
37693
|
accountId: text("account_id").notNull(),
|
|
37694
|
-
issuer: text("issuer")
|
|
37694
|
+
issuer: text("issuer"),
|
|
37695
37695
|
providerId: text("provider_id").notNull(),
|
|
37696
37696
|
accessToken: text("access_token"),
|
|
37697
37697
|
refreshToken: text("refresh_token"),
|
|
37698
|
+
idToken: text("id_token"),
|
|
37698
37699
|
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
|
37699
37700
|
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
|
37700
37701
|
scope: text("scope"),
|
|
@@ -59788,6 +59789,8 @@ var envSchema = exports_external.object({
|
|
|
59788
59789
|
EMBEDDING_FALLBACK_2_BASE_URL: exports_external.string().optional(),
|
|
59789
59790
|
EMBEDDING_FALLBACK_2_API_KEY: exports_external.string().optional(),
|
|
59790
59791
|
EMBEDDING_FALLBACK_2_MODEL: exports_external.string().optional(),
|
|
59792
|
+
MCP_HTTP_ENABLED: exports_external.enum(["true", "false"]).default("true").transform((value) => value === "true"),
|
|
59793
|
+
PUBLIC_APP_URL: exports_external.preprocess((value) => value === "" ? undefined : value, exports_external.string().url().refine((value) => ["http:", "https:"].includes(new URL(value).protocol), "PUBLIC_APP_URL must use HTTP or HTTPS").optional()),
|
|
59791
59794
|
API_PORT: exports_external.coerce.number().default(50700),
|
|
59792
59795
|
NODE_ENV: exports_external.enum(["development", "production", "test"]).default("development"),
|
|
59793
59796
|
LOG_LEVEL: exports_external.enum(["trace", "debug", "info", "warn", "error", "fatal"]).default("info"),
|
package/dist/mcp-cli.js
CHANGED
|
@@ -4,8 +4,190 @@
|
|
|
4
4
|
// ../mcp-server/src/index.ts
|
|
5
5
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
6
6
|
|
|
7
|
-
// ../mcp-server/src/
|
|
8
|
-
import {
|
|
7
|
+
// ../mcp-server/src/argument-diagnostics.ts
|
|
8
|
+
import {
|
|
9
|
+
McpServer
|
|
10
|
+
} from "@modelcontextprotocol/server";
|
|
11
|
+
var contracts = new WeakMap;
|
|
12
|
+
function object(value) {
|
|
13
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
14
|
+
}
|
|
15
|
+
function captureMcpInputSchema(server, name, schema) {
|
|
16
|
+
let registered = contracts.get(server);
|
|
17
|
+
if (!registered) {
|
|
18
|
+
registered = new Map;
|
|
19
|
+
contracts.set(server, registered);
|
|
20
|
+
}
|
|
21
|
+
registered.set(name, {
|
|
22
|
+
validate: (value) => schema["~standard"].validate(value, undefined),
|
|
23
|
+
jsonSchema: () => schema["~standard"].jsonSchema.input({ target: "draft-2020-12" })
|
|
24
|
+
});
|
|
25
|
+
return schema;
|
|
26
|
+
}
|
|
27
|
+
var codes = new Set([
|
|
28
|
+
"invalid_type",
|
|
29
|
+
"too_big",
|
|
30
|
+
"too_small",
|
|
31
|
+
"invalid_format",
|
|
32
|
+
"not_multiple_of",
|
|
33
|
+
"unrecognized_keys",
|
|
34
|
+
"invalid_union",
|
|
35
|
+
"invalid_key",
|
|
36
|
+
"invalid_element",
|
|
37
|
+
"invalid_value",
|
|
38
|
+
"custom"
|
|
39
|
+
]);
|
|
40
|
+
function diagnostics(tool, input, schemaValue, issues) {
|
|
41
|
+
const schema = object(schemaValue) ?? {};
|
|
42
|
+
const branches = Array.isArray(schema.oneOf) ? schema.oneOf.map((item) => object(item) ?? {}) : [schema];
|
|
43
|
+
const knownFields = new Set;
|
|
44
|
+
function fields(value) {
|
|
45
|
+
const item = object(value);
|
|
46
|
+
if (!item)
|
|
47
|
+
return;
|
|
48
|
+
for (const [name, child] of Object.entries(object(item.properties) ?? {})) {
|
|
49
|
+
knownFields.add(name);
|
|
50
|
+
fields(child);
|
|
51
|
+
}
|
|
52
|
+
if (item.items)
|
|
53
|
+
fields(item.items);
|
|
54
|
+
for (const key of ["oneOf", "anyOf", "allOf"])
|
|
55
|
+
if (Array.isArray(item[key]))
|
|
56
|
+
for (const child of item[key])
|
|
57
|
+
fields(child);
|
|
58
|
+
}
|
|
59
|
+
fields(schema);
|
|
60
|
+
const args = object(input) ?? {};
|
|
61
|
+
const selector = ["mode", "action", "view", "kind"].find((key) => branches.some((branch2) => {
|
|
62
|
+
const property = object(object(branch2.properties)?.[key]);
|
|
63
|
+
return property && (typeof property.const === "string" || Array.isArray(property.enum));
|
|
64
|
+
}));
|
|
65
|
+
const variants = branches.map((branch2) => {
|
|
66
|
+
const property = selector ? object(object(branch2.properties)?.[selector]) : undefined;
|
|
67
|
+
const values = property && typeof property.const === "string" ? [property.const] : Array.isArray(property?.enum) ? property.enum.filter((value) => typeof value === "string") : [];
|
|
68
|
+
return {
|
|
69
|
+
values,
|
|
70
|
+
required: Array.isArray(branch2.required) ? branch2.required.filter((value) => typeof value === "string" && knownFields.has(value)) : []
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
const selected = selector ? args[selector] : undefined;
|
|
74
|
+
const branch = typeof selected === "string" && variants.some((variant) => variant.values.includes(selected)) ? selected : null;
|
|
75
|
+
return {
|
|
76
|
+
tool,
|
|
77
|
+
branch,
|
|
78
|
+
expectedArgs: variants.map((variant) => ({
|
|
79
|
+
branches: variant.values,
|
|
80
|
+
required: variant.required
|
|
81
|
+
})),
|
|
82
|
+
issues: issues.slice(0, 32).map((value) => {
|
|
83
|
+
const issue = object(value) ?? {};
|
|
84
|
+
const path = Array.isArray(issue.path) ? issue.path.map((part) => object(part)?.key ?? part).filter((part) => typeof part === "string" ? knownFields.has(part) : typeof part === "number" && Number.isInteger(part) && part >= 0 && part < 1e4) : [];
|
|
85
|
+
return {
|
|
86
|
+
path,
|
|
87
|
+
code: typeof issue.code === "string" && codes.has(issue.code) ? issue.code : "invalid_argument"
|
|
88
|
+
};
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function decorateMcpArgumentTransport(transport, server) {
|
|
93
|
+
const pending = new Map;
|
|
94
|
+
let closed = false;
|
|
95
|
+
let overflowed = false;
|
|
96
|
+
function remember(message) {
|
|
97
|
+
if (closed || overflowed)
|
|
98
|
+
return;
|
|
99
|
+
if (!("method" in message) || !("id" in message) || typeof message.id !== "string" && typeof message.id !== "number")
|
|
100
|
+
return;
|
|
101
|
+
const previous = pending.get(message.id);
|
|
102
|
+
if (previous) {
|
|
103
|
+
previous.count++;
|
|
104
|
+
previous.ambiguous = true;
|
|
105
|
+
previous.candidate = undefined;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (pending.size >= 1024) {
|
|
109
|
+
overflowed = true;
|
|
110
|
+
pending.clear();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const params = "params" in message ? object(message.params) : undefined;
|
|
114
|
+
const name = params?.name;
|
|
115
|
+
const contract = message.method === "tools/call" && typeof name === "string" ? contracts.get(server)?.get(name) : undefined;
|
|
116
|
+
pending.set(message.id, {
|
|
117
|
+
count: 1,
|
|
118
|
+
ambiguous: false,
|
|
119
|
+
...contract && typeof name === "string" ? { candidate: { tool: name, args: params?.arguments ?? {}, contract } } : {}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async function send(message, options) {
|
|
123
|
+
const id = "id" in message && (typeof message.id === "string" || typeof message.id === "number") && !("method" in message) ? message.id : undefined;
|
|
124
|
+
const entry = id === undefined ? undefined : pending.get(id);
|
|
125
|
+
let outgoing = message;
|
|
126
|
+
try {
|
|
127
|
+
const candidate = entry && !entry.ambiguous ? entry.candidate : undefined;
|
|
128
|
+
const result = "result" in message ? object(message.result) : undefined;
|
|
129
|
+
const block = result && Array.isArray(result.content) && result.content.length === 1 ? object(result.content[0]) : undefined;
|
|
130
|
+
if (id !== undefined && candidate && result?.isError === true && Object.keys(result).length === 2 && block?.type === "text" && Object.keys(block).length === 2 && typeof block.text === "string" && block.text.startsWith(`Input validation error: Invalid arguments for tool ${candidate.tool}:`)) {
|
|
131
|
+
try {
|
|
132
|
+
const validation = object(await candidate.contract.validate(candidate.args));
|
|
133
|
+
if (Array.isArray(validation?.issues) && validation.issues.length && !entry?.ambiguous && pending.get(id) === entry) {
|
|
134
|
+
const data = diagnostics(candidate.tool, candidate.args, candidate.contract.jsonSchema(), validation.issues);
|
|
135
|
+
outgoing = {
|
|
136
|
+
jsonrpc: "2.0",
|
|
137
|
+
id,
|
|
138
|
+
error: { code: -32602, message: "Invalid tool arguments", data }
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
} catch {}
|
|
142
|
+
}
|
|
143
|
+
await transport.send(outgoing, options);
|
|
144
|
+
} finally {
|
|
145
|
+
if (id !== undefined && entry && pending.get(id) === entry && --entry.count === 0)
|
|
146
|
+
pending.delete(id);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return new Proxy(transport, {
|
|
150
|
+
get(target, property) {
|
|
151
|
+
if (property === "send")
|
|
152
|
+
return send;
|
|
153
|
+
if (property === "close")
|
|
154
|
+
return async () => {
|
|
155
|
+
closed = true;
|
|
156
|
+
pending.clear();
|
|
157
|
+
await target.close();
|
|
158
|
+
};
|
|
159
|
+
const value = Reflect.get(target, property, target);
|
|
160
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
161
|
+
},
|
|
162
|
+
set(target, property, value) {
|
|
163
|
+
if (property === "onmessage")
|
|
164
|
+
return Reflect.set(target, property, (message, extra) => {
|
|
165
|
+
try {
|
|
166
|
+
remember(message);
|
|
167
|
+
} catch {
|
|
168
|
+
overflowed = true;
|
|
169
|
+
pending.clear();
|
|
170
|
+
}
|
|
171
|
+
if (typeof value === "function")
|
|
172
|
+
value(message, extra);
|
|
173
|
+
}, target);
|
|
174
|
+
if (property === "onclose")
|
|
175
|
+
return Reflect.set(target, property, () => {
|
|
176
|
+
closed = true;
|
|
177
|
+
pending.clear();
|
|
178
|
+
if (typeof value === "function")
|
|
179
|
+
value();
|
|
180
|
+
}, target);
|
|
181
|
+
return Reflect.set(target, property, value, target);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
class DocsMintMcpServer extends McpServer {
|
|
187
|
+
connect(transport) {
|
|
188
|
+
return super.connect(decorateMcpArgumentTransport(transport, this));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
9
191
|
|
|
10
192
|
// dist/client.js
|
|
11
193
|
var docsApiErrorBrand = Symbol.for("io.github.hiai-gg.docsmint.DocsApiError");
|
|
@@ -58,11 +240,15 @@ class DocsTimeoutError extends DocsNetworkError {
|
|
|
58
240
|
class DocsClient {
|
|
59
241
|
config;
|
|
60
242
|
constructor(config) {
|
|
243
|
+
if (config.apiPrefix !== undefined && config.apiPrefix !== "/api" && config.apiPrefix !== "/api/v1") {
|
|
244
|
+
throw new Error("DocsClient: apiPrefix must be /api or /api/v1");
|
|
245
|
+
}
|
|
61
246
|
if (!config.baseUrl) {
|
|
62
247
|
throw new Error("DocsClient: `baseUrl` is required");
|
|
63
248
|
}
|
|
64
249
|
this.config = {
|
|
65
250
|
baseUrl: config.baseUrl.replace(/\/+$/, ""),
|
|
251
|
+
apiPrefix: config.apiPrefix ?? "/api",
|
|
66
252
|
apiKey: config.apiKey,
|
|
67
253
|
requestContext: this.snapshotContext(config.requestContext),
|
|
68
254
|
fetch: config.fetch ?? fetch,
|
|
@@ -102,6 +288,16 @@ class DocsClient {
|
|
|
102
288
|
return this.request("GET", "/api/documents", {
|
|
103
289
|
query: this.cleanQuery({
|
|
104
290
|
folderId: options?.folderId,
|
|
291
|
+
categoryId: options?.categoryId,
|
|
292
|
+
visibility: options?.visibility,
|
|
293
|
+
rootOnly: options?.rootOnly,
|
|
294
|
+
tagIds: options?.tagIds?.join(","),
|
|
295
|
+
tagMatch: options?.tagMatch,
|
|
296
|
+
q: options?.q,
|
|
297
|
+
updatedFrom: options?.updatedFrom,
|
|
298
|
+
updatedTo: options?.updatedTo,
|
|
299
|
+
sortBy: options?.sortBy,
|
|
300
|
+
sortOrder: options?.sortOrder,
|
|
105
301
|
tag: options?.tag,
|
|
106
302
|
page: options?.page,
|
|
107
303
|
limit: options?.limit
|
|
@@ -112,6 +308,15 @@ class DocsClient {
|
|
|
112
308
|
return this.request("GET", "/api/documents/cursor", {
|
|
113
309
|
query: this.cleanQuery({
|
|
114
310
|
categoryId: options.categoryId,
|
|
311
|
+
folderId: options.folderId,
|
|
312
|
+
rootOnly: options.rootOnly,
|
|
313
|
+
tag: options.tag,
|
|
314
|
+
tagIds: options.tagIds?.join(","),
|
|
315
|
+
tagMatch: options.tagMatch,
|
|
316
|
+
visibility: options.visibility,
|
|
317
|
+
q: options.q,
|
|
318
|
+
updatedFrom: options.updatedFrom,
|
|
319
|
+
updatedTo: options.updatedTo,
|
|
115
320
|
cursor: options.cursor,
|
|
116
321
|
limit: options.limit,
|
|
117
322
|
sortBy: options.sortBy,
|
|
@@ -143,6 +348,14 @@ class DocsClient {
|
|
|
143
348
|
async unpublishDoc(id, context) {
|
|
144
349
|
return this.request("POST", `/api/documents/${encodeURIComponent(id)}/unpublish`, undefined, context);
|
|
145
350
|
}
|
|
351
|
+
async exportDocWithMetadata(id, context) {
|
|
352
|
+
const response = await this.fetchRaw("GET", `/api/documents/${encodeURIComponent(id)}/export`, { query: { format: "json" } }, context);
|
|
353
|
+
if (!response.ok)
|
|
354
|
+
throw await this.toApiError(response);
|
|
355
|
+
if (response.headers.get("content-type")?.includes("json"))
|
|
356
|
+
return response.json();
|
|
357
|
+
return { markdown: await response.text() };
|
|
358
|
+
}
|
|
146
359
|
async exportDoc(id, context) {
|
|
147
360
|
return this.getDocMarkdown(id, context);
|
|
148
361
|
}
|
|
@@ -226,6 +439,12 @@ class DocsClient {
|
|
|
226
439
|
async revokeApiKey(id, context) {
|
|
227
440
|
return this.request("DELETE", `/api/keys/${encodeURIComponent(id)}`, undefined, context);
|
|
228
441
|
}
|
|
442
|
+
async whoami(context) {
|
|
443
|
+
return this.request("GET", "/api/whoami", undefined, context);
|
|
444
|
+
}
|
|
445
|
+
async listWorkspaces(context) {
|
|
446
|
+
return this.request("GET", "/api/workspaces", undefined, context);
|
|
447
|
+
}
|
|
229
448
|
async search(query, options, context) {
|
|
230
449
|
return this.request("GET", "/api/search", {
|
|
231
450
|
query: this.cleanQuery({
|
|
@@ -241,7 +460,8 @@ class DocsClient {
|
|
|
241
460
|
graph: options?.graph,
|
|
242
461
|
graphHops: options?.graphHops,
|
|
243
462
|
graphBoost: options?.graphBoost,
|
|
244
|
-
includeChunks: options?.includeChunks
|
|
463
|
+
includeChunks: options?.includeChunks,
|
|
464
|
+
includeDiagnostics: options?.includeDiagnostics
|
|
245
465
|
})
|
|
246
466
|
}, context);
|
|
247
467
|
}
|
|
@@ -431,7 +651,8 @@ class DocsClient {
|
|
|
431
651
|
throw this.wrapNetworkError(lastError, requestContext?.requestId);
|
|
432
652
|
}
|
|
433
653
|
buildUrl(path, query) {
|
|
434
|
-
|
|
654
|
+
const resolvedPath = path.startsWith("/api/") ? `${this.config.apiPrefix}${path.slice(4)}` : path;
|
|
655
|
+
let url = `${this.config.baseUrl}${resolvedPath}`;
|
|
435
656
|
if (query && Object.keys(query).length > 0) {
|
|
436
657
|
const params = new URLSearchParams;
|
|
437
658
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -725,6 +946,12 @@ var folderSchema = z.looseObject({
|
|
|
725
946
|
documents: z.array(documentListItemSchema).optional()
|
|
726
947
|
});
|
|
727
948
|
var exportedDocumentSchema = z.looseObject({
|
|
949
|
+
id: z.string().optional(),
|
|
950
|
+
title: z.string().optional(),
|
|
951
|
+
updatedAt: z.string().optional(),
|
|
952
|
+
workspaceId: z.string().nullable().optional(),
|
|
953
|
+
workspaceSlug: z.string().nullable().optional(),
|
|
954
|
+
url: z.string().nullable().optional(),
|
|
728
955
|
markdown: z.string(),
|
|
729
956
|
filename: z.string().optional()
|
|
730
957
|
});
|
|
@@ -950,7 +1177,9 @@ function createMcpDocsClient(docsClient, requestContext) {
|
|
|
950
1177
|
search: (params) => docsClient.search(params.query, {
|
|
951
1178
|
folder: params.folder,
|
|
952
1179
|
tags: params.tags?.join(","),
|
|
953
|
-
limit: params.limit
|
|
1180
|
+
limit: params.limit,
|
|
1181
|
+
includeChunks: params.includeChunks,
|
|
1182
|
+
includeDiagnostics: params.includeDiagnostics
|
|
954
1183
|
}, context),
|
|
955
1184
|
getDocument: (id) => docsClient.getDoc(id, context),
|
|
956
1185
|
createDocument: (input) => docsClient.createDoc({
|
|
@@ -971,7 +1200,7 @@ function createMcpDocsClient(docsClient, requestContext) {
|
|
|
971
1200
|
refreshDocumentIndex: (documentId) => docsClient.refreshDocumentIndex(documentId, context),
|
|
972
1201
|
createSnapshot: (documentId, input) => docsClient.createSnapshot(documentId, input, context),
|
|
973
1202
|
getVersionHistory: (documentId, onlySnapshots) => docsClient.listVersions(documentId, { onlySnapshots }, context),
|
|
974
|
-
exportDocument:
|
|
1203
|
+
exportDocument: (id) => docsClient.exportDocWithMetadata(id, context)
|
|
975
1204
|
};
|
|
976
1205
|
}
|
|
977
1206
|
function createDefaultDocsClient() {
|
|
@@ -988,6 +1217,31 @@ var client = new Proxy({}, {
|
|
|
988
1217
|
|
|
989
1218
|
// ../mcp-server/src/client-routing-schema.ts
|
|
990
1219
|
import { z as z2 } from "zod";
|
|
1220
|
+
function canonical(value) {
|
|
1221
|
+
if (Array.isArray(value))
|
|
1222
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
1223
|
+
if (value && typeof value === "object")
|
|
1224
|
+
return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${JSON.stringify(key)}:${canonical(item)}`).join(",")}}`;
|
|
1225
|
+
return JSON.stringify(value) ?? "null";
|
|
1226
|
+
}
|
|
1227
|
+
function mergePropertyVariants(values) {
|
|
1228
|
+
const unique = [
|
|
1229
|
+
...new Map(values.map((value) => [canonical(value), value])).values()
|
|
1230
|
+
];
|
|
1231
|
+
if (unique.length === 1)
|
|
1232
|
+
return unique[0];
|
|
1233
|
+
const literalObjects = unique.filter((value) => value && typeof value === "object" && ("const" in value));
|
|
1234
|
+
if (literalObjects.length === unique.length) {
|
|
1235
|
+
const withoutConst = literalObjects.map(({ const: _literal, ...rest }) => rest);
|
|
1236
|
+
if (withoutConst.every((value) => canonical(value) === canonical(withoutConst[0]))) {
|
|
1237
|
+
return {
|
|
1238
|
+
...withoutConst[0],
|
|
1239
|
+
enum: literalObjects.map((value) => value.const)
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return { anyOf: unique };
|
|
1244
|
+
}
|
|
991
1245
|
function hoistObjectUnionClosure(schema) {
|
|
992
1246
|
const variants = schema.oneOf;
|
|
993
1247
|
if (!Array.isArray(variants) || !variants.every((variant2) => typeof variant2 === "object" && variant2 !== null && variant2.type === "object" && variant2.additionalProperties === false && typeof variant2.properties === "object" && variant2.properties !== null))
|
|
@@ -1005,7 +1259,7 @@ function hoistObjectUnionClosure(schema) {
|
|
|
1005
1259
|
type: "object",
|
|
1006
1260
|
properties: Object.fromEntries([...propertyVariants].map(([key, values]) => [
|
|
1007
1261
|
key,
|
|
1008
|
-
values
|
|
1262
|
+
mergePropertyVariants(values)
|
|
1009
1263
|
])),
|
|
1010
1264
|
additionalProperties: false,
|
|
1011
1265
|
oneOf: variants.map((variant2) => {
|
|
@@ -1033,11 +1287,21 @@ function withClientRoutingSchema(schema) {
|
|
|
1033
1287
|
const { workspaceId, ...args } = value;
|
|
1034
1288
|
const selected = selector.safeParse(workspaceId);
|
|
1035
1289
|
if (!selected.success)
|
|
1036
|
-
return {
|
|
1290
|
+
return {
|
|
1291
|
+
issues: selected.error.issues.map((issue) => ({
|
|
1292
|
+
...issue,
|
|
1293
|
+
path: ["workspaceId", ...issue.path]
|
|
1294
|
+
}))
|
|
1295
|
+
};
|
|
1037
1296
|
const validated = await standard.validate(args, options);
|
|
1038
1297
|
if (validated.issues)
|
|
1039
1298
|
return validated;
|
|
1040
|
-
return {
|
|
1299
|
+
return {
|
|
1300
|
+
value: {
|
|
1301
|
+
...validated.value,
|
|
1302
|
+
...selected.data ? { workspaceId: selected.data } : {}
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1041
1305
|
},
|
|
1042
1306
|
jsonSchema: {
|
|
1043
1307
|
...standard.jsonSchema,
|
|
@@ -1046,11 +1310,17 @@ function withClientRoutingSchema(schema) {
|
|
|
1046
1310
|
const routingProperty = z2.toJSONSchema(selector);
|
|
1047
1311
|
return {
|
|
1048
1312
|
...published,
|
|
1049
|
-
properties: {
|
|
1313
|
+
properties: {
|
|
1314
|
+
...published.properties,
|
|
1315
|
+
workspaceId: routingProperty
|
|
1316
|
+
},
|
|
1050
1317
|
...Array.isArray(published.oneOf) ? {
|
|
1051
1318
|
oneOf: published.oneOf.map((branch) => ({
|
|
1052
1319
|
...branch,
|
|
1053
|
-
properties: {
|
|
1320
|
+
properties: {
|
|
1321
|
+
...branch.properties,
|
|
1322
|
+
workspaceId: routingProperty
|
|
1323
|
+
}
|
|
1054
1324
|
}))
|
|
1055
1325
|
} : {}
|
|
1056
1326
|
};
|
|
@@ -1126,13 +1396,13 @@ function registerBatchAndWorkspaceCapabilities(server, client2, wrap) {
|
|
|
1126
1396
|
}
|
|
1127
1397
|
server.registerTool("batch_documents", {
|
|
1128
1398
|
description: "Use for multiple explicitly selected documents that need the same action; for one document prefer the matching single-document tool. Accepts 1\u201325 IDs for automation compatibility. Supports move, set_category, add_tag, remove_tag, trash, restore, or refresh_index. Processes sequentially through the existing API with a permission check per document and a per-ID result; partial success is possible. Stops after authentication or rate-limit failure. Never expands a search result or permanently purges documents; version restore is separate.",
|
|
1129
|
-
inputSchema: withClientRoutingSchema(batchInput),
|
|
1399
|
+
inputSchema: captureMcpInputSchema(server, "batch_documents", withClientRoutingSchema(batchInput)),
|
|
1130
1400
|
outputSchema: toolOutputSchemas.batch_documents,
|
|
1131
1401
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
1132
1402
|
}, wrap("batch_documents", batch, toolOutputSchemas.batch_documents));
|
|
1133
1403
|
server.registerTool("get_workspace_item", {
|
|
1134
1404
|
description: "Read one visible folder, category, or tag by UUID. Folder uses its direct API getter; category and tag lookup uses the complete permission-filtered lists. An absent or out-of-scope ID is reported as not found. Use list_workspace_structure to discover IDs first.",
|
|
1135
|
-
inputSchema: withClientRoutingSchema(z3.strictObject({ kind: z3.enum(["folder", "category", "tag"]).describe("The workspace resource type to read by ID."), id: uuid })),
|
|
1405
|
+
inputSchema: captureMcpInputSchema(server, "get_workspace_item", withClientRoutingSchema(z3.strictObject({ kind: z3.enum(["folder", "category", "tag"]).describe("The workspace resource type to read by ID."), id: uuid }))),
|
|
1136
1406
|
outputSchema: toolOutputSchemas.get_workspace_item,
|
|
1137
1407
|
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1138
1408
|
}, wrap("get_workspace_item", async ({ kind, id }) => {
|
|
@@ -1161,11 +1431,11 @@ function required2(value, name) {
|
|
|
1161
1431
|
}
|
|
1162
1432
|
function registerCompactCapabilities(server, client2, wrap) {
|
|
1163
1433
|
function register(name, description, inputSchema, annotations, handler) {
|
|
1164
|
-
server.registerTool(name, { description, inputSchema: withClientRoutingSchema(inputSchema), outputSchema: toolOutputSchemas[name], annotations }, wrap(name, handler, toolOutputSchemas[name]));
|
|
1434
|
+
server.registerTool(name, { description, inputSchema: captureMcpInputSchema(server, name, withClientRoutingSchema(inputSchema)), outputSchema: toolOutputSchemas[name], annotations }, wrap(name, handler, toolOutputSchemas[name]));
|
|
1165
1435
|
}
|
|
1166
1436
|
register("find_documents", "Find readable documents in the active scope. Use mode=list for paginated browsing by folder or tag UUID; use mode=search for hybrid text and semantic retrieval with tag names.", z4.discriminatedUnion("mode", [
|
|
1167
|
-
z4.strictObject({ mode: z4.literal("list").describe("Select the list operation explicitly."), folderId: uuid2.optional(), tag: uuid2.optional(), page: z4.number().int().min(1).optional().describe("One-based page number; defaults to the API first page."), limit: z4.number().int().min(1).max(1000).optional().describe("Maximum documents per page, up to 1000.") }),
|
|
1168
|
-
z4.strictObject({ mode: z4.literal("search").describe("Select the search operation explicitly."), query: text.describe("Text to search in the original language."), folder: z4.string().optional().describe("Optional folder UUID filter for search."), tags: z4.array(z4.string()).optional().describe("Optional tag names; all supplied names must match."), limit: z4.number().int().min(1).max(100).optional().describe("Maximum results to return, up to 100.") })
|
|
1437
|
+
z4.strictObject({ mode: z4.literal("list").describe("Select the list operation explicitly."), folderId: uuid2.optional(), categoryId: uuid2.optional().describe("Filter by effective category UUID, including inherited folder placement."), visibility: z4.enum(["private", "shared", "public"]).optional().describe("Optional document visibility filter; never expands access."), rootOnly: z4.boolean().optional().describe("Return only documents without a folder; cannot combine with folderId."), tag: uuid2.optional(), tagIds: z4.array(uuid2).min(1).optional().describe("Filter by tag UUIDs; cannot combine with the legacy tag field."), tagMatch: z4.enum(["all", "any"]).optional().describe("Require all supplied tags by default, or any supplied tag."), q: z4.string().optional().describe("Literal case-insensitive title/content filter; does not invoke semantic search."), updatedFrom: z4.iso.datetime({ offset: true }).optional().describe("Inclusive updated timestamp lower bound, with timezone."), updatedTo: z4.iso.datetime({ offset: true }).optional().describe("Exclusive updated timestamp upper bound, with timezone."), sortBy: z4.enum(["updatedAt", "createdAt", "title"]).optional().describe("Stable server-side sort field; defaults to updatedAt."), sortOrder: z4.enum(["asc", "desc"]).optional().describe("Sort direction, descending by default with an ID tie-breaker."), page: z4.number().int().min(1).optional().describe("One-based page number; defaults to the API first page."), limit: z4.number().int().min(1).max(1000).optional().describe("Maximum documents per page, up to 1000.") }),
|
|
1438
|
+
z4.strictObject({ mode: z4.literal("search").describe("Select the search operation explicitly."), query: text.describe("Text to search in the original language."), includeDiagnostics: z4.boolean().optional().describe("Include redacted diagnostic details; omitted by default."), includeChunks: z4.boolean().optional().describe("Include matching text chunks only when requested."), folder: z4.string().optional().describe("Optional folder UUID filter for search."), tags: z4.array(z4.string()).optional().describe("Optional tag names; all supplied names must match."), limit: z4.number().int().min(1).max(100).optional().describe("Maximum results to return, up to 100.") })
|
|
1169
1439
|
]), read, async (input) => input.mode === "list" ? { operation: "list", result: await client2.listDocuments(input) } : { operation: "search", result: await client2.search(input) });
|
|
1170
1440
|
register("read_document", "Read one document by UUID. Choose detail for content and metadata, markdown for portable export, or versions for saved revisions and snapshots. All views are read-only.", z4.discriminatedUnion("view", [
|
|
1171
1441
|
z4.strictObject({ view: z4.literal("detail").describe("Select the detail operation explicitly."), id: uuid2 }),
|
|
@@ -1349,9 +1619,15 @@ Use find_documents(mode=search) for normal retrieval. Use explore_graph only wit
|
|
|
1349
1619
|
};
|
|
1350
1620
|
});
|
|
1351
1621
|
}
|
|
1622
|
+
// ../mcp-server/src/catalog.ts
|
|
1623
|
+
import {
|
|
1624
|
+
InMemoryTransport
|
|
1625
|
+
} from "@modelcontextprotocol/server";
|
|
1626
|
+
// ../mcp-server/src/http.ts
|
|
1627
|
+
import { createMcpHandler } from "@modelcontextprotocol/server";
|
|
1352
1628
|
|
|
1353
1629
|
// ../mcp-server/src/server.ts
|
|
1354
|
-
function wrapHandler(name, handler, outputSchema, workspaceRouting) {
|
|
1630
|
+
function wrapHandler(name, handler, outputSchema, workspaceRouting, decorateResult) {
|
|
1355
1631
|
return async (args) => {
|
|
1356
1632
|
try {
|
|
1357
1633
|
const { workspaceId, ...data } = args;
|
|
@@ -1369,12 +1645,15 @@ function wrapHandler(name, handler, outputSchema, workspaceRouting) {
|
|
|
1369
1645
|
} else {
|
|
1370
1646
|
output = await handler(data);
|
|
1371
1647
|
}
|
|
1648
|
+
if (decorateResult)
|
|
1649
|
+
output = await decorateResult(name, output);
|
|
1372
1650
|
const parsedOutput = outputSchema ? await outputSchema.safeParseAsync(output) : undefined;
|
|
1373
1651
|
if (parsedOutput && !parsedOutput.success) {
|
|
1374
1652
|
throw new Error(`Tool '${name}' returned a result outside its published output schema`);
|
|
1375
1653
|
}
|
|
1654
|
+
const result = parsedOutput?.success ? parsedOutput.data : output;
|
|
1376
1655
|
return {
|
|
1377
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
1656
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
1378
1657
|
...parsedOutput?.success ? { structuredContent: parsedOutput.data } : {}
|
|
1379
1658
|
};
|
|
1380
1659
|
} catch (error) {
|
|
@@ -1402,15 +1681,15 @@ function wrapHandler(name, handler, outputSchema, workspaceRouting) {
|
|
|
1402
1681
|
}
|
|
1403
1682
|
};
|
|
1404
1683
|
}
|
|
1405
|
-
function registerDocsmintMcpCapabilities(server, client2, workspaceRouting) {
|
|
1406
|
-
const wrap = (name, handler, outputSchema) => wrapHandler(name, handler, outputSchema, workspaceRouting);
|
|
1684
|
+
function registerDocsmintMcpCapabilities(server, client2, workspaceRouting, decorateResult) {
|
|
1685
|
+
const wrap = (name, handler, outputSchema) => wrapHandler(name, handler, outputSchema, workspaceRouting, decorateResult);
|
|
1407
1686
|
registerCompactCapabilities(server, client2, wrap);
|
|
1408
1687
|
registerPromptsAndResources(server, client2);
|
|
1409
1688
|
}
|
|
1410
1689
|
function createDocsmintMcpServer(options = {}) {
|
|
1411
|
-
const server = new
|
|
1690
|
+
const server = new DocsMintMcpServer({ name: "docsmint", version: "2.1.0" });
|
|
1412
1691
|
const client2 = options.docsClient ? createMcpDocsClient(options.docsClient, options.requestContext) : options.client ?? createMcpDocsClient(createDefaultDocsClient(), options.requestContext);
|
|
1413
|
-
registerDocsmintMcpCapabilities(server, client2, options.workspaceRouting);
|
|
1692
|
+
registerDocsmintMcpCapabilities(server, client2, options.workspaceRouting, options.decorateResult);
|
|
1414
1693
|
return server;
|
|
1415
1694
|
}
|
|
1416
1695
|
|