Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/tools/correspondents.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp";
import { z } from "zod";
import { toTextResult } from "./result";

export function registerCorrespondentTools(server: McpServer, api) {
server.tool(
"list_correspondents",
"Retrieve all available correspondents (people, companies, organizations that send/receive documents). Returns names and automatic matching patterns for document assignment.",
{ }, async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.getCorrespondents();
return toTextResult(await api.getCorrespondents());
});

server.tool(
Expand All @@ -22,7 +23,7 @@ export function registerCorrespondentTools(server: McpServer, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.createCorrespondent(args);
return toTextResult(await api.createCorrespondent(args));
}
);

Expand All @@ -49,17 +50,19 @@ export function registerCorrespondentTools(server: McpServer, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.bulkEditObjects(
args.correspondent_ids,
"correspondents",
args.operation,
args.operation === "set_permissions"
? {
owner: args.owner,
permissions: args.permissions,
merge: args.merge,
}
: {}
return toTextResult(
await api.bulkEditObjects(
args.correspondent_ids,
"correspondents",
args.operation,
args.operation === "set_permissions"
? {
owner: args.owner,
permissions: args.permissions,
merge: args.merge,
}
: {}
)
);
}
);
Expand Down
29 changes: 16 additions & 13 deletions src/tools/documentTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod";
import { toTextResult } from "./result";

export function registerDocumentTypeTools(server, api) {
server.tool(
Expand All @@ -8,7 +9,7 @@ export function registerDocumentTypeTools(server, api) {
// No parameters - returns all available document types
}, async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.getDocumentTypes();
return toTextResult(await api.getDocumentTypes());
});

server.tool(
Expand All @@ -23,7 +24,7 @@ export function registerDocumentTypeTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.createDocumentType(args);
return toTextResult(await api.createDocumentType(args));
}
);

Expand All @@ -50,17 +51,19 @@ export function registerDocumentTypeTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.bulkEditObjects(
args.document_type_ids,
"document_types",
args.operation,
args.operation === "set_permissions"
? {
owner: args.owner,
permissions: args.permissions,
merge: args.merge,
}
: {}
return toTextResult(
await api.bulkEditObjects(
args.document_type_ids,
"document_types",
args.operation,
args.operation === "set_permissions"
? {
owner: args.owner,
permissions: args.permissions,
merge: args.merge,
}
: {}
)
);
}
);
Expand Down
15 changes: 8 additions & 7 deletions src/tools/documents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod";
import { toTextResult } from "./result";

export function registerDocumentTools(server, api) {
server.tool(
Expand Down Expand Up @@ -53,7 +54,7 @@ export function registerDocumentTools(server, api) {
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
const { documents, method, ...parameters } = args;
return api.bulkEditDocuments(documents, method, parameters);
return toTextResult(await api.bulkEditDocuments(documents, method, parameters));
}
);

Expand All @@ -78,7 +79,7 @@ export function registerDocumentTools(server, api) {
const blob = new Blob([binaryData]);
const file = new File([blob], args.filename);
const { file: _, filename: __, ...metadata } = args;
return api.postDocument(file, metadata);
return toTextResult(await api.postDocument(file, metadata));
}
);

Expand All @@ -91,7 +92,7 @@ export function registerDocumentTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.getDocument(args.id);
return toTextResult(await api.getDocument(args.id));
}
);

Expand All @@ -114,7 +115,7 @@ export function registerDocumentTools(server, api) {
if (Object.keys(data).length === 0) {
throw new Error("At least one field must be provided to update.");
}
return api.updateDocument(id, data);
return toTextResult(await api.updateDocument(id, data));
}
);

Expand All @@ -128,7 +129,7 @@ export function registerDocumentTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.searchDocuments(args.query, args.page, args.page_size);
return toTextResult(await api.searchDocuments(args.query, args.page, args.page_size));
}
);

Expand All @@ -142,14 +143,14 @@ export function registerDocumentTools(server, api) {
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
const response = await api.downloadDocument(args.id, args.original);
return {
return toTextResult({
blob: Buffer.from(await response.arrayBuffer()).toString("base64"),
filename:
response.headers
.get("content-disposition")
?.split("filename=")[1]
?.replace(/"/g, "") || `document-${args.id}`,
};
});
}
);
}
7 changes: 7 additions & 0 deletions src/tools/result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function toTextResult(data: unknown) {
return {
content: [
{ type: "text" as const, text: JSON.stringify(data, null, 2) },
],
};
}
33 changes: 18 additions & 15 deletions src/tools/tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod";
import { toTextResult } from "./result";

export function registerTagTools(server, api) {
server.tool(
Expand All @@ -8,7 +9,7 @@ export function registerTagTools(server, api) {
// No parameters - returns all available tags
}, async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.getTags();
return toTextResult(await api.getTags());
});

server.tool(
Expand All @@ -25,7 +26,7 @@ export function registerTagTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.createTag(args);
return toTextResult(await api.createTag(args));
}
);

Expand All @@ -44,7 +45,7 @@ export function registerTagTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.updateTag(args.id, args);
return toTextResult(await api.updateTag(args.id, args));
}
);

Expand All @@ -56,7 +57,7 @@ export function registerTagTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.deleteTag(args.id);
return toTextResult(await api.deleteTag(args.id));
}
);

Expand All @@ -83,17 +84,19 @@ export function registerTagTools(server, api) {
},
async (args, extra) => {
if (!api) throw new Error("Please configure API connection first");
return api.bulkEditObjects(
args.tag_ids,
"tags",
args.operation,
args.operation === "set_permissions"
? {
owner: args.owner,
permissions: args.permissions,
merge: args.merge,
}
: {}
return toTextResult(
await api.bulkEditObjects(
args.tag_ids,
"tags",
args.operation,
args.operation === "set_permissions"
? {
owner: args.owner,
permissions: args.permissions,
merge: args.merge,
}
: {}
)
);
}
);
Expand Down