Skip to content

abstraction/reprompter-mcp

Repository files navigation

Reprompter MPC Server

An MCP (Model Context Protocol) server that analyzes prompts, compares them with relevant data, and uses OpenRouter (Claude 3.7 Sonnet) to refactor them.

Features

  • Prompt Analysis: Analyze prompts to identify strengths, weaknesses, and suggested improvements
  • Prompt Refactoring: Refactor prompts using AI to improve their effectiveness
  • Context Integration: Incorporate relevant context and chat history into the analysis and refactoring process
  • Technique Application: Apply specific prompt engineering techniques to improve prompts

Installation

  1. Clone the repository
  2. Install dependencies:
    npm install
    
  3. Create a .env file with your OpenRouter API key:
    OpenRouter_API_KEY=your-api-key
    
  4. Build the project:
    npm run build
    

Security

API Key Management

To securely manage your OpenRouter API key:

  1. Never hard-code API keys in files that might be committed to version control
  2. Use environment variables to store sensitive credentials
  3. Add .env to your .gitignore file to prevent accidentally committing it
  4. Consider using a secrets manager for production deployments

Environment Variable Setup

# On Windows
setx OPENROUTER_API_KEY "your-api-key"

# On macOS/Linux
export OPENROUTER_API_KEY="your-api-key"

Usage

Starting the Server

npm start

Configuring in MCP Settings

A template configuration file is provided in reprompter-mpc-config.template.json. Copy this file to reprompter-mpc-config.json and update it with your specific paths:

{
  "mcpServers": {
    "reprompter": {
      "command": "node",
      "args": ["build/index.js"],
      "cwd": "PATH_TO_YOUR_REPROMPTER_MPC_DIRECTORY",
      "env": {
        "OpenRouter_API_KEY": "${OPENROUTER_API_KEY}"
      },
      "alwaysAllow": [
        "analyze_prompt",
        "refactor_prompt"
      ]
    }
  }
}

Important:

  1. Replace PATH_TO_YOUR_REPROMPTER_MPC_DIRECTORY with the absolute path to your reprompter-mpc directory
  2. Set up your OpenRouter API key using environment variables as described in the security section below
  3. Add this configuration to your MCP settings file

Available Tools

analyze_prompt

Analyzes a prompt and provides structured feedback on its strengths, weaknesses, and suggested improvements.

Input Schema:

{
  "prompt": "The prompt to analyze",
  "context": "Optional context relevant to the prompt",
  "chatHistory": [
    {
      "role": "user|assistant|system",
      "content": "Content of the message",
      "timestamp": "Optional timestamp"
    }
  ]
}

Output:

{
  "strengths": ["strength1", "strength2", ...],
  "weaknesses": ["weakness1", "weakness2", ...],
  "suggestedTechniques": ["technique1", "technique2", ...],
  "contextRelevance": {
    "missingContext": ["item1", "item2", ...],
    "irrelevantContext": ["item1", "item2", ...]
  },
  "complexity": "low|medium|high",
  "clarity": "low|medium|high",
  "specificity": "low|medium|high"
}

refactor_prompt

Refactors a prompt using AI to improve its effectiveness based on analysis and suggested techniques.

Input Schema:

{
  "prompt": "The prompt to refactor",
  "analysis": {
    // Optional analysis from analyze_prompt tool
    "strengths": ["strength1", "strength2", ...],
    "weaknesses": ["weakness1", "weakness2", ...],
    "suggestedTechniques": ["technique1", "technique2", ...],
    "contextRelevance": {
      "missingContext": ["item1", "item2", ...],
      "irrelevantContext": ["item1", "item2", ...]
    },
    "complexity": "low|medium|high",
    "clarity": "low|medium|high",
    "specificity": "low|medium|high"
  },
  "techniques": ["Optional specific techniques to apply"],
  "context": "Optional context relevant to the prompt",
  "chatHistory": [
    {
      "role": "user|assistant|system",
      "content": "Content of the message",
      "timestamp": "Optional timestamp"
    }
  ]
}

Output: The refactored prompt text.

Example Usage

// Example of using the analyze_prompt tool
const analysis = await use_mcp_tool({
  server_name: "reprompter",
  tool_name: "analyze_prompt",
  arguments: {
    prompt: "Tell me about the history of artificial intelligence.",
    context: "The user is a beginner in AI concepts."
  }
});

// Example of using the refactor_prompt tool
const refactoredPrompt = await use_mcp_tool({
  server_name: "reprompter",
  tool_name: "refactor_prompt",
  arguments: {
    prompt: "Tell me about the history of artificial intelligence.",
    analysis: analysis, // Result from analyze_prompt
    techniques: ["Chain-of-Thought", "Few-Shot Examples"],
    context: "The user is a beginner in AI concepts."
  }
});

Contributing

Contributions are welcome! Here's how you can contribute to this project:

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/your-feature-name)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some feature')
  5. Push to the branch (git push origin feature/your-feature-name)
  6. Open a Pull Request

Please make sure your code follows the existing style and includes appropriate tests.

GitHub Features

Issues

If you encounter any bugs or have feature requests, please open an issue on GitHub. When creating an issue, please provide:

  • A clear and descriptive title
  • A detailed description of the issue or feature request
  • Steps to reproduce the issue (if applicable)
  • Any relevant logs or error messages
  • Your environment (OS, Node.js version, etc.)

Pull Requests

Pull requests are welcome! Please see the Contributing section for guidelines.

License

ISC - See LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published