Skip to content

Integration: Custom MCP Client

MCP: ✅ — Any MCP-compatible client can connect via stdio or HTTP/SSE.


  1. Install MemStrata and run memstrata init in your project.
  2. Start the MCP server: memstrata mcp --stdio (stdio) or memstrata serve --port 8080 (HTTP).
  3. Configure your client using the JSON snippet below.
  4. Call context_query before sending prompts to your LLM.

  • ✅ Any request that calls context_query before 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).

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.


MemStrata supports two MCP transports:

TransportCommandWhen to use
stdiomemstrata mcp --stdioSubprocess clients (most common)
HTTP/SSEmemstrata serve --port 8080Network clients, multi-process setups

Most MCP clients launch the server as a subprocess and communicate over stdin/stdout. Configure your client to run:

Terminal window
memstrata mcp --stdio

Example 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": {}
}
}
}

For clients that connect over HTTP or need a persistent server:

Terminal window
memstrata serve --port 8080

The MCP endpoint is at:

http://localhost:8080/mcp

SSE stream (for clients that use Server-Sent Events):

http://localhost:8080/mcp/sse

MemStrata exposes three MCP tools:

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
}

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"
}

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
}

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())
# Initialize
proc.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 context
result = call_tool("context_query", {"query": "database schema and migrations"})
print(result["result"]["content"][0]["text"])

Terminal window
# Start the server
memstrata mcp --stdio &
# Send a JSON-RPC initialize message
echo '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1"}}}' | memstrata mcp --stdio

Expected response includes "serverInfo": {"name": "memstrata", "version": "5.x.x"}.


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.