About mcp-context-server
mcp-context-server is an MCP server for persistent multimodal context storage for LLM agents. It supports shared thread-scoped context, access controls, and several search and retrieval methods across SQLite or PostgreSQL.
Key features
- 01Text and image context storage
- 02Shared context scoped by thread
- 03Per-record ownership and access grants
- 04Full-text, semantic, and hybrid search
- 05Metadata, date, and tag filtering
- 06Partial reads and document sync
Use cases
- 01Share context among agents on one task
- 02Search stored context by meaning or text
- 03Manage access to private and public entries
- 04Sync a document directory as a knowledge base
MCP support
Exposes context-management, search, navigation, sync, sharing, and batch-operation tools to MCP clients. It works with MCP-compatible clients.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
uvx mcp-context-serverLOG_LEVELLog levelSTORAGE_BACKENDStorage backend type: sqlite (default) or postgresqlMAX_IMAGE_SIZE_MBMaximum individual image size in megabytesMAX_TOTAL_SIZE_MBMaximum total request size in megabytesDB_PATHCustom database file location pathPOOL_MAX_READERSMaximum number of concurrent read connections in the poolPOOL_MAX_WRITERSMaximum number of concurrent write connections in the poolPOOL_CONNECTION_TIMEOUT_SConnection timeout in secondsPOOL_IDLE_TIMEOUT_SIdle connection timeout in secondsPOOL_HEALTH_CHECK_INTERVAL_SConnection health check interval in secondsRETRY_MAX_RETRIESMaximum number of retry attempts for failed operationsRETRY_BASE_DELAY_SBase delay in seconds between retry attemptsRETRY_MAX_DELAY_SMaximum delay in seconds between retry attemptsRETRY_JITTEREnable random jitter in retry delaysRETRY_BACKOFF_FACTORExponential backoff multiplication factor for retriesSQLITE_FOREIGN_KEYSSecretEnable SQLite foreign key constraintsSQLITE_JOURNAL_MODESQLite journal mode (e.g., WAL, DELETE)SQLITE_SYNCHRONOUSSQLite synchronous mode (e.g., NORMAL, FULL, OFF)SQLITE_TEMP_STORESQLite temporary storage location (e.g., MEMORY, FILE)SQLITE_MMAP_SIZESQLite memory-mapped I/O size in bytesSQLITE_CACHE_SIZESQLite cache size (negative value for KB, positive for pages)SQLITE_PAGE_SIZESQLite page size in bytesSQLITE_WAL_AUTOCHECKPOINTSQLite WAL autocheckpoint threshold in pagesSQLITE_BUSY_TIMEOUT_MSSQLite busy timeout in millisecondsSQLITE_WAL_CHECKPOINTSQLite WAL checkpoint mode (e.g., PASSIVE, FULL, RESTART)SHUTDOWN_TIMEOUT_SServer shutdown timeout in secondsSHUTDOWN_TIMEOUT_TEST_STest mode shutdown timeout in secondsQUEUE_TIMEOUT_SQueue operation timeout in secondsQUEUE_TIMEOUT_TEST_STest mode queue timeout in secondsCIRCUIT_BREAKER_FAILURE_THRESHOLDCircuit breaker failure threshold before openingCIRCUIT_BREAKER_RECOVERY_TIMEOUT_SCircuit breaker recovery timeout in secondsCIRCUIT_BREAKER_HALF_OPEN_MAX_CALLSMaximum calls allowed in circuit breaker half-open statePOSTGRESQL_CONNECTION_STRINGSecretComplete PostgreSQL connection string (overrides individual settings if provided)POSTGRESQL_HOSTPostgreSQL server host addressPOSTGRESQL_PORTPostgreSQL server port numberPOSTGRESQL_USERPostgreSQL database usernamePOSTGRESQL_PASSWORDSecretPostgreSQL database passwordPOSTGRESQL_DATABASEPostgreSQL database namePOSTGRESQL_POOL_MINPostgreSQL connection pool minimum sizePOSTGRESQL_POOL_MAXPostgreSQL connection pool maximum sizePOSTGRESQL_POOL_TIMEOUT_SPostgreSQL connection pool timeout in secondsPOSTGRESQL_COMMAND_TIMEOUT_SPostgreSQL command execution timeout in secondsPOSTGRESQL_MIGRATION_TIMEOUT_STimeout in seconds for PostgreSQL migration operations (default: 300)POSTGRESQL_MAX_INACTIVE_LIFETIME_SClose idle PostgreSQL connections after this many seconds (0 to disable, default: 300)POSTGRESQL_MAX_QUERIESRecycle PostgreSQL connections after this many queries (0 to disable, default: 10000)POSTGRESQL_TCP_KEEPALIVES_IDLE_SSeconds of idle time before sending first TCP keepalive probe (0 to disable, default: 15)POSTGRESQL_TCP_KEEPALIVES_INTERVAL_SSeconds between subsequent TCP keepalive probes (0 to disable, default: 5)POSTGRESQL_TCP_KEEPALIVES_COUNTNumber of failed TCP keepalive probes before connection is considered dead (0 to disable, default: 3)POSTGRESQL_STATEMENT_CACHE_SIZEasyncpg prepared statement cache size. Set to 0 for external pooler compatibility (PgBouncer transaction mode, Pgpool-II, etc.). Default: 100POSTGRESQL_MAX_CACHED_STATEMENT_LIFETIME_SMaximum lifetime of cached prepared statements in seconds (default: 300). Has no effect when statement_cache_size=0POSTGRESQL_MAX_CACHEABLE_STATEMENT_SIZEMaximum size of statement to cache in bytes (default: 15360). Has no effect when statement_cache_size=0POSTGRESQL_SSL_MODEPostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full)POSTGRESQL_SCHEMAPostgreSQL schema name for table and index operations (default: public)ENABLE_SEMANTIC_SEARCHEnable semantic search functionalityENABLE_EMBEDDING_GENERATIONEnable embedding generation for stored context. Default true - server fails if dependencies not met. Set false to disable embeddings.OLLAMA_HOSTOllama API host URL for embedding generationOLLAMA_AUTO_PULLAutomatically pull missing Ollama models on startup (default: true)OLLAMA_PULL_TIMEOUT_STimeout in seconds for pulling Ollama models (default: 900, range: 30-3600)EMBEDDING_OLLAMA_TRUNCATEOllama embedding truncation mode: false (default) returns error when context exceeded, true enables silent truncationEMBEDDING_OLLAMA_NUM_CTXOllama embedding context window size in tokens (default: 4096, range: 512-2097152)EMBEDDING_MODELEmbedding model name for semantic searchEMBEDDING_DIMEmbedding vector dimensionsEMBEDDING_TIMEOUT_STimeout in seconds for embedding generation API callsEMBEDDING_RETRY_MAX_ATTEMPTSMaximum number of retry attempts for embedding generationEMBEDDING_RETRY_BASE_DELAY_SBase delay in seconds between retry attempts (with exponential backoff)EMBEDDING_MAX_CONCURRENTMaximum concurrent embedding generation operations (default: 3, range: 1-20)ENABLE_SUMMARY_GENERATIONEnable summary generation for stored context. Default true - server fails if dependencies not met. Set false to disable summaries.SUMMARY_PROVIDERSummary provider: ollama (default), openai, or anthropicSUMMARY_MODELSummary generation model name (default: qwen3:0.6b)SUMMARY_MAX_TOKENSSecretMaximum output tokens for summary generation (default: 4000, range: 50-16384). Increase if summaries are truncated by reasoning modelsSUMMARY_TIMEOUT_STimeout in seconds for summary generation API callsSUMMARY_RETRY_MAX_ATTEMPTSMaximum number of retry attempts for summary generationSUMMARY_RETRY_BASE_DELAY_SBase delay in seconds between retry attempts (with exponential backoff)SUMMARY_MAX_CONCURRENTMaximum concurrent summary generation operations (default: 3, range: 1-20)SUMMARY_PROMPTCustom summarization prompt. Overrides the built-in default. Used as system message for the LLM.SUMMARY_MIN_CONTENT_LENGTHMinimum text content length in characters to trigger summary generation (default: 500, range: 0-10000). Set to 0 to always generate.SUMMARY_OLLAMA_NUM_CTXOllama summary context window size in tokens (default: 32768, range: 512-2097152)SUMMARY_OLLAMA_TRUNCATEOllama summary truncation mode: false (default) returns error when context exceeded, true enables silent truncationSUMMARY_OPENAI_REASONING_EFFORTReasoning effort level for OpenAI reasoning models (default: low). Valid values vary by generation: gpt-5: low, medium, high; gpt-5.1+: none, low, medium, high, xhigh. Default low is universally valid across all generationsSUMMARY_ANTHROPIC_EFFORTEffort level for Anthropic Claude models (default: none). Valid values: max, high, medium, low. Controls inference effort (adaptive thinking)ANTHROPIC_API_KEYSecretAnthropic API key for summary generationENABLE_FTSEnable full-text search functionalityFTS_LANGUAGELanguage for FTS stemming (e.g., english, german, french)FTS_RERANK_WINDOW_SIZECharacters of context around each FTS match for reranking passage extraction (default: 750)FTS_RERANK_GAP_MERGEMerge FTS match regions within this character distance (default: 100)ENABLE_HYBRID_SEARCHEnable hybrid search combining FTS and semantic search with RRF fusionHYBRID_RRF_KRRF smoothing constant for hybrid search (default 60)HYBRID_RRF_OVERFETCHMultiplier for over-fetching results before RRF fusion (default: 2)HYBRID_FTS_OR_THRESHOLDMinimum significant query terms to switch hybrid FTS from AND to OR logic (default: 4)SEARCH_DEFAULT_SORT_BYDefault sort order for search results: relevance (only 'relevance' supported in current version)SEARCH_TRUNCATION_LENGTHMaximum character length for truncated text_content in search results (default: 300, range: 50-1000)ENABLE_CHUNKINGEnable text chunking for embedding generation (default: true)CHUNK_SIZETarget chunk size in characters (default: 1500)CHUNK_OVERLAPOverlap between chunks in characters (default: 150)CHUNK_AGGREGATIONChunk score aggregation method: max (only 'max' supported in current version)CHUNK_DEDUP_OVERFETCHMultiplier for over-fetching chunks before deduplication (default: 5)ENABLE_RERANKINGEnable cross-encoder reranking of search results (default: true)RERANKING_PROVIDERReranking provider (default: flashrank)RERANKING_MODELReranking model name (default: ms-marco-MiniLM-L-12-v2)RERANKING_MAX_LENGTHMaximum input length for reranking in tokens (default: 512)RERANKING_OVERFETCHMultiplier for over-fetching results before reranking (default: 4)RERANKING_CACHE_DIRDirectory for caching reranking modelsRERANKING_CHARS_PER_TOKENSecretEstimated characters per token for passage size validation (default: 4.0, range: 2.0-8.0)RERANKING_INTRA_OP_THREADSONNX Runtime intra-operation parallelism threads for reranking (default: 0 = auto-detect)RERANKING_CPU_MEM_ARENAEnable ONNX Runtime CPU memory arena for reranking (default: false)RERANKING_BATCH_SIZEMaximum passages per ONNX Runtime inference batch during reranking (default: 32)EMBEDDING_PROVIDEREmbedding provider: ollama (default), openai, azure, huggingface, or voyageOPENAI_API_KEYSecretOpenAI API key for OpenAI embedding providerOPENAI_API_BASECustom base URL for OpenAI-compatible APIsOPENAI_ORGANIZATIONOpenAI organization IDAZURE_OPENAI_API_KEYSecretAzure OpenAI API keyAZURE_OPENAI_ENDPOINTAzure OpenAI endpoint URLAZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAMEAzure OpenAI embedding deployment nameAZURE_OPENAI_API_VERSIONAzure OpenAI API version (default: 2024-02-01)HUGGINGFACEHUB_API_TOKENSecretHuggingFace Hub API token for HuggingFace embedding providerVOYAGE_API_KEYSecretVoyage AI API key for Voyage embedding providerVOYAGE_TRUNCATIONVoyage AI truncation mode: false (default) returns error when context exceeded, true enables silent truncationVOYAGE_BATCH_SIZEVoyage AI batch size for embedding requestsLANGSMITH_TRACINGEnable LangSmith tracingLANGSMITH_API_KEYSecretLangSmith API keyLANGSMITH_PROJECTLangSmith project nameLANGSMITH_ENDPOINTLangSmith API endpoint URLMETADATA_INDEXED_FIELDSComma-separated list of metadata fields to index (field:type format)METADATA_INDEX_SYNC_MODEIndex sync mode: strict (fail), auto (sync), warn (log), additive (default, add missing only)MCP_TRANSPORTTransport mode: stdio for local, http for Docker/remoteFASTMCP_HOSTHTTP bind address (use 0.0.0.0 for Docker)FASTMCP_PORTHTTP port numberFASTMCP_STATELESS_HTTPEnable stateless HTTP mode for horizontal scaling. Enabled by default as the server has no stateful MCP features. Set to false only if you need server-side MCP session tracking.DISABLED_TOOLSComma-separated list of tools to disable (e.g., delete_context,update_context)MCP_AUTH_TOKENSecretBearer token for HTTP authentication (required when using SimpleTokenVerifier)MCP_AUTH_CLIENT_IDSecretClient ID to assign to authenticated requestsMCP_AUTH_PROVIDERSecretAuthentication provider: none (default), simple_tokenMCP_SERVER_INSTRUCTIONSCustom server instructions text. Overrides built-in default. Set to empty string to disable.Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP Context Server
A high-performance Model Context Protocol (MCP) server providing persistent multimodal context storage for LLM agents. Built with FastMCP, this server enables seamless context sharing across multiple agents working on the same task through thread-based scoping.
Warning
Upgrading from v2.x? Version 3.x.x uses a new database schema with UUIDv7 primary keys. Existing v2.x databases require a one-time data migration before they can be used with v3.x.x. The opt-in CLI
mcp-context-server-migrateships with the server.See the Migration Guide before upgrading. Fresh installations are unaffected.
Key Features
- Multimodal Context Storage: Store and retrieve both text and images
- UUIDv7 Context Identifiers: Every context entry is identified by a 32-character lowercase hex UUIDv7 value, providing time-ordered, globally unique IDs with a stable lex-string ordering
- Thread-Based Scoping: Agents working on the same task share context through thread IDs
- Per-Record Access Control: Every entry has an owner, a
privateorpublicvisibility, and optional user or group grants, enforced on every read, update and delete on both SQLite and PostgreSQL. With IdP-issued JWTs, each caller finds, counts and changes only the entries it may access, the owner of an entry shares it with users or groups throughshare_context, and every returned entry reports itsvisibilityand whether the caller owns it. See the Access Model - Anonymous Read Access: Hand readers without an identity-provider account one shared token that reads
publicentries and can never write: the server refuses every write by the principalACCESS_CONTROL_ANONYMOUS_PRINCIPALnames, and the token must expire. See Anonymous Read Access - PostgreSQL Row-Level Security (optional): With
ENABLE_POSTGRESQL_RLS=true, PostgreSQL also enforces the access model in the database, so a defect in how a query applies the access rules cannot expose another principal's entries. Reads go through an owner-owned, role-gated view that keeps every search index in use. See Row-level security (PostgreSQL) - Flexible Metadata Filtering: Store custom structured data with any JSON-serializable fields and filter using 16 powerful operators
- Date Range Filtering: Filter context entries by creation timestamp using ISO 8601 format
- Tag-Based Organization: Efficient context retrieval with normalized, indexed tags
- Summary Generation: Optional automatic LLM-based summarization returned alongside truncated
text_contentin all search tool results for better agent context efficiency (enabled by default with Ollama) - Full-Text Search: Linguistic search with stemming, ranking, boolean queries (FTS5/tsvector), and cross-encoder reranking. Auto-enabled by default (
ENABLE_FTS=auto); needs no extra dependencies - Semantic Search: Vector similarity search for meaning-based retrieval with cross-encoder reranking. Auto-enabled by default (
ENABLE_SEMANTIC_SEARCH=auto) whenever an embedding provider is available (embedding generation is on by default) - Hybrid Search: Combined FTS + semantic search using Reciprocal Rank Fusion (RRF) with cross-encoder reranking. Auto-enabled by default (
ENABLE_HYBRID_SEARCH=auto) whenever at least one of full-text or semantic search is available - Server-Side Grep: Literal/regex, line-oriented, unranked pattern matching over stored records (
grep_context) — the precise-locate complement to full-text/semantic search, with ripgrep-style output modes and bounded results. Auto-enabled by default (ENABLE_GREP_CONTEXT=auto), pure-Python so it behaves identically on SQLite and PostgreSQL - Record Navigation (index_tree):
navigate_contextbuilds an on-demand Markdown-heading table of contents per record, with the entry summary as the root node; optional per-node LLM summaries (on by default) enrich each section. Pair withread_context_rangeto extract any section - Partial Reads:
read_context_rangereturns a slice of one record by character range, line range, or outlinenode_id— so an agent can read only the relevant span of a long record instead of the whole thing - Knowledge Base Sync: Host document corpora such as handbooks and runbooks in
kb:<corpus>threads that agents search and navigate like any other context. Themcp-context-ingestcommand uploads a directory of documents and keeps it in sync, storing new files, updating changed ones and removing deleted ones, planned by the read-onlyplan_context_synctool (ENABLE_CONTEXT_SYNC=auto). See the Knowledge Base Guide - Cross-Encoder Reranking: Automatic result refinement using FlashRank cross-encoder models for improved search precision (enabled by default)
- Embedding Compression (default ON): Reduces embedding storage by approximately 8x out of the box in v3.0.0. Bit-packed compressed vectors keep semantic and hybrid search working without changes to the tool surface, and the read path bypasses the pgvector >2000-dimension HNSW limit. Set
ENABLE_EMBEDDING_COMPRESSION=falseto opt out and keep fp32 storage. See the Embedding Compression Guide - Multiple Database Backends: Choose between SQLite (default, zero-config) or PostgreSQL (high-concurrency, production-grade)
- High Performance: WAL mode (SQLite) / MVCC (PostgreSQL), strategic indexing, and async operations
- MCP Standard Compliance: Works with Claude Code, LangGraph, and any MCP-compatible client
- Production Ready: Comprehensive test coverage, type safety, and robust error handling
Connecting to Your AI Assistant
The fastest way to connect the MCP Context Server to Claude Code is the one-command Docker bootstrap.
For step-by-step instructions, prerequisites, troubleshooting, and update/uninstall commands, see the Connecting to Your AI Assistant Guide.
Environment Configuration
The server is fully configured via environment variables, supporting core settings, transport, authentication, embedding providers, summary generation, search features, database tuning, and more. Variables can be set in your MCP client configuration, in a .env file, or directly in the shell.
For the complete reference of all environment variables with types, defaults, constraints, and descriptions, see the Environment Variables Reference.
Summary Generation
Summary generation automatically creates concise LLM-based summaries for each stored context entry. Summaries are returned in the summary field of all search tool results alongside truncated text_content, providing dense, informative summaries that help agents determine relevance without fetching full entries.
For detailed instructions including all providers (Ollama, OpenAI, Anthropic), model selection, and custom prompt configuration, see the Summary Generation Guide.
Semantic Search
Semantic search is auto-enabled by default (ENABLE_SEMANTIC_SEARCH=auto): the semantic_search_context tool registers automatically whenever an embedding provider is available (embedding generation is on by default), and skips quietly otherwise. For detailed instructions on the multiple embedding providers (Ollama, OpenAI, Azure, HuggingFace, Voyage) and how to control the toggle explicitly, see the Semantic Search Guide.
Full-Text Search
Full-text search is auto-enabled by default (ENABLE_FTS=auto) and needs no extra dependencies, using the built-in database FTS engine (FTS5 on SQLite, tsvector on PostgreSQL). For linguistic processing, stemming, ranking, and boolean queries, see the Full-Text Search Guide.
Hybrid Search
Hybrid search is auto-enabled by default (ENABLE_HYBRID_SEARCH=auto): the hybrid_search_context tool registers automatically whenever at least one of full-text or semantic search is available. For combined FTS + semantic search using Reciprocal Rank Fusion (RRF), see the Hybrid Search Guide.
Metadata Filtering
For comprehensive metadata filtering including 16 operators, nested JSON paths, and performance optimization, see the Metadata Guide.
Database Backends
The server supports multiple database backends, selectable via the STORAGE_BACKEND environment variable. SQLite (default) provides zero-configuration local storage perfect for single-user deployments. PostgreSQL offers high-performance capabilities with 10x+ write throughput for multi-user and high-traffic deployments.
For detailed configuration instructions including PostgreSQL setup with Docker, Supabase integration, connection methods, and troubleshooting, see the Database Backends Guide.
API Reference
The MCP Context Server exposes 21 MCP tools for context management:
Core Operations: store_context, search_context, get_context_by_ids, delete_context, update_context, list_threads, get_statistics
Search Tools: semantic_search_context, fts_search_context, hybrid_search_context
Navigation Tools (locate / navigate / extract): grep_context, navigate_context, read_context_range
Sync Tools: plan_context_sync, list_ingest_state
Sharing Tools: share_context, unshare_context, list_context_grants
Batch Operations: store_context_batch, update_context_batch, delete_context_batch
For complete tool documentation including parameters, return values, filtering options, and examples, see the API Reference. For when to use grep vs full-text vs semantic search, the index_tree, and partial reads, see Grep, Navigation & Partial Reads. For hosting and syncing document corpora, see the Knowledge Base Guide.
Docker Deployment
For production deployments with HTTP transport and container orchestration, Docker Compose configurations are available for SQLite, PostgreSQL, and external PostgreSQL (Supabase). See the Docker Deployment Guide for setup instructions and client connection details.
Kubernetes Deployment
For Kubernetes deployments, a Helm chart is provided with configurable values for different environments. See the Helm Deployment Guide for installation instructions, or the Kubernetes Deployment Guide for general Kubernetes concepts.
Authentication
For HTTP transport deployments requiring authentication, see the Authentication Guide for bearer token and IdP-issued JWT configuration, sharing entries with users and groups, and anonymous read access through an operator-minted token.
Getting Help
- Bug reports: Report a bug
- Feature requests: Suggest a feature
- Documentation issues: Report a docs issue
- Questions: Ask a question
License
MCP Context Server is licensed under the Elastic License 2.0 (ELv2).
In short: you may use, copy, modify, distribute, and run the software freely and at no cost — for personal projects, inside companies of any size, and as part of commercial work. The one thing you may not do without a commercial agreement is provide the software to third parties as a hosted or managed service that gives users access to any substantial set of its features or functionality (for example, a cloud "memory for agents" offering built on it).
See Commercial Licensing for plain-language examples of what is and is not permitted, and contact [email protected] for commercial licensing, including hosted or managed service rights.
Releases up to and including v2.2.2 were published under the MIT License and remain available under it; the Elastic License 2.0 applies from v3.0.0 onward.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.