Integrates Google Gemini to provide a session-based AI assistant capable of maintaining conversation history and context across multiple requests.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Middleware ServerRemember that my name is Tapan and I'm working on the MCP project."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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:
3. Environment Configuration
Create a .env file based on the .env.example:
Edit .env and add your GOOGLE_API_KEY.
Usage
Running the Server
Start the MCP server using the following command:
By default, the server will run on http://127.0.0.1:8000/mcp.
Running the Client
In a new terminal, run the client:
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 TapanAI Response:
Hello Tapan! Nice to meet you. How can I help you today?
Verify the memory:
Input:
what is my name?AI Response:
Your name is Tapan.
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.