Skip to main content
Glama
KazKozDev
by KazKozDev

Update YAML Metadata

update_metadata

Modify YAML frontmatter in Markdown documents to update document metadata like status, tags, author, or date.

Instructions

Modifies the document's Frontmatter.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
metadataYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
successNo

Implementation Reference

  • Main tool handler: acquires file lock, updates document metadata via Document.update_metadata(), performs atomic file write, updates cache, confirms journal entry. Handles write errors with rollback.
    async def update_metadata(
        self, file_path: str, metadata: Dict[str, Any]
    ) -> Dict[str, Any]:
        abs_path = resolve_path(file_path)
        with FileLock(abs_path):
            doc = self.get_doc(file_path)
            result = doc.update_metadata(metadata)
            if "success" in result:
                try:
                    self._atomic_write(file_path, doc.get_content())
                    self._update_cache_mtime(abs_path)
                    doc.confirm_journal()
                except Exception as e:
                    doc.rollback_last_entry()
                    self.invalidate_cache(file_path)
                    return {"error": f"Failed to write file: {e}"}
        return result
  • Tool registration in @app.list_tools(): defines name, description, input/output schemas for update_metadata tool.
    Tool(
        name="update_metadata",
        title="Update YAML Metadata",
        description="Modifies the document's Frontmatter.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {
                    "type": "string",
                    "examples": ["./document.md", "./blog/post.md"],
                },
                "metadata": {
                    "type": "object",
                    "examples": [
                        {"status": "published", "tags": ["mcp", "ai"]},
                        {"author": "John Doe", "date": "2025-12-27"},
                    ],
                },
            },
            "required": ["file_path", "metadata"],
            "additionalProperties": False,
        },
        outputSchema={
            "type": "object",
            "properties": {"success": {"type": "boolean"}},
        },
    ),
  • Input/output schema definition for the update_metadata tool, specifying file_path and metadata object.
    Tool(
        name="update_metadata",
        title="Update YAML Metadata",
        description="Modifies the document's Frontmatter.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {
                    "type": "string",
                    "examples": ["./document.md", "./blog/post.md"],
                },
                "metadata": {
                    "type": "object",
                    "examples": [
                        {"status": "published", "tags": ["mcp", "ai"]},
                        {"author": "John Doe", "date": "2025-12-27"},
                    ],
                },
            },
            "required": ["file_path", "metadata"],
            "additionalProperties": False,
        },
        outputSchema={
            "type": "object",
            "properties": {"success": {"type": "boolean"}},
        },
    ),
  • Core Document class method: updates metadata dictionary, rebuilds raw content from structure, creates journal entry for undo support.
    def update_metadata(self, new_metadata: Dict[str, Any]) -> Dict[str, Any]:
        """Update YAML metadata"""
        old = deepcopy(self.metadata)
        self.metadata.update(new_metadata)
        self._rebuild_raw_content()
    
        # Create journal entry for undo support
        entry = JournalEntry(
            operation="update_metadata",
            path="metadata",
            old_value=json.dumps(old, ensure_ascii=False),
            new_value=json.dumps(self.metadata, ensure_ascii=False),
            transaction_id=self._transaction_id,
        )
    
        if not self._transaction_active:
            self.journal.append(entry)
            # Note: _save_journal() is NOT called here
            # Caller must call confirm_journal() after successful file write
            self.version += 1
    
        return {"success": True, "old": old, "new": self.metadata}
  • Dispatch logic in @app.call_tool(): calls the update_document_metadata handler when tool name matches.
    elif name == "update_metadata":
        res = await update_document_metadata(file_path, arguments["metadata"])
        return CallToolResult(
            content=[TextContent(type="text", text="Metadata updated")],
            structuredContent=res,
            isError="error" in res,
        )
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. 'Modifies' implies a mutation operation, but it doesn't address critical aspects like whether this overwrites or merges metadata, what permissions are required, if changes are reversible, or what happens on errors. For a mutation tool with zero annotation coverage, this is insufficient.

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, efficient sentence with zero wasted words. It's appropriately sized for a simple tool and front-loads the core purpose immediately.

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?

Given this is a mutation tool with 2 parameters, nested objects, no annotations, but with an output schema, the description is minimally adequate. The output schema reduces the need to describe return values, but the description should do more to explain behavioral aspects and parameter usage for a tool that modifies documents.

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 description doesn't explain either parameter beyond what the schema shows through examples. With 0% schema description coverage, the description adds no semantic value about 'file_path' or 'metadata' parameters. However, since there are only 2 parameters and the schema provides clear examples, this meets the baseline for minimal viability.

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 ('Modifies') and target ('document's Frontmatter'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'replace_content' or 'insert_element' that might also modify document content, which prevents a perfect score.

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 like 'replace_content' or 'insert_element' for document modifications. It mentions the target ('Frontmatter') but doesn't specify prerequisites, exclusions, or contextual usage patterns.

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/KazKozDev/markdown-editor-mcp-server'

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