MCP Server for Persistent Tool Specific Context
Preserve tool-specific context and rules with an MCP server to prevent context loss between chat sessions and ensure consistent AI behavior across interactions.
npx -y @doobidoo/MCP-Context-ProviderOverview
This MCP (Model Context Protocol) server provides a small, persistent service for storing and serving tool-specific context and behavior rules to AI agents and tools. Instead of embedding tool instructions, conversation state, or policy snippets directly in a chat session (which are lost when a session ends), the MCP server holds those artifacts centrally and serves them on demand. That makes it easy to preserve important configuration, guardrails, and tool behavior across multiple sessions, model versions, or distributed agents.
Using a dedicated context provider improves consistency: every agent that integrates with the MCP server receives the same tool-specific system prompts, rule sets, or contextual metadata before generating outputs. This reduces drift between interactions, makes auditing and updates simpler, and enables explicit lifecycle controls (versioning, retention, or access control) for the context objects that guide model behavior.
Features
- Persistent storage of tool-specific context and rules (file-based or pluggable DB)
- Per-tool scoping so each tool/agent can have its own context bundle
- Simple RESTful API for create/read/update/delete of contexts and rules
- Support for structured context entries (system prompts, constraints, metadata)
- Optional versioning or timestamps for changes
- Configurable retention and scoping policies (TTL, environments)
- Lightweight, easy to self-host or containerize
Installation / Configuration
Clone the repository and follow the repo README for exact platform dependencies. The steps below show a typical workflow for a Node-based MCP server; if the upstream project uses a different stack, adapt the commands accordingly.
- Clone and install
# Install dependencies (example for Node.js)
- Configure environment Create a .env file or set environment variables. Example variables:
PORT=3000
STORAGE_PATH=./data/contexts.json
LOG_LEVEL=info
# Optional DB URL if using PostgreSQL/Mongo
DATABASE_URL=postgres://user:pass@localhost:5432/mcp
- Start the server
# Development
# Production
# Or build and run with Docker (example)
Note: Check the repository for exact build/start commands and any required migrations for database-backed storage.
Available Resources
The server exposes a small set of REST endpoints to manage contexts and rules. Example endpoints (adjusted to the actual server path):
- GET /health — server status
- GET /contexts — list available tool contexts
- GET /contexts/:toolId — retrieve context bundle for a specific tool
- POST /contexts/:toolId — create or replace a tool context
- PATCH /contexts/:toolId — modify parts of a context bundle
- DELETE /contexts/:toolId — remove a tool context
- GET /rules/:toolId — fetch rule set for a tool
Example request to store a context bundle:
Example response:
Below is a quick reference table of common endpoints:
| Endpoint | Method | Purpose |
|---|---|---|
| /contexts | GET | List tool contexts |
| /contexts/:toolId | GET | Get context bundle |
| /contexts/:toolId | POST | Create/replace bundle |
| /contexts/:toolId | PATCH | Update bundle |
| /contexts/:toolId | DELETE | Delete bundle |
| /rules/:toolId | GET | Retrieve rule set |
Use Cases
- Persisting system prompts and constraints for a tool
- Store the canonical system prompt for a “customer-support” tool so every conversation begins with the same policy and tone constraints.
- Consistent behavior across sessions
- When models restart or users open new chats, agents fetch the current context bundle to avoid divergent behavior or forgotten rules.
- Multi-agent coordination
- Different agents (summarizer, translator, extractor) can request their own tool context before processing, ensuring role-specific instructions are applied correctly.
- Governance and policy updates
- Update a rule in the MCP server to sweep new behavior constraints to all live agents without redeploying them.
- A/B testing and versioned behavior
- Maintain multiple context versions (v1, v2) and route subsets of traffic to different tool contexts for controlled experiments.
Example integration (pseudo-JavaScript):
// Fetch context and prepend to prompt
For full API details, advanced configuration options, and deployment recipes, see the project repository: https://github.com/doobidoo/MCP-Context-Provider.