@docrouter/mcp 0.2.1 → 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.
@@ -762,13 +762,172 @@ Include clear descriptions that explain:
762
762
 
763
763
  DocRouter provides multiple ways to interact with schemas programmatically:
764
764
 
765
- - **TypeScript/JavaScript SDK** - Type-safe client library for Node.js and browsers (see `packages/typescript/docrouter-sdk/`)
766
- - **Python SDK** - Type-safe Python client library (see `packages/docrouter_sdk/`)
765
+ - **TypeScript/JavaScript SDK** - Type-safe client library for Node.js and browsers (see `packages/typescript/sdk/`)
766
+ - **Python SDK** - Type-safe Python client library (see `packages/python/sdk/`)
767
767
  - **REST API** - Direct HTTP requests (see API documentation for endpoints)
768
768
  - **MCP (Model Context Protocol)** - Integration with AI assistants like Claude Code
769
769
 
770
770
  All methods support the same schema operations: create, list, retrieve, update, delete, and validate against schemas.
771
771
 
772
+ ### MCP Tool Examples
773
+
774
+ #### create_schema
775
+
776
+ Creates a new schema. Requires `name` and `response_format` parameters.
777
+
778
+ ```
779
+ create_schema(
780
+ name: "Invoice Extraction",
781
+ response_format: {
782
+ "type": "json_schema",
783
+ "json_schema": {
784
+ "name": "document_extraction",
785
+ "schema": { ... }, // See schema format above
786
+ "strict": true
787
+ }
788
+ }
789
+ )
790
+ ```
791
+
792
+ **Parameters:**
793
+ - `name` (string, required): Human-readable name for the schema
794
+ - `response_format` (object, required): The schema definition following the format documented above
795
+
796
+ **Returns:** Created schema object with `schema_id`, `schema_revid`, and `schema_version`
797
+
798
+ #### list_schemas
799
+
800
+ Lists all schemas with optional filtering.
801
+
802
+ ```
803
+ list_schemas(skip: 0, limit: 10, nameSearch: "Invoice")
804
+ ```
805
+
806
+ **Parameters:**
807
+ - `skip` (number, optional): Number of schemas to skip (default: 0)
808
+ - `limit` (number, optional): Number of schemas to return (default: 10)
809
+ - `nameSearch` (string, optional): Filter schemas by name
810
+
811
+ **Returns:** Object with `schemas` array and `total` count
812
+
813
+ #### get_schema
814
+
815
+ Retrieves a specific schema by its revision ID.
816
+
817
+ ```
818
+ get_schema(schemaRevId: "696c4a89fc1c7a2d00322b95")
819
+ ```
820
+
821
+ **Parameters:**
822
+ - `schemaRevId` (string, required): The schema revision ID
823
+
824
+ **Returns:** Full schema object including `name`, `response_format`, `schema_id`, `schema_revid`, `schema_version`
825
+
826
+ #### update_schema
827
+
828
+ Updates an existing schema. Creates a new version while preserving history. You can update just the name, just the response_format, or both. Fields not provided will be preserved from the current schema.
829
+
830
+ ```
831
+ # Update only the name (does not create a new version)
832
+ update_schema(
833
+ schemaId: "696c4a89fc1c7a2d00322b95",
834
+ schema: {
835
+ "name": "Invoice Extraction v2"
836
+ }
837
+ )
838
+
839
+ # Update only the response_format
840
+ update_schema(
841
+ schemaId: "696c4a89fc1c7a2d00322b95",
842
+ schema: {
843
+ "response_format": {
844
+ "type": "json_schema",
845
+ "json_schema": {
846
+ "name": "document_extraction",
847
+ "schema": { ... }, // See schema format above
848
+ "strict": true
849
+ }
850
+ }
851
+ }
852
+ )
853
+
854
+ # Update both name and response_format
855
+ update_schema(
856
+ schemaId: "696c4a89fc1c7a2d00322b95",
857
+ schema: {
858
+ "name": "Invoice Extraction",
859
+ "response_format": {
860
+ "type": "json_schema",
861
+ "json_schema": {
862
+ "name": "document_extraction",
863
+ "schema": { ... }, // See schema format above
864
+ "strict": true
865
+ }
866
+ }
867
+ }
868
+ )
869
+ ```
870
+
871
+ **Parameters:**
872
+ - `schemaId` (string, required): The schema ID (not revision ID) to update
873
+ - `schema` (object, required): Object containing:
874
+ - `name` (string, optional): New name for the schema (if omitted, current name is preserved)
875
+ - `response_format` (object, optional): The updated schema definition (if omitted, current response_format is preserved)
876
+
877
+ **Returns:** Updated schema object. Note: Updating only the name does not create a new version (same `schema_revid` and `schema_version`). Updating `response_format` creates a new version with incremented `schema_version`.
878
+
879
+ #### delete_schema
880
+
881
+ Deletes a schema and all its versions.
882
+
883
+ ```
884
+ delete_schema(schemaId: "696c4a89fc1c7a2d00322b95")
885
+ ```
886
+
887
+ **Parameters:**
888
+ - `schemaId` (string, required): The schema ID to delete
889
+
890
+ **Returns:** Confirmation of deletion
891
+
892
+ #### validate_schema
893
+
894
+ Validates a schema format without creating it. Useful for checking correctness before creating/updating.
895
+
896
+ ```
897
+ validate_schema(
898
+ schema: '{"type": "json_schema", "json_schema": {...}}' // JSON string
899
+ )
900
+ ```
901
+
902
+ **Parameters:**
903
+ - `schema` (string, required): JSON string of the schema to validate
904
+
905
+ **Returns:** Object with `valid` (boolean), `errors` (array), and `warnings` (array)
906
+
907
+ ### Common Workflow
908
+
909
+ ```
910
+ # 1. Create a new schema
911
+ create_schema(name: "Purchase Order", response_format: { ... })
912
+ # Returns: { schema_id: "abc123", schema_revid: "abc123", schema_version: 1 }
913
+
914
+ # 2. List schemas to find the one you need
915
+ list_schemas(nameSearch: "Purchase")
916
+ # Returns: { schemas: [...], total: 1 }
917
+
918
+ # 3. Get full schema details
919
+ get_schema(schemaRevId: "abc123")
920
+ # Returns: Full schema object
921
+
922
+ # 4. Update the schema to add a new field
923
+ update_schema(schemaId: "abc123", schema: { "name": "Purchase Order", "response_format": { ... } })
924
+ # Returns: { schema_id: "abc123", schema_revid: "def456", schema_version: 2 }
925
+
926
+ # 5. Delete the schema when no longer needed
927
+ delete_schema(schemaId: "abc123")
928
+ # Returns: Deletion confirmation
929
+ ```
930
+
772
931
  ---
