notion-mcp-server 1.0.0 → 2.4.2

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.
Files changed (95) hide show
  1. package/README.md +383 -192
  2. package/build/config/index.js +3 -1
  3. package/build/dispatch/concurrency.js +15 -0
  4. package/build/dispatch/idempotency.js +38 -0
  5. package/build/dispatch/index.js +175 -0
  6. package/build/dispatch/rate-limit.js +56 -0
  7. package/build/dispatch/retry.js +97 -0
  8. package/build/index.js +1 -1
  9. package/build/markdown/parse.js +265 -0
  10. package/build/operations/blocks.js +331 -0
  11. package/build/operations/comments.js +191 -0
  12. package/build/operations/data-sources.js +85 -0
  13. package/build/operations/databases.js +345 -0
  14. package/build/operations/files.js +239 -0
  15. package/build/operations/index.js +19 -0
  16. package/build/operations/pages.js +486 -0
  17. package/build/operations/registry.js +16 -0
  18. package/build/operations/users.js +101 -0
  19. package/build/prompts/index.js +105 -0
  20. package/build/schema/blocks.js +19 -77
  21. package/build/schema/database.js +27 -86
  22. package/build/schema/emit.js +68 -0
  23. package/build/schema/file.js +1 -1
  24. package/build/schema/filter-dsl.js +333 -0
  25. package/build/schema/icon.js +1 -1
  26. package/build/schema/page-properties.js +17 -3
  27. package/build/schema/page.js +12 -88
  28. package/build/schema/refs.js +16 -0
  29. package/build/schema/rich-text.js +1 -1
  30. package/build/server/index.js +15 -2
  31. package/build/services/auth.js +19 -0
  32. package/build/services/notion.js +14 -17
  33. package/build/tools/index.js +119 -51
  34. package/build/utils/error.js +125 -86
  35. package/build/utils/handler.js +11 -0
  36. package/build/utils/learning-error.js +40 -0
  37. package/build/utils/notion-types.js +16 -0
  38. package/build/utils/paginate.js +35 -0
  39. package/build/utils/schema-slice.js +156 -0
  40. package/build/utils/slim.js +269 -0
  41. package/package.json +13 -7
  42. package/build/resources/imageList.js +0 -62
  43. package/build/resources/index.js +0 -1
  44. package/build/resources/predictionList.js +0 -43
  45. package/build/resources/svgList.js +0 -69
  46. package/build/schema/comments.js +0 -34
  47. package/build/schema/notion.js +0 -57
  48. package/build/schema/richText.js +0 -757
  49. package/build/schema/tools.js +0 -17
  50. package/build/schema/users.js +0 -13
  51. package/build/services/replicate.js +0 -23
  52. package/build/tools/appendBlockChildren.js +0 -25
  53. package/build/tools/batchAppendBlockChildren.js +0 -33
  54. package/build/tools/batchDeleteBlocks.js +0 -32
  55. package/build/tools/batchMixedOperations.js +0 -58
  56. package/build/tools/batchUpdateBlocks.js +0 -33
  57. package/build/tools/comments.js +0 -62
  58. package/build/tools/createDatabase.js +0 -18
  59. package/build/tools/createPage.js +0 -18
  60. package/build/tools/createPrediction.js +0 -28
  61. package/build/tools/deleteBlock.js +0 -24
  62. package/build/tools/formatRichText.js +0 -83
  63. package/build/tools/generateImage.js +0 -48
  64. package/build/tools/generateImageVariants.js +0 -105
  65. package/build/tools/generateMultipleImages.js +0 -60
  66. package/build/tools/generateSVG.js +0 -43
  67. package/build/tools/getPrediction.js +0 -22
  68. package/build/tools/predictionList.js +0 -30
  69. package/build/tools/queryDatabase.js +0 -22
  70. package/build/tools/retrieveBlock.js +0 -24
  71. package/build/tools/retrieveBlockChildren.js +0 -32
  72. package/build/tools/searchPage.js +0 -24
  73. package/build/tools/updateBlock.js +0 -25
  74. package/build/tools/updateDatabase.js +0 -18
  75. package/build/tools/updatePage.js +0 -40
  76. package/build/tools/updatePageProperties.js +0 -21
  77. package/build/tools/users.js +0 -62
  78. package/build/types/blocks.js +0 -11
  79. package/build/types/comments.js +0 -6
  80. package/build/types/database.js +0 -5
  81. package/build/types/notion.js +0 -1
  82. package/build/types/page.js +0 -7
  83. package/build/types/richText.js +0 -1
  84. package/build/types/tools.js +0 -1
  85. package/build/types/users.js +0 -5
  86. package/build/utils/blob.js +0 -5
  87. package/build/utils/image.js +0 -34
  88. package/build/utils/index.js +0 -1
  89. package/build/utils/richText.js +0 -174
  90. package/build/validation/blocks.js +0 -568
  91. package/build/validation/notion.js +0 -51
  92. package/build/validation/page.js +0 -262
  93. package/build/validation/richText.js +0 -744
  94. package/build/validation/tools.js +0 -16
  95. /package/build/{types/index.js → operations/types.js} +0 -0
