🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

prompt-context

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prompt-context

Memory Context Protocol for AI agents to maintain conversation context

latest
Source
npmnpm
Version
0.1.0-beta
Version published
Maintainers
1
Created
Source

Memory Context Protocol (MCP) for AI Agents

prompt-context is a TypeScript library that helps AI agents efficiently remember and utilize previous conversation context. This protocol tracks conversation history for each file or context, periodically summarizes it, and saves the summaries to enhance the AI agent's contextual understanding.

Key Features

  • Context-based Memory Management: Organize conversations separately by file or topic.
  • Automatic Summary Generation: Automatically generate summaries when message count or token count reaches thresholds.
  • Code Block Preservation: Preserve code blocks in summaries to maintain important information.
  • Git Integration: Manage summary files with Git for version control.
  • Efficient Storage and Loading: Store summaries in JSON format for quick loading.
  • Customizable Settings: Allow users to adjust summary trigger thresholds and other settings.
  • Extensible Design: Provide flexible architecture for integration with various AI models.
  • CLI Tool: Configure and use MCP easily from the command line.
  • MCP Server: Run as a Model Context Protocol server for use with Claude, Cursor, and other AI tools.

Installation

Note: This package is currently in beta. You can install the beta version using the @beta tag.

# Global installation
npm install -g prompt-context@beta

# Or install in a project
npm install prompt-context@beta

MCP Server Usage

This library can be used as an MCP (Model Context Protocol) server with AI tools like Claude, Cursor, etc.

Using with Claude Desktop

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
    "prompt-context": {
      "command": "npx",
      "args": [
        "-y",
        "prompt-context-mcp"
      ]
    }
  }
}

Using with Docker

{
  "mcpServers": {
    "prompt-context": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "prompt-context"
      ]
    }
  }
}

Building the Docker Image

docker build -t prompt-context .

Available MCP Tool

context_memory

Allows AI agents to maintain and retrieve conversation context for different files or topics.

Inputs:

  • action (string): The action to perform - 'add', 'retrieve', or 'summarize'
  • contextId (string): The identifier for the context (typically a file path or topic name)
  • role (string, for 'add' action): Role of the message sender ('user' or 'assistant')
  • content (string, for 'add' action): Content of the message

Example Usage:

Adding a message:

{
  "action": "add",
  "contextId": "file.js",
  "role": "user",
  "content": "Please optimize this code"
}

Retrieving context:

{
  "action": "retrieve",
  "contextId": "file.js"
}

Forcing a summary:

{
  "action": "summarize",
  "contextId": "file.js"
}

CLI Usage

After installation, you can use it directly from the command line:

# Initialize MCP in the current directory
npx prompt-context init

# Check configuration
npx prompt-context config

# Change configuration (e.g., set message threshold)
npx prompt-context config messageLimitThreshold 5

# Add messages
npx prompt-context add file.js user "Please optimize this code"
npx prompt-context add file.js assistant "The optimized code is as follows: ..."

# Generate summary
npx prompt-context summary file.js

# Summarize all contexts
npx prompt-context summary

# Display help
npx prompt-context help

Integrating MCP

While using the CLI tool is the simplest approach, you can also use MCP programmatically:

import { MemoryContextProtocol } from 'prompt-context';

// Create MCP instance
const mcp = new MemoryContextProtocol({
  messageLimitThreshold: 10,
  tokenLimitPercentage: 80,
  contextDir: '.prompt-context',
  useGit: true,
  autoSummarize: true
});

// Add message
await mcp.addMessage('file.ts', {
  role: 'user',
  content: 'Please add a React component to this file.',
  timestamp: Date.now()
});

// Summarize context (automatic or manual)
await mcp.summarizeContext('file.ts');

// Load summary
const summary = await mcp.loadSummary('file.ts');
console.log(summary);

Custom AI Summary Integration

To generate summaries using your own AI model or external AI service, you can implement a custom summarizer service:

import { CustomAISummarizer, MemoryContextProtocol } from 'prompt-context';

// Custom AI summarization function
const myAISummarizer = async (messages) => {
  // Call external AI API or custom summarization logic
  // Example: OpenAI API, Anthropic API, etc.
  return 'This is a summary of the conversation...';
};

// Create custom summarizer service
const summarizer = new CustomAISummarizer(myAISummarizer);

// Pass custom summarizer when creating MCP instance
const mcp = new MemoryContextProtocol({}, summarizer);

Advanced Configuration

Configuration Options

Options that can be passed to the MemoryContextProtocol constructor:

OptionDescriptionDefault
messageLimitThresholdMessage count threshold to trigger summary10
tokenLimitPercentageToken count threshold as percentage of model limit80
contextDirContext storage directory'.prompt-context'
useGitWhether to use Git repositorytrue
ignorePatternsPatterns for files and directories to ignore[]
autoSummarizeWhether to enable automatic summarizationtrue

.gitignore Integration

Patterns defined in the .gitignore file are automatically loaded and used as ignore patterns. Additionally, the following default patterns are applied:

  • node_modules
  • .git
  • dist
  • build
  • coverage
  • tmp
  • *.log
  • *.lock
  • .min.
  • *.map

Contributing

We welcome contributions to the Memory Context Protocol! Here's how you can help:

  • Fork the Repository: Start by forking the repository and then cloning it locally.

  • Create a Branch: Create a branch for your contribution.

    git checkout -b feature/your-feature-name
    
  • Make Changes: Implement your changes, following the code style of the project.

  • Write Tests: If applicable, write tests for your changes.

  • Build and Test: Run the build and test to make sure everything works.

    npm run build
    npm test
    
  • Commit Changes: Commit your changes with a clear commit message.

    git commit -m "Add feature: your feature description"
    
  • Push Changes: Push your changes to your fork.

    git push origin feature/your-feature-name
    
  • Submit a Pull Request: Go to the original repository and submit a pull request with a clear description of your changes.

Code Style

Please follow the existing code style in the project. We use ESLint for linting, which you can run with:

npm run lint

Issues and Feature Requests

If you find any bugs or have feature requests, please open an issue on the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024 Axistant

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. 

Keywords

ai

FAQs

Package last updated on 28 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts