notion-mcp-server 1.0.1 → 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 (99) 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 -138
  21. package/build/schema/database.js +27 -111
  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 -125
  28. package/build/schema/refs.js +16 -0
  29. package/build/schema/rich-text.js +1 -1
  30. package/build/server/index.js +16 -3
  31. package/build/services/auth.js +19 -0
  32. package/build/services/notion.js +14 -17
  33. package/build/tools/index.js +119 -21
  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 -60
  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 -39
  51. package/build/services/loggs.js +0 -13
  52. package/build/services/replicate.js +0 -23
  53. package/build/tools/appendBlockChildren.js +0 -25
  54. package/build/tools/batchAppendBlockChildren.js +0 -33
  55. package/build/tools/batchDeleteBlocks.js +0 -32
  56. package/build/tools/batchMixedOperations.js +0 -58
  57. package/build/tools/batchUpdateBlocks.js +0 -33
  58. package/build/tools/blocks.js +0 -34
  59. package/build/tools/comments.js +0 -81
  60. package/build/tools/createDatabase.js +0 -18
  61. package/build/tools/createPage.js +0 -18
  62. package/build/tools/createPrediction.js +0 -28
  63. package/build/tools/database.js +0 -16
  64. package/build/tools/deleteBlock.js +0 -24
  65. package/build/tools/formatRichText.js +0 -83
  66. package/build/tools/generateImage.js +0 -48
  67. package/build/tools/generateImageVariants.js +0 -105
  68. package/build/tools/generateMultipleImages.js +0 -60
  69. package/build/tools/generateSVG.js +0 -43
  70. package/build/tools/getPrediction.js +0 -22
  71. package/build/tools/pages.js +0 -22
  72. package/build/tools/predictionList.js +0 -30
  73. package/build/tools/queryDatabase.js +0 -22
  74. package/build/tools/retrieveBlock.js +0 -24
  75. package/build/tools/retrieveBlockChildren.js +0 -32
  76. package/build/tools/searchPage.js +0 -24
  77. package/build/tools/updateBlock.js +0 -25
  78. package/build/tools/updateDatabase.js +0 -18
  79. package/build/tools/updatePage.js +0 -40
  80. package/build/tools/updatePageProperties.js +0 -21
  81. package/build/tools/users.js +0 -75
  82. package/build/types/blocks.js +0 -12
  83. package/build/types/comments.js +0 -7
  84. package/build/types/database.js +0 -6
  85. package/build/types/notion.js +0 -1
  86. package/build/types/page.js +0 -8
  87. package/build/types/richText.js +0 -1
  88. package/build/types/tools.js +0 -1
  89. package/build/types/users.js +0 -6
  90. package/build/utils/blob.js +0 -5
  91. package/build/utils/image.js +0 -34
  92. package/build/utils/index.js +0 -1
  93. package/build/utils/richText.js +0 -174
  94. package/build/validation/blocks.js +0 -568
  95. package/build/validation/notion.js +0 -51
  96. package/build/validation/page.js +0 -262
  97. package/build/validation/richText.js +0 -744
  98. package/build/validation/tools.js +0 -16
  99. /package/build/{types/index.js → operations/types.js} +0 -0
