@hiai-gg/docsmint 0.9.4 → 1.0.1
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 +12 -8
- package/dist/backend/index.js +1 -1
- package/dist/mcp-cli.js +361 -588
- package/dist/mcp-server.js +392 -627
- package/package.json +1 -1
- package/packages/cli/src/index.ts +1 -1
- package/server.json +3 -3
- package/skills/docsmint-document-manager/SKILL.md +9 -8
package/dist/mcp-server.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __returnValue = (v) => v;
|
|
4
|
-
function __exportSetter(name, newValue) {
|
|
5
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
-
}
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, {
|
|
10
|
-
get: all[name],
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
set: __exportSetter.bind(all, name)
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
2
|
// ../mcp-server/src/server.ts
|
|
18
3
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
19
|
-
import { z as z15 } from "zod";
|
|
20
4
|
|
|
21
5
|
// dist/client.js
|
|
22
6
|
var docsApiErrorBrand = Symbol.for("io.github.hiai-gg.docsmint.DocsApiError");
|
|
@@ -586,8 +570,8 @@ var RESOURCE_PERMISSIONS = new Set([
|
|
|
586
570
|
"edit",
|
|
587
571
|
"write"
|
|
588
572
|
]);
|
|
589
|
-
// ../mcp-server/src/
|
|
590
|
-
import { z as
|
|
573
|
+
// ../mcp-server/src/compact.ts
|
|
574
|
+
import { z as z3 } from "zod";
|
|
591
575
|
|
|
592
576
|
// ../mcp-server/src/output-schemas.ts
|
|
593
577
|
import { z } from "zod";
|
|
@@ -764,7 +748,7 @@ var deleteAcknowledgmentSchema = z.looseObject({
|
|
|
764
748
|
id: z.string().uuid(),
|
|
765
749
|
deleted: z.literal(true)
|
|
766
750
|
});
|
|
767
|
-
var
|
|
751
|
+
var operationOutputSchemas = {
|
|
768
752
|
search_documents: z.looseObject({
|
|
769
753
|
items: z.array(searchResultSchema),
|
|
770
754
|
total: z.number(),
|
|
@@ -816,355 +800,78 @@ var toolOutputSchemas = {
|
|
|
816
800
|
restore_trashed_document: z.looseObject({ success: z.literal(true) }),
|
|
817
801
|
permanently_delete_document: deleteAcknowledgmentSchema
|
|
818
802
|
};
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
annotations: update,
|
|
888
|
-
inputSchema: z3.object({ id: uuid, name: z3.string().min(1).max(100).optional().describe("Replacement tag name; omit to keep the current name."), color: z3.string().max(20).optional().describe("Replacement display color; omit to keep the current color.") }).refine((value) => value.name !== undefined || value.color !== undefined),
|
|
889
|
-
outputSchema: toolOutputSchemas.update_tag
|
|
890
|
-
}, wrap("update_tag", async ({ id, ...input }) => client.updateTag ? client.updateTag(id, input) : unsupported2("update_tag")));
|
|
891
|
-
server.registerTool("delete_tag", {
|
|
892
|
-
description: "Delete a tag in the active workspace and remove its document assignments. Requires full workspace write access; category-scoped credentials cannot manage tags.",
|
|
893
|
-
annotations: purge,
|
|
894
|
-
inputSchema: z3.object({ id: uuid }),
|
|
895
|
-
outputSchema: toolOutputSchemas.delete_tag
|
|
896
|
-
}, wrap("delete_tag", async ({ id }) => {
|
|
897
|
-
if (!client.deleteTag)
|
|
898
|
-
return unsupported2("delete_tag");
|
|
899
|
-
await client.deleteTag(id);
|
|
900
|
-
return { id, deleted: true };
|
|
901
|
-
}));
|
|
902
|
-
server.registerTool("add_tag_to_document", {
|
|
903
|
-
description: "Assign a tag from list_tags to an existing document. Requires edit access to the document and permission to use the tag.",
|
|
904
|
-
annotations: write,
|
|
905
|
-
inputSchema: z3.object({ documentId: uuid.describe("UUID of the document to tag."), tagId: uuid.describe("UUID of the tag returned by list_tags.") }),
|
|
906
|
-
outputSchema: toolOutputSchemas.add_tag_to_document
|
|
907
|
-
}, wrap("add_tag_to_document", async ({ documentId, tagId }) => {
|
|
908
|
-
if (!client.addTagToDocument)
|
|
909
|
-
return unsupported2("add_tag_to_document");
|
|
910
|
-
await client.addTagToDocument(documentId, tagId);
|
|
911
|
-
return { documentId, tagId, assigned: true };
|
|
912
|
-
}));
|
|
913
|
-
server.registerTool("remove_tag_from_document", {
|
|
914
|
-
description: "Remove a tag assignment from a document. Requires edit access; the tag itself is preserved.",
|
|
915
|
-
annotations: update,
|
|
916
|
-
inputSchema: z3.object({ documentId: uuid.describe("UUID of the document whose tag assignment changes."), tagId: uuid.describe("UUID of the assigned tag to remove.") }),
|
|
917
|
-
outputSchema: toolOutputSchemas.remove_tag_from_document
|
|
918
|
-
}, wrap("remove_tag_from_document", async ({ documentId, tagId }) => {
|
|
919
|
-
if (!client.removeTagFromDocument)
|
|
920
|
-
return unsupported2("remove_tag_from_document");
|
|
921
|
-
await client.removeTagFromDocument(documentId, tagId);
|
|
922
|
-
return { documentId, tagId, removed: true };
|
|
923
|
-
}));
|
|
924
|
-
server.registerTool("update_folder", {
|
|
925
|
-
description: "Rename or move a folder; changes to category or parent follow API scope rules and trigger reindexing. Requires write access.",
|
|
926
|
-
annotations: update,
|
|
927
|
-
inputSchema: z3.object({ id: uuid, name: z3.string().min(1).max(255).optional().describe("Replacement folder name; omit to preserve the name."), parentId: uuid.nullable().optional().describe("New parent folder UUID, or null for a root folder."), categoryId: uuid.nullable().optional().describe("New category UUID, or null to clear the category."), order: z3.number().int().nonnegative().optional().describe("New non-negative order within the containing folder.") }).refine((value) => value.name !== undefined || value.parentId !== undefined || value.categoryId !== undefined || value.order !== undefined),
|
|
928
|
-
outputSchema: toolOutputSchemas.update_folder
|
|
929
|
-
}, wrap("update_folder", async ({ id, ...input }) => client.updateFolder ? client.updateFolder(id, input) : unsupported2("update_folder")));
|
|
930
|
-
server.registerTool("update_category", {
|
|
931
|
-
description: "Rename or reorder a category. Requires full workspace write access; category-scoped credentials cannot modify categories.",
|
|
932
|
-
annotations: update,
|
|
933
|
-
inputSchema: z3.object({ id: uuid, name: z3.string().min(1).max(255).optional().describe("New category name, up to 255 characters."), order: z3.number().int().nonnegative().optional().describe("New non-negative category order.") }).refine((value) => value.name !== undefined || value.order !== undefined),
|
|
934
|
-
outputSchema: toolOutputSchemas.update_category
|
|
935
|
-
}, wrap("update_category", async ({ id, ...input }) => client.updateCategory ? client.updateCategory(id, input) : unsupported2("update_category")));
|
|
936
|
-
server.registerTool("list_trash", {
|
|
937
|
-
description: "List soft-deleted documents visible to the active workspace/category. Requires read access.",
|
|
938
|
-
annotations: read,
|
|
939
|
-
inputSchema: z3.object({}),
|
|
940
|
-
outputSchema: toolOutputSchemas.list_trash
|
|
941
|
-
}, wrap("list_trash", async () => client.listTrash ? client.listTrash() : unsupported2("list_trash")));
|
|
942
|
-
server.registerTool("restore_trashed_document", {
|
|
943
|
-
description: "Restore a soft-deleted document from list_trash. Requires write access. This is different from restoring a content version.",
|
|
944
|
-
annotations: write,
|
|
945
|
-
inputSchema: z3.object({ id: uuid }),
|
|
946
|
-
outputSchema: toolOutputSchemas.restore_trashed_document
|
|
947
|
-
}, wrap("restore_trashed_document", async ({ id }) => client.restoreTrashedDocument ? client.restoreTrashedDocument(id) : unsupported2("restore_trashed_document")));
|
|
948
|
-
server.registerTool("permanently_delete_document", {
|
|
949
|
-
description: "Irreversibly purge a document already in trash, including its content and version history. Requires write access. Use only on explicit user request after checking list_trash.",
|
|
950
|
-
annotations: purge,
|
|
951
|
-
inputSchema: z3.object({ id: uuid }),
|
|
952
|
-
outputSchema: toolOutputSchemas.permanently_delete_document
|
|
953
|
-
}, wrap("permanently_delete_document", async ({ id }) => {
|
|
954
|
-
if (!client.permanentlyDeleteDocument)
|
|
955
|
-
return unsupported2("permanently_delete_document");
|
|
956
|
-
await client.permanentlyDeleteDocument(id);
|
|
957
|
-
return { id, deleted: true };
|
|
958
|
-
}));
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
// ../mcp-server/src/capabilities.ts
|
|
962
|
-
import { z as z4 } from "zod";
|
|
963
|
-
var capabilityCatalog = {
|
|
964
|
-
tools: [
|
|
965
|
-
"search_documents",
|
|
966
|
-
"get_document",
|
|
967
|
-
"create_document",
|
|
968
|
-
"update_document",
|
|
969
|
-
"list_documents",
|
|
970
|
-
"list_folders",
|
|
971
|
-
"create_folder",
|
|
972
|
-
"create_snapshot",
|
|
973
|
-
"get_version_history",
|
|
974
|
-
"export_document",
|
|
975
|
-
"list_categories",
|
|
976
|
-
"create_category",
|
|
977
|
-
"list_tags",
|
|
978
|
-
"get_related_documents",
|
|
979
|
-
"search_knowledge_graph",
|
|
980
|
-
"get_document_index_status",
|
|
981
|
-
"refresh_document_index",
|
|
982
|
-
"delete_document",
|
|
983
|
-
"delete_folder",
|
|
984
|
-
"delete_category",
|
|
985
|
-
"restore_document_version",
|
|
986
|
-
"create_tag",
|
|
987
|
-
"update_tag",
|
|
988
|
-
"delete_tag",
|
|
989
|
-
"add_tag_to_document",
|
|
990
|
-
"remove_tag_from_document",
|
|
991
|
-
"update_folder",
|
|
992
|
-
"update_category",
|
|
993
|
-
"list_trash",
|
|
994
|
-
"restore_trashed_document",
|
|
995
|
-
"permanently_delete_document"
|
|
996
|
-
],
|
|
997
|
-
prompts: ["organize_workspace", "research_workspace"],
|
|
998
|
-
resources: [
|
|
999
|
-
"docsmint://guide/editor",
|
|
1000
|
-
"docsmint://guide/search",
|
|
1001
|
-
"docsmint://workspace/catalog"
|
|
1002
|
-
]
|
|
803
|
+
var variant = (operation, result) => z.object({ operation: z.literal(operation), result });
|
|
804
|
+
var toolOutputSchemas = {
|
|
805
|
+
delete_document: operationOutputSchemas.delete_document,
|
|
806
|
+
delete_folder: operationOutputSchemas.delete_folder,
|
|
807
|
+
delete_category: operationOutputSchemas.delete_category,
|
|
808
|
+
delete_tag: operationOutputSchemas.delete_tag,
|
|
809
|
+
create_snapshot: operationOutputSchemas.create_snapshot,
|
|
810
|
+
restore_document_version: operationOutputSchemas.restore_document_version,
|
|
811
|
+
get_document_index_status: operationOutputSchemas.get_document_index_status,
|
|
812
|
+
refresh_document_index: operationOutputSchemas.refresh_document_index,
|
|
813
|
+
list_trash: operationOutputSchemas.list_trash,
|
|
814
|
+
restore_trashed_document: operationOutputSchemas.restore_trashed_document,
|
|
815
|
+
permanently_delete_document: operationOutputSchemas.permanently_delete_document,
|
|
816
|
+
find_documents: z.union([
|
|
817
|
+
variant("list", operationOutputSchemas.list_documents),
|
|
818
|
+
variant("search", operationOutputSchemas.search_documents)
|
|
819
|
+
]),
|
|
820
|
+
read_document: z.union([
|
|
821
|
+
variant("detail", operationOutputSchemas.get_document),
|
|
822
|
+
variant("markdown", operationOutputSchemas.export_document),
|
|
823
|
+
variant("versions", operationOutputSchemas.get_version_history)
|
|
824
|
+
]),
|
|
825
|
+
save_document: z.union([
|
|
826
|
+
variant("create", operationOutputSchemas.create_document),
|
|
827
|
+
variant("update", operationOutputSchemas.update_document)
|
|
828
|
+
]),
|
|
829
|
+
list_workspace_structure: z.union([
|
|
830
|
+
variant("folders", operationOutputSchemas.list_folders),
|
|
831
|
+
variant("categories", operationOutputSchemas.list_categories),
|
|
832
|
+
variant("tags", operationOutputSchemas.list_tags)
|
|
833
|
+
]),
|
|
834
|
+
save_folder: z.union([
|
|
835
|
+
variant("create", operationOutputSchemas.create_folder),
|
|
836
|
+
variant("update", operationOutputSchemas.update_folder)
|
|
837
|
+
]),
|
|
838
|
+
save_category: z.union([
|
|
839
|
+
variant("create", operationOutputSchemas.create_category),
|
|
840
|
+
variant("update", operationOutputSchemas.update_category)
|
|
841
|
+
]),
|
|
842
|
+
save_tag: z.union([
|
|
843
|
+
variant("create", operationOutputSchemas.create_tag),
|
|
844
|
+
variant("update", operationOutputSchemas.update_tag)
|
|
845
|
+
]),
|
|
846
|
+
set_document_tag: z.union([
|
|
847
|
+
variant("add", operationOutputSchemas.add_tag_to_document),
|
|
848
|
+
variant("remove", operationOutputSchemas.remove_tag_from_document)
|
|
849
|
+
]),
|
|
850
|
+
explore_graph: z.union([
|
|
851
|
+
variant("neighbors", operationOutputSchemas.get_related_documents),
|
|
852
|
+
variant("search", operationOutputSchemas.search_knowledge_graph)
|
|
853
|
+
]),
|
|
854
|
+
batch_documents: z.looseObject({
|
|
855
|
+
action: z.enum(["move", "set_category", "add_tag", "remove_tag", "trash", "restore", "refresh_index"]),
|
|
856
|
+
total: z.number().int().min(1).max(25),
|
|
857
|
+
succeeded: z.number().int().nonnegative(),
|
|
858
|
+
failed: z.number().int().nonnegative(),
|
|
859
|
+
aborted: z.boolean(),
|
|
860
|
+
results: z.array(z.union([
|
|
861
|
+
z.looseObject({ id: z.string().uuid(), status: z.literal("ok") }),
|
|
862
|
+
z.looseObject({ id: z.string().uuid(), status: z.literal("error"), error: z.looseObject({ status: z.number().int(), code: z.string(), message: z.string() }) }),
|
|
863
|
+
z.looseObject({ id: z.string().uuid(), status: z.literal("skipped") })
|
|
864
|
+
]))
|
|
865
|
+
}),
|
|
866
|
+
get_workspace_item: z.union([
|
|
867
|
+
variant("folder", folderSchema),
|
|
868
|
+
variant("category", categoryListItemSchema),
|
|
869
|
+
variant("tag", tagSchema)
|
|
870
|
+
])
|
|
1003
871
|
};
|
|
1004
|
-
function registerExtendedCapabilities(server, client, wrapHandler) {
|
|
1005
|
-
server.registerTool("list_categories", {
|
|
1006
|
-
annotations: {
|
|
1007
|
-
readOnlyHint: true,
|
|
1008
|
-
destructiveHint: false,
|
|
1009
|
-
idempotentHint: true,
|
|
1010
|
-
openWorldHint: false
|
|
1011
|
-
},
|
|
1012
|
-
description: "List categories visible in the active workspace or category scope. Requires read access; a category-scoped credential sees only its configured category. Use this before create_document or create_folder when you need an existing category ID.",
|
|
1013
|
-
inputSchema: z4.object({}),
|
|
1014
|
-
outputSchema: toolOutputSchemas.list_categories
|
|
1015
|
-
}, wrapHandler("list_categories", async () => client.listCategories()));
|
|
1016
|
-
server.registerTool("create_category", {
|
|
1017
|
-
annotations: {
|
|
1018
|
-
readOnlyHint: false,
|
|
1019
|
-
destructiveHint: false,
|
|
1020
|
-
idempotentHint: false,
|
|
1021
|
-
openWorldHint: false
|
|
1022
|
-
},
|
|
1023
|
-
description: "Create a new category for the active workspace. Requires workspace-level write access; category-scoped credentials cannot create categories. Returns the created category. Use list_categories to inspect existing categories.",
|
|
1024
|
-
inputSchema: z4.object({
|
|
1025
|
-
name: z4.string().trim().min(1).max(255).describe("Non-empty display name, up to 255 characters, for example Project notes.")
|
|
1026
|
-
}),
|
|
1027
|
-
outputSchema: toolOutputSchemas.create_category
|
|
1028
|
-
}, wrapHandler("create_category", async (input) => client.createCategory(input)));
|
|
1029
|
-
server.registerTool("list_tags", {
|
|
1030
|
-
annotations: {
|
|
1031
|
-
readOnlyHint: true,
|
|
1032
|
-
destructiveHint: false,
|
|
1033
|
-
idempotentHint: true,
|
|
1034
|
-
openWorldHint: false
|
|
1035
|
-
},
|
|
1036
|
-
description: "List tags visible in the active workspace or configured category scope. Requires read access; use returned tag IDs to filter list_documents and returned tag names to filter search_documents.",
|
|
1037
|
-
inputSchema: z4.object({}),
|
|
1038
|
-
outputSchema: toolOutputSchemas.list_tags
|
|
1039
|
-
}, wrapHandler("list_tags", async () => client.listTags()));
|
|
1040
|
-
server.registerTool("get_related_documents", {
|
|
1041
|
-
annotations: {
|
|
1042
|
-
readOnlyHint: true,
|
|
1043
|
-
destructiveHint: false,
|
|
1044
|
-
idempotentHint: true,
|
|
1045
|
-
openWorldHint: false
|
|
1046
|
-
},
|
|
1047
|
-
description: "Traverse graph relations from one readable document without a text query. Requires read access and returns related document IDs plus relation metadata. Use search_knowledge_graph to rank graph neighbors with query text, or search_documents for normal hybrid retrieval. Results stay in the active scope and may be empty when graph data is unavailable.",
|
|
1048
|
-
inputSchema: z4.object({
|
|
1049
|
-
documentId: z4.string().min(1).describe("Document ID returned by search_documents or list_documents; it must be readable in the active scope."),
|
|
1050
|
-
limit: z4.number().int().min(1).max(100).optional().describe("Maximum related documents to return, from 1 to 100. Omit to use the server default.")
|
|
1051
|
-
}),
|
|
1052
|
-
outputSchema: toolOutputSchemas.get_related_documents
|
|
1053
|
-
}, wrapHandler("get_related_documents", async ({ documentId, limit }) => client.getRelatedDocuments(documentId, limit)));
|
|
1054
|
-
server.registerTool("search_knowledge_graph", {
|
|
1055
|
-
annotations: {
|
|
1056
|
-
readOnlyHint: true,
|
|
1057
|
-
destructiveHint: false,
|
|
1058
|
-
idempotentHint: true,
|
|
1059
|
-
openWorldHint: false
|
|
1060
|
-
},
|
|
1061
|
-
description: "Search graph relations from one or more readable seed documents, optionally using query text to filter and rank related documents. Requires read access and returns seed entities plus relatedDocs. Use search_documents first to obtain authorized seed IDs; use get_related_documents for one-seed neighbors without graph search. Results stay in the active scope and graph data may be empty when unavailable.",
|
|
1062
|
-
inputSchema: z4.object({
|
|
1063
|
-
query: z4.string().max(2000).optional().describe("Optional search text up to 2,000 characters to filter and rank graph-related documents; omit it to inspect relations without query filtering."),
|
|
1064
|
-
docIds: z4.array(z4.string().min(1)).min(1).max(50).describe("Between 1 and 50 document IDs returned by search_documents or list_documents; each seed must be readable in the active scope."),
|
|
1065
|
-
limit: z4.number().int().min(1).max(100).optional().describe("Maximum related documents to return, from 1 to 100. Omit to use the server default.")
|
|
1066
|
-
}),
|
|
1067
|
-
outputSchema: toolOutputSchemas.search_knowledge_graph
|
|
1068
|
-
}, wrapHandler("search_knowledge_graph", async (input) => client.searchGraph(input)));
|
|
1069
|
-
server.registerTool("get_document_index_status", {
|
|
1070
|
-
annotations: {
|
|
1071
|
-
readOnlyHint: true,
|
|
1072
|
-
destructiveHint: false,
|
|
1073
|
-
idempotentHint: true,
|
|
1074
|
-
openWorldHint: false
|
|
1075
|
-
},
|
|
1076
|
-
description: "Read indexing and knowledge-pipeline status for an existing document without starting work. Requires read access. Use after a save or refresh_document_index to check progress or failures.",
|
|
1077
|
-
inputSchema: z4.object({
|
|
1078
|
-
documentId: z4.string().uuid().describe("UUID of a document returned by search_documents or list_documents; it must be readable in the active scope.")
|
|
1079
|
-
}),
|
|
1080
|
-
outputSchema: toolOutputSchemas.get_document_index_status
|
|
1081
|
-
}, wrapHandler("get_document_index_status", async ({ documentId }) => client.getDocumentIndexStatus(documentId)));
|
|
1082
|
-
server.registerTool("refresh_document_index", {
|
|
1083
|
-
annotations: {
|
|
1084
|
-
readOnlyHint: false,
|
|
1085
|
-
destructiveHint: false,
|
|
1086
|
-
idempotentHint: false,
|
|
1087
|
-
openWorldHint: false
|
|
1088
|
-
},
|
|
1089
|
-
description: "Queue an explicit reindex for an existing document; processing is asynchronous and the response acknowledges the generation. Requires write access. Normal content and placement changes schedule indexing when needed, so use get_document_index_status first and refresh only when a retry is intended.",
|
|
1090
|
-
inputSchema: z4.object({
|
|
1091
|
-
documentId: z4.string().uuid().describe("UUID of the document to refresh, obtained from search_documents or list_documents and visible in the active scope.")
|
|
1092
|
-
}),
|
|
1093
|
-
outputSchema: toolOutputSchemas.refresh_document_index
|
|
1094
|
-
}, wrapHandler("refresh_document_index", async ({ documentId }) => client.refreshDocumentIndex(documentId)));
|
|
1095
|
-
server.registerPrompt("organize_workspace", {
|
|
1096
|
-
description: "Plan safe document organization using DocsMint categories and folders.",
|
|
1097
|
-
argsSchema: z4.object({
|
|
1098
|
-
objective: z4.string(),
|
|
1099
|
-
language: z4.string().optional()
|
|
1100
|
-
})
|
|
1101
|
-
}, ({ objective, language }) => ({
|
|
1102
|
-
messages: [
|
|
1103
|
-
{
|
|
1104
|
-
role: "user",
|
|
1105
|
-
content: {
|
|
1106
|
-
type: "text",
|
|
1107
|
-
text: `Organize this DocsMint workspace for: ${objective}. Work in ${language ?? "the document language"}. Inspect categories, folders, tags, and documents before proposing or applying changes. Preserve document content and obey the API key scope.`
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
]
|
|
1111
|
-
}));
|
|
1112
|
-
server.registerPrompt("research_workspace", {
|
|
1113
|
-
description: "Research a question with hybrid search and GraphRAG while citing DocsMint document IDs.",
|
|
1114
|
-
argsSchema: z4.object({
|
|
1115
|
-
question: z4.string(),
|
|
1116
|
-
language: z4.string().optional()
|
|
1117
|
-
})
|
|
1118
|
-
}, ({ question, language }) => ({
|
|
1119
|
-
messages: [
|
|
1120
|
-
{
|
|
1121
|
-
role: "user",
|
|
1122
|
-
content: {
|
|
1123
|
-
type: "text",
|
|
1124
|
-
text: `Answer this question from DocsMint: ${question}. Respond in ${language ?? "the question language"}. Start with hybrid search, use graph traversal only from authorized result documents, and cite document IDs. Distinguish retrieved facts from inference.`
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
]
|
|
1128
|
-
}));
|
|
1129
|
-
server.registerResource("editor-guide", "docsmint://guide/editor", {}, async (uri) => ({
|
|
1130
|
-
contents: [
|
|
1131
|
-
{
|
|
1132
|
-
uri: uri.href,
|
|
1133
|
-
mimeType: "text/markdown",
|
|
1134
|
-
text: `# DocsMint editing rules
|
|
1135
872
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
]
|
|
1139
|
-
}));
|
|
1140
|
-
server.registerResource("search-guide", "docsmint://guide/search", {}, async (uri) => ({
|
|
1141
|
-
contents: [
|
|
1142
|
-
{
|
|
1143
|
-
uri: uri.href,
|
|
1144
|
-
mimeType: "text/markdown",
|
|
1145
|
-
text: `# DocsMint retrieval rules
|
|
1146
|
-
|
|
1147
|
-
Use search_documents for normal retrieval. Use get_related_documents or search_knowledge_graph only with document IDs already authorized by the active API key. Keep multilingual queries in their original language and cite document IDs in answers.`
|
|
1148
|
-
}
|
|
1149
|
-
]
|
|
1150
|
-
}));
|
|
1151
|
-
server.registerResource("workspace-catalog", "docsmint://workspace/catalog", {}, async (uri) => {
|
|
1152
|
-
const [categories, folders, tags] = await Promise.all([
|
|
1153
|
-
client.listCategories(),
|
|
1154
|
-
client.listFolders({}),
|
|
1155
|
-
client.listTags()
|
|
1156
|
-
]);
|
|
1157
|
-
return {
|
|
1158
|
-
contents: [
|
|
1159
|
-
{
|
|
1160
|
-
uri: uri.href,
|
|
1161
|
-
mimeType: "application/json",
|
|
1162
|
-
text: JSON.stringify({ categories, folders, tags }, null, 2)
|
|
1163
|
-
}
|
|
1164
|
-
]
|
|
1165
|
-
};
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
873
|
+
// ../mcp-server/src/batch-workspace.ts
|
|
874
|
+
import { z as z2 } from "zod";
|
|
1168
875
|
|
|
1169
876
|
// ../mcp-server/src/client.ts
|
|
1170
877
|
var DEFAULT_BASE_URL = "http://localhost:50700";
|
|
@@ -1204,6 +911,7 @@ function sanitizeMcpRequestContext(context) {
|
|
|
1204
911
|
function createMcpDocsClient(docsClient, requestContext) {
|
|
1205
912
|
const context = sanitizeMcpRequestContext(requestContext);
|
|
1206
913
|
return {
|
|
914
|
+
getFolder: (id) => docsClient.getFolder(id, context),
|
|
1207
915
|
createTag: (input) => docsClient.createTag(input, context),
|
|
1208
916
|
updateTag: (id, input) => docsClient.updateTag(id, input, context),
|
|
1209
917
|
deleteTag: (id) => docsClient.deleteTag(id, context),
|
|
@@ -1257,236 +965,332 @@ var client = new Proxy({}, {
|
|
|
1257
965
|
}
|
|
1258
966
|
});
|
|
1259
967
|
|
|
1260
|
-
// ../mcp-server/src/
|
|
1261
|
-
var
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
})
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
});
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
};
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
};
|
|
1346
|
-
var handler4 = createHandler4(client);
|
|
968
|
+
// ../mcp-server/src/batch-workspace.ts
|
|
969
|
+
var uuid = z2.string().uuid().describe("UUID of an item visible to the active API key.");
|
|
970
|
+
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.");
|
|
971
|
+
var base = { documentIds };
|
|
972
|
+
var batchInput = z2.discriminatedUnion("action", [
|
|
973
|
+
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.") }),
|
|
974
|
+
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.") }),
|
|
975
|
+
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.") }),
|
|
976
|
+
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.") }),
|
|
977
|
+
z2.strictObject({ ...base, action: z2.literal("trash").describe("Move every document to trash without permanent deletion.") }),
|
|
978
|
+
z2.strictObject({ ...base, action: z2.literal("restore").describe("Restore every selected document from trash.") }),
|
|
979
|
+
z2.strictObject({ ...base, action: z2.literal("refresh_index").describe("Request explicit indexing retry for every document.") })
|
|
980
|
+
]);
|
|
981
|
+
function required(method, name) {
|
|
982
|
+
if (!method)
|
|
983
|
+
throw new Error(`The injected legacy MCP client does not support ${name}; use a public DocsClient.`);
|
|
984
|
+
return method;
|
|
985
|
+
}
|
|
986
|
+
function registerBatchAndWorkspaceCapabilities(server, client2, wrap) {
|
|
987
|
+
async function batch(input) {
|
|
988
|
+
const results = [];
|
|
989
|
+
let aborted = false;
|
|
990
|
+
for (const id of input.documentIds) {
|
|
991
|
+
if (aborted) {
|
|
992
|
+
results.push({ id, status: "skipped" });
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
try {
|
|
996
|
+
switch (input.action) {
|
|
997
|
+
case "move":
|
|
998
|
+
await client2.updateDocument(id, { folderId: input.folderId });
|
|
999
|
+
break;
|
|
1000
|
+
case "set_category":
|
|
1001
|
+
await client2.updateDocument(id, { categoryId: input.categoryId });
|
|
1002
|
+
break;
|
|
1003
|
+
case "add_tag":
|
|
1004
|
+
await required(client2.addTagToDocument, "add_tag")(id, input.tagId);
|
|
1005
|
+
break;
|
|
1006
|
+
case "remove_tag":
|
|
1007
|
+
await required(client2.removeTagFromDocument, "remove_tag")(id, input.tagId);
|
|
1008
|
+
break;
|
|
1009
|
+
case "trash":
|
|
1010
|
+
await required(client2.deleteDocument, "trash")(id);
|
|
1011
|
+
break;
|
|
1012
|
+
case "restore":
|
|
1013
|
+
await required(client2.restoreTrashedDocument, "restore")(id);
|
|
1014
|
+
break;
|
|
1015
|
+
case "refresh_index":
|
|
1016
|
+
await client2.refreshDocumentIndex(id);
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
results.push({ id, status: "ok" });
|
|
1020
|
+
} catch (error) {
|
|
1021
|
+
const known = isDocsApiError(error) || error instanceof HiaiDocsError;
|
|
1022
|
+
const status = known ? error.status : 500;
|
|
1023
|
+
const code = known ? error.code : "INTERNAL_ERROR";
|
|
1024
|
+
results.push({ id, status: "error", error: { status, code, message: known ? error.message : "Document operation failed" } });
|
|
1025
|
+
if (status === 401 || status === 429)
|
|
1026
|
+
aborted = true;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
const succeeded = results.filter((result) => result.status === "ok").length;
|
|
1030
|
+
return { action: input.action, total: input.documentIds.length, succeeded, failed: results.filter((result) => result.status === "error").length, aborted, results };
|
|
1031
|
+
}
|
|
1032
|
+
server.registerTool("batch_documents", {
|
|
1033
|
+
description: "Apply one action to 1\u201325 explicitly selected document IDs. Supports move, set_category, add_tag, remove_tag, trash, restore, or refresh_index. Processes sequentially through the existing API so each document keeps its own workspace and category permission check. Returns per-ID success or error; partial success is possible. Stops after authentication or rate-limit failure. Permanent purge and version restore are intentionally separate tools.",
|
|
1034
|
+
inputSchema: batchInput,
|
|
1035
|
+
outputSchema: toolOutputSchemas.batch_documents,
|
|
1036
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
1037
|
+
}, wrap("batch_documents", batch, toolOutputSchemas.batch_documents));
|
|
1038
|
+
server.registerTool("get_workspace_item", {
|
|
1039
|
+
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.",
|
|
1040
|
+
inputSchema: z2.strictObject({ kind: z2.enum(["folder", "category", "tag"]).describe("The workspace resource type to read by ID."), id: uuid }),
|
|
1041
|
+
outputSchema: toolOutputSchemas.get_workspace_item,
|
|
1042
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1043
|
+
}, wrap("get_workspace_item", async ({ kind, id }) => {
|
|
1044
|
+
if (kind === "folder")
|
|
1045
|
+
return { operation: kind, result: await required(client2.getFolder, "get_workspace_item(folder)")(id) };
|
|
1046
|
+
const listed = kind === "category" ? await client2.listCategories() : await client2.listTags();
|
|
1047
|
+
const result = Array.isArray(listed) ? listed.find((item) => item.id === id) : undefined;
|
|
1048
|
+
if (!result)
|
|
1049
|
+
throw new HiaiDocsError(`${kind} not found`, 404, null, "NOT_FOUND");
|
|
1050
|
+
return { operation: kind, result };
|
|
1051
|
+
}, toolOutputSchemas.get_workspace_item));
|
|
1052
|
+
}
|
|
1347
1053
|
|
|
1348
|
-
// ../mcp-server/src/
|
|
1349
|
-
var
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1054
|
+
// ../mcp-server/src/compact.ts
|
|
1055
|
+
var uuid2 = z3.string().uuid().describe("UUID returned by the corresponding list or read operation.");
|
|
1056
|
+
var text = z3.string().min(1).describe("Non-empty human-readable name or title.");
|
|
1057
|
+
var title = z3.string().min(1).max(500).describe("Document title, from 1 to 500 characters.");
|
|
1058
|
+
var content = z3.string().describe("Markdown document content; an empty string clears the content on update.");
|
|
1059
|
+
var read = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
1060
|
+
var write = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false };
|
|
1061
|
+
var destructive = { ...write, destructiveHint: true };
|
|
1062
|
+
function required2(value, name) {
|
|
1063
|
+
if (!value)
|
|
1064
|
+
throw new Error(`The injected legacy MCP client does not support ${name}; use a public DocsClient.`);
|
|
1065
|
+
return value;
|
|
1066
|
+
}
|
|
1067
|
+
function registerCompactCapabilities(server, client2, wrap) {
|
|
1068
|
+
function register(name, description, inputSchema, annotations, handler) {
|
|
1069
|
+
server.registerTool(name, { description, inputSchema, outputSchema: toolOutputSchemas[name], annotations }, wrap(name, handler, toolOutputSchemas[name]));
|
|
1070
|
+
}
|
|
1071
|
+
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", [
|
|
1072
|
+
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.") }),
|
|
1073
|
+
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.") })
|
|
1074
|
+
]), read, async (input) => input.mode === "list" ? { operation: "list", result: await client2.listDocuments(input) } : { operation: "search", result: await client2.search(input) });
|
|
1075
|
+
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", [
|
|
1076
|
+
z3.strictObject({ view: z3.literal("detail").describe("Select the detail operation explicitly."), id: uuid2 }),
|
|
1077
|
+
z3.strictObject({ view: z3.literal("markdown").describe("Select the markdown operation explicitly."), id: uuid2 }),
|
|
1078
|
+
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.") })
|
|
1079
|
+
]), read, async (input) => {
|
|
1080
|
+
if (input.view === "detail")
|
|
1081
|
+
return { operation: "detail", result: await client2.getDocument(input.id) };
|
|
1082
|
+
if (input.view === "markdown")
|
|
1083
|
+
return { operation: "markdown", result: await client2.exportDocument(input.id) };
|
|
1084
|
+
return { operation: "versions", result: await client2.getVersionHistory(input.id, input.onlySnapshots) };
|
|
1085
|
+
});
|
|
1086
|
+
register("save_document", "Create a new document or update an existing document. action=create requires write access; action=update requires edit access for content, and placement changes may require write access. Content or placement changes queue normal indexing.", z3.discriminatedUnion("action", [
|
|
1087
|
+
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.") }),
|
|
1088
|
+
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)
|
|
1089
|
+
]), destructive, async (input) => {
|
|
1090
|
+
if (input.action === "create") {
|
|
1091
|
+
const { action: _action2, ...data2 } = input;
|
|
1092
|
+
return { operation: "create", result: await client2.createDocument(data2) };
|
|
1093
|
+
}
|
|
1094
|
+
const { action: _action, id, ...data } = input;
|
|
1095
|
+
return { operation: "update", result: await client2.updateDocument(id, data) };
|
|
1096
|
+
});
|
|
1097
|
+
register("delete_document", "Move a writable document to trash without purging content or versions. Use only on an explicit delete request; permanently_delete_document is a separate irreversible action.", z3.strictObject({ id: uuid2 }), destructive, async ({ id }) => {
|
|
1098
|
+
await required2(client2.deleteDocument, "delete_document")(id);
|
|
1099
|
+
return { id, deleted: true };
|
|
1100
|
+
});
|
|
1101
|
+
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", [
|
|
1102
|
+
z3.strictObject({ kind: z3.literal("folders").describe("Select the folders operation explicitly."), parentId: uuid2.optional() }),
|
|
1103
|
+
z3.strictObject({ kind: z3.literal("categories").describe("Select the categories operation explicitly.") }),
|
|
1104
|
+
z3.strictObject({ kind: z3.literal("tags").describe("Select the tags operation explicitly.") })
|
|
1105
|
+
]), read, async (input) => {
|
|
1106
|
+
if (input.kind === "folders")
|
|
1107
|
+
return { operation: "folders", result: await client2.listFolders({ parentId: input.parentId }) };
|
|
1108
|
+
if (input.kind === "categories")
|
|
1109
|
+
return { operation: "categories", result: await client2.listCategories() };
|
|
1110
|
+
return { operation: "tags", result: await client2.listTags() };
|
|
1111
|
+
});
|
|
1112
|
+
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", [
|
|
1113
|
+
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.") }),
|
|
1114
|
+
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)
|
|
1115
|
+
]), destructive, async (input) => {
|
|
1116
|
+
if (input.action === "create") {
|
|
1117
|
+
const { action: _action2, ...data2 } = input;
|
|
1118
|
+
return { operation: "create", result: await client2.createFolder(data2) };
|
|
1119
|
+
}
|
|
1120
|
+
const { action: _action, id, ...data } = input;
|
|
1121
|
+
return { operation: "update", result: await required2(client2.updateFolder, "update_folder")(id, data) };
|
|
1122
|
+
});
|
|
1123
|
+
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 }) => {
|
|
1124
|
+
await required2(client2.deleteFolder, "delete_folder")(id);
|
|
1125
|
+
return { id, deleted: true };
|
|
1126
|
+
});
|
|
1127
|
+
register("save_category", "Create or update a workspace category. Full workspace write access is required; category-scoped credentials cannot manage categories.", z3.discriminatedUnion("action", [
|
|
1128
|
+
z3.strictObject({ action: z3.literal("create").describe("Select the create operation explicitly."), name: text.max(255) }),
|
|
1129
|
+
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)
|
|
1130
|
+
]), destructive, async (input) => {
|
|
1131
|
+
if (input.action === "create")
|
|
1132
|
+
return { operation: "create", result: await client2.createCategory({ name: input.name }) };
|
|
1133
|
+
const { action: _action, id, ...data } = input;
|
|
1134
|
+
return { operation: "update", result: await required2(client2.updateCategory, "update_category")(id, data) };
|
|
1135
|
+
});
|
|
1136
|
+
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 }) => {
|
|
1137
|
+
await required2(client2.deleteCategory, "delete_category")(id);
|
|
1138
|
+
return { id, deleted: true };
|
|
1139
|
+
});
|
|
1140
|
+
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", [
|
|
1141
|
+
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.") }),
|
|
1142
|
+
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)
|
|
1143
|
+
]), destructive, async (input) => {
|
|
1144
|
+
if (input.action === "create")
|
|
1145
|
+
return { operation: "create", result: await required2(client2.createTag, "create_tag")({ name: input.name, color: input.color }) };
|
|
1146
|
+
const { action: _action, id, ...data } = input;
|
|
1147
|
+
return { operation: "update", result: await required2(client2.updateTag, "update_tag")(id, data) };
|
|
1148
|
+
});
|
|
1149
|
+
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 }) => {
|
|
1150
|
+
await required2(client2.deleteTag, "delete_tag")(id);
|
|
1151
|
+
return { id, deleted: true };
|
|
1152
|
+
});
|
|
1153
|
+
register("set_document_tag", "Add or remove one existing tag assignment on a readable document. Requires edit access to that 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 }) => {
|
|
1154
|
+
if (action === "add") {
|
|
1155
|
+
await required2(client2.addTagToDocument, "add_tag_to_document")(documentId, tagId);
|
|
1156
|
+
return { operation: "add", result: { documentId, tagId, assigned: true } };
|
|
1157
|
+
}
|
|
1158
|
+
await required2(client2.removeTagFromDocument, "remove_tag_from_document")(documentId, tagId);
|
|
1159
|
+
return { operation: "remove", result: { documentId, tagId, removed: true } };
|
|
1160
|
+
});
|
|
1161
|
+
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 }));
|
|
1162
|
+
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));
|
|
1163
|
+
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", [
|
|
1164
|
+
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.") }),
|
|
1165
|
+
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.") })
|
|
1166
|
+
]), read, async (input) => input.mode === "neighbors" ? { operation: "neighbors", result: await client2.getRelatedDocuments(input.documentId, input.limit) } : { operation: "search", result: await client2.searchGraph(input) });
|
|
1167
|
+
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));
|
|
1168
|
+
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.", z3.strictObject({ documentId: uuid2 }), write, async ({ documentId }) => client2.refreshDocumentIndex(documentId));
|
|
1169
|
+
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")());
|
|
1170
|
+
register("restore_trashed_document", "Return one soft-deleted document to the active library. 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));
|
|
1171
|
+
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 }) => {
|
|
1172
|
+
await required2(client2.permanentlyDeleteDocument, "permanently_delete_document")(id);
|
|
1173
|
+
return { id, deleted: true };
|
|
1174
|
+
});
|
|
1175
|
+
registerBatchAndWorkspaceCapabilities(server, client2, wrap);
|
|
1176
|
+
}
|
|
1367
1177
|
|
|
1368
|
-
// ../mcp-server/src/
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1178
|
+
// ../mcp-server/src/prompts-resources.ts
|
|
1179
|
+
import { z as z4 } from "zod";
|
|
1180
|
+
function registerPromptsAndResources(server, client2) {
|
|
1181
|
+
server.registerPrompt("organize_workspace", {
|
|
1182
|
+
description: "Plan safe document organization using DocsMint categories and folders.",
|
|
1183
|
+
argsSchema: z4.object({
|
|
1184
|
+
objective: z4.string(),
|
|
1185
|
+
language: z4.string().optional()
|
|
1186
|
+
})
|
|
1187
|
+
}, ({ objective, language }) => ({
|
|
1188
|
+
messages: [
|
|
1189
|
+
{
|
|
1190
|
+
role: "user",
|
|
1191
|
+
content: {
|
|
1192
|
+
type: "text",
|
|
1193
|
+
text: `Organize this DocsMint workspace for: ${objective}. Work in ${language ?? "the document language"}. Inspect categories, folders, tags, and documents before proposing or applying changes. Preserve document content and obey the API key scope.`
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
]
|
|
1197
|
+
}));
|
|
1198
|
+
server.registerPrompt("research_workspace", {
|
|
1199
|
+
description: "Research a question with hybrid search and GraphRAG while citing DocsMint document IDs.",
|
|
1200
|
+
argsSchema: z4.object({
|
|
1201
|
+
question: z4.string(),
|
|
1202
|
+
language: z4.string().optional()
|
|
1203
|
+
})
|
|
1204
|
+
}, ({ question, language }) => ({
|
|
1205
|
+
messages: [
|
|
1206
|
+
{
|
|
1207
|
+
role: "user",
|
|
1208
|
+
content: {
|
|
1209
|
+
type: "text",
|
|
1210
|
+
text: `Answer this question from DocsMint: ${question}. Respond in ${language ?? "the question language"}. Start with hybrid search, use graph traversal only from authorized result documents, and cite document IDs. Distinguish retrieved facts from inference.`
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
]
|
|
1214
|
+
}));
|
|
1215
|
+
server.registerResource("editor-guide", "docsmint://guide/editor", {}, async (uri) => ({
|
|
1216
|
+
contents: [
|
|
1217
|
+
{
|
|
1218
|
+
uri: uri.href,
|
|
1219
|
+
mimeType: "text/markdown",
|
|
1220
|
+
text: `# DocsMint editing rules
|
|
1390
1221
|
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
description: "List folders readable in the active workspace/category. Omit parentId to list root folders, or supply a parent UUID to list its immediate children as a flat list. Use create_folder to add a folder.",
|
|
1402
|
-
inputSchema: {
|
|
1403
|
-
parentId: z11.string().uuid().optional().describe("Optional parent folder UUID from list_folders; omit to list root folders.")
|
|
1404
|
-
}
|
|
1405
|
-
};
|
|
1406
|
-
var createHandler7 = (api) => async function listFolders(args) {
|
|
1407
|
-
return await api.listFolders(args);
|
|
1408
|
-
};
|
|
1409
|
-
var handler7 = createHandler7(client);
|
|
1222
|
+
Read a document before updating it. Preserve its language, title intent, TipTap/Markdown structure, category, folder, and tags unless the user explicitly requests a change. After content changes, verify index status and request refresh only when needed.`
|
|
1223
|
+
}
|
|
1224
|
+
]
|
|
1225
|
+
}));
|
|
1226
|
+
server.registerResource("search-guide", "docsmint://guide/search", {}, async (uri) => ({
|
|
1227
|
+
contents: [
|
|
1228
|
+
{
|
|
1229
|
+
uri: uri.href,
|
|
1230
|
+
mimeType: "text/markdown",
|
|
1231
|
+
text: `# DocsMint retrieval rules
|
|
1410
1232
|
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
return await api.search({
|
|
1431
|
-
query: args.query,
|
|
1432
|
-
folder: args.folder,
|
|
1433
|
-
tags: args.tags,
|
|
1434
|
-
limit: args.limit
|
|
1233
|
+
Use find_documents(mode=search) for normal retrieval. Use explore_graph only with document IDs already authorized by the active API key. Keep multilingual queries in their original language and cite document IDs in answers.`
|
|
1234
|
+
}
|
|
1235
|
+
]
|
|
1236
|
+
}));
|
|
1237
|
+
server.registerResource("workspace-catalog", "docsmint://workspace/catalog", {}, async (uri) => {
|
|
1238
|
+
const [categories, folders, tags] = await Promise.all([
|
|
1239
|
+
client2.listCategories(),
|
|
1240
|
+
client2.listFolders({}),
|
|
1241
|
+
client2.listTags()
|
|
1242
|
+
]);
|
|
1243
|
+
return {
|
|
1244
|
+
contents: [
|
|
1245
|
+
{
|
|
1246
|
+
uri: uri.href,
|
|
1247
|
+
mimeType: "application/json",
|
|
1248
|
+
text: JSON.stringify({ categories, folders, tags }, null, 2)
|
|
1249
|
+
}
|
|
1250
|
+
]
|
|
1251
|
+
};
|
|
1435
1252
|
});
|
|
1436
|
-
}
|
|
1437
|
-
var handler8 = createHandler8(client);
|
|
1438
|
-
|
|
1439
|
-
// ../mcp-server/src/tools/update-document.ts
|
|
1440
|
-
var exports_update_document = {};
|
|
1441
|
-
__export(exports_update_document, {
|
|
1442
|
-
createHandler: () => createHandler9,
|
|
1443
|
-
definition: () => definition9,
|
|
1444
|
-
handler: () => handler9
|
|
1445
|
-
});
|
|
1446
|
-
import { z as z13 } from "zod";
|
|
1447
|
-
var definition9 = {
|
|
1448
|
-
name: "update_document",
|
|
1449
|
-
description: "Modify an existing document by UUID after reading its current state. Omitted fields remain unchanged; null folderId removes folder placement and null categoryId clears the explicit category, while a categorized folder can still supply the effective category. Changing title or Markdown content requires edit access, while moving placement requires write access in the active workspace/category. The server stores the prior content in version history and queues indexing when content or placement changes. Returns the updated document. Use create_document for new content.",
|
|
1450
|
-
inputSchema: {
|
|
1451
|
-
id: z13.string().uuid().describe("UUID of the existing document, obtained from search_documents, list_documents, or get_document."),
|
|
1452
|
-
title: z13.string().min(1).max(500).optional().describe("Optional replacement title, 1 to 500 characters; omit to leave the current title unchanged."),
|
|
1453
|
-
content: z13.string().optional().describe("New markdown content for the document."),
|
|
1454
|
-
folderId: z13.string().uuid().nullable().optional().describe("Optional destination folder UUID from list_folders; omit to keep current placement or pass null to remove folder placement."),
|
|
1455
|
-
categoryId: z13.string().uuid().nullable().optional().describe("Optional destination category UUID from list_categories; omit to keep the explicit category or pass null to clear it. A categorized folder may still supply the effective category. Category-scoped credentials cannot move outside their configured category.")
|
|
1456
|
-
}
|
|
1457
|
-
};
|
|
1458
|
-
var createHandler9 = (api) => async function updateDocument(args) {
|
|
1459
|
-
const { id, ...patch } = args;
|
|
1460
|
-
return await api.updateDocument(id, patch);
|
|
1461
|
-
};
|
|
1462
|
-
var handler9 = createHandler9(client);
|
|
1253
|
+
}
|
|
1463
1254
|
|
|
1464
|
-
// ../mcp-server/src/
|
|
1465
|
-
var
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1255
|
+
// ../mcp-server/src/capabilities.ts
|
|
1256
|
+
var capabilityCatalog = {
|
|
1257
|
+
tools: [
|
|
1258
|
+
"find_documents",
|
|
1259
|
+
"read_document",
|
|
1260
|
+
"save_document",
|
|
1261
|
+
"delete_document",
|
|
1262
|
+
"list_workspace_structure",
|
|
1263
|
+
"save_folder",
|
|
1264
|
+
"delete_folder",
|
|
1265
|
+
"save_category",
|
|
1266
|
+
"delete_category",
|
|
1267
|
+
"save_tag",
|
|
1268
|
+
"delete_tag",
|
|
1269
|
+
"set_document_tag",
|
|
1270
|
+
"create_snapshot",
|
|
1271
|
+
"restore_document_version",
|
|
1272
|
+
"explore_graph",
|
|
1273
|
+
"get_document_index_status",
|
|
1274
|
+
"refresh_document_index",
|
|
1275
|
+
"list_trash",
|
|
1276
|
+
"restore_trashed_document",
|
|
1277
|
+
"permanently_delete_document",
|
|
1278
|
+
"batch_documents",
|
|
1279
|
+
"get_workspace_item"
|
|
1280
|
+
],
|
|
1281
|
+
prompts: ["organize_workspace", "research_workspace"],
|
|
1282
|
+
resources: [
|
|
1283
|
+
"docsmint://guide/editor",
|
|
1284
|
+
"docsmint://guide/search",
|
|
1285
|
+
"docsmint://workspace/catalog"
|
|
1286
|
+
]
|
|
1482
1287
|
};
|
|
1483
|
-
var handler10 = createHandler10(client);
|
|
1484
1288
|
|
|
1485
1289
|
// ../mcp-server/src/server.ts
|
|
1486
|
-
function wrapHandler(name,
|
|
1290
|
+
function wrapHandler(name, handler, outputSchema) {
|
|
1487
1291
|
return async (args) => {
|
|
1488
1292
|
try {
|
|
1489
|
-
const output = await
|
|
1293
|
+
const output = await handler(args);
|
|
1490
1294
|
const parsedOutput = outputSchema ? await outputSchema.safeParseAsync(output) : undefined;
|
|
1491
1295
|
if (parsedOutput && !parsedOutput.success) {
|
|
1492
1296
|
throw new Error(`Tool '${name}' returned a result outside its published output schema`);
|
|
@@ -1521,50 +1325,11 @@ function wrapHandler(name, handler11, outputSchema) {
|
|
|
1521
1325
|
};
|
|
1522
1326
|
}
|
|
1523
1327
|
function registerDocsmintMcpCapabilities(server, client2) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
description,
|
|
1527
|
-
inputSchema: z15.object(inputSchema),
|
|
1528
|
-
annotations: {
|
|
1529
|
-
readOnlyHint: ![
|
|
1530
|
-
"create_document",
|
|
1531
|
-
"update_document",
|
|
1532
|
-
"create_folder",
|
|
1533
|
-
"create_snapshot"
|
|
1534
|
-
].includes(name),
|
|
1535
|
-
destructiveHint: name === "update_document",
|
|
1536
|
-
idempotentHint: ![
|
|
1537
|
-
"create_document",
|
|
1538
|
-
"update_document",
|
|
1539
|
-
"create_folder",
|
|
1540
|
-
"create_snapshot"
|
|
1541
|
-
].includes(name),
|
|
1542
|
-
openWorldHint: false
|
|
1543
|
-
},
|
|
1544
|
-
outputSchema: toolOutputSchemas[name]
|
|
1545
|
-
}, wrapHandler(name, handler11, toolOutputSchemas[name]));
|
|
1546
|
-
};
|
|
1547
|
-
const tools = [
|
|
1548
|
-
exports_search,
|
|
1549
|
-
exports_get_document,
|
|
1550
|
-
exports_create_document,
|
|
1551
|
-
exports_update_document,
|
|
1552
|
-
exports_list_documents,
|
|
1553
|
-
exports_list_folders,
|
|
1554
|
-
exports_create_folder,
|
|
1555
|
-
exports_create_snapshot,
|
|
1556
|
-
exports_version_history,
|
|
1557
|
-
exports_export_document
|
|
1558
|
-
];
|
|
1559
|
-
for (const tool of tools) {
|
|
1560
|
-
register(tool.definition.name, tool.definition.description, tool.definition.inputSchema, tool.createHandler(client2));
|
|
1561
|
-
}
|
|
1562
|
-
registerExtendedCapabilities(server, client2, (name, handler11) => wrapHandler(name, handler11, toolOutputSchemas[name]));
|
|
1563
|
-
registerLifecycleCapabilities(server, client2, (name, handler11) => wrapHandler(name, handler11, toolOutputSchemas[name]));
|
|
1564
|
-
registerManagementCapabilities(server, client2, (name, handler11) => wrapHandler(name, handler11, toolOutputSchemas[name]));
|
|
1328
|
+
registerCompactCapabilities(server, client2, wrapHandler);
|
|
1329
|
+
registerPromptsAndResources(server, client2);
|
|
1565
1330
|
}
|
|
1566
1331
|
function createDocsmintMcpServer(options = {}) {
|
|
1567
|
-
const server = new McpServer({ name: "docsmint", version: "0.
|
|
1332
|
+
const server = new McpServer({ name: "docsmint", version: "1.0.1" });
|
|
1568
1333
|
const client2 = options.docsClient ? createMcpDocsClient(options.docsClient, options.requestContext) : options.client ?? createMcpDocsClient(createDefaultDocsClient(), options.requestContext);
|
|
1569
1334
|
registerDocsmintMcpCapabilities(server, client2);
|
|
1570
1335
|
return server;
|