MCP Middleware Server MCP Server

A FastMCP server providing session-based memory and dynamic authentication

README.md

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:

  1. 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?
  2. 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 using MultiServerMCPClient to interact with the server.
  • .env.example: Template for environment variables.
  • requirements.txt: Project dependencies.

Environment Variables

GOOGLE_API_KEYrequiredAPI key for Google Gemini LLM access

Try it

Hi, my name is Alex, please remember this for our conversation.
What is my name based on our previous interaction?
Can you help me summarize the conversation history we have had so far?

Frequently Asked Questions

What are the key features of MCP Middleware Server?

Session-based memory for persistent conversation history. Dynamic authentication via API key headers. Streamable HTTP transport for robust session management. Multi-server session compatibility.

What can I use MCP Middleware Server for?

Maintaining long-term context in AI-assisted coding sessions. Building multi-server architectures that share user session state. Developing secure AI tools that require per-user authentication.

How do I install MCP Middleware Server?

Install MCP Middleware Server by running: pip install -r requirements.txt

What MCP clients work with MCP Middleware Server?

MCP Middleware Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep MCP Middleware Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Open Conare