@talonic/mcp 0.1.18 → 0.1.20

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/server.js CHANGED
@@ -7,7 +7,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
7
7
  import { z } from 'zod';
8
8
 
9
9
  // src/resources/schemas-resource.ts
10
- function registerSchemasResource(server, talonic) {
10
+ function registerSchemasResource(server, getTalonic) {
11
11
  server.registerResource(
12
12
  "talonic-schemas",
13
13
  "talonic://schemas",
@@ -17,7 +17,7 @@ function registerSchemasResource(server, talonic) {
17
17
  mimeType: "application/json"
18
18
  },
19
19
  async (uri) => {
20
- const result = await talonic.schemas.list();
20
+ const result = await getTalonic().schemas.list();
21
21
  return {
22
22
  contents: [
23
23
  {
@@ -50,7 +50,7 @@ var WEBHOOK_INFO_ENDPOINTS = [
50
50
  description: "Retry schedule and backoff policy"
51
51
  }
52
52
  ];
53
- function registerWebhooksResource(server, apiKey, baseUrl) {
53
+ function registerWebhooksResource(server, getToken, baseUrl) {
54
54
  const base = baseUrl ?? "https://api.talonic.com";
55
55
  server.registerResource(
56
56
  "talonic-webhooks-reference",
@@ -62,12 +62,13 @@ function registerWebhooksResource(server, apiKey, baseUrl) {
62
62
  },
63
63
  async (uri) => {
64
64
  const results = {};
65
+ const token = getToken();
65
66
  await Promise.all(
66
67
  WEBHOOK_INFO_ENDPOINTS.map(async ({ path, key }) => {
67
68
  try {
68
69
  const res = await fetch(`${base}${path}`, {
69
70
  headers: {
70
- Authorization: `Bearer ${apiKey}`,
71
+ Authorization: `Bearer ${token}`,
71
72
  Accept: "application/json"
72
73
  }
73
74
  });
@@ -302,7 +303,7 @@ async function handleExtract(talonic, args) {
302
303
  return toolError(err);
303
304
  }
304
305
  }
305
- function registerExtract(server, talonic) {
306
+ function registerExtract(server, getTalonic) {
306
307
  server.registerTool(
307
308
  "talonic_extract",
308
309
  {
@@ -317,7 +318,7 @@ function registerExtract(server, talonic) {
317
318
  openWorldHint: true
318
319
  }
319
320
  },
320
- async (args) => handleExtract(talonic, args)
321
+ async (args) => handleExtract(getTalonic(), args)
321
322
  );
322
323
  }
323
324
  var DESCRIPTION2 = [
@@ -440,7 +441,7 @@ async function handleFilter(talonic, args) {
440
441
  return toolError(err);
441
442
  }
442
443
  }
443
- function registerFilter(server, talonic) {
444
+ function registerFilter(server, getTalonic) {
444
445
  server.registerTool(
445
446
  "talonic_filter",
446
447
  {
@@ -454,7 +455,7 @@ function registerFilter(server, talonic) {
454
455
  openWorldHint: true
455
456
  }
456
457
  },
457
- async (args) => handleFilter(talonic, args)
458
+ async (args) => handleFilter(getTalonic(), args)
458
459
  );
459
460
  }
460
461
  var DESCRIPTION3 = [
@@ -529,7 +530,7 @@ async function handleGetDocument(talonic, args) {
529
530
  return toolError(err);
530
531
  }
531
532
  }
532
- function registerGetDocument(server, talonic) {
533
+ function registerGetDocument(server, getTalonic) {
533
534
  server.registerTool(
534
535
  "talonic_get_document",
535
536
  {
@@ -543,7 +544,7 @@ function registerGetDocument(server, talonic) {
543
544
  openWorldHint: true
544
545
  }
545
546
  },
546
- async (args) => handleGetDocument(talonic, args)
547
+ async (args) => handleGetDocument(getTalonic(), args)
547
548
  );
548
549
  }
549
550
  var DESCRIPTION4 = [
@@ -598,7 +599,7 @@ async function handleListSchemas(talonic) {
598
599
  return toolError(err);
599
600
  }
600
601
  }
601
- function registerListSchemas(server, talonic) {
602
+ function registerListSchemas(server, getTalonic) {
602
603
  server.registerTool(
603
604
  "talonic_list_schemas",
604
605
  {
@@ -612,7 +613,7 @@ function registerListSchemas(server, talonic) {
612
613
  openWorldHint: true
613
614
  }
614
615
  },
615
- async () => handleListSchemas(talonic)
616
+ async () => handleListSchemas(getTalonic())
616
617
  );
617
618
  }
618
619
  var DESCRIPTION5 = [
@@ -671,7 +672,7 @@ async function handleSaveSchema(talonic, args) {
671
672
  return toolError(err);
672
673
  }
673
674
  }
674
- function registerSaveSchema(server, talonic) {
675
+ function registerSaveSchema(server, getTalonic) {
675
676
  server.registerTool(
676
677
  "talonic_save_schema",
677
678
  {
@@ -686,7 +687,7 @@ function registerSaveSchema(server, talonic) {
686
687
  openWorldHint: true
687
688
  }
688
689
  },
689
- async (args) => handleSaveSchema(talonic, args)
690
+ async (args) => handleSaveSchema(getTalonic(), args)
690
691
  );
691
692
  }
692
693
  var DESCRIPTION6 = [
@@ -762,7 +763,7 @@ async function handleSearch(talonic, args) {
762
763
  return toolError(err);
763
764
  }
764
765
  }
765
- function registerSearch(server, talonic) {
766
+ function registerSearch(server, getTalonic) {
766
767
  server.registerTool(
767
768
  "talonic_search",
768
769
  {
@@ -776,7 +777,7 @@ function registerSearch(server, talonic) {
776
777
  openWorldHint: true
777
778
  }
778
779
  },
779
- async (args) => handleSearch(talonic, args)
780
+ async (args) => handleSearch(getTalonic(), args)
780
781
  );
781
782
  }
782
783
  var DESCRIPTION7 = [
@@ -795,14 +796,19 @@ var DESCRIPTION7 = [
795
796
  "DO NOT USE WHEN:",
796
797
  "- The user wants specific structured fields (use talonic_extract with a schema).",
797
798
  "",
798
- "INPUTS (provide exactly one):",
799
- "- document_id: id of an already-ingested document (cheapest path; one API call)",
800
- "- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
801
- " the original filename (with extension). Use this whenever you already have the file",
802
- " in memory, e.g. the user attached it to the conversation. Works in every MCP client.",
799
+ "INPUTS (provide exactly EXACTLY ONE; never combine, e.g. do NOT pass both file_data and file_path):",
800
+ "- document_id: id of an already-ingested document. Cheapest path, one API call.",
801
+ "- file_data + filename: base64-encoded file bytes plus the original filename (with extension).",
802
+ " RECOMMENDED for local-stdio installs (Claude Desktop, Cursor, Cline, Continue, Cowork).",
803
+ " WARNING for hosted-MCP via Claude.ai connectors: Claude.ai imposes a hard size limit on",
804
+ " tool-call arguments (effectively under ~1KB), so file_data CANNOT carry a real PDF through",
805
+ " Claude.ai's pipeline. The bytes get truncated before reaching the MCP server. For files",
806
+ " larger than a trivial test, use file_url or document_id instead when running through",
807
+ " Claude.ai. Local stdio installs do NOT have this limit.",
803
808
  "- file_path: local path to a document file. Only works if the MCP server has read access",
804
809
  " to that path; in sandboxed chat clients use file_data instead.",
805
- "- file_url: URL to a document file (the Talonic API fetches it server-side)"
810
+ "- file_url: a URL the Talonic API will fetch directly. Use for documents already on the",
811
+ " public web. Best path for Claude.ai users dealing with files larger than the parameter cap."
806
812
  ].join("\n");
807
813
  var inputSchema6 = {
808
814
  document_id: z.string().min(1).optional().describe(
@@ -868,7 +874,7 @@ async function handleToMarkdown(talonic, args) {
868
874
  return toolError(err);
869
875
  }
870
876
  }
871
- function registerToMarkdown(server, talonic) {
877
+ function registerToMarkdown(server, getTalonic) {
872
878
  server.registerTool(
873
879
  "talonic_to_markdown",
874
880
  {
@@ -883,13 +889,13 @@ function registerToMarkdown(server, talonic) {
883
889
  openWorldHint: true
884
890
  }
885
891
  },
886
- async (args) => handleToMarkdown(talonic, args)
892
+ async (args) => handleToMarkdown(getTalonic(), args)
887
893
  );
888
894
  }
889
895
 
890
896
  // package.json
891
897
  var package_default = {
892
- version: "0.1.18"};
898
+ version: "0.1.20"};
893
899
 
894
900
  // src/version.ts
895
901
  var VERSION = package_default.version;
@@ -897,10 +903,43 @@ var SERVER_NAME = "talonic";
897
903
 
898
904
  // src/server-factory.ts
899
905
  function createServer(options) {
900
- const talonic = options.talonic ?? new Talonic({
901
- apiKey: options.apiKey,
902
- ...options.baseUrl ? { baseUrl: options.baseUrl } : {}
903
- });
906
+ const baseUrl = options.baseUrl;
907
+ const getToken = (() => {
908
+ if (options.tokenProvider) return options.tokenProvider;
909
+ const fallback = options.apiKey ?? "";
910
+ return () => fallback;
911
+ })();
912
+ const getTalonic = (() => {
913
+ if (options.talonic) {
914
+ const t = options.talonic;
915
+ return () => t;
916
+ }
917
+ if (options.tokenProvider) {
918
+ const tp = options.tokenProvider;
919
+ let cached = null;
920
+ return () => {
921
+ const tok = tp();
922
+ if (!cached || cached.token !== tok) {
923
+ cached = {
924
+ token: tok,
925
+ client: new Talonic({
926
+ apiKey: tok,
927
+ ...baseUrl ? { baseUrl } : {}
928
+ })
929
+ };
930
+ }
931
+ return cached.client;
932
+ };
933
+ }
934
+ if (options.apiKey) {
935
+ const t = new Talonic({
936
+ apiKey: options.apiKey,
937
+ ...baseUrl ? { baseUrl } : {}
938
+ });
939
+ return () => t;
940
+ }
941
+ throw new Error("createServer: provide one of `apiKey`, `talonic`, or `tokenProvider`");
942
+ })();
904
943
  const server = new McpServer(
905
944
  {
906
945
  name: SERVER_NAME,
@@ -919,15 +958,15 @@ function createServer(options) {
919
958
  ].join(" ")
920
959
  }
921
960
  );
922
- registerListSchemas(server, talonic);
923
- registerSaveSchema(server, talonic);
924
- registerGetDocument(server, talonic);
925
- registerSearch(server, talonic);
926
- registerFilter(server, talonic);
927
- registerToMarkdown(server, talonic);
928
- registerExtract(server, talonic);
929
- registerSchemasResource(server, talonic);
930
- registerWebhooksResource(server, options.apiKey, options.baseUrl);
961
+ registerListSchemas(server, getTalonic);
962
+ registerSaveSchema(server, getTalonic);
963
+ registerGetDocument(server, getTalonic);
964
+ registerSearch(server, getTalonic);
965
+ registerFilter(server, getTalonic);
966
+ registerToMarkdown(server, getTalonic);
967
+ registerExtract(server, getTalonic);
968
+ registerSchemasResource(server, getTalonic);
969
+ registerWebhooksResource(server, getToken, baseUrl);
931
970
  return server;
932
971
  }
933
972