@anuma/sdk 6.26.2 → 6.27.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.
@@ -23178,6 +23178,19 @@ async function refreshNotionAccessToken(params) {
23178
23178
  return result;
23179
23179
  }
23180
23180
 
23181
+ // src/lib/connectors/errors.ts
23182
+ function buildConnectorErrorResult(code, provider, connectUrl, extras) {
23183
+ const payload = {
23184
+ __anuma_connector_error_v1: true,
23185
+ code,
23186
+ provider,
23187
+ connect_url: connectUrl,
23188
+ missing_scopes: extras?.missingScopes,
23189
+ required: extras?.required
23190
+ };
23191
+ return JSON.stringify(payload);
23192
+ }
23193
+
23181
23194
  // src/tools/notion.ts
23182
23195
  var MCP_HTTP_ENDPOINT = "https://mcp.notion.com/mcp";
23183
23196
  var MAX_CONTENT_LENGTH2 = 5e4;
@@ -23350,8 +23363,83 @@ async function callMCPTool(accessToken, toolName, args) {
23350
23363
  }
23351
23364
  return truncateToolResult(jsonRpcResponse.result);
23352
23365
  }
23353
- function createNotionSearchTool(getAccessToken, requestNotionAccess) {
23366
+ var NOTION_PROVIDER = "notion";
23367
+ function directRunner(getAccessToken, requestNotionAccess) {
23368
+ return async (toolName, args) => {
23369
+ let token = getAccessToken();
23370
+ if (!token) {
23371
+ token = await requestNotionAccess();
23372
+ }
23373
+ return callMCPTool(token, toolName, args);
23374
+ };
23375
+ }
23376
+ function readField(json4, key) {
23377
+ return typeof json4 === "object" && json4 !== null ? json4[key] : void 0;
23378
+ }
23379
+ function readString(json4, key) {
23380
+ const value = readField(json4, key);
23381
+ return typeof value === "string" ? value : void 0;
23382
+ }
23383
+ function notionConnectorError(status, json4) {
23384
+ const code = readField(json4, "code");
23385
+ if (status === 503) {
23386
+ return code === "upstream_unavailable" ? buildConnectorErrorResult("upstream_unavailable", NOTION_PROVIDER) : null;
23387
+ }
23388
+ if (status !== 401 && status !== 403 && status !== 412) return null;
23389
+ switch (code) {
23390
+ case "scope_not_covered": {
23391
+ const missingScopes = readField(json4, "missing_scopes");
23392
+ return buildConnectorErrorResult(
23393
+ "scope_not_covered",
23394
+ NOTION_PROVIDER,
23395
+ readString(json4, "connect_url"),
23396
+ Array.isArray(missingScopes) ? { missingScopes } : void 0
23397
+ );
23398
+ }
23399
+ case "insufficient_scope":
23400
+ return buildConnectorErrorResult("insufficient_scope", NOTION_PROVIDER, void 0, {
23401
+ required: readString(json4, "required")
23402
+ });
23403
+ case "upstream_unavailable":
23404
+ return buildConnectorErrorResult("upstream_unavailable", NOTION_PROVIDER);
23405
+ default:
23406
+ return buildConnectorErrorResult(
23407
+ "connector_not_connected",
23408
+ NOTION_PROVIDER,
23409
+ readString(json4, "connect_url")
23410
+ );
23411
+ }
23412
+ }
23413
+ function proxyRunner(callMcp) {
23414
+ return async (toolName, args) => {
23415
+ const { status, json: json4 } = await callMcp(toolName, args);
23416
+ if (status >= 200 && status < 300) {
23417
+ const result = readField(json4, "result");
23418
+ if (result === void 0) {
23419
+ throw new Error(`Notion returned no result (${status})`);
23420
+ }
23421
+ return truncateToolResult(result);
23422
+ }
23423
+ const connectorError = notionConnectorError(status, json4);
23424
+ if (connectorError) return connectorError;
23425
+ const message = readField(json4, "error");
23426
+ throw new Error(`${typeof message === "string" ? message : JSON.stringify(json4)} (${status})`);
23427
+ };
23428
+ }
23429
+ function withNotionExecutor(run, errorPrefix, tool) {
23354
23430
  return {
23431
+ ...tool,
23432
+ executor: async (args) => {
23433
+ try {
23434
+ return await run(tool.function.name, args);
23435
+ } catch (error) {
23436
+ return `${errorPrefix}: ${error instanceof Error ? error.message : String(error)}`;
23437
+ }
23438
+ }
23439
+ };
23440
+ }
23441
+ function notionSearchTool(run) {
23442
+ return withNotionExecutor(run, "Error searching Notion", {
23355
23443
  type: "function",
23356
23444
  function: {
23357
23445
  name: "notion-search",
@@ -23392,22 +23480,11 @@ function createNotionSearchTool(getAccessToken, requestNotionAccess) {
23392
23480
  },
23393
23481
  required: ["query"]
23394
23482
  }
23395
- },
23396
- executor: async (args) => {
23397
- let token = getAccessToken();
23398
- if (!token) {
23399
- token = await requestNotionAccess();
23400
- }
23401
- try {
23402
- return await callMCPTool(token, "notion-search", args);
23403
- } catch (error) {
23404
- return `Error searching Notion: ${error instanceof Error ? error.message : String(error)}`;
23405
- }
23406
23483
  }
23407
- };
23484
+ });
23408
23485
  }
23409
- function createNotionFetchTool(getAccessToken, requestNotionAccess) {
23410
- return {
23486
+ function notionFetchTool(run) {
23487
+ return withNotionExecutor(run, "Error fetching Notion page", {
23411
23488
  type: "function",
23412
23489
  function: {
23413
23490
  name: "notion-fetch",
@@ -23430,22 +23507,11 @@ function createNotionFetchTool(getAccessToken, requestNotionAccess) {
23430
23507
  },
23431
23508
  required: ["id"]
23432
23509
  }
23433
- },
23434
- executor: async (args) => {
23435
- let token = getAccessToken();
23436
- if (!token) {
23437
- token = await requestNotionAccess();
23438
- }
23439
- try {
23440
- return await callMCPTool(token, "notion-fetch", args);
23441
- } catch (error) {
23442
- return `Error fetching Notion page: ${error instanceof Error ? error.message : String(error)}`;
23443
- }
23444
23510
  }
23445
- };
23511
+ });
23446
23512
  }
23447
- function createNotionCreatePagesTool(getAccessToken, requestNotionAccess) {
23448
- return {
23513
+ function notionCreatePagesTool(run) {
23514
+ return withNotionExecutor(run, "Error creating Notion page", {
23449
23515
  type: "function",
23450
23516
  function: {
23451
23517
  name: "notion-create-pages",
@@ -23478,22 +23544,11 @@ function createNotionCreatePagesTool(getAccessToken, requestNotionAccess) {
23478
23544
  },
23479
23545
  required: ["pages"]
23480
23546
  }
23481
- },
23482
- executor: async (args) => {
23483
- let token = getAccessToken();
23484
- if (!token) {
23485
- token = await requestNotionAccess();
23486
- }
23487
- try {
23488
- return await callMCPTool(token, "notion-create-pages", args);
23489
- } catch (error) {
23490
- return `Error creating Notion page: ${error instanceof Error ? error.message : String(error)}`;
23491
- }
23492
23547
  }
23493
- };
23548
+ });
23494
23549
  }
