@hiai-gg/docsmint 0.10.0 → 1.0.2
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 +11 -11
- package/dist/backend/index.js +1 -1
- package/dist/mcp-cli.js +279 -171
- package/dist/mcp-server.js +282 -172
- package/package.json +1 -1
- package/packages/cli/src/index.ts +1 -1
- package/server.json +3 -3
package/dist/mcp-cli.js
CHANGED
|
@@ -576,7 +576,7 @@ var RESOURCE_PERMISSIONS = new Set([
|
|
|
576
576
|
"write"
|
|
577
577
|
]);
|
|
578
578
|
// ../mcp-server/src/compact.ts
|
|
579
|
-
import { z as
|
|
579
|
+
import { z as z3 } from "zod";
|
|
580
580
|
|
|
581
581
|
// ../mcp-server/src/output-schemas.ts
|
|
582
582
|
import { z } from "zod";
|
|
@@ -855,140 +855,339 @@ var toolOutputSchemas = {
|
|
|
855
855
|
explore_graph: z.union([
|
|
856
856
|
variant("neighbors", operationOutputSchemas.get_related_documents),
|
|
857
857
|
variant("search", operationOutputSchemas.search_knowledge_graph)
|
|
858
|
+
]),
|
|
859
|
+
batch_documents: z.looseObject({
|
|
860
|
+
action: z.enum(["move", "set_category", "add_tag", "remove_tag", "trash", "restore", "refresh_index"]),
|
|
861
|
+
total: z.number().int().min(1).max(25),
|
|
862
|
+
succeeded: z.number().int().nonnegative(),
|
|
863
|
+
failed: z.number().int().nonnegative(),
|
|
864
|
+
aborted: z.boolean(),
|
|
865
|
+
results: z.array(z.union([
|
|
866
|
+
z.looseObject({ id: z.string().uuid(), status: z.literal("ok") }),
|
|
867
|
+
z.looseObject({ id: z.string().uuid(), status: z.literal("error"), error: z.looseObject({ status: z.number().int(), code: z.string(), message: z.string() }) }),
|
|
868
|
+
z.looseObject({ id: z.string().uuid(), status: z.literal("skipped") })
|
|
869
|
+
]))
|
|
870
|
+
}),
|
|
871
|
+
get_workspace_item: z.union([
|
|
872
|
+
variant("folder", folderSchema),
|
|
873
|
+
variant("category", categoryListItemSchema),
|
|
874
|
+
variant("tag", tagSchema)
|
|
858
875
|
])
|
|
859
876
|
};
|
|
860
877
|
|
|
878
|
+
// ../mcp-server/src/batch-workspace.ts
|
|
879
|
+
import { z as z2 } from "zod";
|
|
880
|
+
|
|
881
|
+
// ../mcp-server/src/client.ts
|
|
882
|
+
var DEFAULT_BASE_URL = "http://localhost:50700";
|
|
883
|
+
function readConfig() {
|
|
884
|
+
const baseUrl = (process.env.HIAI_DOCS_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
885
|
+
const apiKey = process.env.HIAI_DOCS_API_KEY;
|
|
886
|
+
return { baseUrl, apiKey: apiKey || undefined };
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
class HiaiDocsError extends Error {
|
|
890
|
+
status;
|
|
891
|
+
body;
|
|
892
|
+
code;
|
|
893
|
+
constructor(message, status, body, code = `http_${status}`) {
|
|
894
|
+
super(message);
|
|
895
|
+
this.status = status;
|
|
896
|
+
this.body = body;
|
|
897
|
+
this.code = code;
|
|
898
|
+
this.name = "HiaiDocsError";
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function sanitizeMcpRequestContext(context) {
|
|
902
|
+
if (!context)
|
|
903
|
+
return;
|
|
904
|
+
const headers = new Headers(context.headers);
|
|
905
|
+
if (context.workspaceAssertion) {
|
|
906
|
+
headers.delete("Authorization");
|
|
907
|
+
headers.delete("Cookie");
|
|
908
|
+
}
|
|
909
|
+
return {
|
|
910
|
+
...context,
|
|
911
|
+
authorization: context.workspaceAssertion ? undefined : context.authorization,
|
|
912
|
+
cookie: context.workspaceAssertion ? undefined : context.cookie,
|
|
913
|
+
headers
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
function createMcpDocsClient(docsClient, requestContext) {
|
|
917
|
+
const context = sanitizeMcpRequestContext(requestContext);
|
|
918
|
+
return {
|
|
919
|
+
getFolder: (id) => docsClient.getFolder(id, context),
|
|
920
|
+
createTag: (input) => docsClient.createTag(input, context),
|
|
921
|
+
updateTag: (id, input) => docsClient.updateTag(id, input, context),
|
|
922
|
+
deleteTag: (id) => docsClient.deleteTag(id, context),
|
|
923
|
+
addTagToDocument: (documentId, tagId) => docsClient.addTagToDoc(documentId, tagId, context),
|
|
924
|
+
removeTagFromDocument: (documentId, tagId) => docsClient.removeTagFromDoc(documentId, tagId, context),
|
|
925
|
+
updateFolder: (id, input) => docsClient.updateFolder(id, input, context),
|
|
926
|
+
updateCategory: (id, input) => docsClient.updateCategory(id, input, context),
|
|
927
|
+
listTrash: () => docsClient.listTrash(context),
|
|
928
|
+
restoreTrashedDocument: (id) => docsClient.restoreTrashedDocument(id, context),
|
|
929
|
+
permanentlyDeleteDocument: (id) => docsClient.permanentlyDeleteDocument(id, context),
|
|
930
|
+
deleteDocument: (id) => docsClient.deleteDoc(id, context),
|
|
931
|
+
deleteFolder: (id) => docsClient.deleteFolder(id, context),
|
|
932
|
+
deleteCategory: (id) => docsClient.deleteCategory(id, context),
|
|
933
|
+
restoreDocumentVersion: (documentId, versionId) => docsClient.restoreVersion(documentId, versionId, context),
|
|
934
|
+
search: (params) => docsClient.search(params.query, {
|
|
935
|
+
folder: params.folder,
|
|
936
|
+
tags: params.tags?.join(","),
|
|
937
|
+
limit: params.limit
|
|
938
|
+
}, context),
|
|
939
|
+
getDocument: (id) => docsClient.getDoc(id, context),
|
|
940
|
+
createDocument: (input) => docsClient.createDoc({
|
|
941
|
+
...input,
|
|
942
|
+
folderId: input.folderId ?? undefined,
|
|
943
|
+
categoryId: input.categoryId ?? undefined
|
|
944
|
+
}, context),
|
|
945
|
+
updateDocument: (id, input) => docsClient.updateDoc(id, input, context),
|
|
946
|
+
listDocuments: (params) => docsClient.listDocs(params, context),
|
|
947
|
+
listFolders: (params) => docsClient.listFolders(params.parentId, context),
|
|
948
|
+
createFolder: (input) => docsClient.createFolder(input, context),
|
|
949
|
+
listCategories: () => docsClient.listCategories(context),
|
|
950
|
+
createCategory: (input) => docsClient.createCategory(input, context),
|
|
951
|
+
listTags: () => docsClient.listTags(context),
|
|
952
|
+
getRelatedDocuments: (documentId, limit) => docsClient.getRelatedDocuments(documentId, context, { limit }),
|
|
953
|
+
searchGraph: (input) => docsClient.searchGraph({ query: input.query, docIds: input.docIds, maxResults: input.limit }, context),
|
|
954
|
+
getDocumentIndexStatus: (documentId) => docsClient.getDocumentIndexStatus(documentId, context),
|
|
955
|
+
refreshDocumentIndex: (documentId) => docsClient.refreshDocumentIndex(documentId, context),
|
|
956
|
+
createSnapshot: (documentId, input) => docsClient.createSnapshot(documentId, input, context),
|
|
957
|
+
getVersionHistory: (documentId, onlySnapshots) => docsClient.listVersions(documentId, { onlySnapshots }, context),
|
|
958
|
+
exportDocument: async (id) => ({ markdown: await docsClient.exportDoc(id, context) })
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
function createDefaultDocsClient() {
|
|
962
|
+
const { baseUrl, apiKey } = readConfig();
|
|
963
|
+
return new DocsClient({ baseUrl, apiKey, retries: 1 });
|
|
964
|
+
}
|
|
965
|
+
var client = new Proxy({}, {
|
|
966
|
+
get(_target, property) {
|
|
967
|
+
const configured = createMcpDocsClient(createDefaultDocsClient());
|
|
968
|
+
const value = configured[property];
|
|
969
|
+
return typeof value === "function" ? value.bind(configured) : value;
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
// ../mcp-server/src/batch-workspace.ts
|
|
974
|
+
var uuid = z2.string().uuid().describe("UUID of an item visible to the active API key.");
|
|
975
|
+
var documentIds = z2.array(uuid).min(1).max(25).refine((ids) => new Set(ids).size === ids.length, "Document IDs must be unique.").describe("One to 25 distinct document UUIDs, explicitly selected by the user; no search expansion.");
|
|
976
|
+
var base = { documentIds };
|
|
977
|
+
var batchInput = z2.discriminatedUnion("action", [
|
|
978
|
+
z2.strictObject({ ...base, action: z2.literal("move").describe("Move each document to the same folder."), folderId: uuid.nullable().describe("Destination folder UUID, or null for no folder.") }),
|
|
979
|
+
z2.strictObject({ ...base, action: z2.literal("set_category").describe("Set one explicit category on every document."), categoryId: uuid.nullable().describe("Category UUID, or null to clear explicit category.") }),
|
|
980
|
+
z2.strictObject({ ...base, action: z2.literal("add_tag").describe("Assign one existing tag to every document."), tagId: uuid.describe("Existing tag UUID to assign to each document.") }),
|
|
981
|
+
z2.strictObject({ ...base, action: z2.literal("remove_tag").describe("Remove one tag assignment from every document."), tagId: uuid.describe("Existing tag UUID to unassign from each document.") }),
|
|
982
|
+
z2.strictObject({ ...base, action: z2.literal("trash").describe("Move every document to trash without permanent deletion.") }),
|
|
983
|
+
z2.strictObject({ ...base, action: z2.literal("restore").describe("Restore every selected document from trash.") }),
|
|
984
|
+
z2.strictObject({ ...base, action: z2.literal("refresh_index").describe("Request explicit indexing retry for every document.") })
|
|
985
|
+
]);
|
|
986
|
+
function required(method, name) {
|
|
987
|
+
if (!method)
|
|
988
|
+
throw new Error(`The injected legacy MCP client does not support ${name}; use a public DocsClient.`);
|
|
989
|
+
return method;
|
|
990
|
+
}
|
|
991
|
+
function registerBatchAndWorkspaceCapabilities(server, client2, wrap) {
|
|
992
|
+
async function batch(input) {
|
|
993
|
+
const results = [];
|
|
994
|
+
let aborted = false;
|
|
995
|
+
for (const id of input.documentIds) {
|
|
996
|
+
if (aborted) {
|
|
997
|
+
results.push({ id, status: "skipped" });
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
try {
|
|
1001
|
+
switch (input.action) {
|
|
1002
|
+
case "move":
|
|
1003
|
+
await client2.updateDocument(id, { folderId: input.folderId });
|
|
1004
|
+
break;
|
|
1005
|
+
case "set_category":
|
|
1006
|
+
await client2.updateDocument(id, { categoryId: input.categoryId });
|
|
1007
|
+
break;
|
|
1008
|
+
case "add_tag":
|
|
1009
|
+
await required(client2.addTagToDocument, "add_tag")(id, input.tagId);
|
|
1010
|
+
break;
|
|
1011
|
+
case "remove_tag":
|
|
1012
|
+
await required(client2.removeTagFromDocument, "remove_tag")(id, input.tagId);
|
|
1013
|
+
break;
|
|
1014
|
+
case "trash":
|
|
1015
|
+
await required(client2.deleteDocument, "trash")(id);
|
|
1016
|
+
break;
|
|
1017
|
+
case "restore":
|
|
1018
|
+
await required(client2.restoreTrashedDocument, "restore")(id);
|
|
1019
|
+
break;
|
|
1020
|
+
case "refresh_index":
|
|
1021
|
+
await client2.refreshDocumentIndex(id);
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
results.push({ id, status: "ok" });
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
const known = isDocsApiError(error) || error instanceof HiaiDocsError;
|
|
1027
|
+
const status = known ? error.status : 500;
|
|
1028
|
+
const code = known ? error.code : "INTERNAL_ERROR";
|
|
1029
|
+
results.push({ id, status: "error", error: { status, code, message: known ? error.message : "Document operation failed" } });
|
|
1030
|
+
if (status === 401 || status === 429)
|
|
1031
|
+
aborted = true;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
const succeeded = results.filter((result) => result.status === "ok").length;
|
|
1035
|
+
return { action: input.action, total: input.documentIds.length, succeeded, failed: results.filter((result) => result.status === "error").length, aborted, results };
|
|
1036
|
+
}
|
|
1037
|
+
server.registerTool("batch_documents", {
|
|
1038
|
+
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.",
|
|
1039
|
+
inputSchema: batchInput,
|
|
1040
|
+
outputSchema: toolOutputSchemas.batch_documents,
|
|
1041
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
1042
|
+
}, wrap("batch_documents", batch, toolOutputSchemas.batch_documents));
|
|
1043
|
+
server.registerTool("get_workspace_item", {
|
|
1044
|
+
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.",
|
|
1045
|
+
inputSchema: z2.strictObject({ kind: z2.enum(["folder", "category", "tag"]).describe("The workspace resource type to read by ID."), id: uuid }),
|
|
1046
|
+
outputSchema: toolOutputSchemas.get_workspace_item,
|
|
1047
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1048
|
+
}, wrap("get_workspace_item", async ({ kind, id }) => {
|
|
1049
|
+
if (kind === "folder")
|
|
1050
|
+
return { operation: kind, result: await required(client2.getFolder, "get_workspace_item(folder)")(id) };
|
|
1051
|
+
const listed = kind === "category" ? await client2.listCategories() : await client2.listTags();
|
|
1052
|
+
const result = Array.isArray(listed) ? listed.find((item) => item.id === id) : undefined;
|
|
1053
|
+
if (!result)
|
|
1054
|
+
throw new HiaiDocsError(`${kind} not found`, 404, null, "NOT_FOUND");
|
|
1055
|
+
return { operation: kind, result };
|
|
1056
|
+
}, toolOutputSchemas.get_workspace_item));
|
|
1057
|
+
}
|
|
1058
|
+
|
|
861
1059
|
// ../mcp-server/src/compact.ts
|
|
862
|
-
var
|
|
863
|
-
var text =
|
|
864
|
-
var title =
|
|
865
|
-
var content =
|
|
1060
|
+
var uuid2 = z3.string().uuid().describe("UUID returned by the corresponding list or read operation.");
|
|
1061
|
+
var text = z3.string().min(1).describe("Non-empty human-readable name or title.");
|
|
1062
|
+
var title = z3.string().min(1).max(500).describe("Document title, from 1 to 500 characters.");
|
|
1063
|
+
var content = z3.string().describe("Markdown document content; an empty string clears the content on update.");
|
|
866
1064
|
var read = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
867
1065
|
var write = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
|
|
868
1066
|
var destructive = { ...write, destructiveHint: true };
|
|
869
|
-
function
|
|
1067
|
+
function required2(value, name) {
|
|
870
1068
|
if (!value)
|
|
871
1069
|
throw new Error(`The injected legacy MCP client does not support ${name}; use a public DocsClient.`);
|
|
872
1070
|
return value;
|
|
873
1071
|
}
|
|
874
|
-
function registerCompactCapabilities(server,
|
|
1072
|
+
function registerCompactCapabilities(server, client2, wrap) {
|
|
875
1073
|
function register(name, description, inputSchema, annotations, handler) {
|
|
876
1074
|
server.registerTool(name, { description, inputSchema, outputSchema: toolOutputSchemas[name], annotations }, wrap(name, handler, toolOutputSchemas[name]));
|
|
877
1075
|
}
|
|
878
|
-
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.",
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
]), read, async (input) => input.mode === "list" ? { operation: "list", result: await
|
|
882
|
-
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.",
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1076
|
+
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.", z3.discriminatedUnion("mode", [
|
|
1077
|
+
z3.strictObject({ mode: z3.literal("list").describe("Select the list operation explicitly."), folderId: uuid2.optional(), tag: uuid2.optional(), page: z3.number().int().min(1).optional().describe("One-based page number; defaults to the API first page."), limit: z3.number().int().min(1).max(1000).optional().describe("Maximum documents per page, up to 1000.") }),
|
|
1078
|
+
z3.strictObject({ mode: z3.literal("search").describe("Select the search operation explicitly."), query: text.describe("Text to search in the original language."), folder: z3.string().optional().describe("Optional folder UUID filter for search."), tags: z3.array(z3.string()).optional().describe("Optional tag names; all supplied names must match."), limit: z3.number().int().min(1).max(100).optional().describe("Maximum results to return, up to 100.") })
|
|
1079
|
+
]), read, async (input) => input.mode === "list" ? { operation: "list", result: await client2.listDocuments(input) } : { operation: "search", result: await client2.search(input) });
|
|
1080
|
+
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.", z3.discriminatedUnion("view", [
|
|
1081
|
+
z3.strictObject({ view: z3.literal("detail").describe("Select the detail operation explicitly."), id: uuid2 }),
|
|
1082
|
+
z3.strictObject({ view: z3.literal("markdown").describe("Select the markdown operation explicitly."), id: uuid2 }),
|
|
1083
|
+
z3.strictObject({ view: z3.literal("versions").describe("Select the versions operation explicitly."), id: uuid2, onlySnapshots: z3.boolean().optional().describe("When true, return only named snapshots.") })
|
|
886
1084
|
]), read, async (input) => {
|
|
887
1085
|
if (input.view === "detail")
|
|
888
|
-
return { operation: "detail", result: await
|
|
1086
|
+
return { operation: "detail", result: await client2.getDocument(input.id) };
|
|
889
1087
|
if (input.view === "markdown")
|
|
890
|
-
return { operation: "markdown", result: await
|
|
891
|
-
return { operation: "versions", result: await
|
|
1088
|
+
return { operation: "markdown", result: await client2.exportDocument(input.id) };
|
|
1089
|
+
return { operation: "versions", result: await client2.getVersionHistory(input.id, input.onlySnapshots) };
|
|
892
1090
|
});
|
|
893
|
-
register("save_document", "Create a new document or update an existing
|
|
894
|
-
|
|
895
|
-
|
|
1091
|
+
register("save_document", "Create or update one document. Use action=create for a new document or action=update for an existing one; batch_documents handles the same placement change across multiple existing documents. Creation requires write access; content edits require edit access, and placement changes may require write access. Content or placement changes queue normal indexing.", z3.discriminatedUnion("action", [
|
|
1092
|
+
z3.strictObject({ action: z3.literal("create").describe("Select the create operation explicitly."), title: title.optional(), content: content.optional(), folderId: uuid2.optional(), categoryId: uuid2.nullable().optional().describe("Optional category UUID; null clears the explicit category.") }),
|
|
1093
|
+
z3.strictObject({ action: z3.literal("update").describe("Select the update operation explicitly."), id: uuid2, title: title.optional(), content: content.optional(), folderId: uuid2.nullable().optional().describe("Optional folder UUID; null clears the placement on update."), categoryId: uuid2.nullable().optional().describe("Optional category UUID; null clears the explicit category.") }).refine((value) => value.title !== undefined || value.content !== undefined || value.folderId !== undefined || value.categoryId !== undefined)
|
|
896
1094
|
]), destructive, async (input) => {
|
|
897
1095
|
if (input.action === "create") {
|
|
898
1096
|
const { action: _action2, ...data2 } = input;
|
|
899
|
-
return { operation: "create", result: await
|
|
1097
|
+
return { operation: "create", result: await client2.createDocument(data2) };
|
|
900
1098
|
}
|
|
901
1099
|
const { action: _action, id, ...data } = input;
|
|
902
|
-
return { operation: "update", result: await
|
|
1100
|
+
return { operation: "update", result: await client2.updateDocument(id, data) };
|
|
903
1101
|
});
|
|
904
|
-
register("delete_document", "Move
|
|
905
|
-
await
|
|
1102
|
+
register("delete_document", "Move one document to trash without purging content or versions. Use batch_documents(action=trash) for multiple explicit IDs. Requires write access and an explicit delete request; permanently_delete_document is a separate irreversible action.", z3.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
|
|
1103
|
+
await required2(client2.deleteDocument, "delete_document")(id);
|
|
906
1104
|
return { id, deleted: true };
|
|
907
1105
|
});
|
|
908
|
-
register("list_workspace_structure", "List visible folders, categories, or tags in the active workspace or category scope. Set kind=folders to inspect root folders or children of parentId.",
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1106
|
+
register("list_workspace_structure", "List visible folders, categories, or tags in the active workspace or category scope. Set kind=folders to inspect root folders or children of parentId.", z3.discriminatedUnion("kind", [
|
|
1107
|
+
z3.strictObject({ kind: z3.literal("folders").describe("Select the folders operation explicitly."), parentId: uuid2.optional() }),
|
|
1108
|
+
z3.strictObject({ kind: z3.literal("categories").describe("Select the categories operation explicitly.") }),
|
|
1109
|
+
z3.strictObject({ kind: z3.literal("tags").describe("Select the tags operation explicitly.") })
|
|
912
1110
|
]), read, async (input) => {
|
|
913
1111
|
if (input.kind === "folders")
|
|
914
|
-
return { operation: "folders", result: await
|
|
1112
|
+
return { operation: "folders", result: await client2.listFolders({ parentId: input.parentId }) };
|
|
915
1113
|
if (input.kind === "categories")
|
|
916
|
-
return { operation: "categories", result: await
|
|
917
|
-
return { operation: "tags", result: await
|
|
1114
|
+
return { operation: "categories", result: await client2.listCategories() };
|
|
1115
|
+
return { operation: "tags", result: await client2.listTags() };
|
|
918
1116
|
});
|
|
919
|
-
register("save_folder", "Create or update a folder. action=update can rename or move an existing folder; the API enforces category boundaries and queues affected documents for reindexing.",
|
|
920
|
-
|
|
921
|
-
|
|
1117
|
+
register("save_folder", "Create or update a folder. action=update can rename or move an existing folder; the API enforces category boundaries and queues affected documents for reindexing.", z3.discriminatedUnion("action", [
|
|
1118
|
+
z3.strictObject({ action: z3.literal("create").describe("Select the create operation explicitly."), name: text.max(255), parentId: uuid2.nullable().optional().describe("Optional parent folder UUID; null selects the root."), categoryId: uuid2.nullable().optional().describe("Optional category UUID; null clears the explicit category.") }),
|
|
1119
|
+
z3.strictObject({ action: z3.literal("update").describe("Select the update operation explicitly."), id: uuid2, name: text.max(255).optional(), parentId: uuid2.nullable().optional().describe("Optional parent folder UUID; null selects the root."), categoryId: uuid2.nullable().optional().describe("Optional category UUID; null clears the explicit category."), order: z3.number().int().nonnegative().optional().describe("New non-negative display order.") }).refine((value) => value.name !== undefined || value.parentId !== undefined || value.categoryId !== undefined || value.order !== undefined)
|
|
922
1120
|
]), destructive, async (input) => {
|
|
923
1121
|
if (input.action === "create") {
|
|
924
1122
|
const { action: _action2, ...data2 } = input;
|
|
925
|
-
return { operation: "create", result: await
|
|
1123
|
+
return { operation: "create", result: await client2.createFolder(data2) };
|
|
926
1124
|
}
|
|
927
1125
|
const { action: _action, id, ...data } = input;
|
|
928
|
-
return { operation: "update", result: await
|
|
1126
|
+
return { operation: "update", result: await required2(client2.updateFolder, "update_folder")(id, data) };
|
|
929
1127
|
});
|
|
930
|
-
register("delete_folder", "Delete a folder while preserving its documents; child folders and documents are detached under the API rules. Requires write access.",
|
|
931
|
-
await
|
|
1128
|
+
register("delete_folder", "Delete a folder while preserving its documents; child folders and documents are detached under the API rules. Requires write access.", z3.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
|
|
1129
|
+
await required2(client2.deleteFolder, "delete_folder")(id);
|
|
932
1130
|
return { id, deleted: true };
|
|
933
1131
|
});
|
|
934
|
-
register("save_category", "Create or update a workspace category. Full workspace write access is required; category-scoped credentials cannot manage categories.",
|
|
935
|
-
|
|
936
|
-
|
|
1132
|
+
register("save_category", "Create or update a workspace category. Full workspace write access is required; category-scoped credentials cannot manage categories.", z3.discriminatedUnion("action", [
|
|
1133
|
+
z3.strictObject({ action: z3.literal("create").describe("Select the create operation explicitly."), name: text.max(255) }),
|
|
1134
|
+
z3.strictObject({ action: z3.literal("update").describe("Select the update operation explicitly."), id: uuid2, name: text.max(255).optional(), order: z3.number().int().nonnegative().optional().describe("New non-negative display order.") }).refine((value) => value.name !== undefined || value.order !== undefined)
|
|
937
1135
|
]), destructive, async (input) => {
|
|
938
1136
|
if (input.action === "create")
|
|
939
|
-
return { operation: "create", result: await
|
|
1137
|
+
return { operation: "create", result: await client2.createCategory({ name: input.name }) };
|
|
940
1138
|
const { action: _action, id, ...data } = input;
|
|
941
|
-
return { operation: "update", result: await
|
|
1139
|
+
return { operation: "update", result: await required2(client2.updateCategory, "update_category")(id, data) };
|
|
942
1140
|
});
|
|
943
|
-
register("delete_category", "Delete a workspace category and detach its documents without deleting them. Requires full workspace write access; category-scoped credentials are denied.",
|
|
944
|
-
await
|
|
1141
|
+
register("delete_category", "Delete a workspace category and detach its documents without deleting them. Requires full workspace write access; category-scoped credentials are denied.", z3.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
|
|
1142
|
+
await required2(client2.deleteCategory, "delete_category")(id);
|
|
945
1143
|
return { id, deleted: true };
|
|
946
1144
|
});
|
|
947
|
-
register("save_tag", "Create or update a workspace tag. Full workspace write access is required; renaming or recoloring a tag causes affected documents to be reindexed.",
|
|
948
|
-
|
|
949
|
-
|
|
1145
|
+
register("save_tag", "Create or update a workspace tag. Full workspace write access is required; renaming or recoloring a tag causes affected documents to be reindexed.", z3.discriminatedUnion("action", [
|
|
1146
|
+
z3.strictObject({ action: z3.literal("create").describe("Select the create operation explicitly."), name: text.max(100), color: z3.string().max(20).optional().describe("Optional tag color, at most 20 characters.") }),
|
|
1147
|
+
z3.strictObject({ action: z3.literal("update").describe("Select the update operation explicitly."), id: uuid2, name: text.max(100).optional(), color: z3.string().max(20).optional().describe("Optional tag color, at most 20 characters.") }).refine((value) => value.name !== undefined || value.color !== undefined)
|
|
950
1148
|
]), destructive, async (input) => {
|
|
951
1149
|
if (input.action === "create")
|
|
952
|
-
return { operation: "create", result: await
|
|
1150
|
+
return { operation: "create", result: await required2(client2.createTag, "create_tag")({ name: input.name, color: input.color }) };
|
|
953
1151
|
const { action: _action, id, ...data } = input;
|
|
954
|
-
return { operation: "update", result: await
|
|
1152
|
+
return { operation: "update", result: await required2(client2.updateTag, "update_tag")(id, data) };
|
|
955
1153
|
});
|
|
956
|
-
register("delete_tag", "Delete a workspace tag and remove its document assignments. Full workspace write access is required; documents themselves remain.",
|
|
957
|
-
await
|
|
1154
|
+
register("delete_tag", "Delete a workspace tag and remove its document assignments. Full workspace write access is required; documents themselves remain.", z3.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
|
|
1155
|
+
await required2(client2.deleteTag, "delete_tag")(id);
|
|
958
1156
|
return { id, deleted: true };
|
|
959
1157
|
});
|
|
960
|
-
register("set_document_tag", "Add or remove
|
|
1158
|
+
register("set_document_tag", "Add or remove an existing tag assignment on one document. Use batch_documents for the same tag action across multiple explicit IDs. Requires edit access to each document; action=remove preserves the tag itself.", z3.strictObject({ action: z3.enum(["add", "remove"]).describe("Add or remove exactly one tag assignment."), documentId: uuid2, tagId: uuid2 }), destructive, async ({ action, documentId, tagId }) => {
|
|
961
1159
|
if (action === "add") {
|
|
962
|
-
await
|
|
1160
|
+
await required2(client2.addTagToDocument, "add_tag_to_document")(documentId, tagId);
|
|
963
1161
|
return { operation: "add", result: { documentId, tagId, assigned: true } };
|
|
964
1162
|
}
|
|
965
|
-
await
|
|
1163
|
+
await required2(client2.removeTagFromDocument, "remove_tag_from_document")(documentId, tagId);
|
|
966
1164
|
return { operation: "remove", result: { documentId, tagId, removed: true } };
|
|
967
1165
|
});
|
|
968
|
-
register("create_snapshot", "Save a named snapshot of an existing document before a planned change. The snapshot can later be restored with restore_document_version.",
|
|
969
|
-
register("restore_document_version", "Restore content from a version or snapshot listed by read_document(view=versions). This changes current content and queues indexing; it does not restore a trashed document.",
|
|
970
|
-
register("explore_graph", "Explore graph relations from readable seed documents. mode=neighbors traverses one document without a query; mode=search ranks relations from one or more seed IDs with optional query text.",
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
]), read, async (input) => input.mode === "neighbors" ? { operation: "neighbors", result: await
|
|
974
|
-
register("get_document_index_status", "Read current indexing and pipeline status for one document without starting work. Use refresh_document_index only when an explicit retry is intended.",
|
|
975
|
-
register("refresh_document_index", "Queue an explicit asynchronous reindex for one document. Routine content and placement changes already schedule indexing; check get_document_index_status first.",
|
|
976
|
-
register("list_trash", "List soft-deleted documents visible to the active workspace or category scope. Requires read access and does not restore or purge anything.",
|
|
977
|
-
register("restore_trashed_document", "Return one
|
|
978
|
-
register("permanently_delete_document", "Irreversibly purge a document already in trash, including its version history. Use only on an explicit user request after checking list_trash.",
|
|
979
|
-
await
|
|
1166
|
+
register("create_snapshot", "Save a named snapshot of an existing document before a planned change. The snapshot can later be restored with restore_document_version.", z3.strictObject({ documentId: uuid2, label: text.max(200).describe("Snapshot label, from 1 to 200 characters."), description: z3.string().max(1000).optional().describe("Optional snapshot note, at most 1000 characters.") }), write, async ({ documentId, label, description }) => client2.createSnapshot(documentId, { label, description }));
|
|
1167
|
+
register("restore_document_version", "Restore content from a version or snapshot listed by read_document(view=versions). This changes current content and queues indexing; it does not restore a trashed document.", z3.strictObject({ documentId: uuid2, versionId: uuid2 }), destructive, async ({ documentId, versionId }) => required2(client2.restoreDocumentVersion, "restore_document_version")(documentId, versionId));
|
|
1168
|
+
register("explore_graph", "Explore graph relations from readable seed documents. mode=neighbors traverses one document without a query; mode=search ranks relations from one or more seed IDs with optional query text.", z3.discriminatedUnion("mode", [
|
|
1169
|
+
z3.strictObject({ mode: z3.literal("neighbors").describe("Select the neighbors operation explicitly."), documentId: uuid2, limit: z3.number().int().min(1).max(100).optional().describe("Maximum results to return, up to 100.") }),
|
|
1170
|
+
z3.strictObject({ mode: z3.literal("search").describe("Select the search operation explicitly."), docIds: z3.array(uuid2).min(1).max(50).describe("One to 50 authorized seed document UUIDs."), query: z3.string().max(2000).optional().describe("Optional graph relevance query, at most 2000 characters."), limit: z3.number().int().min(1).max(100).optional().describe("Maximum results to return, up to 100.") })
|
|
1171
|
+
]), read, async (input) => input.mode === "neighbors" ? { operation: "neighbors", result: await client2.getRelatedDocuments(input.documentId, input.limit) } : { operation: "search", result: await client2.searchGraph(input) });
|
|
1172
|
+
register("get_document_index_status", "Read current indexing and pipeline status for one document without starting work. Use refresh_document_index only when an explicit retry is intended.", z3.strictObject({ documentId: uuid2 }), read, async ({ documentId }) => client2.getDocumentIndexStatus(documentId));
|
|
1173
|
+
register("refresh_document_index", "Queue an explicit asynchronous reindex for one document; use batch_documents(action=refresh_index) for multiple explicit IDs. Routine content and placement changes already schedule indexing; check get_document_index_status first.", z3.strictObject({ documentId: uuid2 }), write, async ({ documentId }) => client2.refreshDocumentIndex(documentId));
|
|
1174
|
+
register("list_trash", "List soft-deleted documents visible to the active workspace or category scope. Requires read access and does not restore or purge anything.", z3.strictObject({}), read, async () => required2(client2.listTrash, "list_trash")());
|
|
1175
|
+
register("restore_trashed_document", "Return one document from trash to the active library; use batch_documents(action=restore) for multiple explicit IDs. This restores the document itself, unlike restore_document_version which changes content.", z3.strictObject({ id: uuid2 }), write, async ({ id }) => required2(client2.restoreTrashedDocument, "restore_trashed_document")(id));
|
|
1176
|
+
register("permanently_delete_document", "Irreversibly purge a document already in trash, including its version history. Use only on an explicit user request after checking list_trash.", z3.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
|
|
1177
|
+
await required2(client2.permanentlyDeleteDocument, "permanently_delete_document")(id);
|
|
980
1178
|
return { id, deleted: true };
|
|
981
1179
|
});
|
|
1180
|
+
registerBatchAndWorkspaceCapabilities(server, client2, wrap);
|
|
982
1181
|
}
|
|
983
1182
|
|
|
984
1183
|
// ../mcp-server/src/prompts-resources.ts
|
|
985
|
-
import { z as
|
|
986
|
-
function registerPromptsAndResources(server,
|
|
1184
|
+
import { z as z4 } from "zod";
|
|
1185
|
+
function registerPromptsAndResources(server, client2) {
|
|
987
1186
|
server.registerPrompt("organize_workspace", {
|
|
988
1187
|
description: "Plan safe document organization using DocsMint categories and folders.",
|
|
989
|
-
argsSchema:
|
|
990
|
-
objective:
|
|
991
|
-
language:
|
|
1188
|
+
argsSchema: z4.object({
|
|
1189
|
+
objective: z4.string(),
|
|
1190
|
+
language: z4.string().optional()
|
|
992
1191
|
})
|
|
993
1192
|
}, ({ objective, language }) => ({
|
|
994
1193
|
messages: [
|
|
@@ -1003,9 +1202,9 @@ function registerPromptsAndResources(server, client) {
|
|
|
1003
1202
|
}));
|
|
1004
1203
|
server.registerPrompt("research_workspace", {
|
|
1005
1204
|
description: "Research a question with hybrid search and GraphRAG while citing DocsMint document IDs.",
|
|
1006
|
-
argsSchema:
|
|
1007
|
-
question:
|
|
1008
|
-
language:
|
|
1205
|
+
argsSchema: z4.object({
|
|
1206
|
+
question: z4.string(),
|
|
1207
|
+
language: z4.string().optional()
|
|
1009
1208
|
})
|
|
1010
1209
|
}, ({ question, language }) => ({
|
|
1011
1210
|
messages: [
|
|
@@ -1042,9 +1241,9 @@ Use find_documents(mode=search) for normal retrieval. Use explore_graph only wit
|
|
|
1042
1241
|
}));
|
|
1043
1242
|
server.registerResource("workspace-catalog", "docsmint://workspace/catalog", {}, async (uri) => {
|
|
1044
1243
|
const [categories, folders, tags] = await Promise.all([
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1244
|
+
client2.listCategories(),
|
|
1245
|
+
client2.listFolders({}),
|
|
1246
|
+
client2.listTags()
|
|
1048
1247
|
]);
|
|
1049
1248
|
return {
|
|
1050
1249
|
contents: [
|
|
@@ -1058,97 +1257,6 @@ Use find_documents(mode=search) for normal retrieval. Use explore_graph only wit
|
|
|
1058
1257
|
});
|
|
1059
1258
|
}
|
|
1060
1259
|
|
|
1061
|
-
// ../mcp-server/src/client.ts
|
|
1062
|
-
var DEFAULT_BASE_URL = "http://localhost:50700";
|
|
1063
|
-
function readConfig() {
|
|
1064
|
-
const baseUrl = (process.env.HIAI_DOCS_URL ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1065
|
-
const apiKey = process.env.HIAI_DOCS_API_KEY;
|
|
1066
|
-
return { baseUrl, apiKey: apiKey || undefined };
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
class HiaiDocsError extends Error {
|
|
1070
|
-
status;
|
|
1071
|
-
body;
|
|
1072
|
-
code;
|
|
1073
|
-
constructor(message, status, body, code = `http_${status}`) {
|
|
1074
|
-
super(message);
|
|
1075
|
-
this.status = status;
|
|
1076
|
-
this.body = body;
|
|
1077
|
-
this.code = code;
|
|
1078
|
-
this.name = "HiaiDocsError";
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
function sanitizeMcpRequestContext(context) {
|
|
1082
|
-
if (!context)
|
|
1083
|
-
return;
|
|
1084
|
-
const headers = new Headers(context.headers);
|
|
1085
|
-
if (context.workspaceAssertion) {
|
|
1086
|
-
headers.delete("Authorization");
|
|
1087
|
-
headers.delete("Cookie");
|
|
1088
|
-
}
|
|
1089
|
-
return {
|
|
1090
|
-
...context,
|
|
1091
|
-
authorization: context.workspaceAssertion ? undefined : context.authorization,
|
|
1092
|
-
cookie: context.workspaceAssertion ? undefined : context.cookie,
|
|
1093
|
-
headers
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
function createMcpDocsClient(docsClient, requestContext) {
|
|
1097
|
-
const context = sanitizeMcpRequestContext(requestContext);
|
|
1098
|
-
return {
|
|
1099
|
-
createTag: (input) => docsClient.createTag(input, context),
|
|
1100
|
-
updateTag: (id, input) => docsClient.updateTag(id, input, context),
|
|
1101
|
-
deleteTag: (id) => docsClient.deleteTag(id, context),
|
|
1102
|
-
addTagToDocument: (documentId, tagId) => docsClient.addTagToDoc(documentId, tagId, context),
|
|
1103
|
-
removeTagFromDocument: (documentId, tagId) => docsClient.removeTagFromDoc(documentId, tagId, context),
|
|
1104
|
-
updateFolder: (id, input) => docsClient.updateFolder(id, input, context),
|
|
1105
|
-
updateCategory: (id, input) => docsClient.updateCategory(id, input, context),
|
|
1106
|
-
listTrash: () => docsClient.listTrash(context),
|
|
1107
|
-
restoreTrashedDocument: (id) => docsClient.restoreTrashedDocument(id, context),
|
|
1108
|
-
permanentlyDeleteDocument: (id) => docsClient.permanentlyDeleteDocument(id, context),
|
|
1109
|
-
deleteDocument: (id) => docsClient.deleteDoc(id, context),
|
|
1110
|
-
deleteFolder: (id) => docsClient.deleteFolder(id, context),
|
|
1111
|
-
deleteCategory: (id) => docsClient.deleteCategory(id, context),
|
|
1112
|
-
restoreDocumentVersion: (documentId, versionId) => docsClient.restoreVersion(documentId, versionId, context),
|
|
1113
|
-
search: (params) => docsClient.search(params.query, {
|
|
1114
|
-
folder: params.folder,
|
|
1115
|
-
tags: params.tags?.join(","),
|
|
1116
|
-
limit: params.limit
|
|
1117
|
-
}, context),
|
|
1118
|
-
getDocument: (id) => docsClient.getDoc(id, context),
|
|
1119
|
-
createDocument: (input) => docsClient.createDoc({
|
|
1120
|
-
...input,
|
|
1121
|
-
folderId: input.folderId ?? undefined,
|
|
1122
|
-
categoryId: input.categoryId ?? undefined
|
|
1123
|
-
}, context),
|
|
1124
|
-
updateDocument: (id, input) => docsClient.updateDoc(id, input, context),
|
|
1125
|
-
listDocuments: (params) => docsClient.listDocs(params, context),
|
|
1126
|
-
listFolders: (params) => docsClient.listFolders(params.parentId, context),
|
|
1127
|
-
createFolder: (input) => docsClient.createFolder(input, context),
|
|
1128
|
-
listCategories: () => docsClient.listCategories(context),
|
|
1129
|
-
createCategory: (input) => docsClient.createCategory(input, context),
|
|
1130
|
-
listTags: () => docsClient.listTags(context),
|
|
1131
|
-
getRelatedDocuments: (documentId, limit) => docsClient.getRelatedDocuments(documentId, context, { limit }),
|
|
1132
|
-
searchGraph: (input) => docsClient.searchGraph({ query: input.query, docIds: input.docIds, maxResults: input.limit }, context),
|
|
1133
|
-
getDocumentIndexStatus: (documentId) => docsClient.getDocumentIndexStatus(documentId, context),
|
|
1134
|
-
refreshDocumentIndex: (documentId) => docsClient.refreshDocumentIndex(documentId, context),
|
|
1135
|
-
createSnapshot: (documentId, input) => docsClient.createSnapshot(documentId, input, context),
|
|
1136
|
-
getVersionHistory: (documentId, onlySnapshots) => docsClient.listVersions(documentId, { onlySnapshots }, context),
|
|
1137
|
-
exportDocument: async (id) => ({ markdown: await docsClient.exportDoc(id, context) })
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
function createDefaultDocsClient() {
|
|
1141
|
-
const { baseUrl, apiKey } = readConfig();
|
|
1142
|
-
return new DocsClient({ baseUrl, apiKey, retries: 1 });
|
|
1143
|
-
}
|
|
1144
|
-
var client = new Proxy({}, {
|
|
1145
|
-
get(_target, property) {
|
|
1146
|
-
const configured = createMcpDocsClient(createDefaultDocsClient());
|
|
1147
|
-
const value = configured[property];
|
|
1148
|
-
return typeof value === "function" ? value.bind(configured) : value;
|
|
1149
|
-
}
|
|
1150
|
-
});
|
|
1151
|
-
|
|
1152
1260
|
// ../mcp-server/src/server.ts
|
|
1153
1261
|
function wrapHandler(name, handler, outputSchema) {
|
|
1154
1262
|
return async (args) => {
|
|
@@ -1192,7 +1300,7 @@ function registerDocsmintMcpCapabilities(server, client2) {
|
|
|
1192
1300
|
registerPromptsAndResources(server, client2);
|
|
1193
1301
|
}
|
|
1194
1302
|
function createDocsmintMcpServer(options = {}) {
|
|
1195
|
-
const server = new McpServer({ name: "docsmint", version: "0.
|
|
1303
|
+
const server = new McpServer({ name: "docsmint", version: "1.0.2" });
|
|
1196
1304
|
const client2 = options.docsClient ? createMcpDocsClient(options.docsClient, options.requestContext) : options.client ?? createMcpDocsClient(createDefaultDocsClient(), options.requestContext);
|
|
1197
1305
|
registerDocsmintMcpCapabilities(server, client2);
|
|
1198
1306
|
return server;
|