Skip to main content
Glama
AlexiFeng

MCP Chat Logger

by AlexiFeng

save_chat_history

Converts chat conversations into organized Markdown files, capturing messages with timestamps and optional session IDs for easy reference.

Instructions

Save chat history as a Markdown file

Args:
    messages: List of chat messages, each containing role and content
    conversation_id: Optional conversation ID for file naming

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conversation_idNo
messagesYes

Implementation Reference

  • The core handler function for the 'save_chat_history' tool. It is decorated with @mcp.tool() which handles registration. Formats chat messages into Markdown and saves them to a file in the 'chat_logs' directory.
    @mcp.tool()
    async def save_chat_history(messages: List[Dict[str, Any]], conversation_id: str = None) -> str:
        """
        Save chat history as a Markdown file
        
        Args:
            messages: List of chat messages, each containing role and content
            conversation_id: Optional conversation ID for file naming
        """
        ensure_logs_directory()
        
        # Generate filename
        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        filename = f"chat_logs/chat_{conversation_id}_{timestamp}.md" if conversation_id else f"chat_logs/chat_{timestamp}.md"
        
        # Format all messages
        formatted_content = "# Chat History\n\n"
        formatted_content += f"Conversation ID: {conversation_id}\n" if conversation_id else ""
        formatted_content += f"Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
        
        for message in messages:
            formatted_content += format_message(message)
        
        # Save file
        with open(filename, "w", encoding="utf-8") as f:
            f.write(formatted_content)
        
        return f"Chat history has been saved to file: {filename}"
  • Helper function to format individual chat messages into Markdown sections, used within save_chat_history.
    def format_message(message: Dict[str, Any]) -> str:
        """Format message into Markdown format"""
        role = message.get("role", "unknown")
        content = message.get("content", "")
        timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        
        return f"""
    ### {role.capitalize()} - {timestamp}
    
    {content}
    
    ---
    """
  • Helper function to create the 'chat_logs' directory if it doesn't exist, called at the start of save_chat_history.
    def ensure_logs_directory():
        """Ensure the logs directory exists"""
        if not os.path.exists("chat_logs"):
            os.makedirs("chat_logs")
  • chat_logger.py:28-28 (registration)
    The @mcp.tool() decorator on the save_chat_history function, which registers the tool with the FastMCP server.
    @mcp.tool()
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 the tool saves to a file but doesn't specify where the file is saved (e.g., local path, cloud storage), permissions required, error handling, or whether the operation is idempotent. This leaves significant gaps in understanding the tool's behavior.

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 brief and front-loaded with the core purpose, followed by parameter explanations. It avoids unnecessary words, though the formatting with 'Args:' could be slightly more integrated. Overall, it's efficient with minimal waste.

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 the tool's moderate complexity (2 parameters, no annotations, no output schema), the description covers the basic purpose and parameters but lacks details on output (e.g., file location, success indicators), error cases, and behavioral traits. It's minimally viable but has clear gaps for a file-saving operation.

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 adds basic semantics for both parameters ('messages' as a list of chat messages with role and content, 'conversation_id' for file naming), which is valuable since schema description coverage is 0%. However, it doesn't detail the structure of message objects or provide examples, leaving some ambiguity.

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 ('Save chat history') and the output format ('as a Markdown file'), providing a specific verb+resource combination. It distinguishes the tool's function well, though there are no sibling tools to differentiate from, which prevents a perfect score of 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 alternatives, prerequisites, or context for invocation. It lacks any mention of when-not-to-use scenarios or comparisons with other tools, leaving usage entirely implicit.

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/AlexiFeng/MCP_Chat_Logger'

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