23495
- function createNotionUpdatePageTool(getAccessToken, requestNotionAccess) {
23496
- return {
23550
+ function notionUpdatePageTool(run) {
23551
+ return withNotionExecutor(run, "Error updating Notion page", {
23497
23552
  type: "function",
23498
23553
  function: {
23499
23554
  name: "notion-update-page",
@@ -23541,22 +23596,11 @@ function createNotionUpdatePageTool(getAccessToken, requestNotionAccess) {
23541
23596
  },
23542
23597
  required: ["data"]
23543
23598
  }
23544
- },
23545
- executor: async (args) => {
23546
- let token = getAccessToken();
23547
- if (!token) {
23548
- token = await requestNotionAccess();
23549
- }
23550
- try {
23551
- return await callMCPTool(token, "notion-update-page", args);
23552
- } catch (error) {
23553
- return `Error updating Notion page: ${error instanceof Error ? error.message : String(error)}`;
23554
- }
23555
23599
  }
23556
- };
23600
+ });
23557
23601
  }
23558
- function createNotionMovePagesTool(getAccessToken, requestNotionAccess) {
23559
- return {
23602
+ function notionMovePagesTool(run) {
23603
+ return withNotionExecutor(run, "Error moving Notion pages", {
23560
23604
  type: "function",
23561
23605
  function: {
23562
23606
  name: "notion-move-pages",
@@ -23576,22 +23620,11 @@ function createNotionMovePagesTool(getAccessToken, requestNotionAccess) {
23576
23620
  },
23577
23621
  required: ["page_or_database_ids", "new_parent"]
23578
23622
  }
23579
- },
23580
- executor: async (args) => {
23581
- let token = getAccessToken();
23582
- if (!token) {
23583
- token = await requestNotionAccess();
23584
- }
23585
- try {
23586
- return await callMCPTool(token, "notion-move-pages", args);
23587
- } catch (error) {
23588
- return `Error moving Notion pages: ${error instanceof Error ? error.message : String(error)}`;
23589
- }
23590
23623
  }
23591
- };
23624
+ });
23592
23625
  }
23593
- function createNotionDuplicatePageTool(getAccessToken, requestNotionAccess) {
23594
- return {
23626
+ function notionDuplicatePageTool(run) {
23627
+ return withNotionExecutor(run, "Error duplicating Notion page", {
23595
23628
  type: "function",
23596
23629
  function: {
23597
23630
  name: "notion-duplicate-page",
@@ -23606,22 +23639,11 @@ function createNotionDuplicatePageTool(getAccessToken, requestNotionAccess) {
23606
23639
  },
23607
23640
  required: ["page_id"]
23608
23641
  }
23609
- },
23610
- executor: async (args) => {
23611
- let token = getAccessToken();
23612
- if (!token) {
23613
- token = await requestNotionAccess();
23614
- }
23615
- try {
23616
- return await callMCPTool(token, "notion-duplicate-page", args);
23617
- } catch (error) {
23618
- return `Error duplicating Notion page: ${error instanceof Error ? error.message : String(error)}`;
23619
- }
23620
23642
  }
23621
- };
23643
+ });
23622
23644
  }
23623
- function createNotionCreateDatabaseTool(getAccessToken, requestNotionAccess) {
23624
- return {
23645
+ function notionCreateDatabaseTool(run) {
23646
+ return withNotionExecutor(run, "Error creating Notion database", {
23625
23647
  type: "function",
23626
23648
  function: {
23627
23649
  name: "notion-create-database",
@@ -23650,22 +23672,11 @@ function createNotionCreateDatabaseTool(getAccessToken, requestNotionAccess) {
23650
23672
  },
23651
23673
  required: ["properties"]
23652
23674
  }
23653
- },
23654
- executor: async (args) => {
23655
- let token = getAccessToken();
23656
- if (!token) {
23657
- token = await requestNotionAccess();
23658
- }
23659
- try {
23660
- return await callMCPTool(token, "notion-create-database", args);
23661
- } catch (error) {
23662
- return `Error creating Notion database: ${error instanceof Error ? error.message : String(error)}`;
23663
- }
23664
23675
  }
23665
- };
23676
+ });
23666
23677
  }
