Skip to main content
Glama

flatten_messages

Replace large tool_result blocks in Messages API arrays with compact markers to reduce token count, and return extracted data for reversible restoration.

Instructions

Flatten a raw Anthropic Messages API messages[] array in memory: every bulky tool_result block (large text or base64 image) larger than min_size bytes is swapped for a compact [FLATTENED id=...] marker, and the originals are returned in "extracted". Persist "extracted" yourself — you are the store — and feed it back to unflatten_messages to restore the conversation byte-for-byte. Purely functional: no session file, no disk, no network; the input is never mutated. This is the same engine as the flatten-mcp library export; for production use inside your own process, prefer importing the library so the conversation does not travel over a transport.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messagesYesThe raw Messages API messages[] array ({ role, content } objects, verbatim).
min_sizeNoOnly flatten tool_result blocks larger than N serialized bytes.
Behavior4/5

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

Discloses key behaviors: purely functional, no mutation, no disk/network, same engine as library. With no annotations, it covers essential traits, though could mention error handling or size limits.

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

Conciseness3/5

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

Description is thorough but slightly verbose; includes some redundant phrasing. Front-loads core action ('flatten a raw Anthropic Messages API messages[] array in memory'), but could be tightened.

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

Completeness3/5

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

Missing output schema means description should explain return format (e.g., structure of 'extracted'). It mentions markers and originals but not the exact shape, leaving some ambiguity for the agent.

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

Parameters4/5

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

Schema already describes both parameters (100% coverage). Description adds context about Anthropic Messages API, tool_result blocks, and the effect of min_size threshold, adding meaning beyond the schema.

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?

Clearly states it flattens raw Anthropic Messages API messages[] array in memory, swapping bulky tool_result blocks with markers. Distinguishes from siblings like unflatten_messages and flatten_session.

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?

Explicitly tells when to use (in-memory flattening) and when not ('for production use inside your own process, prefer importing the library'). Also states to persist 'extracted' and feed to unflatten_messages, providing clear usage pattern.

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/shayaShav/flatten-mcp'

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