
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
prompt-context
Advanced tools
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.
Note: This package is currently in beta. You can install the beta version using the
@betatag.
# Global installation
npm install -g prompt-context@beta
# Or install in a project
npm install prompt-context@beta
This library can be used as an MCP (Model Context Protocol) server with AI tools like Claude, Cursor, etc.
Add this to your claude_desktop_config.json:
{
"mcpServers": {
"prompt-context": {
"command": "npx",
"args": [
"-y",
"prompt-context-mcp"
]
}
}
}
{
"mcpServers": {
"prompt-context": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"prompt-context"
]
}
}
}
docker build -t prompt-context .
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 messageExample 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"
}
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
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);
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);
Options that can be passed to the MemoryContextProtocol constructor:
| Option | Description | Default |
|---|---|---|
messageLimitThreshold | Message count threshold to trigger summary | 10 |
tokenLimitPercentage | Token count threshold as percentage of model limit | 80 |
contextDir | Context storage directory | '.prompt-context' |
useGit | Whether to use Git repository | true |
ignorePatterns | Patterns for files and directories to ignore | [] |
autoSummarize | Whether to enable automatic summarization | true |
Patterns defined in the .gitignore file are automatically loaded and used as ignore patterns. Additionally, the following default patterns are applied:
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.
Please follow the existing code style in the project. We use ESLint for linting, which you can run with:
npm run lint
If you find any bugs or have feature requests, please open an issue on the GitHub repository.
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.
FAQs
Memory Context Protocol for AI agents to maintain conversation context
We found that prompt-context demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.