Skip to main content
Glama
Prompt Log MCP Server

Prompt Log MCP Server

by r-strawser
README.md
# Prompt Log MCP Server

A lightweight Model Context Protocol (MCP) server that logs prompts from Claude Code and Claude Desktop for reflection and journaling purposes.

## Features

- 🔒 **Privacy-First**: All data stored locally by default
- 📝 **Workflow-Based Logging**: Integrate logging into your Claude workflow via CLAUDE.md
- 🔍 **Search & Query**: Find historical prompts with powerful search
- 📊 **Statistics**: Track usage patterns and prompt frequency
- 🏷ïļ **Tagging System**: Organize prompts with custom tags
- ðŸ“Ī **Export Options**: Export to JSON, CSV, or Markdown
- ðŸŠķ **Lightweight**: Minimal resource usage with SQLite backend

## Installation

### Prerequisites

- Node.js 18+
- npm or yarn
- Claude Code and/or Claude Desktop with MCP support

### Quick Start

1. Clone this repository:
```bash
git clone https://github.com/r-strawser/prompt-log.git
cd prompt-log
```

2. Install dependencies:
```bash
npm install
```

3. Build the project:
```bash
npm run build
```

4. Create the data directory (for first-time setup):
```bash
mkdir -p data
```

5. (Optional) Configure environment variables:
```bash
cp .env.example .env
# Edit .env to customize settings
```

### Important Notes

- The SQLite database will be created automatically on first use
- Default database location: `./data/prompts.db`
- You can change the location via `PROMPT_LOG_DB_PATH` environment variable

## Configuration

### Claude Code Configuration

Add the following to your Claude Code settings:

```json
{
  "mcpServers": {
    "prompt-log": {
      "command": "node",
      "args": ["/path/to/prompt-log/dist/index.js"],
      "env": {
        "PROMPT_LOG_DB_PATH": "~/.prompt-log/prompts.db"
      }
    }
  }
}
```

### Claude Desktop Configuration

1. Open Claude Desktop settings
2. Navigate to MCP Servers section
3. Add a new server with:
   - Name: `prompt-log`
   - Command: `node`
   - Arguments: `/path/to/prompt-log/dist/index.js`

## Usage

Once configured, the server provides logging tools that can be called manually or integrated into your workflow.

### Available MCP Tools

#### Query Prompts
Search through your historical prompts:
```
Use the query_prompts tool to search for "function" from claude-code with limit 10
```

#### Export Prompts
Export prompts to various formats:
```
Use the export_prompts tool with format "markdown" and startDate "2024-01-01"
```

#### Get Statistics
View usage statistics:
```
Use the get_stats tool
```

#### Tag Prompts
Add tags to organize prompts:
```
Use the tag_prompt tool with promptId 123 and tags ["javascript", "async"]
```

## Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `PROMPT_LOG_DB_PATH` | Database file location | `./data/prompts.db` |
| `DEBUG` | Enable debug logging | `false` |
| `MAX_PROMPTS` | Maximum prompts to keep | `0` (unlimited) |
| `RETENTION_DAYS` | Auto-delete after X days | `0` (disabled) |

## Database Schema

The SQLite database uses the following schema:

```sql
prompts (
  id: INTEGER PRIMARY KEY,
  timestamp: TEXT,
  app_source: TEXT,
  prompt_text: TEXT,
  session_id: TEXT,
  tags: TEXT (JSON array),
  metadata: TEXT (JSON object)
)
```

## Development

Run in development mode with auto-reload:
```bash
npm run dev
```

## Security Considerations

- All data is stored locally by default
- No external network requests are made
- Database file permissions should be set appropriately
- Consider enabling encryption for sensitive prompts

## Making Logging Feel Automatic

While MCP servers can't intercept prompts automatically, you can create a workflow that feels automatic:

### Using CLAUDE.md for Workflow Integration

Create a `CLAUDE.md` file in your project root:

```markdown
# Project Assistant Instructions

When I provide a new prompt or task:
1. First, log it using: Use the log_prompt tool with prompt "[the user's prompt]" and appSource "claude-code"
2. Then proceed with the actual task

This helps maintain a complete history of our interactions.
```

This way, Claude will log prompts as part of its normal workflow when working in that project.

## Troubleshooting

### Prompts not being logged
1. Remember: logging requires explicit tool calls (manual or via CLAUDE.md workflow)
2. Check that the server is listed in your Claude app's MCP configuration  
3. Verify the database path is writable
4. Check logs for any error messages

### Database locked errors
- The server uses WAL mode for better concurrent access
- If issues persist, ensure only one instance is running

## License

MIT