Deploys as a Cloudflare Worker with Durable Objects for stateful MCP sessions, providing edge computing capabilities with multi-tenant support via request headers.
Uses OpenAI's API for generating embeddings for semantic search, image analysis and description, and processing uploaded documents.
Enables semantic search and document management using Supabase as the backend database, including pgvector for embeddings, document storage, and chunk-based search functionality.
MCP Knowledge Base Server
A Model Context Protocol (MCP) server that enables semantic search and document management using your own Supabase and OpenAI accounts.
Live Demo: https://mcp-supabase.maxsmosarski.me/mcp
Features
š Upload and process documents (text, PDF, images)
š Semantic search across your knowledge base
š¼ļø AI-powered image description and search
š Use your own API keys - no shared credentials
āļø Deploy to Cloudflare Workers or run locally
š Edge computing with Durable Objects
š„ Multi-tenant support via request headers
Example Applications
This repository includes two complete example applications that demonstrate how to build on top of the MCP server:
1. Middle Layer (applications/middle-layer/)
A Python FastAPI server that bridges the MCP server with OpenAI's Agents SDK:
Provides a conversational AI interface with memory
Manages conversation sessions and history
Integrates with OpenAI Agents for advanced reasoning
Handles file uploads and document processing
See applications/middle-layer/README.md for setup
2. Web Application (applications/web-app/)
A modern React frontend for the knowledge base system:
Clean, responsive chat interface
Document management sidebar
File upload with drag-and-drop support
Real-time conversation streaming
Image preview and management
See applications/web-app/README.md for setup
Quick Start with Example Apps
For detailed setup instructions, see the README files in each application folder.
Quick Start
Three Implementations
This repository contains three implementations of the MCP server:
1. HTTP Server (src/mcp-server.js)
Uses
@modelcontextprotocol/sdkwith StreamableHTTPServerTransportRuns as an HTTP server on port 3000 (configurable)
Perfect for API integrations and web clients
Can be deployed to any Node.js hosting environment
2. STDIO Server (src/stdio-server.js)
Uses
@modelcontextprotocol/sdkwith StdioServerTransportCommunicates via standard input/output
Designed for Claude Desktop and CLI integrations
Ideal for local tool usage
3. Cloudflare Workers (src/mcp-agent.js)
Uses Cloudflare's
agentsSDK (v0.0.109) with native Worker supportImplements McpAgent with Durable Objects for stateful sessions
Credentials passed via request headers for multi-tenant support
Provides both SSE (
/sse) and streamable HTTP (/mcp) endpointsLive deployment:
https://mcp-supabase.max-smosarski.workers.dev
Prerequisites
Supabase account with a configured database
OpenAI API key
Node.js 18+ (for local development)
Cloudflare account (free tier works) for Workers deployment
Wrangler CLI (
npm install -g wrangler) for deployment
Supabase Setup
Create a new Supabase project and run these SQL commands in the SQL editor:
Installation
Running Locally
Option 1: HTTP Server (for API access)
Option 2: STDIO Server (for Claude Desktop)
Run directly:
Or add to your Claude Desktop configuration:
Deploying to Cloudflare Workers
Using the Agents SDK Implementation
Login to Cloudflare:
Deploy the Worker:
Important Notes:
Uses Durable Objects for stateful MCP sessions
Free tier requires
new_sqlite_classesin migrationsCredentials are passed via headers, not environment variables
Each request must include credential headers
The deployed worker will be available at:
Health check:
https://your-worker.workers.dev/SSE endpoint:
https://your-worker.workers.dev/sseMCP endpoint:
https://your-worker.workers.dev/mcp
Cloudflare Configuration
Note: The Cloudflare Workers implementation uses request headers for credentials, not environment variables. This allows multi-tenant usage where each user provides their own API keys.
Required Headers for Each Request:
x-supabase-url: Your Supabase project URLx-supabase-key: Your Supabase service keyx-openai-key: Your OpenAI API key
Durable Objects Configuration (in
Usage
API Examples
1. Initialize MCP Session (Required First)
2. Search Documents
3. List All Files
For Local MCP Server
For Cloudflare Workers
The middle layer automatically passes credentials as headers to the Cloudflare Worker.
Available Tools
upload_document- Upload text or PDF documentsupload_image- Upload and analyze imagessearch_chunks- Semantic search across documentsget_files- List all documentsget_document- Retrieve specific documentdelete_document- Delete a documentdelete_documents- Bulk delete documents
Directory Structure
Environment Variables
For Local Development (HTTP/STDIO servers):
SUPABASE_URL- Your Supabase project URLSUPABASE_SERVICE_KEY- Your Supabase service keyOPENAI_API_KEY- Your OpenAI API keyMCP_PORT- Port for HTTP server (default: 3000)
For Cloudflare Workers:
Credentials are passed via request headers, not environment variables:
x-supabase-url- Supabase URL in request headerx-supabase-key- Supabase key in request headerx-openai-key- OpenAI key in request header
This design allows multiple users to use the same deployment with their own credentials.
Testing
Troubleshooting
Cloudflare Workers Issues
"Invalid binding" error:
Ensure Durable Objects are configured in
wrangler.tomlUse
new_sqlite_classesfor free tier accountsCheck that the binding name matches (
MCP_OBJECT)
"Missing credentials" error:
Ensure request headers include all required credentials
Check middle layer is passing credentials in headers
Verify credential values are correct
Build errors with duplicate exports:
Don't re-export classes that use
export classCheck for multiple exports of the same name
405 Method Not Allowed:
Normal for GET/DELETE on certain endpoints
MCP protocol uses specific HTTP methods
Durable Objects on free tier:
Must use
new_sqlite_classesinstead ofnew_classesError code 10097 indicates this issue
Local Development Issues
Port conflicts: Change the port using
MCP_PORTenvironment variableCredential issues: Ensure all environment variables are set correctly
CORS errors: The server includes appropriate CORS headers
Migration Guide
From Local to Cloudflare Workers
Update middle layer
# Change from: MCP_SERVER_URL=http://localhost:3000/mcp # To: MCP_SERVER_URL=https://mcp-supabase.max-smosarski.workers.dev/mcpEnsure credentials in middle layer
SUPABASE_URL=your-url SUPABASE_SERVICE_KEY=your-key OPENAI_API_KEY=your-keyDeploy to Cloudflare:
wrangler deploy