MC

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.

Quick Install
npx -y @doobidoo/MCP-Context-Provider

Overview

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.

  1. Clone and install
git clone https://github.com/doobidoo/MCP-Context-Provider.git
cd MCP-Context-Provider
# Install dependencies (example for Node.js)
npm ci
  1. 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
  1. Start the server
# Development
npm run dev

# Production
npm start

# Or build and run with Docker (example)
docker build -t mcp-context-provider .
docker run -p 3000:3000 --env-file .env mcp-context-provider

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:

curl -X POST "http://localhost:3000/contexts/code-runner" \
  -H "Content-Type: application/json" \
  -d '{
    "system_prompt": "You are a safe code execution tool. Validate input.",
    "constraints": ["no external network calls", "report runtime errors"],
    "metadata": {"version": "1.2.0", "owner": "infra-team"}
  }'

Example response:

{
  "toolId": "code-runner",
  "version": "1.2.0",
  "createdAt": "2026-04-01T12:34:56Z"
}

Below is a quick reference table of common endpoints:

EndpointMethodPurpose
/contextsGETList tool contexts
/contexts/:toolIdGETGet context bundle
/contexts/:toolIdPOSTCreate/replace bundle
/contexts/:toolIdPATCHUpdate bundle
/contexts/:toolIdDELETEDelete bundle
/rules/:toolIdGETRetrieve 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
async function buildPrompt(toolId, userInput) {
  const resp = await fetch(`http://localhost:3000/contexts/${toolId}`);
  const context = await resp.json();
  return `${context.system_prompt}\n\nConstraints: ${context.constraints.join(';')}\n\nUser: ${userInput}`;
}

For full API details, advanced configuration options, and deployment recipes, see the project repository: https://github.com/doobidoo/MCP-Context-Provider.