Integration: Custom MCP Client
Coverage status
Section titled “Coverage status”MCP: ✅ — Any MCP-compatible client can connect via stdio or HTTP/SSE.
Setup (60-second path)
Section titled “Setup (60-second path)”- Install MemStrata and run
memstrata initin your project. - Start the MCP server:
memstrata mcp --stdio(stdio) ormemstrata serve --port 8080(HTTP). - Configure your client using the JSON snippet below.
- Call
context_querybefore sending prompts to your LLM.
What’s captured
Section titled “What’s captured”- ✅ Any request that calls
context_querybefore prompting — MemStrata compresses context and tracks token savings. - ⚠️ If your client calls the LLM directly without going through
context_query, those turns are not tracked. - ❌ Responses from your LLM are not captured by default (the client handles those directly).
Overview
Section titled “Overview”MemStrata exposes a standard MCP server that any MCP-compatible client can connect to. If your tool isn’t in the integration list, use this guide.
Transport options
Section titled “Transport options”MemStrata supports two MCP transports:
| Transport | Command | When to use |
|---|---|---|
| stdio | memstrata mcp --stdio | Subprocess clients (most common) |
| HTTP/SSE | memstrata serve --port 8080 | Network clients, multi-process setups |
stdio transport (subprocess)
Section titled “stdio transport (subprocess)”Most MCP clients launch the server as a subprocess and communicate over stdin/stdout. Configure your client to run:
memstrata mcp --stdioExample MCP client configuration (JSON):
{ "mcpServers": { "memstrata": { "command": "memstrata", "args": ["mcp", "--stdio"], "env": {} } }}On Windows, if memstrata is not on PATH:
{ "mcpServers": { "memstrata": { "command": "C:\\Users\\you\\AppData\\Local\\Programs\\MemStrata\\memstrata.exe", "args": ["mcp", "--stdio"], "env": {} } }}HTTP/SSE transport
Section titled “HTTP/SSE transport”For clients that connect over HTTP or need a persistent server:
memstrata serve --port 8080The MCP endpoint is at:
http://localhost:8080/mcpSSE stream (for clients that use Server-Sent Events):
http://localhost:8080/mcp/sseAvailable tools
Section titled “Available tools”MemStrata exposes three MCP tools:
context_query
Section titled “context_query”Returns a compressed context slice for a given query. Call this before sending a prompt to your LLM.
Input schema:
{ "type": "object", "properties": { "query": { "type": "string", "description": "Natural language query describing what context you need" }, "max_tokens": { "type": "integer", "description": "Maximum tokens to return (default: 4000)", "default": 4000 }, "include_paths": { "type": "array", "items": { "type": "string" }, "description": "Glob patterns to restrict context to specific paths (optional)" } }, "required": ["query"]}Example call:
{ "name": "context_query", "arguments": { "query": "How does authentication work in this codebase?", "max_tokens": 3000 }}Response:
{ "context": "..compressed code context slice..", "tokens_used": 2847, "tokens_saved": 4120, "files_included": ["src/auth/middleware.py", "src/auth/tokens.py"], "graph_depth": 2}index_status
Section titled “index_status”Returns the current state of the local index.
Input: none required
Response:
{ "indexed_files": 1247, "last_indexed": "2025-01-15T14:23:11Z", "coverage_percent": 98.2, "index_path": "/home/user/memstrata/index.db", "project_root": "/home/user/my-project"}savings_summary
Section titled “savings_summary”Returns session token savings and estimated dollar amount.
Input: none required
Response:
{ "session_tokens_saved": 84230, "session_dollar_savings": 0.42, "total_tokens_saved": 1240000, "total_dollar_savings": 6.20, "session_turns": 18}Python example
Section titled “Python example”import subprocess, json
proc = subprocess.Popen( ["memstrata", "mcp", "--stdio"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,)
def call_tool(name, args): msg = json.dumps({"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": name, "arguments": args}}) + "\n" proc.stdin.write(msg.encode()) proc.stdin.flush() return json.loads(proc.stdout.readline())
# Initializeproc.stdin.write(b'{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"my-client","version":"1.0"}}}\n')proc.stdin.flush()proc.stdout.readline() # read init response
# Query contextresult = call_tool("context_query", {"query": "database schema and migrations"})print(result["result"]["content"][0]["text"])Verifying the connection
Section titled “Verifying the connection”# Start the servermemstrata mcp --stdio &
# Send a JSON-RPC initialize messageecho '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1"}}}' | memstrata mcp --stdioExpected response includes "serverInfo": {"name": "memstrata", "version": "5.x.x"}.
Troubleshooting
Section titled “Troubleshooting”command not found: memstrata
Add MemStrata to your PATH, or use the full binary path in the command config.
Empty context response
Run memstrata status to verify the index is built. If indexed_files is 0, run memstrata index in your project directory first.
Tool not listed after initialize
Ensure you’re running MemStrata v5.0+. Run memstrata --version to check.