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