23667
- function createNotionUpdateDataSourceTool(getAccessToken, requestNotionAccess) {
23668
- return {
23678
+ function notionUpdateDataSourceTool(run) {
23679
+ return withNotionExecutor(run, "Error updating Notion data source", {
23669
23680
  type: "function",
23670
23681
  function: {
23671
23682
  name: "notion-update-data-source",
@@ -23702,22 +23713,11 @@ function createNotionUpdateDataSourceTool(getAccessToken, requestNotionAccess) {
23702
23713
  },
23703
23714
  required: ["data_source_id"]
23704
23715
  }
23705
- },
23706
- executor: async (args) => {
23707
- let token = getAccessToken();
23708
- if (!token) {
23709
- token = await requestNotionAccess();
23710
- }
23711
- try {
23712
- return await callMCPTool(token, "notion-update-data-source", args);
23713
- } catch (error) {
23714
- return `Error updating Notion data source: ${error instanceof Error ? error.message : String(error)}`;
23715
- }
23716
23716
  }
23717
- };
23717
+ });
23718
23718
  }
23719
- function createNotionCreateCommentTool(getAccessToken, requestNotionAccess) {
23720
- return {
23719
+ function notionCreateCommentTool(run) {
23720
+ return withNotionExecutor(run, "Error creating Notion comment", {
23721
23721
  type: "function",
23722
23722
  function: {
23723
23723
  name: "notion-create-comment",
@@ -23757,22 +23757,11 @@ function createNotionCreateCommentTool(getAccessToken, requestNotionAccess) {
23757
23757
  },
23758
23758
  required: ["page_id", "rich_text"]
23759
23759
  }
23760
- },
23761
- executor: async (args) => {
23762
- let token = getAccessToken();
23763
- if (!token) {
23764
- token = await requestNotionAccess();
23765
- }
23766
- try {
23767
- return await callMCPTool(token, "notion-create-comment", args);
23768
- } catch (error) {
23769
- return `Error creating Notion comment: ${error instanceof Error ? error.message : String(error)}`;
23770
- }
23771
23760
  }
23772
- };
23761
+ });
23773
23762
  }
23774
- function createNotionGetCommentsTool(getAccessToken, requestNotionAccess) {
23775
- return {
23763
+ function notionGetCommentsTool(run) {
23764
+ return withNotionExecutor(run, "Error retrieving Notion comments", {
23776
23765
  type: "function",
23777
23766
  function: {
23778
23767
  name: "notion-get-comments",
@@ -23799,22 +23788,11 @@ function createNotionGetCommentsTool(getAccessToken, requestNotionAccess) {
23799
23788
  },
23800
23789
  required: ["page_id"]
23801
23790
  }
23802
- },
23803
- executor: async (args) => {
23804
- let token = getAccessToken();
23805
- if (!token) {
23806
- token = await requestNotionAccess();
23807
- }
23808
- try {
23809
- return await callMCPTool(token, "notion-get-comments", args);
23810
- } catch (error) {
23811
- return `Error retrieving Notion comments: ${error instanceof Error ? error.message : String(error)}`;
23812
- }
23813
23791
  }
23814
- };
23792
+ });
23815
23793
  }
23816
- function createNotionGetUsersTool(getAccessToken, requestNotionAccess) {
23817
- return {
23794
+ function notionGetUsersTool(run) {
23795
+ return withNotionExecutor(run, "Error listing Notion users", {
23818
23796
  type: "function",
23819
23797
  function: {
23820
23798
  name: "notion-get-users",
@@ -23840,22 +23818,11 @@ function createNotionGetUsersTool(getAccessToken, requestNotionAccess) {
23840
23818
  }
23841
23819
  }
23842
23820
  }
23843
- },
23844
- executor: async (args) => {
23845
- let token = getAccessToken();
23846
- if (!token) {
23847
- token = await requestNotionAccess();
23848
- }
23849
- try {
23850
- return await callMCPTool(token, "notion-get-users", args);
23851
- } catch (error) {
23852
- return `Error listing Notion users: ${error instanceof Error ? error.message : String(error)}`;
23853
- }
23854
23821
  }
23855
- };
23822
+ });
23856
23823
  }
