Prepare the server locally
Run this once before adding it to Claude Code.
pip install -r requirements.txtRegister it in Claude Code
claude mcp add -e "GOOGLE_API_KEY=${GOOGLE_API_KEY}" mcp-middleware -- python /path/to/server.pyReplace any placeholder paths in the command with the real path on your machine.
GOOGLE_API_KEYMake your agent remember this setup
mcp-middleware's config, env vars, and the gotchas you hit — recalled in every future Claude Code, Cursor, and Codex session.
npx conare@latestFree · one command · indexes the sessions already on disk. Set up in the browser instead →
What it does
- Session-based memory for persistent conversation history
- Dynamic authentication via API key headers
- Streamable HTTP transport for robust session management
- Multi-server session compatibility
Environment Variables
GOOGLE_API_KEYrequiredAPI key for Google Gemini LLM accessTry it
Original README from TapanBhavsar/mcp_middleware
MCP Middleware Server & Client
This project implements a FastMCP server with session-based memory using LangChain and Google Gemini, along with a client that demonstrates multi-server session compatibility.
Features
- Session-based Memory: Each client session maintains its own conversation history.
- Dynamic Authentication: API keys are passed via headers and used to initialize session-specific LLMs.
- Streamable HTTP: Uses HTTP transport for robust session management.
Setup Instructions
1. Prerequisites
- Python 3.10+
- A Google Gemini API Key
2. Installation
Clone the repository and install the dependencies:
pip install -r requirements.txt
3. Environment Configuration
Create a .env file based on the .env.example:
cp .env.example .env
Edit .env and add your GOOGLE_API_KEY.
Usage
Running the Server
Start the MCP server using the following command:
python server.py
By default, the server will run on http://127.0.0.1:8000/mcp.
Running the Client
In a new terminal, run the client:
python client.py
Session Compatibility Example
The server maintains state across multiple requests within the same session. You can verify this by following these steps in the client:
Inform the AI of your name:
- Input:
HI my name is Tapan - AI Response:
Hello Tapan! Nice to meet you. How can I help you today?
- Input:
Verify the memory:
- Input:
what is my name? - AI Response:
Your name is Tapan.
- Input:
This works because the session_id is tracked in the _session_histories dictionary on the server, ensuring that each user has a personalized and continuous conversation.
Files
server.py: The FastMCP server implementation with Auth middleware and session handling.client.py: A Python client usingMultiServerMCPClientto interact with the server..env.example: Template for environment variables.requirements.txt: Project dependencies.