Skip to main content
Glama

get_image_size

Retrieve the dimensions (width and height) of an image directly from its URL for accurate sizing and processing in applications.

Instructions

Get the size of an image from URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
optionsYesOptions for retrieving image size

Implementation Reference

  • MCP tool handler that extracts the image URL from input options, calls the helper function getImageSizeFromUrl, formats the result as JSON text content, and handles errors.
    async ({ options = {} }) => {
      try {
        const { imageUrl } = options as { imageUrl: string };
        // Call tool function implementation
        const result = await getImageSizeFromUrl(imageUrl);
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new Error(
          `Failed to get image size: ${(error as Error).message}`,
        );
      }
    },
  • Core helper function that uses probe-image-size to fetch and return width, height, type, and mime of an image from a given URL.
    export async function getImageSizeFromUrl(imageUrl: string) {
      // 获取图片尺寸信息
      const imageInfo = await probe(imageUrl);
      return {
        width: imageInfo.width,
        height: imageInfo.height,
        type: imageInfo.type,
        mime: imageInfo.mime,
      };
    }
  • Zod input schema defining the required 'imageUrl' string parameter for the tool.
    options: z
      .object({
        imageUrl: z.string().describe("Url of the image to retrieve"),
      })
      .describe("Options for retrieving image size"),
  • src/server.ts:169-198 (registration)
    Full registration of the 'get_image_size' tool on the MCP server, including name, description, schema, and handler implementation.
    server.tool(
      "get_image_size",
      "Get the size of an image from URL",
      {
        options: z
          .object({
            imageUrl: z.string().describe("Url of the image to retrieve"),
          })
          .describe("Options for retrieving image size"),
      },
      async ({ options = {} }) => {
        try {
          const { imageUrl } = options as { imageUrl: string };
          // Call tool function implementation
          const result = await getImageSizeFromUrl(imageUrl);
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error) {
          throw new Error(
            `Failed to get image size: ${(error as Error).message}`,
          );
        }
      },
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks details on performance (e.g., network timeouts, rate limits), error handling (e.g., invalid URLs, unsupported formats), or output format (e.g., dimensions in pixels). This leaves significant gaps for a tool that performs network operations.

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?

The description is a single, direct sentence with zero wasted words. It front-loads the core purpose ('Get the size of an image') and efficiently specifies the source ('from URL'). Every word earns its place, making it highly concise and well-structured.

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

Completeness2/5

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

Given the tool's network-based operation and lack of annotations or output schema, the description is incomplete. It doesn't address critical context like what 'size' means (e.g., dimensions, file size), potential errors, or response format. For a tool with no structured output documentation, this leaves too much unspecified.

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?

Schema description coverage is 100%, so the schema fully documents the single parameter 'imageUrl'. The description adds no additional semantic context beyond implying the URL is for an image, which is already clear from the parameter name. This meets the baseline for high schema coverage but doesn't enhance understanding.

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

Purpose4/5

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

The description clearly states the action ('Get the size') and resource ('an image from URL'), making the purpose immediately understandable. It distinguishes from the sibling tool 'get_local_image_size' by specifying the image source as 'from URL' rather than local. However, it doesn't explicitly contrast with the sibling, so it's not a perfect 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus its sibling 'get_local_image_size'. There's no mention of prerequisites, alternative scenarios, or exclusion criteria. The agent must infer usage from the name and description alone without explicit direction.

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

Related 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/kshern/image-tools-mcp'

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