@@ -1,17 +0,0 @@
1
- // import { z } from "zod";
2
- // import { blockSchema } from "./blocks.js";
3
- // import { parentSchema } from "./page.js";
4
- export {};
5
- // export const createPageSchema = {
6
- // parent: parentSchema,
7
- // properties: z.object({
8
- // title: z.object({
9
- // title: z.array(z.any()), // Rich text array
10
- // }),
11
- // }),
12
- // children: z.array(blockSchema).optional(),
13
- // };
14
- // export const appendBlocksSchema = {
15
- // block_id: z.string(),
16
- // children: z.array(blockSchema),
17
- // };
@@ -1,39 +0,0 @@
1
- import { z } from "zod";
2
- import { preprocessJson } from "./preprocess.js";
3
- // Schema for listing users with pagination
4
- export const LIST_USERS_SCHEMA = {
5
- start_cursor: z.string().optional().describe("Pagination cursor"),
6
- page_size: z
7
- .number()
8
- .optional()
9
- .describe("Number of users to return per page"),
10
- };
11
- // Schema for getting a single user
12
- export const GET_USER_SCHEMA = {
13
- user_id: z.string().describe("The ID of the user to retrieve"),
14
- };
15
- // Combined schema for all user operations
16
- export const USERS_OPERATION_SCHEMA = {
17
- payload: z
18
- .preprocess(preprocessJson, z.discriminatedUnion("action", [
19
- z.object({
20
- action: z
21
- .literal("list_users")
22
- .describe("Use this action to list users."),
23
- params: z.object(LIST_USERS_SCHEMA),
24
- }),
25
- z.object({
26
- action: z
27
- .literal("get_user")
28
- .describe("Use this action to get a single user."),
29
- params: z.object(GET_USER_SCHEMA),
30
- }),
31
- z.object({
32
- action: z
33
- .literal("get_bot_user")
34
- .describe("Use this action to get the bot user."),
35
- params: z.object({}),
36
- }),
37
- ]))
38
- .describe("A union of all possible user operations. Each operation has a specific action and corresponding parameters. Use this schema to validate the input for user operations such as listing, getting a single user, and getting the bot user. Available actions include: 'list_users', 'get_user', and 'get_bot_user'. Each operation requires specific parameters as defined in the corresponding schemas."),
39
- };
@@ -1,13 +0,0 @@
1
- export function sendLog(level, message, data = null) {
2
- fetch("http://localhost:4400/api/log", {
3
- method: "POST",
4
- headers: {
5
- "Content-Type": "application/json",
6
- },
7
- body: JSON.stringify({
8
- level, // 'debug', 'info', 'warn', 'error'
9
- message,
10
- data, // Optional additional data object or string
11
- }),
12
- }).catch((error) => console.error("Error sending log:", error));
13
- }
@@ -1,23 +0,0 @@
1
- import Replicate from "replicate";
2
- import { CONFIG } from "../config/index.js";
3
- export function getReplicateApiToken() {
4
- const token = process.env.REPLICATE_API_TOKEN;
5
- if (!token) {
6
- console.error("Error: REPLICATE_API_TOKEN environment variable is required");
7
- process.exit(1);
8
- }
9
- return token;
10
- }
11
- export const replicate = new Replicate({
12
- auth: getReplicateApiToken(),
13
- });
14
- export async function pollForCompletion(predictionId) {
15
- for (let i = 0; i < CONFIG.pollingAttempts; i++) {
16
- const latest = await replicate.predictions.get(predictionId);
17
- if (latest.status !== "starting" && latest.status !== "processing") {
18
- return latest;
19
- }
20
- await new Promise((resolve) => setTimeout(resolve, CONFIG.pollingInterval));
21
- }
22
- return null;
23
- }
@@ -1,25 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const appendBlockChildren = async (params) => {
4
- try {
5
- const response = await notion.blocks.children.append({
6
- block_id: params.blockId,
7
- children: params.children,
8
- });
9
- return {
10
- content: [
11
- {
12
- type: "text",
13
- text: `Successfully appended ${params.children.length} block(s) to ${params.blockId}`,
14
- },
15
- {
16
- type: "text",
17
- text: `Block ID: ${JSON.stringify(response, null, 2)}`,
18
- },
19
- ],
20
- };
21
- }
22
- catch (error) {
23
- return handleNotionError(error);
24
- }
25
- };
@@ -1,33 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const batchAppendBlockChildren = async (params) => {
4
- try {
5
- const results = [];
6
- for (const operation of params.operations) {
7
- const response = await notion.blocks.children.append({
8
- block_id: operation.blockId,
9
- children: operation.children,
10
- });
11
- results.push({
12
- blockId: operation.blockId,
13
- success: true,
14
- response,
15
- });
16
- }
17
- return {
18
- content: [
19
- {
20
- type: "text",
21
- text: `Successfully completed ${params.operations.length} append operations`,
22
- },
23
- {
24
- type: "text",
25
- text: JSON.stringify(results, null, 2),
26
- },
27
- ],
28
- };
29
- }
30
- catch (error) {
31
- return handleNotionError(error);
32
- }
33
- };
@@ -1,32 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const batchDeleteBlocks = async (params) => {
4
- try {
5
- const results = [];
6
- for (const blockId of params.blockIds) {
7
- const response = await notion.blocks.delete({
8
- block_id: blockId,
9
- });
10
- results.push({
11
- blockId,
12
- success: true,
13
- response,
14
- });
15
- }
16
- return {
17
- content: [
18
- {
19
- type: "text",
20
- text: `Successfully deleted ${params.blockIds.length} blocks (moved to trash)`,
21
- },
22
- {
23
- type: "text",
24
- text: JSON.stringify(results, null, 2),
25
- },
26
- ],
27
- };
28
- }
29
- catch (error) {
30
- return handleNotionError(error);
31
- }
32
- };
@@ -1,58 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const batchMixedOperations = async (params) => {
4
- try {
5
- const results = [];
6
- const operationCounts = {
7
- append: 0,
8
- update: 0,
9
- delete: 0,
10
- };
11
- for (const op of params.operations) {
12
- let response;
13
- switch (op.operation) {
14
- case "append":
15
- response = await notion.blocks.children.append({
16
- block_id: op.blockId,
17
- children: op.children,
18
- });
19
- operationCounts.append++;
20
- break;
21
- case "update":
22
- response = await notion.blocks.update({
23
- block_id: op.blockId,
24
- ...op.data,
25
- });
26
- operationCounts.update++;
27
- break;
28
- case "delete":
29
- response = await notion.blocks.delete({
30
- block_id: op.blockId,
31
- });
32
- operationCounts.delete++;
33
- break;
34
- }
35
- results.push({
36
- operation: op.operation,
37
- blockId: op.blockId,
38
- success: true,
39
- response,
40
- });
41
- }
42
- return {
43
- content: [
44
- {
45
- type: "text",
46
- text: `Successfully performed ${params.operations.length} operations (${operationCounts.append} append, ${operationCounts.update} update, ${operationCounts.delete} delete)`,
47
- },
48
- {
49
- type: "text",
50
- text: JSON.stringify(results, null, 2),
51
- },
52
- ],
53
- };
54
- }
55
- catch (error) {
56
- return handleNotionError(error);
57
- }
58
- };
@@ -1,33 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const batchUpdateBlocks = async (params) => {
4
- try {
5
- const results = [];
6
- for (const operation of params.operations) {
7
- const response = await notion.blocks.update({
8
- block_id: operation.blockId,
9
- ...operation.data,
10
- });
11
- results.push({
12
- blockId: operation.blockId,
13
- success: true,
14
- response,
15
- });
16
- }
17
- return {
18
- content: [
19
- {
20
- type: "text",
21
- text: `Successfully updated ${params.operations.length} blocks`,
22
- },
23
- {
24
- type: "text",
25
- text: JSON.stringify(results, null, 2),
26
- },
27
- ],
28
- };
29
- }
30
- catch (error) {
31
- return handleNotionError(error);
32
- }
33
- };
@@ -1,34 +0,0 @@
1
- import { handleNotionError } from "../utils/error.js";
2
- import { appendBlockChildren } from "./appendBlockChildren.js";
3
- import { retrieveBlock } from "./retrieveBlock.js";
4
- import { retrieveBlockChildren } from "./retrieveBlockChildren.js";
5
- import { updateBlock } from "./updateBlock.js";
6
- import { deleteBlock } from "./deleteBlock.js";
7
- import { batchAppendBlockChildren } from "./batchAppendBlockChildren.js";
8
- import { batchUpdateBlocks } from "./batchUpdateBlocks.js";
9
- import { batchDeleteBlocks } from "./batchDeleteBlocks.js";
10
- import { batchMixedOperations } from "./batchMixedOperations.js";
11
- export const registerBlocksOperationTool = async (params) => {
12
- switch (params.payload.action) {
13
- case "append_block_children":
14
- return appendBlockChildren(params.payload.params);
15
- case "retrieve_block":
16
- return retrieveBlock(params.payload.params);
17
- case "retrieve_block_children":
18
- return retrieveBlockChildren(params.payload.params);
19
- case "update_block":
20
- return updateBlock(params.payload.params);
21
- case "delete_block":
22
- return deleteBlock(params.payload.params);
23
- case "batch_append_block_children":
24
- return batchAppendBlockChildren(params.payload.params);
25
- case "batch_update_blocks":
26
- return batchUpdateBlocks(params.payload.params);
27
- case "batch_delete_blocks":
28
- return batchDeleteBlocks(params.payload.params);
29
- case "batch_mixed_operations":
30
- return batchMixedOperations(params.payload.params);
31
- default:
32
- return handleNotionError(new Error(`Unsupported action, use one of the following: "append_block_children", "retrieve_block", "retrieve_block_children", "update_block", "delete_block", "batch_append_block_children", "batch_update_blocks", "batch_delete_blocks", "batch_mixed_operations"`));
33
- }
34
- };
@@ -1,81 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- const registerGetCommentsTool = async (params) => {
4
- try {
5
- const response = await notion.comments.list(params);
6
- return {
7
- content: [
8
- {
9
- type: "text",
10
- text: `Comments 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
- const registerAddPageCommentTool = async (params) => {
24
- try {
25
- const response = await notion.comments.create(params);
26
- return {
27
- content: [
28
- {
29
- type: "text",
30
- text: `Comment created 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
- const registerAddDiscussionCommentTool = async (params) => {
44
- try {
45
- const response = await notion.comments.create(params);
46
- return {
47
- content: [
48
- {
49
- type: "text",
50
- text: `Comment created 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
- };
63
- // Combined tool function that handles all comment operations
64
- export const registerCommentsOperationTool = async (params) => {
65
- try {
66
- const { payload } = params;
67
- switch (payload.action) {
68
- case "get_comments":
69
- return registerGetCommentsTool(payload.params);
70
- case "add_page_comment":
71
- return registerAddPageCommentTool(payload.params);
72
- case "add_discussion_comment":
73
- return registerAddDiscussionCommentTool(payload.params);
74
- default:
75
- throw new Error(`Unsupported action, use one of the following: "get_comments", "add_page_comment", "add_discussion_comment"`);
76
- }
77
- }
78
- catch (error) {
79
- return handleNotionError(error);
80
- }
81
- };
@@ -1,18 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const createDatabase = async (params) => {
4
- try {
5
- const response = await notion.databases.create(params);
6
- return {
7
- content: [
8
- {
9
- type: "text",
10
- text: `Database created successfully: ${response.id}`,
11
- },
12
- ],
13
- };
14
- }
15
- catch (error) {
16
- return handleNotionError(error);
17
- }
18
- };
@@ -1,18 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const registerCreatePageTool = async (params) => {
4
- try {
5
- const response = await notion.pages.create(params);
6
- return {
7
- content: [
8
- {
9
- type: "text",
10
- text: `Page created successfully: ${response.id}`,
11
- },
12
- ],
13
- };
14
- }
15
- catch (error) {
16
- return handleNotionError(error);
17
- }
18
- };
@@ -1,28 +0,0 @@
1
- // import { CreatePredictionParams } from "../types/index.js";
2
- // import { pollForCompletion, replicate } from "../services/replicate.js";
3
- // import { handleError } from "../utils/error.js";
4
- // import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
5
- // import { CONFIG } from "../config/index.js";
6
- export {};
7
- // export const registerCreatePredictionTool = async (
8
- // input: CreatePredictionParams
9
- // ): Promise<CallToolResult> => {
10
- // try {
11
- // const prediction = await replicate.predictions.create({
12
- // model: CONFIG.imageModelId,
13
- // input,
14
- // });
15
- // await replicate.predictions.get(prediction.id);
16
- // const completed = await pollForCompletion(prediction.id);
17
- // return {
18
- // content: [
19
- // {
20
- // type: "text",
21
- // text: JSON.stringify(completed || "Processing timed out", null, 2),
22
- // },
23
- // ],
24
- // };
25
- // } catch (error) {
26
- // handleError(error);
27
- // }
28
- // };
@@ -1,16 +0,0 @@
1
- import { handleNotionError } from "../utils/error.js";
2
- import { createDatabase } from "./createDatabase.js";
3
- import { queryDatabase } from "./queryDatabase.js";
4
- import { updateDatabase } from "./updateDatabase.js";
5
- export const registerDatabaseOperationTool = async (params) => {
6
- switch (params.payload.action) {
7
- case "create_database":
8
- return createDatabase(params.payload.params);
9
- case "query_database":
10
- return queryDatabase(params.payload.params);
11
- case "update_database":
12
- return updateDatabase(params.payload.params);
13
- default:
14
- return handleNotionError(new Error(`Unsupported action, use one of the following: "create_database", "query_database", "update_database"`));
15
- }
16
- };
@@ -1,24 +0,0 @@
1
- import { notion } from "../services/notion.js";
2
- import { handleNotionError } from "../utils/error.js";
3
- export const deleteBlock = async (params) => {
4
- try {
5
- const response = await notion.blocks.delete({
6
- block_id: params.blockId,
7
- });
8
- return {
9
- content: [
10
- {
11
- type: "text",
12
- text: `Block ${params.blockId} deleted (moved to trash) successfully`,
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,83 +0,0 @@
1
- import { z } from "zod";
2
- import { handleError } from "../utils/error.js";
3
- import { boldText, italicText, codeText, colorText, createTextRichText, } from "../utils/richText.js";
4
- // Schema for the formatRichText tool as a record of ZodTypes
5
- export const formatRichTextSchema = {
6
- text: z.string().describe("Text content to format"),
7
- include_bold: z
8
- .boolean()
9
- .optional()
10
- .describe("Whether to include bold formatting"),
11
- include_italic: z
12
- .boolean()
13
- .optional()
14
- .describe("Whether to include italic formatting"),
15
- include_code: z
16
- .boolean()
17
- .optional()
18
- .describe("Whether to include code formatting"),
19
- include_color: z
20
- .boolean()
21
- .optional()
22
- .describe("Whether to include color formatting"),
23
- include_link: z.boolean().optional().describe("Whether to include a link"),
24
- link_url: z
25
- .string()
26
- .url()
27
- .optional()
28
- .describe("URL to link to if include_link is true"),
29
- color: z
30
- .string()
31
- .optional()
32
- .describe("Color to use if include_color is true"),
33
- };
34
- // Object schema for type inference
35
- const formatRichTextObjectSchema = z.object(formatRichTextSchema);
36
- /**
37
- * Tool that demonstrates rich text formatting in Notion
38
- * @param params The parameters for formatting rich text
39
- * @returns A formatted JSON representation of the rich text
40
- */
41
- export const registerFormatRichTextTool = async (params) => {
42
- try {
43
- const { text, include_bold = false, include_italic = false, include_code = false, include_color = false, include_link = false, link_url = "https://example.com", color = "blue", } = params;
44
- // Split the text into parts to demonstrate formatting each part differently
45
- const parts = text.split(" ");
46
- const formattedParts = [];
47
- // Format each part based on the parameters
48
- for (let i = 0; i < parts.length; i++) {
49
- const part = parts[i];
50
- if (i % 5 === 0 && include_bold) {
51
- formattedParts.push(boldText(part + " "));
52
- }
53
- else if (i % 5 === 1 && include_italic) {
54
- formattedParts.push(italicText(part + " "));
55
- }
56
- else if (i % 5 === 2 && include_code) {
57
- formattedParts.push(codeText(part + " "));
58
- }
59
- else if (i % 5 === 3 && include_color) {
60
- formattedParts.push(colorText(part + " ", color));
61
- }
62
- else if (i % 5 === 4 && include_link) {
63
- formattedParts.push(createTextRichText(part + " ", undefined, link_url));
64
- }
65
- else {
66
- formattedParts.push(createTextRichText(part + " "));
67
- }
68
- }
69
- // The resulting rich text array
70
- const richText = formattedParts;
71
- return {
72
- content: [
73
- {
74
- type: "text",
75
- text: JSON.stringify(richText, null, 2),
76
- },
77
- ],
78
- };
79
- }
80
- catch (error) {
81
- return handleError(error);
82
- }
83
- };
@@ -1,48 +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 registerGenerateImageTool = async (input) => {
6
- const { support_image_mcp_response_type, ...predictionInput } = input;
7
- try {
8
- const [output] = (await replicate.run(CONFIG.imageModelId, {
9
- input: predictionInput,
10
- }));
11
- const imageUrl = output.url();
12
- if (support_image_mcp_response_type) {
13
- const imageBase64 = await outputToBase64(output);
14
- return {
15
- content: [
16
- {
17
- type: "text",
18
- text: `This is a generated image link: ${imageUrl}`,
19
- },
20
- {
21
- type: "image",
22
- data: imageBase64,
23
- mimeType: "image/png",
24
- },
25
- {
26
- type: "text",
27
- text: `The image above is generated by the Flux model and prompt: ${input.prompt}`,
28
- },
29
- ],
30
- };
31
- }
32
- return {
33
- content: [
34
- {
35
- type: "text",
36
- text: `This is a generated image link: ${imageUrl}`,
37
- },
38
- {
39
- type: "text",
40
- text: `The image above is generated by the Flux model and prompt: ${input.prompt}`,
41
- },
42
- ],
43
- };
44
- }
45
- catch (error) {
46
- handleError(error);
47
- }
48
- };