Skip to main content
Glama

measure_text

Measure text dimensions and overflow risk for UI layouts without browser dependencies. Validate text fits containers, detect responsive breakpoint issues, and ensure compliance with line constraints before design or development.

Instructions

Predict text layout dimensions — height, line count, overflow risk, and breakpoint behavior — without a browser or Figma connection.

Prerequisites: None — runs entirely in Node.js using canvas-based text measurement. No Figma or AI dependencies.

Returns on success: Result object with { height: number (px), lineCount: number, lines: string[] (wrapped line strings) }. If containerHeight is provided, adds { overflow: { overflows: boolean, excessHeight: number } }. If checkBreakpoints is true, adds { breakpoints: { mobile: {...}, tablet: {...}, desktop: {...} } } each with the same height/lineCount/overflow shape.

Error behavior: Never throws — returns 0 height and 1 line if the font string is unparseable.

Use this tool: to validate that a UI label or body text will fit inside a fixed-height container before generating Figma designs or code, to detect which breakpoints cause overflow for responsive layouts, or to size containers accurately without a live browser. Particularly useful when a spec defines a maxLines constraint and you need to verify the real text content respects it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe text content to measure. Include all characters including newlines if the source content has them.
maxWidthYesMaximum container width in pixels for line wrapping calculations.
fontNoCSS font shorthand string used for measurement (e.g. '16px Inter', 'bold 14px sans-serif', '500 13px/1.4 system-ui'). Use the same font as your target UI for accurate results.16px sans-serif
lineHeightNoLine height in pixels. Defaults to fontSize × 1.5 if omitted. Provide this to match your Tailwind leading-* or Figma line height setting.
containerHeightNoIf provided, checks whether the measured text fits within this height (in pixels) and reports overflow. Omit if you only need dimensions.
checkBreakpointsNoIf true, also measures text at mobile (375px), tablet (768px), and desktop (1280px) widths in addition to maxWidth. Useful for responsive overflow detection.
Behavior4/5

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

With no annotations provided, the description carries the full burden and does so well by disclosing key behavioral traits: it describes the return object structure in detail, explains conditional additions based on parameters, and specifies error behavior ('Never throws — returns 0 height and 1 line if the font string is unparseable'). It could mention performance or rate limits but covers core behavior thoroughly.

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

Conciseness4/5

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

The description is well-structured and front-loaded with the core purpose, followed by prerequisites, return values, error behavior, and usage scenarios. Most sentences earn their place, though it could be slightly more concise by integrating some details more tightly.

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

Completeness5/5

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

Given the tool's complexity (6 parameters, no output schema, no annotations), the description provides complete context: it explains what the tool does, when to use it, behavioral details including error handling, and ties parameters to outcomes. This compensates adequately for the lack of structured metadata.

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 already documents all parameters thoroughly. The description adds some context by mentioning 'containerHeight' and 'checkBreakpoints' effects on the return object, but doesn't provide significant additional semantics beyond what the schema descriptions offer. Baseline 3 is appropriate given high schema coverage.

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's purpose with specific verbs ('predict text layout dimensions') and resources ('height, line count, overflow risk, and breakpoint behavior'), distinguishing it from siblings like 'analyze_design' or 'generate_code' by focusing on text measurement without browser/Figma dependencies.

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

Usage Guidelines5/5

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

Explicit guidance is provided on when to use this tool ('to validate that a UI label or body text will fit inside a fixed-height container', 'to detect which breakpoints cause overflow', 'to size containers accurately without a live browser') and when it's particularly useful ('when a spec defines a maxLines constraint'). It also clarifies prerequisites ('None — runs entirely in Node.js').

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/sarveshsea/m-moire'

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