@docrouter/mcp 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/docs/knowledge_base/prompts.md +171 -36
- package/dist/docs/knowledge_base/schemas.md +159 -0
- package/dist/index.js +136 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -159,16 +159,19 @@ var server = new index_js.Server(
|
|
|
159
159
|
}
|
|
160
160
|
);
|
|
161
161
|
var docrouterClient;
|
|
162
|
+
var docrouterAccountClient;
|
|
163
|
+
var orgToken;
|
|
162
164
|
async function initializeClient(config) {
|
|
163
165
|
try {
|
|
164
166
|
console.error("Resolving organization ID from token...");
|
|
165
|
-
|
|
167
|
+
docrouterAccountClient = new sdk.DocRouterAccount({
|
|
166
168
|
baseURL: config.baseURL,
|
|
167
169
|
accountToken: config.orgToken,
|
|
168
170
|
timeout: config.timeout,
|
|
169
171
|
retries: config.retries
|
|
170
172
|
});
|
|
171
|
-
|
|
173
|
+
orgToken = config.orgToken;
|
|
174
|
+
const tokenResponse = await docrouterAccountClient.getOrganizationFromToken(config.orgToken);
|
|
172
175
|
const organizationId = tokenResponse.organization_id;
|
|
173
176
|
if (!organizationId) {
|
|
174
177
|
throw new Error("Token is an account-level token, not an organization-specific token. Please use an organization API token.");
|
|
@@ -565,7 +568,7 @@ var tools = [
|
|
|
565
568
|
// ========== DOCUMENTS ==========
|
|
566
569
|
{
|
|
567
570
|
name: "upload_documents",
|
|
568
|
-
description: "Upload documents to DocRouter",
|
|
571
|
+
description: "Upload documents to DocRouter from file paths",
|
|
569
572
|
inputSchema: {
|
|
570
573
|
type: "object",
|
|
571
574
|
properties: {
|
|
@@ -575,12 +578,12 @@ var tools = [
|
|
|
575
578
|
items: {
|
|
576
579
|
type: "object",
|
|
577
580
|
properties: {
|
|
578
|
-
|
|
579
|
-
|
|
581
|
+
file_path: { type: "string", description: "Path to the document file on disk" },
|
|
582
|
+
name: { type: "string", description: "Document name (optional, defaults to filename)" },
|
|
580
583
|
tag_ids: { type: "array", items: { type: "string" }, description: "Optional list of tag IDs" },
|
|
581
584
|
metadata: { type: "object", description: "Optional metadata" }
|
|
582
585
|
},
|
|
583
|
-
required: ["
|
|
586
|
+
required: ["file_path"]
|
|
584
587
|
}
|
|
585
588
|
}
|
|
586
589
|
},
|
|
@@ -603,12 +606,13 @@ var tools = [
|
|
|
603
606
|
},
|
|
604
607
|
{
|
|
605
608
|
name: "get_document",
|
|
606
|
-
description: "Get document
|
|
609
|
+
description: "Get document metadata (state, tags, metadata) and optionally download the file to disk",
|
|
607
610
|
inputSchema: {
|
|
608
611
|
type: "object",
|
|
609
612
|
properties: {
|
|
610
613
|
documentId: { type: "string", description: "ID of the document to retrieve" },
|
|
611
|
-
fileType: { type: "string", description: "File type to retrieve (
|
|
614
|
+
fileType: { type: "string", description: "File type to retrieve (original or pdf)", default: "original" },
|
|
615
|
+
save_path: { type: "string", description: "Optional file path or directory to save the document. If directory, uses original filename. If not provided, file is not downloaded." }
|
|
612
616
|
},
|
|
613
617
|
required: ["documentId"]
|
|
614
618
|
}
|
|
@@ -945,9 +949,12 @@ var tools = [
|
|
|
945
949
|
type: "object",
|
|
946
950
|
properties: {
|
|
947
951
|
promptId: { type: "string", description: "ID of the prompt" },
|
|
948
|
-
content: { type: "string", description: "Prompt content" }
|
|
952
|
+
content: { type: "string", description: "Prompt content" },
|
|
953
|
+
model: { type: "string", description: "LLM model to use" },
|
|
954
|
+
schema_id: { type: "string", description: "Schema ID to link" },
|
|
955
|
+
tag_ids: { type: "array", items: { type: "string" }, description: "Tag IDs that trigger this prompt" }
|
|
949
956
|
},
|
|
950
|
-
required: ["promptId"
|
|
957
|
+
required: ["promptId"]
|
|
951
958
|
}
|
|
952
959
|
},
|
|
953
960
|
{
|
|
@@ -1081,6 +1088,22 @@ var tools = [
|
|
|
1081
1088
|
required: ["messages", "model"]
|
|
1082
1089
|
}
|
|
1083
1090
|
},
|
|
1091
|
+
{
|
|
1092
|
+
name: "get_organization",
|
|
1093
|
+
description: "Get information about the current organization (name, type, ID)",
|
|
1094
|
+
inputSchema: {
|
|
1095
|
+
type: "object",
|
|
1096
|
+
properties: {}
|
|
1097
|
+
}
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
name: "list_llm_models",
|
|
1101
|
+
description: "List enabled LLM models available for use in prompts for this organization",
|
|
1102
|
+
inputSchema: {
|
|
1103
|
+
type: "object",
|
|
1104
|
+
properties: {}
|
|
1105
|
+
}
|
|
1106
|
+
},
|
|
1084
1107
|
// ========== HELPER TOOLS ==========
|
|
1085
1108
|
{
|
|
1086
1109
|
name: "help",
|
|
@@ -1142,21 +1165,57 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
|
|
|
1142
1165
|
};
|
|
1143
1166
|
}
|
|
1144
1167
|
case "get_document": {
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
|
|
1168
|
+
const documentId = getArg(args, "documentId");
|
|
1169
|
+
const fileType = getArg(args, "fileType", "original");
|
|
1170
|
+
const savePath = getOptionalArg(args, "save_path");
|
|
1171
|
+
const fileResult = await docrouterClient.getDocument({
|
|
1172
|
+
documentId,
|
|
1173
|
+
fileType
|
|
1148
1174
|
});
|
|
1149
|
-
const
|
|
1175
|
+
const response = {
|
|
1176
|
+
id: fileResult.id,
|
|
1177
|
+
pdf_id: fileResult.pdf_id,
|
|
1178
|
+
document_name: fileResult.document_name,
|
|
1179
|
+
upload_date: fileResult.upload_date,
|
|
1180
|
+
uploaded_by: fileResult.uploaded_by,
|
|
1181
|
+
state: fileResult.state,
|
|
1182
|
+
tag_ids: fileResult.tag_ids,
|
|
1183
|
+
type: fileResult.type,
|
|
1184
|
+
metadata: fileResult.metadata
|
|
1185
|
+
};
|
|
1186
|
+
if (savePath) {
|
|
1187
|
+
let finalPath;
|
|
1188
|
+
if (path.isAbsolute(savePath)) {
|
|
1189
|
+
finalPath = savePath;
|
|
1190
|
+
} else {
|
|
1191
|
+
finalPath = path.resolve(process.cwd(), savePath);
|
|
1192
|
+
}
|
|
1193
|
+
let isDirectory = false;
|
|
1194
|
+
try {
|
|
1195
|
+
const stats = fs.statSync(finalPath);
|
|
1196
|
+
isDirectory = stats.isDirectory();
|
|
1197
|
+
} catch {
|
|
1198
|
+
isDirectory = savePath.endsWith("/") || savePath.endsWith("\\");
|
|
1199
|
+
}
|
|
1200
|
+
if (isDirectory) {
|
|
1201
|
+
const extension = fileType === "pdf" ? ".pdf" : path.extname(fileResult.document_name) || ".pdf";
|
|
1202
|
+
const fileName = path.basename(fileResult.document_name, path.extname(fileResult.document_name)) + extension;
|
|
1203
|
+
finalPath = path.join(finalPath, fileName);
|
|
1204
|
+
}
|
|
1205
|
+
const targetDir = path.dirname(finalPath);
|
|
1206
|
+
if (!fs.existsSync(targetDir)) {
|
|
1207
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
1208
|
+
}
|
|
1209
|
+
const fileBuffer = Buffer.from(fileResult.content);
|
|
1210
|
+
fs.writeFileSync(finalPath, fileBuffer);
|
|
1211
|
+
response.saved_path = finalPath;
|
|
1212
|
+
response.file_size = fileBuffer.length;
|
|
1213
|
+
}
|
|
1150
1214
|
return {
|
|
1151
1215
|
content: [
|
|
1152
1216
|
{
|
|
1153
1217
|
type: "text",
|
|
1154
|
-
text: JSON.stringify(
|
|
1155
|
-
...serializeDates(result),
|
|
1156
|
-
content: base64Content,
|
|
1157
|
-
content_type: "base64",
|
|
1158
|
-
content_size: result.content.byteLength
|
|
1159
|
-
}, null, 2)
|
|
1218
|
+
text: JSON.stringify(response, null, 2)
|
|
1160
1219
|
}
|
|
1161
1220
|
]
|
|
1162
1221
|
};
|
|
@@ -1279,7 +1338,28 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
|
|
|
1279
1338
|
// ========== DOCUMENTS ==========
|
|
1280
1339
|
case "upload_documents": {
|
|
1281
1340
|
const documentsInput = getArg(args, "documents");
|
|
1282
|
-
const
|
|
1341
|
+
const documents = [];
|
|
1342
|
+
for (const doc of documentsInput) {
|
|
1343
|
+
let filePath;
|
|
1344
|
+
if (path.isAbsolute(doc.file_path)) {
|
|
1345
|
+
filePath = doc.file_path;
|
|
1346
|
+
} else {
|
|
1347
|
+
filePath = path.resolve(process.cwd(), doc.file_path);
|
|
1348
|
+
}
|
|
1349
|
+
if (!fs.existsSync(filePath)) {
|
|
1350
|
+
throw new Error(`File not found: ${filePath}`);
|
|
1351
|
+
}
|
|
1352
|
+
const fileBuffer = fs.readFileSync(filePath);
|
|
1353
|
+
const base64Content = fileBuffer.toString("base64");
|
|
1354
|
+
const fileName = doc.name || filePath.split(/[/\\]/).pop() || "document";
|
|
1355
|
+
documents.push({
|
|
1356
|
+
name: fileName,
|
|
1357
|
+
content: base64Content,
|
|
1358
|
+
tag_ids: doc.tag_ids,
|
|
1359
|
+
metadata: doc.metadata
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
const result = await docrouterClient.uploadDocuments({ documents });
|
|
1283
1363
|
return {
|
|
1284
1364
|
content: [
|
|
1285
1365
|
{
|
|
@@ -1534,7 +1614,10 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
|
|
|
1534
1614
|
}
|
|
1535
1615
|
case "update_prompt": {
|
|
1536
1616
|
const promptId = getArg(args, "promptId");
|
|
1537
|
-
const content =
|
|
1617
|
+
const content = getOptionalArg(args, "content");
|
|
1618
|
+
const model = getOptionalArg(args, "model");
|
|
1619
|
+
const schema_id = getOptionalArg(args, "schema_id");
|
|
1620
|
+
const tag_ids = getOptionalArg(args, "tag_ids");
|
|
1538
1621
|
let currentPrompt = null;
|
|
1539
1622
|
const allPrompts = await docrouterClient.listPrompts({});
|
|
1540
1623
|
for (const p of allPrompts.prompts) {
|
|
@@ -1550,11 +1633,11 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
|
|
|
1550
1633
|
promptId,
|
|
1551
1634
|
prompt: {
|
|
1552
1635
|
name: currentPrompt.name,
|
|
1553
|
-
content,
|
|
1554
|
-
schema_id: currentPrompt.schema_id,
|
|
1636
|
+
content: content ?? currentPrompt.content,
|
|
1637
|
+
schema_id: schema_id ?? currentPrompt.schema_id,
|
|
1555
1638
|
schema_version: currentPrompt.schema_version,
|
|
1556
|
-
tag_ids: currentPrompt.tag_ids,
|
|
1557
|
-
model: currentPrompt.model
|
|
1639
|
+
tag_ids: tag_ids ?? currentPrompt.tag_ids,
|
|
1640
|
+
model: model ?? currentPrompt.model
|
|
1558
1641
|
}
|
|
1559
1642
|
});
|
|
1560
1643
|
return {
|
|
@@ -1739,6 +1822,28 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
|
|
|
1739
1822
|
]
|
|
1740
1823
|
};
|
|
1741
1824
|
}
|
|
1825
|
+
case "get_organization": {
|
|
1826
|
+
const result = await docrouterAccountClient.getOrganizationFromToken(orgToken);
|
|
1827
|
+
return {
|
|
1828
|
+
content: [
|
|
1829
|
+
{
|
|
1830
|
+
type: "text",
|
|
1831
|
+
text: JSON.stringify(serializeDates(result), null, 2)
|
|
1832
|
+
}
|
|
1833
|
+
]
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
case "list_llm_models": {
|
|
1837
|
+
const result = await docrouterClient.listLLMModels();
|
|
1838
|
+
return {
|
|
1839
|
+
content: [
|
|
1840
|
+
{
|
|
1841
|
+
type: "text",
|
|
1842
|
+
text: JSON.stringify(serializeDates(result), null, 2)
|
|
1843
|
+
}
|
|
1844
|
+
]
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1742
1847
|
// ========== HELPER TOOLS ==========
|
|
1743
1848
|
case "help": {
|
|
1744
1849
|
const helpText = `
|
|
@@ -1749,7 +1854,7 @@ This server provides access to DocRouter resources and tools.
|
|
|
1749
1854
|
## Available Tools
|
|
1750
1855
|
|
|
1751
1856
|
### Documents
|
|
1752
|
-
- \`upload_documents(documents)\` - Upload documents
|
|
1857
|
+
- \`upload_documents(documents)\` - Upload documents from file paths
|
|
1753
1858
|
- \`list_documents(skip, limit, tagIds, nameSearch, metadataSearch)\` - List documents
|
|
1754
1859
|
- \`get_document(documentId, fileType)\` - Get document by ID
|
|
1755
1860
|
- \`update_document(documentId, documentName, tagIds, metadata)\` - Update document
|
|
@@ -1803,6 +1908,10 @@ This server provides access to DocRouter resources and tools.
|
|
|
1803
1908
|
### LLM Chat
|
|
1804
1909
|
- \`run_llm_chat(messages, model, temperature, max_tokens, stream)\` - Run chat
|
|
1805
1910
|
|
|
1911
|
+
### Organization
|
|
1912
|
+
- \`get_organization()\` - Get information about the current organization (name, type, ID)
|
|
1913
|
+
- \`list_llm_models()\` - List enabled LLM models available for use in prompts
|
|
1914
|
+
|
|
1806
1915
|
### Help Tools
|
|
1807
1916
|
- \`help()\` - Get general API help information
|
|
1808
1917
|
- \`help_prompts()\` - Get detailed help on creating and configuring prompts
|