MCP Prompt Library Server
by soniccccc
README.md
# MCP Prompt Library Server
A personal prompt library with semantic search capabilities using ChromaDB and the Model Context Protocol (MCP). This server allows you to store, search, and retrieve prompts using semantic similarity, making it easy to find relevant prompts even when you don't remember the exact wording.
## Features
- **Semantic Search**: Find similar prompts using natural language queries
- **Persistent Storage**: All prompts are stored in a local ChromaDB database
- **MCP Integration**: Works seamlessly with Claude Desktop and other MCP clients
- **Rich Metadata**: Track source, creation time, and statistics for each prompt
- **Easy Retrieval**: Get specific prompts by ID or search by content
## Installation
### Prerequisites
- Python 3.8 or higher
- pip or uv package manager
### Setup
1. **Clone the repository**:
```bash
git clone <repository-url>
cd MCP_Prompt_Library
```
2. **Install dependencies**:
```bash
# Using uv (recommended)
uv sync
# Or using pip
pip install -r requirements.txt
```
3. **Environment Setup** (optional):
```bash
# Set custom ChromaDB path (defaults to ./chroma_db)
export CHROMA_DB_PATH="/path/to/your/chroma_db"
```
## Usage
### Running the Server
The server can be run in two ways:
1. **Direct execution** (for testing):
```bash
python prompt_library_mcp_server.py
```
2. **As an MCP server** (recommended):
Configure your MCP client (e.g., Claude Desktop) to use this server.
### Claude Desktop Configuration
Add this to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"prompt-library": {
"command": "/path/to/your/project/.venv/bin/python",
"args": ["/path/to/your/project/prompt_library_mcp_server.py"],
"env": {
"CHROMA_DB_PATH": "/path/to/your/project/chroma_db"
}
}
}
}
```
**Important**: Make sure to use the Python interpreter from your virtual environment and update the paths to match your actual project location.
### Available Tools
The server provides three main tools:
#### 1. `store_prompt`
Add a new prompt to your library.
**Parameters**:
- `prompt` (required): The prompt text to store
- `source` (optional): Where this prompt was used (e.g., "claude", "gpt4", "cursor")
**Example**:
```json
{
"prompt": "Explain the attention mechanism in transformers",
"source": "claude"
}
```
#### 2. `search_prompts`
Search for similar prompts using semantic similarity.
**Parameters**:
- `keywords` (required): Keywords to search for in previous prompts
- `limit` (optional): Number of results to return (default: 8, max: 20)
**Example**:
```json
{
"keywords": "transformer attention",
"limit": 5
}
```
#### 3. `get_prompt`
Retrieve a specific prompt by its ID.
**Parameters**:
- `prompt_id` (required): The unique identifier for the prompt
**Example**:
```json
{
"prompt_id": "prompt_1234567890"
}
```
## Testing
Run the test suite to verify functionality:
```bash
python test_server.py
```
This will:
- Test prompt storage and retrieval
- Test semantic search functionality
- Verify error handling
- Clean up test data automatically
## Database Structure
The server uses ChromaDB for persistent storage with the following structure:
- **Collection**: `prompt_library`
- **Documents**: The actual prompt text
- **Metadata**:
- `prompt_id`: Unique identifier
- `timestamp`: Creation timestamp (ISO format)
- `source`: Where the prompt was used
- `character_count`: Number of characters
- `word_count`: Number of words
## API Response Format
All responses are returned as JSON with the following structure:
### Search Response
```json
{
"search_keywords": "query terms",
"found": 3,
"total_prompts_in_library": 15,
"prompts": [
{
"id": "prompt_1234567890",
"prompt": "Full prompt text...",
"similarity": "95.2%",
"created": "2024-01-15T10:30:00",
"source": "claude",
"preview": "First 100 characters..."
}
]
}
```
### Store Response
```json
{
"status": "success",
"prompt_id": "prompt_1234567890",
"source": "claude",
"stats": {
"characters": 150,
"words": 25
},
"total_prompts": 16
}
```
### Get Response
```json
{
"status": "found",
"prompt_id": "prompt_1234567890",
"prompt_text": "Full prompt text...",
"metadata": {
"created": "2024-01-15T10:30:00",
"source": "claude",
"character_count": 150,
"word_count": 25
}
}
```
## Development
### Project Structure
```
MCP_Prompt_Library/
├── prompt_library_mcp_server.py # Main server implementation
├── test_server.py # Test suite
├── requirements.txt # Python dependencies
├── pyproject.toml # Project configuration
├── README.md # This file
└── chroma_db/ # ChromaDB database files
```
### Adding New Features
1. **New Tools**: Add tool definitions in `setup_handlers()`
2. **Database Changes**: Modify the metadata structure in `store_prompt()`
3. **Search Improvements**: Enhance the `search_prompts()` method
### Error Handling
The server includes comprehensive error handling:
- Graceful handling of empty collections
- Proper error messages for missing prompts
- Exception catching with informative error responses
## Troubleshooting
### Common Issues
1. **"spawn python ENOENT"**: Make sure to use the virtual environment Python path in your MCP configuration
2. **"No such file or directory"**: Verify the paths in your MCP configuration match your actual project location
3. **Import errors**: Ensure all dependencies are installed in your virtual environment
### Debugging
- Check the MCP server logs in Claude Desktop
- Run `test_server.py` to verify functionality
- Use direct execution mode for debugging
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Copyright (c) 2025 B Chahal
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues