Skip to main content
Glama
PuemMTH
by PuemMTH

log_command_tool

Log AI command usage with name, category, and context to track execution history and analyze patterns in AI workflows.

Instructions

Log one AI command usage.

Args:
    command:  The command name, e.g. '/commit', '/recap', 'deep-research'
    category: Optional group, e.g. 'git', 'research', 'oracle', 'session'
    context:  Optional free-text note about where/why it was used

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYes
categoryNo
contextNo

Implementation Reference

  • The main log_command_tool handler function decorated with @mcp.tool() that logs AI command usage. Accepts command (required), category (optional), and context (optional) parameters, calls the storage layer, and returns a confirmation message with the new row ID.
    @mcp.tool()
    def log_command_tool(
        command: str,
        category: str = "",
        context: str = "",
    ) -> str:
        """
        Log one AI command usage.
    
        Args:
            command:  The command name, e.g. '/commit', '/recap', 'deep-research'
            category: Optional group, e.g. 'git', 'research', 'oracle', 'session'
            context:  Optional free-text note about where/why it was used
        """
        row_id = log_command(
            command=command,
            category=category or None,
            context=context or None,
        )
        return f"✅ Logged command '{command}' (id={row_id})"
  • Tool registration using @mcp.tool() decorator that registers log_command_tool as an available MCP tool.
    @mcp.tool()
  • The log_command helper function in the storage layer that handles the actual database insertion. Opens a PostgreSQL connection, inserts the command record with command, category, context, and extra fields, and returns the new row ID.
    def log_command(
        command: str,
        category: Optional[str] = None,
        context: Optional[str] = None,
        extra: Optional[dict] = None,
    ) -> int:
        """Insert one command-usage record. Returns the new row id."""
        conn = get_connection()
        with conn.cursor() as cur:
            cur.execute(
                """
                INSERT INTO command_log (command, category, context, extra, used_at)
                VALUES (%s, %s, %s, %s, %s)
                RETURNING id
                """,
                (
                    command,
                    category,
                    context,
                    json.dumps(extra) if extra else None,
                    datetime.now().isoformat(timespec="seconds"),
                ),
            )
            row_id = cur.fetchone()[0]
        conn.commit()
        conn.close()
        return row_id

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/PuemMTH/mcp-commands'

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