@@ -1,60 +0,0 @@
1
- import { replicate } from "../services/replicate.js";
2
- import { handleError } from "../utils/error.js";
3
- import { outputToBase64 } from "../utils/image.js";
4
- import { CONFIG } from "../config/index.js";
5
- export const registerGenerateMultipleImagesTool = async (input) => {
6
- const { prompts, support_image_mcp_response_type, ...commonParams } = input;
7
- try {
8
- // Process all prompts in parallel
9
- const generationPromises = prompts.map(async (prompt) => {
10
- const [output] = (await replicate.run(CONFIG.imageModelId, {
11
- input: {
12
- prompt,
13
- ...commonParams,
14
- },
15
- }));
16
- const imageUrl = output.url();
17
- if (support_image_mcp_response_type) {
18
- const imageBase64 = await outputToBase64(output);
19
- return {
20
- prompt,
21
- imageUrl,
22
- imageBase64,
23
- };
24
- }
25
- return {
26
- prompt,
27
- imageUrl,
28
- };
29
- });
30
- // Wait for all image generation to complete
31
- const results = await Promise.all(generationPromises);
32
- // Build response content
33
- const responseContent = [];
34
- // Add intro text
35
- responseContent.push({
36
- type: "text",
37
- text: `Generated ${results.length} images based on your prompts:`,
38
- });
39
- // Add each image with its prompt
40
- for (const result of results) {
41
- responseContent.push({
42
- type: "text",
43
- text: `\n\nPrompt: "${result.prompt}"\nImage URL: ${result.imageUrl}`,
44
- });
45
- if (support_image_mcp_response_type && result.imageBase64) {
46
- responseContent.push({
47
- type: "image",
48
- data: result.imageBase64,
49
- mimeType: `image/${input.output_format === "jpg" ? "jpeg" : input.output_format}`,
50
- });
51
- }
52
- }
53
- return {
54
- content: responseContent,
55
- };
56
- }
57
- catch (error) {
58
- handleError(error);
59
- }
60
- };
@@ -1,43 +0,0 @@
1
- import { replicate } from "../services/replicate.js";
2
- import { handleError } from "../utils/error.js";
3
- import { urlToSvg } from "../utils/image.js";
4
- import { CONFIG } from "../config/index.js";
5
- export const registerGenerateSvgTool = async (input) => {
6
- try {
7
- const output = (await replicate.run(CONFIG.svgModelId, {
8
- input,
9
- }));
10
- const svgUrl = output.url();
11
- if (!svgUrl) {
12
- throw new Error("Failed to generate SVG URL");
13
- }
14
- try {
15
- const svg = await urlToSvg(svgUrl);
16
- return {
17
- content: [
18
- {
19
- type: "text",
20
- text: `This is a generated SVG url: ${svgUrl}`,
21
- },
22
- {
23
- type: "text",
24
- text: svg,
25
- },
26
- ],
27
- };
28
- }
29
- catch (error) {
30
- return {
31
- content: [
32
- {
33
- type: "text",
34
- text: `This is a generated SVG url: ${svgUrl}`,
35
- },
36
- ],
37
- };
38
- }
39
- }
40
- catch (error) {
41
- return handleError(error);
42
- }
43
- };
@@ -1,22 +0,0 @@
1
- // import { replicate } from "../services/replicate.js";
2
- // import { handleError } from "../utils/error.js";
3
- // import { GetPredictionParams } from "../types/index.js";
4
- // import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
5
- export {};
6
- // export const registerGetPredictionTool = async ({
7
- // predictionId,
8
- // }: GetPredictionParams): Promise<CallToolResult> => {
9
- // try {
10
- // const prediction = await replicate.predictions.get(predictionId);
11
- // return {
12
- // content: [
13
- // {
14
- // type: "text",
15
- // text: JSON.stringify(prediction, null, 2),
16
- // },
17
- // ],
18
- // };
19
- // } catch (error) {
20
- // handleError(error);
21
- // }
22
- // };
@@ -1,30 +0,0 @@
1
- import { replicate } from "../services/replicate.js";
2
- import { handleError } from "../utils/error.js";
3
- export const registerPredictionListTool = async ({ limit, }) => {
4
- try {
5
- const predictions = [];
6
- for await (const page of replicate.paginate(replicate.predictions.list)) {
7
- predictions.push(...page);
8
- if (predictions.length >= limit) {
9
- break;
10
- }
11
- }
12
- const limitedPredictions = predictions.slice(0, limit);
13
- const totalPages = Math.ceil(predictions.length / limit);
14
- return {
15
- content: [
16
- {
17
- type: "text",
18
- text: `Found ${limitedPredictions.length} predictions (showing ${limitedPredictions.length} of ${predictions.length} total, page 1 of ${totalPages})`,
19
- },
20
- {
21
- type: "text",
22
- text: JSON.stringify(limitedPredictions, null, 2),
23
- },
24
- ],
25
- };
26
- }
27
- catch (error) {
28
- handleError(error);
29
- }
30
- };
@@ -1,22 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const queryDatabase = async (params) => {
4
- try {
5
- const response = await notion.databases.query(params);
6
- return {
7
- content: [
8
- {
9
- type: "text",
10
- text: `Database queried successfully. Found ${response.results.length} results.`,
11
- },
12
- {
13
- type: "text",
14
- text: JSON.stringify(response, null, 2),
15
- },
16
- ],
17
- };
18
- }
19
- catch (error) {
20
- return handleNotionError(error);
21
- }
22
- };
@@ -1,24 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const retrieveBlock = async (params) => {
4
- try {
5
- const response = await notion.blocks.retrieve({
6
- block_id: params.blockId,
7
- });
8
- return {
9
- content: [
10
- {
11
- type: "text",
12
- text: "Block retrieved successfully! Note: If this block has children, use the retrieve_block_children endpoint to get the list of child blocks.",
13
- },
14
- {
15
- type: "text",
16
- text: JSON.stringify(response, null, 2),
17
- },
18
- ],
19
- };
20
- }
21
- catch (error) {
22
- return handleNotionError(error);
23
- }
24
- };
@@ -1,32 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const retrieveBlockChildren = async (params) => {
4
- try {
5
- const response = await notion.blocks.children.list({
6
- block_id: params.blockId,
7
- start_cursor: params.start_cursor,
8
- page_size: params.page_size,
9
- });
10
- return {
11
- content: [
12
- {
13
- type: "text",
14
- text: `Successfully retrieved ${response.results.length} children of block ${params.blockId}`,
15
- },
16
- {
17
- type: "text",
18
- text: `Has more: ${response.has_more ? "Yes" : "No"}${response.has_more && response.next_cursor
19
- ? `, Next cursor: ${response.next_cursor}`
20
- : ""}`,
21
- },
22
- {
23
- type: "text",
24
- text: JSON.stringify(response.results, null, 2),
25
- },
26
- ],
27
- };
28
- }
29
- catch (error) {
30
- return handleNotionError(error);
31
- }
32
- };
@@ -1,24 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export async function searchPages(params) {
4
- try {
5
- const response = await notion.search({
6
- query: params.query || "",
7
- sort: params.sort,
8
- start_cursor: params.start_cursor,
9
- page_size: params.page_size || 10,
10
- });
11
- const resultsText = JSON.stringify(response, null, 2);
12
- return {
13
- content: [
14
- {
15
- type: "text",
16
- text: `Found ${response.results.length} results. ${response.has_more ? "More results available." : ""}\n\n${resultsText}`,
17
- },
18
- ],
19
- };
20
- }
21
- catch (error) {
22
- return handleNotionError(error);
23
- }
24
- }
@@ -1,25 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const updateBlock = async (params) => {
4
- try {
5
- const response = await notion.blocks.update({
6
- block_id: params.blockId,
7
- ...params.data,
8
- });
9
- return {
10
- content: [
11
- {
12
- type: "text",
13
- text: `Block ${response.id} updated successfully`,
14
- },
15
- {
16
- type: "text",
17
- text: JSON.stringify(response, null, 2),
18
- },
19
- ],
20
- };
21
- }
22
- catch (error) {
23
- return handleNotionError(error);
24
- }
25
- };
@@ -1,18 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const updateDatabase = async (params) => {
4
- try {
5
- const response = await notion.databases.update(params);
6
- return {
7
- content: [
8
- {
9
- type: "text",
10
- text: `Database updated successfully: ${response.id}`,
11
- },
12
- ],
13
- };
14
- }
15
- catch (error) {
16
- return handleNotionError(error);
17
- }
18
- };
@@ -1,40 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export async function archivePage(params) {
4
- try {
5
- const response = await notion.pages.update({
6
- page_id: params.pageId,
7
- archived: true,
8
- });
9
- return {
10
- content: [
11
- {
12
- type: "text",
13
- text: `Page archived successfully: ${response.id}`,
14
- },
15
- ],
16
- };
17
- }
18
- catch (error) {
19
- return handleNotionError(error);
20
- }
21
- }
22
- export async function restorePage(params) {
23
- try {
24
- const response = await notion.pages.update({
25
- page_id: params.pageId,
26
- archived: false,
27
- });
28
- return {
29
- content: [
30
- {
31
- type: "text",
32
- text: `Page restored successfully: ${response.id}`,
33
- },
34
- ],
35
- };
36
- }
37
- catch (error) {
38
- return handleNotionError(error);
39
- }
40
- }
@@ -1,21 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export async function updatePageProperties(params) {
4
- try {
5
- const response = await notion.pages.update({
6
- page_id: params.pageId,
7
- properties: params.properties,
8
- });
9
- return {
10
- content: [
11
- {
12
- type: "text",
13
- text: `Page properties updated successfully: ${response.id}`,
14
- },
15
- ],
16
- };
17
- }
18
- catch (error) {
19
- return handleNotionError(error);
20
- }
21
- }
@@ -1,62 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const registerGetListUsersTool = async (params) => {
4
- try {
5
- const response = await notion.users.list(params);
6
- return {
7
- content: [
8
- {
9
- type: "text",
10
- text: `Users retrieved successfully: ${response.results.length}`,
11
- },
12
- {
13
- type: "text",
14
- text: JSON.stringify(response, null, 2),
15
- },
16
- ],
17
- };
18
- }
19
- catch (error) {
20
- return handleNotionError(error);
21
- }
22
- };
23
- export const registerGetUserTool = async (params) => {
24
- try {
25
- const response = await notion.users.retrieve(params);
26
- return {
27
- content: [
28
- {
29
- type: "text",
30
- text: `User retrieved successfully: ${response.id}`,
31
- },
32
- {
33
- type: "text",
34
- text: JSON.stringify(response, null, 2),
35
- },
36
- ],
37
- };
38
- }
39
- catch (error) {
40
- return handleNotionError(error);
41
- }
42
- };
43
- export const registerGetBotUserTool = async () => {
44
- try {
45
- const response = await notion.users.me({});
46
- return {
47
- content: [
48
- {
49
- type: "text",
50
- text: `Bot user retrieved successfully: ${response.id}`,
51
- },
52
- {
53
- type: "text",
54
- text: JSON.stringify(response, null, 2),
55
- },
56
- ],
57
- };
58
- }
59
- catch (error) {
60
- return handleNotionError(error);
61
- }
62
- };
@@ -1,11 +0,0 @@
1
- import { z } from "zod";
2
- import { APPEND_BLOCK_CHILDREN_SCHEMA, RETRIEVE_BLOCK_SCHEMA, RETRIEVE_BLOCK_CHILDREN_SCHEMA, UPDATE_BLOCK_SCHEMA, DELETE_BLOCK_SCHEMA, BATCH_APPEND_BLOCK_CHILDREN_SCHEMA, BATCH_UPDATE_BLOCKS_SCHEMA, BATCH_DELETE_BLOCKS_SCHEMA, BATCH_MIXED_OPERATIONS_SCHEMA, } from "../schema/blocks.js";
3
- export const appendBlockChildrenSchema = z.object(APPEND_BLOCK_CHILDREN_SCHEMA);
4
- export const retrieveBlockSchema = z.object(RETRIEVE_BLOCK_SCHEMA);
5
- export const retrieveBlockChildrenSchema = z.object(RETRIEVE_BLOCK_CHILDREN_SCHEMA);
6
- export const updateBlockSchema = z.object(UPDATE_BLOCK_SCHEMA);
7
- export const deleteBlockSchema = z.object(DELETE_BLOCK_SCHEMA);
8
- export const batchAppendBlockChildrenSchema = z.object(BATCH_APPEND_BLOCK_CHILDREN_SCHEMA);
9
- export const batchUpdateBlocksSchema = z.object(BATCH_UPDATE_BLOCKS_SCHEMA);
10
- export const batchDeleteBlocksSchema = z.object(BATCH_DELETE_BLOCKS_SCHEMA);
11
- export const batchMixedOperationsSchema = z.object(BATCH_MIXED_OPERATIONS_SCHEMA);
@@ -1,6 +0,0 @@
1
- import { z } from "zod";
2
- import { GET_COMMENTS_SCHEMA, ADD_PAGE_COMMENT_SCHEMA, ADD_DISCUSSION_COMMENT_SCHEMA, } from "../schema/comments.js";
3
- // Types inferred from the schemas
4
- export const getCommentsSchema = z.object(GET_COMMENTS_SCHEMA);
5
- export const addPageCommentSchema = z.object(ADD_PAGE_COMMENT_SCHEMA);
6
- export const addDiscussionCommentSchema = z.object(ADD_DISCUSSION_COMMENT_SCHEMA);
@@ -1,5 +0,0 @@
1
- import { z } from "zod";
2
- import { CREATE_DATABASE_SCHEMA, QUERY_DATABASE_SCHEMA, UPDATE_DATABASE_SCHEMA, } from "../schema/database.js";
3
- export const createDatabaseSchema = z.object(CREATE_DATABASE_SCHEMA);
4
- export const queryDatabaseSchema = z.object(QUERY_DATABASE_SCHEMA);
5
- export const updateDatabaseSchema = z.object(UPDATE_DATABASE_SCHEMA);
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { z } from "zod";
2
- import { ARCHIVE_PAGE_SCHEMA, CREATE_PAGE_SCHEMA, RESTORE_PAGE_SCHEMA, SEARCH_PAGES_SCHEMA, UPDATE_PAGE_PROPERTIES_SCHEMA, } from "../schema/page.js";
3
- export const createPageSchema = z.object(CREATE_PAGE_SCHEMA);
4
- export const archivePageSchema = z.object(ARCHIVE_PAGE_SCHEMA);
5
- export const restorePageSchema = z.object(RESTORE_PAGE_SCHEMA);
6
- export const searchPagesSchema = z.object(SEARCH_PAGES_SCHEMA);
7
- export const updatePagePropertiesSchema = z.object(UPDATE_PAGE_PROPERTIES_SCHEMA);
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import { z } from "zod";
2
- import { LIST_USERS_SCHEMA, GET_USER_SCHEMA } from "../schema/users.js";
3
- // Types inferred from schemas
4
- const listUsersSchema = z.object(LIST_USERS_SCHEMA);
5
- const getUserSchema = z.object(GET_USER_SCHEMA);
@@ -1,5 +0,0 @@
1
- export async function outputToBase64(output) {
2
- const blob = await output.blob();
3
- const buffer = Buffer.from(await blob.arrayBuffer());
4
- return buffer.toString("base64");
5
- }
@@ -1,34 +0,0 @@
1
- export async function outputToBase64(output) {
2
- const blob = await output.blob();
3
- const buffer = Buffer.from(await blob.arrayBuffer());
4
- return buffer.toString("base64");
5
- }
6
- export async function urlToSvg(url) {
7
- try {
8
- const data = await fetch(url, {
9
- headers: {
10
- Authorization: `Bearer ${process.env.REPLICATE_API_TOKEN}`,
11
- },
12
- });
13
- const text = await data.text();
14
- return text;
15
- }
16
- catch (error) {
17
- throw new Error("Error fetching svg");
18
- }
19
- }
20
- export async function urlToBase64(url) {
21
- try {
22
- const data = await fetch(url, {
23
- headers: {
24
- Authorization: `Bearer ${process.env.REPLICATE_API_TOKEN}`,
25
- },
26
- });
27
- const blob = await data.blob();
28
- let buffer = Buffer.from(await blob.arrayBuffer());
29
- return buffer.toString("base64");
30
- }
31
- catch (error) {
32
- throw new Error("Error fetching image");
33
- }
34
- }
@@ -1 +0,0 @@
1
- export * from "./error.js";