Skip to main content
Glama

Headroom Mini

Headroom Mini הוא שרת MCP מקומי לניתוב וייעול טוקנים עבור פרומפטים ושליחת תוכן ל-LLM.

מה הפרויקט עושה

  • מיישם שרת MCP (@modelcontextprotocol/sdk) עם כלים ל:

    • דחיסת קוד (compress_code)

    • דחיסת JSON (compress_json)

    • אופטימיזציית פרומפטים (optimize_prompt)

    • הזרקת placeholder הפיכה (redact_content)

    • שחזור תוכן דרך placeholder (hydrate)

  • משתמש בספרייה gpt-tokenizer כדי להדפיס סטטיסטיקת טוקנים ברורה לכל פעולה.

  • מנהל מזהי placeholder עם HEADROOM_REDACTED_LOGS_ID_<NUM> ושומר תוכן לשחזור.

  • התהליך מתבצע מקומית בזמן ריצה, ללא אחסון קבוע מחוץ לזיכרון הריצה.

Related MCP server: slimctx-token-optimizer

מבנה הפרויקט

  • src/ – קוד המקור

  • src/tools/ – פונקציות עזר

  • src/storage/ – אחסון placeholder רוחבי לזמן ריצה

  • tests/ – טסטים יחידה

איך להתקין ולהריץ

npm install
npm start

הפקודה npm start תבנה את הקוד לפני ההרצה בעזרת prestart.

לריצה מהירה בסביבת פיתוח (בלי תהליך בנייה נפרד):

npm run dev

להרצת הטסטים:

npm test

דוגמת שימוש

  1. התקנה והרצה:

npm install
npm start
  1. הפעלת שרת MCP מקומי:

npm run dev
  1. בדיקת יחידות:

npm test

להגשה: יש לכלול את כל הקבצים במקור ללא node_modules ובלי dist.

כלים בשרת MCP

  • compress_code – מסיר הערות, docstrings וקווים ריקים מקוד

  • compress_json – בודק JSON וממזג אותו לשורה אחת

  • optimize_prompt – מוציא חותמות זמן ו-UUIDים ומעביר אותם לסוף הפרומפט

  • redact_content – מחליף תוכן ארוך מעל 500 תווים ב-placeholder

  • hydrate – מקבל placeholder או טקסט המכיל אותו ומחזיר את התוכן המקורי

דוגמת schema של כלי MCP

{
  name: "compress_code",
  description: "Compresses code by removing comments and whitespace",
  inputSchema: {
    type: "object",
    properties: {
      code: { type: "string" }
    },
    required: ["code"]
  }
}

זהו המבנה שבו סוכן AI יכול לזהות מתי להפעיל כלי דחיסה לפני שליחה ל-LLM.

תשובה לחלק 1.1

1. למה הזזת שדות דינמיים לסוף זה חשוב?

הזזת שדות דינמיים כמו חותמות זמן או UUID לסוף הפרומפט שומרת על החלק ה"קבוע" של הטקסט זהה בין בקשות שונות. זה מאפשר למודלים ולהיצעי cache של ספקים לזהות שהפרומפט הוא אותו פרומפט עם שינויים קטנים, וכך נמנע "cache miss". ההשפעה הכלכלית היא חיסכון משמעותי בעלויות שימוש ב-API, כי מודלים לא צריכים לנתח שוב ולקדד מחדש פרומפטים שבהם רק הנתונים הדינמיים השתנו.

2. כיצד לולאת פידבק עם placeholders עובדת?

במנגנון זה התוכן המלא נחתך כשגדול מדי, ובמקומו מוחדר מזהה מיוחד כגון: [HEADROOM_REDACTED_LOGS_ID_1]. אם המודל צריך את התוכן המקורי בשיחה הבאה, הוא יכול לבקש אותו במפורש. השרת יכול להזרים חזרה את התוכן דרך hydrate, ובכך לשמור על דחיסה ראשונית ועדיין לאפשר שחזור מלא של המידע במידת הצורך.

תשובה לחלק 1.2

תרשים זרימה של מחזור חיים

flowchart LR
  Dev["מפתח/ת (Cursor IDE)"] --> Client["Cursor / MCP Client"]
  Client --> Server["Headroom-Mini MCP Server"]
  Server --> LLM["מודל יעד (Anthropic / Claude)"]

  subgraph preprocessing ["Headroom-Mini Processing"]
    TokenCount["Token Counting"]
    CacheAnalysis["בדיקת cache / ניתוח סטטי"]
    CompressCode["דחיסת קוד / JSON"]
    PromptOptimize["אופטימיזציית פרומפט"]
    Redact["הזרקת placeholders"]
    Hydration["לולאת פידבק / Hydrate"]
  end

  Client --> TokenCount
  TokenCount --> CacheAnalysis
  CacheAnalysis --> CompressCode
  CompressCode --> PromptOptimize
  PromptOptimize --> Redact
  Redact --> LLM
  LLM --> Hydration
  Hydration --> Server

