ZepAI Memory Layer MCP Server
Automatically converts FastAPI endpoints into MCP tools and resources, enabling semantic search, data ingestion (text, JSON, code, conversations), and knowledge graph operations through the ZepAI Memory Layer backend
Inherits Pydantic model validation from FastAPI endpoints for type-safe MCP tool schemas and data validation
Provides access to OpenAPI/Swagger documentation interface for testing and exploring the auto-generated MCP tools alongside the original FastAPI endpoints
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., "@ZepAI Memory Layer MCP Serversearch for recent conversations about API integration"
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.
FastMCP 2.0 Server - ZepAI Memory Layer
Auto-generated MCP server tα»« FastAPI backend sα» dα»₯ng FastMCP 2.0
ποΈ Architecture
Server nΓ y sα» dα»₯ng FastMCP.from_fastapi() Δα» tα»± Δα»ng convert tαΊ₯t cαΊ£ endpoints tα»« FastAPI app (memory_layer) thΓ nh MCP tools vΓ resources.
Key Components:
server_http.py- Main MCP server file, auto-generates tools tα»« FastAPI endpointsmemory_layer/- FastAPI backend (required dependency, not included in this repo)config.py- Configuration settingstest/- Test suite and examples
π Features
Auto-generated MCP Tools:
All tools are automatically generated from FastAPI POST endpoints:
π Search Tools:
search- Semantic search vα»i reranking strategiessearch_code- Search code changes vα»i metadata filters
π₯ Ingest Tools:
ingest_text- Ingest plain text vΓ o knowledge graphingest_message- Ingest conversation messagesingest_json- Ingest structured JSON dataingest_code- Ingest code changes vα»i LLM importance scoringingest_code_context- Ingest advanced code metadata vα»i TTLingest_conversation- Ingest full conversation context
π Admin Tools (Read-only):
Admin POST endpoints are filtered out for safety
Only GET endpoints are exposed as MCP Resources
Includes: stats, cache info, health checks
Auto-generated MCP Resources:
All GET endpoints with path parameters become Resource Templates:
π¦ Installation
Prerequisites:
memory_layer FastAPI backend phαΊ£i running tαΊ‘i
http://localhost:8000Folder structure:
ZepAI/ βββ memory_layer/ # FastAPI backend (required) β βββ app/ β βββ main.py # Contains FastAPI app βββ fastmcp_server/ # This repository βββ server_http.py βββ config.py βββ requirements.txt
Install Dependencies:
cd fastmcp_server
pip install -r requirements.txt
# Or with uv
uv pip install -r requirements.txtβοΈ Configuration
Create .env file (optional, cΓ³ defaults):
# Memory Layer Backend URL
MEMORY_LAYER_URL=http://localhost:8000
MEMORY_LAYER_TIMEOUT=30
# Default Settings
DEFAULT_PROJECT_ID=default_project
MAX_SEARCH_RESULTS=50
MAX_TEXT_LENGTH=100000
MAX_CONVERSATION_MESSAGES=100π Running the Server
1. Start memory_layer backend first:
cd ../memory_layer
python -m uvicorn app.main:app --port 80002. Start MCP server:
cd ../fastmcp_server
python server_http.pyServer will run on http://localhost:8002
π‘ Available Endpoints
Combined FastAPI + MCP routes:
MCP Endpoints (at /mcp):
GET /mcp/sse- Server-Sent Events connectionPOST /mcp/messages- MCP message endpointMCP Client connection:
http://localhost:8002/mcp
Original FastAPI Routes:
GET /docs- OpenAPI documentationGET /- API root and health checkAll original endpoints from memory_layer
Key MCP Paths:
Tools list: Call via MCP client
Resources list: Call via MCP client
Test connection:
curl http://localhost:8002/mcp/sse
π§ͺ Testing
Run Test Suite:
cd test
python test_client.pyTest suite includes:
Basic functionality tests
Tool calling tests
Resource reading tests
Search and ingest workflows
Comprehensive scenario tests
Using FastMCP Client:
from fastmcp import Client
import asyncio
async def test():
# Connect to server
async with Client("http://localhost:8002/mcp") as client:
# List tools
tools = await client.list_tools()
print(f"Available tools: {[t.name for t in tools]}")
# List resources
resources = await client.list_resources()
print(f"Available resources: {[r.uri for r in resources]}")
# Call a tool (auto-generated from FastAPI)
result = await client.call_tool("ingest_text", {
"text": "Test content",
"project_id": "test_project"
})
print(f"Result: {result.content[0].text}")
if __name__ == "__main__":
asyncio.run(test())Using curl:
# Test SSE connection
curl http://localhost:8002/mcp/sse
# Access FastAPI docs
curl http://localhost:8002/docsπ Comparison: FastMCP vs Custom Implementation
Aspect | Custom MCP | FastMCP 2.0 (Auto-generated) |
Lines of Code | ~2,900 | ~180 (94% reduction) |
Setup Time | 5 weeks | 1 day |
Tools Definition | Manual (11 tools) | Auto-generated from FastAPI |
Tools Registration | Manual (254 lines) | Automatic via |
Validation | Manual Pydantic | Inherits from FastAPI |
Transport | Custom HTTP+SSE | Built-in HTTP/SSE |
Error Handling | Manual | Automatic |
Testing | Custom client | FastMCP Client + test suite |
Maintenance | Update 2 places | Update FastAPI only |
Deployment | Complex |
|
π How It Works
Auto-conversion Process:
# 1. Import FastAPI app from memory_layer
from app.main import app as fastapi_app
# 2. Filter routes (exclude admin POST endpoints)
filtered_routes = [route for route in fastapi_app.routes
if should_include_route(route)]
# 3. Auto-convert to MCP server
mcp = FastMCP.from_fastapi(
app=filtered_app,
name="ZepAI Memory Layer",
route_maps=custom_route_maps # GET with params β Resources
)
# 4. Combine MCP + original FastAPI routes
combined_app = FastAPI(
routes=[
*mcp_app.routes, # MCP at /mcp/*
*fastapi_app.routes, # Original API
]
)Route Mapping Rules:
POST/PUT/DELETE β MCP Tools (writable operations)
GET with
{params}β MCP Resource Templates (dynamic data)GET without params β MCP Resources (static data)
Admin POST endpoints β Filtered out (safety)
Benefits:
β
Single source of truth - Update FastAPI, MCP updates automatically
β
No code duplication - Tools inherit FastAPI validation
β
Type safety - Pydantic models from FastAPI = MCP schemas
β
Zero maintenance - Add new FastAPI endpoint = new MCP tool automatically
β
Combined access - Use via MCP client OR direct HTTP/OpenAPI
π― Key Design Decisions
1. Why Auto-generation?
DRY principle - FastAPI already defines all endpoints, schemas, validation
Zero maintenance - No manual tool registration needed
Type safety - Inherits Pydantic validation from FastAPI
2. Why Filter Admin Endpoints?
Safety - Prevent accidental cache clearing via MCP client
Read-only monitoring - Admin GET endpoints still exposed as resources
Explicit control - Destructive operations require direct API access
3. Why Combined Routes?
Flexibility - Access via MCP client OR OpenAPI/Swagger
Debugging - Use
/docsfor quick endpoint testingMigration path - Existing API clients continue working
4. File Structure:
fastmcp_server/
βββ server_http.py # Main server (180 lines)
βββ config.py # Configuration
βββ memory_client.py # Legacy (not used anymore)
βββ search_results_formatter.py # Result formatting utilities
βββ requirements.txt # Dependencies
βββ .env # Environment config (gitignored)
βββ test/ # Test suite
βββ test_client.py # Basic tests
βββ test_comprehensive_scenarios.py
βββ test_search_analysis.pyπ Documentation
π― Benefits of This Approach
β
94% less code - 180 lines vs 2,900 lines
β
Zero tool registration - Auto-generated from FastAPI
β
Single source of truth - Update FastAPI once
β
Type-safe - Inherits Pydantic validation
β
Dual access - MCP client OR OpenAPI/Swagger
β
Easy testing - Built-in test utilities + /docs
β
Safe by default - Admin operations filtered
β
Future-proof - New FastAPI endpoints = new MCP tools automatically
π Links
π License
Same as original project.
Note: This server requires the memory_layer FastAPI backend to be running. The MCP server acts as a protocol adapter, exposing FastAPI endpoints as MCP tools and resources.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/NguyenTrinh3008/MTM-MCPserver'
If you have feedback or need assistance with the MCP directory API, please join our Discord server