Skip to main content
Glama
diagrammo
by diagrammo

open_in_app

Open a DGMO diagram in the Diagrammo desktop app on macOS, with automatic fallback to browser preview if the app is missing.

Instructions

Open a DGMO diagram in the Diagrammo desktop app (macOS only). Falls back to browser preview if the app is not installed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dgmoYesDGMO diagram markup

Implementation Reference

  • The main handler function for the 'open_in_app' tool. Encodes the DGMO diagram as a URL, attempts to open via deep link (diagrammo://open?dgmo=...) using macOS 'open' command. Falls back to rendering as SVG and opening in a browser if the app is not installed.
    async ({ dgmo }) => {
      const result = encodeDiagramUrl(dgmo);
      if (result.error === 'too-large') {
        return {
          content: [
            {
              type: 'text' as const,
              text: `Diagram is too large for URL encoding. Compressed size: ${result.compressedSize} bytes (limit: ${result.limit} bytes).`,
            },
          ],
          isError: true,
        };
      }
    
      // Extract the hash from the URL and construct a deep link
      const url = result.url;
      const hash = url.split('#')[1] ?? '';
      const deepLink = `diagrammo://open?dgmo=${hash}`;
    
      return new Promise((resolve) => {
        exec(`open ${JSON.stringify(deepLink)}`, async (error) => {
          if (error) {
            // Fallback: render to SVG and open in browser
            try {
              const rendered = await tryRender(dgmo, 'light', 'nord');
              if (!rendered.svg) {
                resolve({
                  content: [
                    {
                      type: 'text' as const,
                      text: `App not installed and render failed: ${rendered.error}`,
                    },
                  ],
                  isError: true,
                });
                return;
              }
              const paletteConfig = getPalette('nord');
              const html = buildPreviewHtml({
                svg: rendered.svg,
                title: 'Diagram Preview',
                dgmoSource: dgmo,
                palette: paletteConfig,
                shareUrl: url,
              });
              const filePath = writeTempHtml(html, 'dgmo-preview');
              await openInBrowser(filePath);
              resolve({
                content: [
                  {
                    type: 'text' as const,
                    text: `Diagrammo app not found — opened preview in browser: ${filePath}`,
                  },
                ],
              });
            } catch (fallbackErr) {
              resolve({
                content: [
                  {
                    type: 'text' as const,
                    text: `Failed to open Diagrammo app and browser fallback failed: ${fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr)}`,
                  },
                ],
                isError: true,
              });
            }
          } else {
            resolve({
              content: [
                {
                  type: 'text' as const,
                  text: 'Opened diagram in Diagrammo app.',
                },
              ],
            });
          }
        });
      });
    },
  • src/index.ts:258-351 (registration)
    Registration of the 'open_in_app' tool via server.tool(), including description, input schema (dgmo string), tool metadata (title, readOnlyHint, destructiveHint, openWorldHint), and the async handler callback.
    // --- Tool 3: open_in_app ---
    
    server.tool(
      'open_in_app',
      'Open a DGMO diagram in the Diagrammo desktop app (macOS only). Falls back to browser preview if the app is not installed.',
      {
        dgmo: z.string().describe('DGMO diagram markup'),
      },
      {
        title: 'Open in Diagrammo App',
        readOnlyHint: false,
        destructiveHint: false,
        openWorldHint: true,
      },
      async ({ dgmo }) => {
        const result = encodeDiagramUrl(dgmo);
        if (result.error === 'too-large') {
          return {
            content: [
              {
                type: 'text' as const,
                text: `Diagram is too large for URL encoding. Compressed size: ${result.compressedSize} bytes (limit: ${result.limit} bytes).`,
              },
            ],
            isError: true,
          };
        }
    
        // Extract the hash from the URL and construct a deep link
        const url = result.url;
        const hash = url.split('#')[1] ?? '';
        const deepLink = `diagrammo://open?dgmo=${hash}`;
    
        return new Promise((resolve) => {
          exec(`open ${JSON.stringify(deepLink)}`, async (error) => {
            if (error) {
              // Fallback: render to SVG and open in browser
              try {
                const rendered = await tryRender(dgmo, 'light', 'nord');
                if (!rendered.svg) {
                  resolve({
                    content: [
                      {
                        type: 'text' as const,
                        text: `App not installed and render failed: ${rendered.error}`,
                      },
                    ],
                    isError: true,
                  });
                  return;
                }
                const paletteConfig = getPalette('nord');
                const html = buildPreviewHtml({
                  svg: rendered.svg,
                  title: 'Diagram Preview',
                  dgmoSource: dgmo,
                  palette: paletteConfig,
                  shareUrl: url,
                });
                const filePath = writeTempHtml(html, 'dgmo-preview');
                await openInBrowser(filePath);
                resolve({
                  content: [
                    {
                      type: 'text' as const,
                      text: `Diagrammo app not found — opened preview in browser: ${filePath}`,
                    },
                  ],
                });
              } catch (fallbackErr) {
                resolve({
                  content: [
                    {
                      type: 'text' as const,
                      text: `Failed to open Diagrammo app and browser fallback failed: ${fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr)}`,
                    },
                  ],
                  isError: true,
                });
              }
            } else {
              resolve({
                content: [
                  {
                    type: 'text' as const,
                    text: 'Opened diagram in Diagrammo app.',
                  },
                ],
              });
            }
          });
        });
      },
    );
  • Input schema for the 'open_in_app' tool - requires a single string parameter 'dgmo' (DGMO diagram markup).
    {
      dgmo: z.string().describe('DGMO diagram markup'),
    },
  • The openInBrowser helper function used by the fallback path. Cross-platform: uses 'open' on macOS, 'start' on Windows, 'xdg-open' on Linux.
    import { exec } from 'node:child_process';
    import { platform } from 'node:os';
    
    /**
     * Open a file path in the default browser. Cross-platform.
     */
    export function openInBrowser(filePath: string): Promise<void> {
      const os = platform();
      const cmd =
        os === 'darwin' ? 'open' : os === 'win32' ? 'start ""' : 'xdg-open';
    
      return new Promise((resolve, reject) => {
        exec(`${cmd} ${JSON.stringify(filePath)}`, (error) => {
          if (error) reject(error);
          else resolve();
        });
      });
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond annotations (readOnlyHint false, destructiveHint false, openWorldHint true), the description adds the fallback behavior to browser preview if the app is not installed. This is useful behavioral context. No contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences with no wasted words. Front-loaded with the core action and immediately provides important constraints (macOS only, fallback).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (one parameter, no output schema), the description is complete enough. It covers the purpose, platform restriction, fallback, and required input. Could theoretically mention that it launches an external app, but for practical purposes it's sufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 100% coverage with a description for the single parameter 'dgmo' ('DGMO diagram markup'). The tool description adds no additional meaning beyond what the schema already provides, so baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool opens a DGMO diagram in the Diagrammo desktop app, with a specific fallback behavior. It distinguishes itself from siblings like preview_diagram and render_diagram by specifying the target app and fallback mechanism.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context: it is for opening in the desktop app and mentions macOS-only and fallback. However, it does not explicitly contrast with preview_diagram or suggest when to use one over the other, leaving some ambiguity for an AI agent.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/diagrammo/dgmo-mcp'

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