773
932
 
774
933
  ## Schema Workflow
package/dist/index.js CHANGED
@@ -19,11 +19,36 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
19
19
  });
20
20
  var ConfigSchema = zod.z.object({
21
21
  baseURL: zod.z.string().default("https://app.docrouter.ai/fastapi"),
22
- organizationId: zod.z.string(),
23
22
  orgToken: zod.z.string(),
24
23
  timeout: zod.z.number().default(3e4),
25
24
  retries: zod.z.number().default(3)
26
25
  });
26
+ function resolveKnowledgeBasePath(filename) {
27
+ const currentFile = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
28
+ const currentDir = path.dirname(currentFile);
29
+ if (currentDir.endsWith("dist")) {
30
+ return path.join(currentDir, "docs/knowledge_base", filename);
31
+ }
32
+ if (currentDir.endsWith("src")) {
33
+ const distPath = path.join(currentDir, "..", "dist", "docs/knowledge_base", filename);
34
+ if (fs.existsSync(distPath)) {
35
+ return distPath;
36
+ }
37
+ throw new Error(
38
+ `Knowledge base file not found: ${filename}
39
+ Expected at: ${distPath}
40
+ Please run 'npm run build' first to generate the knowledge base files.`
41
+ );
42
+ }
43
+ const fallbackPath = path.join(currentDir, "docs/knowledge_base", filename);
44
+ if (fs.existsSync(fallbackPath)) {
45
+ return fallbackPath;
46
+ }
47
+ throw new Error(
48
+ `Knowledge base file not found: ${filename}
49
+ Searched in: ${path.join(currentDir, "docs/knowledge_base", filename)}`
50
+ );
51
+ }
27
52
  function showTools() {
28
53
  const toolNames = tools.map((tool) => tool.name).sort();
29
54
  console.log(toolNames.join("\n"));
@@ -54,8 +79,7 @@ DESCRIPTION:
54
79
  OPTIONS:
55
80
  --url <URL> DocRouter API base URL
56
81
  (default: https://app.docrouter.ai/fastapi)
57
- --org-id <ID> DocRouter organization ID
58
- --org-token <TOKEN> DocRouter organization API token
82
+ --org-token <TOKEN> DocRouter organization API token (required)
59
83
  --timeout <MS> Request timeout in milliseconds (default: 30000)
60
84
  --retries <COUNT> Number of retry attempts (default: 3)
61
85
  --tools List all supported MCP tools
@@ -64,24 +88,22 @@ OPTIONS:
64
88
 
65
89
  ENVIRONMENT VARIABLES:
66
90
  DOCROUTER_API_URL DocRouter API base URL
67
- DOCROUTER_ORG_ID DocRouter organization ID
68
- DOCROUTER_ORG_API_TOKEN DocRouter organization API token
91
+ DOCROUTER_ORG_API_TOKEN DocRouter organization API token (required)
69
92
 
70
93
  EXAMPLES:
71
- # Using command line arguments
72
- docrouter-mcp --org-id "org123" --org-token "token456"
94
+ # Using command line arguments (organization ID will be resolved from token)
95
+ docrouter-mcp --org-token "token456"
73
96
 
74
- # Using environment variables
75
- export DOCROUTER_ORG_ID="org123"
97
+ # Using environment variables (organization ID will be resolved from token)
76
98
  export DOCROUTER_ORG_API_TOKEN="token456"
77
99
  docrouter-mcp
78
100
 
79
101
  # With custom API URL
80
- docrouter-mcp --url "https://custom.docrouter.ai/fastapi" --org-id "org123" --org-token "token456"
102
+ docrouter-mcp --url "https://custom.docrouter.ai/fastapi" --org-token "token456"
81
103
 
82
104
  REQUIRED:
83
- Either provide --org-id and --org-token as command line arguments,
84
- or set DOCROUTER_ORG_ID and DOCROUTER_ORG_API_TOKEN environment variables.
105
+ DOCROUTER_ORG_API_TOKEN environment variable or --org-token argument.
106
+ Organization ID will be automatically resolved from the token.
85
107
 
86
108
  For more information about DocRouter, visit: https://docrouter.ai
87
109
  `);
@@ -109,9 +131,6 @@ function parseConfig() {
109
131
  case "url":
110
132
  config.baseURL = value;
111
133
  break;
112
- case "org-id":
113
- config.organizationId = value;
114
- break;
115
134
  case "org-token":
116
135
  config.orgToken = value;
117
136
  break;
@@ -125,7 +144,6 @@ function parseConfig() {
125
144
  }
126
145
  }
127
146
  config.baseURL = config.baseURL || process.env.DOCROUTER_API_URL || "https://app.docrouter.ai/fastapi";
128
- config.organizationId = config.organizationId || process.env.DOCROUTER_ORG_ID || "";
129
147
  config.orgToken = config.orgToken || process.env.DOCROUTER_ORG_API_TOKEN || "";
130
148
  return ConfigSchema.parse(config);
131
149
  }
@@ -141,20 +159,60 @@ var server = new index_js.Server(
141
159
  }
142
160
  );
143
161
  var docrouterClient;
144
- function initializeClient(config) {
145
- docrouterClient = new sdk.DocRouterOrg({
146
- baseURL: config.baseURL,
147
- orgToken: config.orgToken,
148
- organizationId: config.organizationId,
149
- timeout: config.timeout,
150
- retries: config.retries
151
- });
162
+ var docrouterAccountClient;
163
+ var orgToken;
164
+ async function initializeClient(config) {
165
+ try {
166
+ console.error("Resolving organization ID from token...");
167
+ docrouterAccountClient = new sdk.DocRouterAccount({
168
+ baseURL: config.baseURL,
169
+ accountToken: config.orgToken,
170
+ timeout: config.timeout,
171
+ retries: config.retries
172
+ });
173
+ orgToken = config.orgToken;
174
+ const tokenResponse = await docrouterAccountClient.getOrganizationFromToken(config.orgToken);
175
+ const organizationId = tokenResponse.organization_id;
176
+ if (!organizationId) {
177
+ throw new Error("Token is an account-level token, not an organization-specific token. Please use an organization API token.");
178
+ }
179
+ console.error(`Resolved organization ID: ${organizationId}`);
180
+ docrouterClient = new sdk.DocRouterOrg({
181
+ baseURL: config.baseURL,
182
+ orgToken: config.orgToken,
183
+ organizationId,
184
+ timeout: config.timeout,
185
+ retries: config.retries
186
+ });
187
+ } catch (error) {
188
+ throw new Error(`Failed to resolve organization ID from token: ${error instanceof Error ? error.message : "Unknown error"}`);
189
+ }
152
190
  }
153
191
  function handleError(error) {
154
192
  if (error instanceof Error) {
155
- return JSON.stringify({ error: error.message }, null, 2);
193
+ const apiError = error;
194
+ const errorObj = {
195
+ error: error.message
196
+ };
197
+ if (apiError.status !== void 0) {
198
+ errorObj.status = apiError.status;
199
+ }
200
+ if (apiError.code !== void 0) {
201
+ errorObj.code = apiError.code;
202
+ }
203
+ if (apiError.details !== void 0) {
204
+ errorObj.details = apiError.details;
205
+ }
206
+ return JSON.stringify(errorObj, null, 2);
156
207
  }
157
- return JSON.stringify({ error: "Unknown error occurred" }, null, 2);
208
+ if (typeof error === "object" && error !== null) {
209
+ try {
210
+ return JSON.stringify({ error: "Request failed", details: error }, null, 2);
211
+ } catch {
212
+ return JSON.stringify({ error: "Unknown error occurred (could not serialize)" }, null, 2);
213
+ }
214
+ }
215
+ return JSON.stringify({ error: String(error) || "Unknown error occurred" }, null, 2);
158
216
  }
159
217
  function serializeDates(obj) {
160
218
  if (obj === null || obj === void 0) {
@@ -510,7 +568,7 @@ var tools = [
510
568
  // ========== DOCUMENTS ==========
511
569
  {
512
570
  name: "upload_documents",
513
- description: "Upload documents to DocRouter",
571
+ description: "Upload documents to DocRouter from file paths",
514
572
  inputSchema: {
515
573
  type: "object",
516
574
  properties: {
@@ -520,12 +578,12 @@ var tools = [
520
578
  items: {
521
579
  type: "object",
522
580
  properties: {
523
- name: { type: "string", description: "Document name" },
524
- content: { type: "string", description: "Base64 encoded document content (supports both plain base64 and data URLs)" },
581
+ file_path: { type: "string", description: "Path to the document file on disk" },
582
+ name: { type: "string", description: "Document name (optional, defaults to filename)" },
525
583
  tag_ids: { type: "array", items: { type: "string" }, description: "Optional list of tag IDs" },
526
584
  metadata: { type: "object", description: "Optional metadata" }
527
585
  },
528
- required: ["name", "content"]
586
+ required: ["file_path"]
529
587
  }
530
588
  }
531
589
  },
@@ -548,12 +606,13 @@ var tools = [
548
606
  },
549
607
  {
550
608
  name: "get_document",
551
- description: "Get document by ID from DocRouter",
609
+ description: "Get document metadata (state, tags, metadata) and optionally download the file to disk",
552
610
  inputSchema: {
553
611
  type: "object",
554
612
  properties: {
555
613
  documentId: { type: "string", description: "ID of the document to retrieve" },
556
- fileType: { type: "string", description: "File type to retrieve (pdf, image, etc.)", default: "pdf" }
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." }
557
616
  },
558
617
  required: ["documentId"]
559
618
  }
@@ -890,9 +949,12 @@ var tools = [
890
949
  type: "object",
891
950
  properties: {
892
951
  promptId: { type: "string", description: "ID of the prompt" },
893
- prompt: { type: "object", description: "Prompt data" }
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" }
894
956
  },
895
- required: ["promptId", "prompt"]
957
+ required: ["promptId"]
896
958
  }
897
959
  },
898
960
  {
@@ -1026,6 +1088,22 @@ var tools = [
1026
1088
  required: ["messages", "model"]
1027
1089
  }
1028
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
+ },
1029
1107
  // ========== HELPER TOOLS ==========
1030
1108
  {
1031
1109
  name: "help",
@@ -1087,21 +1165,57 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
1087
1165
  };
1088
1166
  }
1089
1167
  case "get_document": {
1090
- const result = await docrouterClient.getDocument({
1091
- documentId: getArg(args, "documentId"),
1092
- fileType: getArg(args, "fileType", "pdf")
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
1093
1174
  });
1094
- const base64Content = Buffer.from(result.content).toString("base64");
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
+ }
1095
1214
  return {
1096
1215
  content: [
1097
1216
  {
1098
1217
  type: "text",
1099
- text: JSON.stringify({
1100
- ...serializeDates(result),
1101
- content: base64Content,
1102
- content_type: "base64",
1103
- content_size: result.content.byteLength
1104
- }, null, 2)
1218
+ text: JSON.stringify(response, null, 2)
1105
1219
  }
1106
1220
  ]
1107
1221
  };
@@ -1224,7 +1338,28 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
1224
1338
  // ========== DOCUMENTS ==========
1225
1339
  case "upload_documents": {
1226
1340
  const documentsInput = getArg(args, "documents");
1227
- const result = await docrouterClient.uploadDocuments({ documents: documentsInput });
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 });
1228
1363
  return {
1229
1364
  content: [
1230
1365
  {
@@ -1478,9 +1613,32 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
1478
1613
  };
1479
1614
  }
1480
1615
  case "update_prompt": {
1616
+ const promptId = getArg(args, "promptId");
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");
1621
+ let currentPrompt = null;
1622
+ const allPrompts = await docrouterClient.listPrompts({});
1623
+ for (const p of allPrompts.prompts) {
1624
+ if (p.prompt_id === promptId) {
1625
+ currentPrompt = p;
1626
+ break;
1627
+ }
1628
+ }
1629
+ if (!currentPrompt) {
1630
+ throw new Error(`Prompt with ID ${promptId} not found`);
1631
+ }
1481
1632
  const result = await docrouterClient.updatePrompt({
1482
- promptId: getArg(args, "promptId"),
1483
- prompt: getArg(args, "prompt")
1633
+ promptId,
1634
+ prompt: {
1635
+ name: currentPrompt.name,
1636
+ content: content ?? currentPrompt.content,
1637
+ schema_id: schema_id ?? currentPrompt.schema_id,
1638
+ schema_version: currentPrompt.schema_version,
1639
+ tag_ids: tag_ids ?? currentPrompt.tag_ids,
1640
+ model: model ?? currentPrompt.model
1641
+ }
1484
1642
  });
1485
1643
  return {
1486
1644
  content: [
@@ -1664,6 +1822,28 @@ server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
1664
1822
  ]
1665
1823
  };
1666
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
+ }
1667
1847
  // ========== HELPER TOOLS ==========
1668
1848
  case "help": {
1669
1849
  const helpText = `
@@ -1674,7 +1854,7 @@ This server provides access to DocRouter resources and tools.
1674
1854
  ## Available Tools
1675
1855
 
1676
1856
  ### Documents
1677
- - \`upload_documents(documents)\` - Upload documents
1857
+ - \`upload_documents(documents)\` - Upload documents from file paths
1678
1858
  - \`list_documents(skip, limit, tagIds, nameSearch, metadataSearch)\` - List documents
1679
1859
  - \`get_document(documentId, fileType)\` - Get document by ID
1680
1860
  - \`update_document(documentId, documentName, tagIds, metadata)\` - Update document
@@ -1728,6 +1908,10 @@ This server provides access to DocRouter resources and tools.
1728
1908
  ### LLM Chat
1729
1909
  - \`run_llm_chat(messages, model, temperature, max_tokens, stream)\` - Run chat
1730
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
+
1731
1915
  ### Help Tools
1732
1916
  - \`help()\` - Get general API help information
1733
1917
  - \`help_prompts()\` - Get detailed help on creating and configuring prompts
@@ -1771,9 +1955,7 @@ This server provides access to DocRouter resources and tools.
1771
1955
  }
1772
1956
  case "help_prompts": {
1773
1957
  try {
1774
- const currentFile = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1775
- const currentDir = path.dirname(currentFile);
1776
- const promptsPath = path.join(currentDir, "docs/knowledge_base/prompts.md");
1958
+ const promptsPath = resolveKnowledgeBasePath("prompts.md");
1777
1959
  const promptsContent = fs.readFileSync(promptsPath, "utf-8");
1778
1960
  return {
1779
1961
  content: [
@@ -1797,9 +1979,7 @@ This server provides access to DocRouter resources and tools.
1797
1979
  }
1798
1980
  case "help_schemas": {
1799
1981
  try {
1800
- const currentFile = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1801
- const currentDir = path.dirname(currentFile);
1802
- const schemasPath = path.join(currentDir, "docs/knowledge_base/schemas.md");
1982
+ const schemasPath = resolveKnowledgeBasePath("schemas.md");
1803
1983
  const schemasContent = fs.readFileSync(schemasPath, "utf-8");
1804
1984
  return {
1805
1985
  content: [
@@ -1823,9 +2003,7 @@ This server provides access to DocRouter resources and tools.
1823
2003
  }
1824
2004
  case "help_forms": {
1825
2005
  try {
1826
- const currentFile = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
1827
- const currentDir = path.dirname(currentFile);
1828
- const formsPath = path.join(currentDir, "docs/knowledge_base/forms.md");
2006
+ const formsPath = resolveKnowledgeBasePath("forms.md");
1829
2007
  const formsContent = fs.readFileSync(formsPath, "utf-8");
1830
2008
  return {
1831
2009
  content: [
@@ -1865,12 +2043,13 @@ This server provides access to DocRouter resources and tools.
1865
2043
  async function main() {
1866
2044
  try {
1867
2045
  const config = parseConfig();
1868
- if (!config.organizationId || !config.orgToken) {
1869
- console.error("Error: DOCROUTER_ORG_ID and DOCROUTER_ORG_API_TOKEN environment variables are required");
1870
- console.error("Or provide them as command line arguments: --org-id <id> --org-token <token>");
2046
+ if (!config.orgToken) {
2047
+ console.error("Error: DOCROUTER_ORG_API_TOKEN environment variable is required");
2048
+ console.error("Or provide it as command line argument: --org-token <token>");
2049
+ console.error("Organization ID will be automatically resolved from the token.");
1871
2050
  process.exit(1);
1872
2051
  }
1873
- initializeClient(config);
2052
+ await initializeClient(config);
1874
2053
  const transport = new stdio_js.StdioServerTransport();
1875
2054
  await server.connect(transport);
1876
2055
  console.error("DocRouter MCP server started successfully");