23857
- function createNotionGetTeamsTool(getAccessToken, requestNotionAccess) {
23858
- return {
23824
+ function notionGetTeamsTool(run) {
23825
+ return withNotionExecutor(run, "Error retrieving Notion teams", {
23859
23826
  type: "function",
23860
23827
  function: {
23861
23828
  name: "notion-get-teams",
@@ -23869,40 +23836,35 @@ function createNotionGetTeamsTool(getAccessToken, requestNotionAccess) {
23869
23836
  }
23870
23837
  }
23871
23838
  }
23872
- },
23873
- executor: async (args) => {
23874
- let token = getAccessToken();
23875
- if (!token) {
23876
- token = await requestNotionAccess();
23877
- }
23878
- try {
23879
- return await callMCPTool(token, "notion-get-teams", args);
23880
- } catch (error) {
23881
- return `Error retrieving Notion teams: ${error instanceof Error ? error.message : String(error)}`;
23882
- }
23883
23839
  }
23884
- };
23840
+ });
23885
23841
  }
23842
+ var NOTION_TOOLS = [
23843
+ // Search
23844
+ notionSearchTool,
23845
+ // Pages
23846
+ notionFetchTool,
23847
+ notionCreatePagesTool,
23848
+ notionUpdatePageTool,
23849
+ notionMovePagesTool,
23850
+ notionDuplicatePageTool,
23851
+ // Data Sources (Databases)
23852
+ notionCreateDatabaseTool,
23853
+ notionUpdateDataSourceTool,
23854
+ // Comments
23855
+ notionCreateCommentTool,
23856
+ notionGetCommentsTool,
23857
+ // Users & Teams
23858
+ notionGetUsersTool,
23859
+ notionGetTeamsTool
23860
+ ];
23886
23861
  function createNotionTools(getAccessToken, requestNotionAccess) {
23887
- return [
23888
- // Search
23889
- createNotionSearchTool(getAccessToken, requestNotionAccess),
23890
- // Pages
23891
- createNotionFetchTool(getAccessToken, requestNotionAccess),
23892
- createNotionCreatePagesTool(getAccessToken, requestNotionAccess),
23893
- createNotionUpdatePageTool(getAccessToken, requestNotionAccess),
23894
- createNotionMovePagesTool(getAccessToken, requestNotionAccess),
23895
- createNotionDuplicatePageTool(getAccessToken, requestNotionAccess),
23896
- // Data Sources (Databases)
23897
- createNotionCreateDatabaseTool(getAccessToken, requestNotionAccess),
23898
- createNotionUpdateDataSourceTool(getAccessToken, requestNotionAccess),
23899
- // Comments
23900
- createNotionCreateCommentTool(getAccessToken, requestNotionAccess),
23901
- createNotionGetCommentsTool(getAccessToken, requestNotionAccess),
23902
- // Users & Teams
23903
- createNotionGetUsersTool(getAccessToken, requestNotionAccess),
23904
- createNotionGetTeamsTool(getAccessToken, requestNotionAccess)
23905
- ];
23862
+ const run = directRunner(getAccessToken, requestNotionAccess);
23863
+ return NOTION_TOOLS.map((tool) => tool(run));
23864
+ }
23865
+ function createNotionProxyTools(callMcp) {
23866
+ const run = proxyRunner(callMcp);
23867
+ return NOTION_TOOLS.map((tool) => tool(run));
23906
23868
  }
23907
23869
  export {
23908
23870
  CHUNKS_DISCARDED_ORIGIN,
@@ -23997,6 +23959,7 @@ export {
23997
23959
  createMemoryVaultSearchTool,
23998
23960
  createMemoryVaultTool,
23999
23961
  createMessageSourceResolver,
23962
+ createNotionProxyTools,
24000
23963
  createNotionTools,
24001
23964
  createPlatformCursorStore,
24002
23965
  createRecallTool,