Skip to main content
Glama

create-link-preview

Generate and embed link previews in Notion pages by providing a URL and page ID to display content summaries directly within your workspace.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to create a preview for
page_idNoThe ID of the page to add the preview to

Implementation Reference

  • The main handler function for the 'create-link-preview' tool. It invokes the NotionService to create the link preview and returns a formatted text content response or an error message.
      async ({ url, page_id }) => {
        try {
          const result = await this.notionService.createLinkPreview({
            url,
            page_id,
          });
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error) {
          console.error("Error in create-link-preview tool:", error);
          return {
            content: [
              {
                type: "text",
                text: `Error: Failed to create link preview - ${
                  (error as Error).message
                }`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • The registerLinkPreviewTools method where the 'create-link-preview' tool is registered with the MCP server, including inline schema and handler.
    private registerLinkPreviewTools(): void {
      // Create link preview
      this.server.tool(
        "create-link-preview",
        {
          url: z.string().url().describe("The URL to create a preview for"),
          page_id: z
            .string()
            .optional()
            .describe("The ID of the page to add the preview to"),
        },
        async ({ url, page_id }) => {
          try {
            const result = await this.notionService.createLinkPreview({
              url,
              page_id,
            });
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(result, null, 2),
                },
              ],
            };
          } catch (error) {
            console.error("Error in create-link-preview tool:", error);
            return {
              content: [
                {
                  type: "text",
                  text: `Error: Failed to create link preview - ${
                    (error as Error).message
                  }`,
                },
              ],
              isError: true,
            };
          }
        }
      );
    }
  • Inline Zod schema defining input parameters for the create-link-preview tool.
    {
      url: z.string().url().describe("The URL to create a preview for"),
      page_id: z
        .string()
        .optional()
        .describe("The ID of the page to add the preview to"),
    },
  • Zod schema and TypeScript type for LinkPreview parameters, matching the tool input schema and used in NotionService.createLinkPreview.
    export const LinkPreviewSchema = z.object({
      url: z.string().url(),
      page_id: z.string().optional(),
    });
    
    export type LinkPreview = z.infer<typeof LinkPreviewSchema>;
  • Supporting method in NotionService called by the tool handler. Currently a placeholder that throws an error as the feature is not implemented in the Notion SDK.
    async createLinkPreview(params: LinkPreview) {
      try {
        // The Notion API doesn't have a direct method for link previews yet
        // This is a placeholder for when the feature becomes available in the SDK
        throw new NotionAPIError(
          "Link Preview API is not yet available in the official Notion SDK",
          "NOT_IMPLEMENTED"
        );
      } catch (error) {
        this.handleError(error);
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ramidecodes/mcp-server-notion'

If you have feedback or need assistance with the MCP directory API, please join our Discord server