הסבר זרימה

  • המפתח כותב קוד או פרומפט ב-Cursor.

  • Cursor שולח את הבקשה לשרת MCP המקומי.

  • Headroom-Mini סופר טוקנים, מנתח שדות דינמיים, דוחס קוד/JSON ויכול להחליף תוכן גדול ב-placeholders.

  • אם המודל מבקש מידע נוסף, המערכת מקבלת מזהה placeholder מהשיחה, והשרת מחזיר את התוכן המקורי באמצעות hydrate.

תשובה לחלק 3

שימוש ביכולות AI פנימיות של Cursor

בפרויקט זה ניתן היה לנצל את יכולות ה-AI של Cursor כדי להבין את מבנה המלל והכלים של Headroom, וליצור את ה-schema של הכלים בצורה מדויקת. ה־README כולל הסברים על כל כלי והטמעה של שרת MCP, מה שמ יוצר ממשק ברור עבור סוכן.

איך סוכן AI משתמש ב-schema של כלי MCP?

כאשר מגדירים כלי MCP עם name, description ו־inputSchema, סוכן AI יכול להבין באיזה תנאים כדאי להפעיל כל כלי. למשל, אם הטקסט מכיל JSON גדול, הסוכן יכול להפעיל compress_json לפני שליחה. זה יאפשר לו לבחור האם לנסות דחיסה או hydration בהתאם לבקשה ולתוכן.

איך Cursor יכול להפעיל את הכלים

בממשק של Cursor, סוכן ה-AI יכול לבחור כלי MCP מתוך הרשימה שהוגדרה לו ולהפעילו בזמן כתיבת בקשה או שליחת פרומפט. לדוגמה, אם המשתמש כותב בקשה עם קוד ארוך, הסוכן יכול לבחור compress_code; אם יש JSON גדול, הוא יכול לבחור compress_json; ואם יש צורך בשחזור תוכן, הוא יכול להשתמש ב-hydrate. זה הופך את התהליך לאוטומטי, שקוף, וממוקד בהקטנת עלויות התקשורת עם המודל.

מדידת טוקנים

דוגמה להדפסה שנמצאת בזמן הריצה:

Original tokens: 2450
Optimized tokens: 1320
Saved tokens: 1130 (46%)

המדידה הזאת מתבצעת באמצעות gpt-tokenizer ומאפשרת לראות את ההשפעה המעשית של הדחיסה.

טסטים

הפרויקט כולל טסטים למקרים קריטיים:

  • בדיקת הסרת comments מקוד

  • בדיקת minify של JSON

  • בדיקת replacement של placeholder ארוך

  • בדיקת אופטימיזציית prompt עם timestamps ו-UUID

ניתן להריץ את כל הטסטים עם:

npm test

הערות נוספות

  • אין node_modules בתיעוד, וניתן להריץ את הפרויקט אחרי npm install בתוך פחות מ-3 דקות.

  • יש טסטים שמכסים את הלוגיקה המרכזית; ניתן להריץ אותם באמצעות npm test.

Available Tools

5 tools
compress_codeB

Semantic code compression (removes comments + whitespace)

ParametersJSON Schema
NameRequiredDescriptionDefault
codeYes

TDQS

B3.1/5.0
Behavior3/5

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

Without annotations, the description must disclose behavior. It states it removes comments and whitespace, which is transparent, but doesn't mention if it's reversible or language-specific.

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?

One sentence, front-loaded with the core action and details. No unnecessary words.

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?

For a simple tool with one parameter and no output schema, the description covers the main action but lacks details on input constraints or results. Adequate but not comprehensive.

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

Parameters2/5

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

Schema description coverage is 0%, so the description should compensate. The description does not add any information about the 'code' parameter beyond its name, such as format, language support, or size limits.

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 verb 'compress' and the resource 'code', and specifies it removes comments and whitespace. It distinguishes from siblings like compress_json by focusing on code, though not explicitly.

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?

No guidance on when to use this tool versus alternatives such as compress_json or hydrate. No context about prerequisites or limitations.

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

compress_jsonB

Minify JSON safely without breaking structure

ParametersJSON Schema
NameRequiredDescriptionDefault
jsonYes

TDQS

B3/5.0
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It only mentions safety and structure preservation, but lacks details on what exactly is minified (whitespace? comments?), edge cases, or error handling.

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 a single front-loaded sentence with no wasted words. However, it could be slightly more informative without losing conciseness.

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?

For a simple single-string tool, the description gives the purpose but lacks constraints or usage context. Without annotations or output schema, the agent has insufficient guidance to invoke it correctly.

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

Parameters1/5

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

Schema coverage is 0% for the single parameter. The description does not mention the 'json' parameter at all, failing to add meaning beyond the bare schema type definition.

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 uses a specific verb 'minify' and resource 'JSON', and the phrase 'safely without breaking structure' adds clarity. It clearly distinguishes from siblings like compress_code, which targets code, and optimize_prompt, which targets prompts.

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

Usage Guidelines3/5

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

The description implies use for compressing JSON while preserving validity, but does not explicitly state when to use this tool versus alternatives, nor does it provide when-not or exclusion criteria.

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

