@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.
@@ -9,7 +9,7 @@ import { z } from 'zod';
9
9
  // src/http-server.ts
10
10
 
11
11
  // src/resources/schemas-resource.ts
12
- function registerSchemasResource(server, talonic) {
12
+ function registerSchemasResource(server, getTalonic) {
13
13
  server.registerResource(
14
14
  "talonic-schemas",
15
15
  "talonic://schemas",
@@ -19,7 +19,7 @@ function registerSchemasResource(server, talonic) {
19
19
  mimeType: "application/json"
20
20
  },
21
21
  async (uri) => {
22
- const result = await talonic.schemas.list();
22
+ const result = await getTalonic().schemas.list();
23
23
  return {
24
24
  contents: [
25
25
  {
@@ -52,7 +52,7 @@ var WEBHOOK_INFO_ENDPOINTS = [
52
52
  description: "Retry schedule and backoff policy"
53
53
  }
54
54
  ];
55
- function registerWebhooksResource(server, apiKey, baseUrl) {
55
+ function registerWebhooksResource(server, getToken, baseUrl) {
56
56
  const base = baseUrl ?? "https://api.talonic.com";
57
57
  server.registerResource(
58
58
  "talonic-webhooks-reference",
@@ -64,12 +64,13 @@ function registerWebhooksResource(server, apiKey, baseUrl) {
64
64
  },
65
65
  async (uri) => {
66
66
  const results = {};
67
+ const token = getToken();
67
68
  await Promise.all(
68
69
  WEBHOOK_INFO_ENDPOINTS.map(async ({ path, key }) => {
69
70
  try {
70
71
  const res = await fetch(`${base}${path}`, {
71
72
  headers: {
72
- Authorization: `Bearer ${apiKey}`,
73
+ Authorization: `Bearer ${token}`,
73
74
  Accept: "application/json"
74
75
  }
75
76
  });
@@ -304,7 +305,7 @@ async function handleExtract(talonic, args) {
304
305
  return toolError(err);
305
306
  }
306
307
  }
307
- function registerExtract(server, talonic) {
308
+ function registerExtract(server, getTalonic) {
308
309
  server.registerTool(
309
310
  "talonic_extract",
310
311
  {
@@ -319,7 +320,7 @@ function registerExtract(server, talonic) {
319
320
  openWorldHint: true
320
321
  }
321
322
  },
322
- async (args) => handleExtract(talonic, args)
323
+ async (args) => handleExtract(getTalonic(), args)
323
324
  );
324
325
  }
325
326
  var DESCRIPTION2 = [
@@ -442,7 +443,7 @@ async function handleFilter(talonic, args) {
442
443
  return toolError(err);
443
444
  }
444
445
  }
445
- function registerFilter(server, talonic) {
446
+ function registerFilter(server, getTalonic) {
446
447
  server.registerTool(
447
448
  "talonic_filter",
448
449
  {
@@ -456,7 +457,7 @@ function registerFilter(server, talonic) {
456
457
  openWorldHint: true
457
458
  }
458
459
  },
459
- async (args) => handleFilter(talonic, args)
460
+ async (args) => handleFilter(getTalonic(), args)
460
461
  );
461
462
  }
462
463
  var DESCRIPTION3 = [
@@ -531,7 +532,7 @@ async function handleGetDocument(talonic, args) {
531
532
  return toolError(err);
532
533
  }
533
534
  }
534
- function registerGetDocument(server, talonic) {
535
+ function registerGetDocument(server, getTalonic) {
535
536
  server.registerTool(
536
537
  "talonic_get_document",
537
538
  {
@@ -545,7 +546,7 @@ function registerGetDocument(server, talonic) {
545
546
  openWorldHint: true
546
547
  }
547
548
  },
548
- async (args) => handleGetDocument(talonic, args)
549
+ async (args) => handleGetDocument(getTalonic(), args)
549
550
  );
550
551
  }
551
552
  var DESCRIPTION4 = [
@@ -600,7 +601,7 @@ async function handleListSchemas(talonic) {
600
601
  return toolError(err);
601
602
  }
602
603
  }
603
- function registerListSchemas(server, talonic) {
604
+ function registerListSchemas(server, getTalonic) {
604
605
  server.registerTool(
605
606
  "talonic_list_schemas",
606
607
  {
@@ -614,7 +615,7 @@ function registerListSchemas(server, talonic) {
614
615
  openWorldHint: true
615
616
  }
616
617
  },
617
- async () => handleListSchemas(talonic)
618
+ async () => handleListSchemas(getTalonic())
618
619
  );
619
620
  }
620
621
  var DESCRIPTION5 = [
@@ -673,7 +674,7 @@ async function handleSaveSchema(talonic, args) {
673
674
  return toolError(err);
674
675
  }
675
676
  }
676
- function registerSaveSchema(server, talonic) {
677
+ function registerSaveSchema(server, getTalonic) {
677
678
  server.registerTool(
678
679
  "talonic_save_schema",
679
680
  {
@@ -688,7 +689,7 @@ function registerSaveSchema(server, talonic) {
688
689
  openWorldHint: true
689
690
  }
690
691
  },
691
- async (args) => handleSaveSchema(talonic, args)
692
+ async (args) => handleSaveSchema(getTalonic(), args)
692
693
  );
693
694
  }
694
695
  var DESCRIPTION6 = [
@@ -764,7 +765,7 @@ async function handleSearch(talonic, args) {
764
765
  return toolError(err);
765
766
  }
766
767
  }
767
- function registerSearch(server, talonic) {
768
+ function registerSearch(server, getTalonic) {
768
769
  server.registerTool(
769
770
  "talonic_search",
770
771
  {
@@ -778,7 +779,7 @@ function registerSearch(server, talonic) {
778
779
  openWorldHint: true
779
780
  }
780
781
  },
781
- async (args) => handleSearch(talonic, args)
782
+ async (args) => handleSearch(getTalonic(), args)
782
783
  );
783
784
  }
784
785
  var DESCRIPTION7 = [
@@ -797,14 +798,19 @@ var DESCRIPTION7 = [
797
798
  "DO NOT USE WHEN:",
798
799
  "- The user wants specific structured fields (use talonic_extract with a schema).",
799
800
  "",
800
- "INPUTS (provide exactly one):",
801
- "- document_id: id of an already-ingested document (cheapest path; one API call)",
802
- "- file_data + filename (RECOMMENDED for chat clients): base64-encoded file bytes plus",
803
- " the original filename (with extension). Use this whenever you already have the file",
804
- " in memory, e.g. the user attached it to the conversation. Works in every MCP client.",
801
+ "INPUTS (provide exactly EXACTLY ONE; never combine, e.g. do NOT pass both file_data and file_path):",
802
+ "- document_id: id of an already-ingested document. Cheapest path, one API call.",
803
+ "- file_data + filename: base64-encoded file bytes plus the original filename (with extension).",
804
+ " RECOMMENDED for local-stdio installs (Claude Desktop, Cursor, Cline, Continue, Cowork).",
805
+ " WARNING for hosted-MCP via Claude.ai connectors: Claude.ai imposes a hard size limit on",
806
+ " tool-call arguments (effectively under ~1KB), so file_data CANNOT carry a real PDF through",
807
+ " Claude.ai's pipeline. The bytes get truncated before reaching the MCP server. For files",
808
+ " larger than a trivial test, use file_url or document_id instead when running through",
809
+ " Claude.ai. Local stdio installs do NOT have this limit.",
805
810
  "- file_path: local path to a document file. Only works if the MCP server has read access",
806
811
  " to that path; in sandboxed chat clients use file_data instead.",
807
- "- file_url: URL to a document file (the Talonic API fetches it server-side)"
812
+ "- file_url: a URL the Talonic API will fetch directly. Use for documents already on the",
813
+ " public web. Best path for Claude.ai users dealing with files larger than the parameter cap."
808
814
  ].join("\n");
809
815
  var inputSchema6 = {
810
816
  document_id: z.string().min(1).optional().describe(
@@ -870,7 +876,7 @@ async function handleToMarkdown(talonic, args) {
870
876
  return toolError(err);
871
877
  }
872
878
  }
873
- function registerToMarkdown(server, talonic) {
879
+ function registerToMarkdown(server, getTalonic) {
874
880
  server.registerTool(
875
881
  "talonic_to_markdown",
876
882
  {
@@ -885,13 +891,13 @@ function registerToMarkdown(server, talonic) {
885
891
  openWorldHint: true
886
892
  }
887
893
  },
888
- async (args) => handleToMarkdown(talonic, args)
894
+ async (args) => handleToMarkdown(getTalonic(), args)
889
895
  );
890
896
  }
891
897
 
892
898
  // package.json
893
899
  var package_default = {
894
- version: "0.1.18"};
900
+ version: "0.1.20"};
895
901
 
896
902
  // src/version.ts
897
903
  var VERSION = package_default.version;
@@ -899,10 +905,43 @@ var SERVER_NAME = "talonic";
899
905
 
900
906
  // src/server-factory.ts
901
907
  function createServer(options) {
902
- const talonic = options.talonic ?? new Talonic({
903
- apiKey: options.apiKey,
904
- ...options.baseUrl ? { baseUrl: options.baseUrl } : {}
905
- });
908
+ const baseUrl = options.baseUrl;
909
+ const getToken = (() => {
910
+ if (options.tokenProvider) return options.tokenProvider;
911
+ const fallback = options.apiKey ?? "";
912
+ return () => fallback;
913
+ })();
914
+ const getTalonic = (() => {
915
+ if (options.talonic) {
916
+ const t = options.talonic;
917
+ return () => t;
918
+ }
919
+ if (options.tokenProvider) {
920
+ const tp = options.tokenProvider;
921
+ let cached = null;
922
+ return () => {
923
+ const tok = tp();
924
+ if (!cached || cached.token !== tok) {
925
+ cached = {
926
+ token: tok,
927
+ client: new Talonic({
928
+ apiKey: tok,
929
+ ...baseUrl ? { baseUrl } : {}
930
+ })
931
+ };
932
+ }
933
+ return cached.client;
934
+ };
935
+ }
936
+ if (options.apiKey) {
937
+ const t = new Talonic({
938
+ apiKey: options.apiKey,
939
+ ...baseUrl ? { baseUrl } : {}
940
+ });
941
+ return () => t;
942
+ }
943
+ throw new Error("createServer: provide one of `apiKey`, `talonic`, or `tokenProvider`");
944
+ })();
906
945
  const server = new McpServer(
907
946
  {
908
947
  name: SERVER_NAME,
@@ -921,15 +960,15 @@ function createServer(options) {
921
960
  ].join(" ")
922
961
  }
923
962
  );
924
- registerListSchemas(server, talonic);
925
- registerSaveSchema(server, talonic);
926
- registerGetDocument(server, talonic);
927
- registerSearch(server, talonic);
928
- registerFilter(server, talonic);
929
- registerToMarkdown(server, talonic);
930
- registerExtract(server, talonic);
931
- registerSchemasResource(server, talonic);
932
- registerWebhooksResource(server, options.apiKey, options.baseUrl);
963
+ registerListSchemas(server, getTalonic);
964
+ registerSaveSchema(server, getTalonic);
965
+ registerGetDocument(server, getTalonic);
966
+ registerSearch(server, getTalonic);
967
+ registerFilter(server, getTalonic);
968
+ registerToMarkdown(server, getTalonic);
969
+ registerExtract(server, getTalonic);
970
+ registerSchemasResource(server, getTalonic);
971
+ registerWebhooksResource(server, getToken, baseUrl);
933
972
  return server;
934
973
  }
935
974
 
@@ -958,6 +997,7 @@ function extractBearerToken(req) {
958
997
  return void 0;
959
998
  }
960
999
  var sessions = /* @__PURE__ */ new Map();
1000
+ var WWW_AUTHENTICATE = `Bearer resource_metadata="${RESOURCE_URL}/.well-known/oauth-protected-resource"`;
961
1001
  var httpServer = createServer$1(async (req, res) => {
962
1002
  const url = new URL(req.url ?? "/", "http://localhost");
963
1003
  const path = url.pathname;
@@ -1022,7 +1062,10 @@ var httpServer = createServer$1(async (req, res) => {
1022
1062
  }
1023
1063
  const token = extractBearerToken(req);
1024
1064
  if (!token) {
1025
- res.writeHead(401, { "Content-Type": "application/json" });
1065
+ res.writeHead(401, {
1066
+ "Content-Type": "application/json",
1067
+ "WWW-Authenticate": WWW_AUTHENTICATE
1068
+ });
1026
1069
  res.end(
1027
1070
  JSON.stringify({
1028
1071
  error: "unauthorized",
@@ -1034,6 +1077,7 @@ var httpServer = createServer$1(async (req, res) => {
1034
1077
  const sessionId = req.headers["mcp-session-id"];
1035
1078
  if (sessionId && sessions.has(sessionId)) {
1036
1079
  const session = sessions.get(sessionId);
1080
+ session.tokenHolder.current = token;
1037
1081
  await session.transport.handleRequest(req, res);
1038
1082
  return;
1039
1083
  }
@@ -1065,12 +1109,13 @@ var httpServer = createServer$1(async (req, res) => {
1065
1109
  const transport = new StreamableHTTPServerTransport({
1066
1110
  sessionIdGenerator: () => randomUUID()
1067
1111
  });
1068
- const mcpServer = createServer({ apiKey: token });
1112
+ const tokenHolder = { current: token };
1113
+ const mcpServer = createServer({ tokenProvider: () => tokenHolder.current });
1069
1114
  await mcpServer.connect(transport);
1070
1115
  await transport.handleRequest(req, res, parsed);
1071
1116
  const newSessionId = transport.sessionId;
1072
1117
  if (newSessionId) {
1073
- sessions.set(newSessionId, { transport });
1118
+ sessions.set(newSessionId, { transport, tokenHolder });
1074
1119
  }
1075
1120
  });
1076
1121
  httpServer.listen(PORT, () => {