hydrateC

Restores content from HEADROOM_REDACTED placeholders

ParametersJSON Schema
NameRequiredDescriptionDefault
textYes

TDQS

C2.6/5.0
Behavior2/5

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

No annotations provided. The description does not disclose side effects, authentication needs, rate limits, or whether the tool modifies state. It only states the function without behavioral context.

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?

The description is very concise (one sentence). While not verbose, it could include more essential information without being lengthy.

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 no output schema, no annotations, and a single parameter, the description is insufficient. It does not explain return values, limitations, or usage context.

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

Parameters2/5

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

Schema coverage is 0% and the description does not explain the 'text' parameter beyond its type. No details on format, expected input, or purpose.

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 (restores) and the resource (content from placeholders). It distinguishes from sibling tools which are about compression and redaction, implying this is a reversal of redaction.

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?

No guidance on when to use this tool or when not to. Lacks mention of prerequisites like prior redaction or alternatives.

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

optimize_promptB

Moves dynamic fields (timestamps / UUIDs) to end for better cache performance

ParametersJSON Schema
NameRequiredDescriptionDefault
promptYes

TDQS

B3.1/5.0
Behavior2/5

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

With no annotations, the description must fully explain behavior. It states the core transformation but omits critical details: whether the prompt is expected to be a JSON string or plain text, how dynamic fields are identified (e.g., regex), what happens if no dynamic fields exist, and whether the return value is a new string or modified in-place. This lack of specificity limits agent understanding.

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 sentence that immediately states the action and purpose. Every word contributes meaning, and the structure is front-loaded with the verb 'moves'. No redundant or extraneous content.

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 simplicity of the tool (one parameter, no output schema, no annotations), the description lacks essential context for reliable agent invocation. It does not specify expected input format, return value, edge case handling, or performance implications. The agent cannot predict tool behavior beyond the stated transformation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must supplement the parameter definition. However, the description does not clarify what format the 'prompt' parameter should take (e.g., JSON string, plain text) or how dynamic fields are defined within it. The agent has only the type 'string' and no additional semantic clues.

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 action ('Moves dynamic fields... to end') and specifies the resource ('prompt'). It distinguishes itself from sibling tools like compress_code, compress_json, hydrate, and redact_content by focusing on reordering for cache performance rather than compression or content alteration.

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 alternatives. It does not specify prerequisites, typical use cases, or conditions under which the tool is effective. The agent must infer usage from the name and brief action statement.

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

redact_contentB

Redacts oversized code / logs and replaces them with a reversible placeholder

ParametersJSON Schema
NameRequiredDescriptionDefault
contentYes

TDQS

B3.3/5.0
Behavior3/5

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

The description discloses the core behavior (redaction and reversible placeholder) but lacks details on thresholds for 'oversized', the nature of reversibility, or side effects. With no annotations, the description carries the burden but is somewhat sparse.

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 focused sentence with no extraneous words, front-loading the key action and result. It is efficient and to the point.

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?

Despite the tool's simplicity, the description omits important context such as what 'oversized' means, how the placeholder is generated, and whether the operation is reversible automatically. Without annotations or output schema, the agent may miss crucial operational details.

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

Parameters2/5

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

Schema coverage is 0%, yet the description merely implies the 'content' parameter is the code/logs to redact. It does not explain format, size constraints, or expected input, providing minimal compensation for the missing schema details.

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 function: redacting oversized code/logs and replacing them with a reversible placeholder. It distinguishes itself from siblings like compress_code and optimize_prompt by focusing on redaction with reversibility.

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?

No guidance is provided on when to use this tool versus siblings. It does not specify conditions for use, prerequisites, or alternatives, leaving the agent to infer from the name alone.

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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 5 tool updatesv1.0.0
    • First observedcompress_code
    • First observedcompress_json
    • First observedhydrate
    • First observedoptimize_prompt
    • First observedredact_content

TDQS

B3.3/5.0
Disambiguation5/5

Each tool targets a distinct operation: compression of code vs JSON, redaction, hydration, and prompt optimization. There is no functional overlap.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern in snake_case (e.g., compress_code, redact_content), making them predictable for an agent.

Tool Count5/5

With 5 tools, the server is well-scoped for content manipulation tasks. Each tool serves a clear purpose without unnecessary redundancy.

Completeness3/5

The set covers compression, redaction, hydration, and prompt optimization, but lacks a decompress tool for JSON minification and potentially other common formats, leaving a minor gap.

Maintenance

ActivityStale
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    A
    maintenance
    Provides reversible context compression for AI agents, reducing token usage while preserving the ability to retrieve original content, and serves as an MCP server for integration with tools like GitHub Copilot and Claude Code.
    3
    1
    Apache 2.0
  • A
    license
    Not graded
    quality
    C
    maintenance
    A local, zero-cloud MCP server for token and text compression. It provides tools to compress, auto-compress, measure, and decompress text using offline rules, lossless gzip packing, or a local Ollama semantic model.
    1
    MIT

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/lea-blum/headroom-mini-token-optimizer'

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