Purpose
MCP Plexus is a secure, multi-tenant MCP server framework for modern AI applications. Built in Python and based on the jlowin/fastmcp (FastMCP 2.7) library, it helps developers deploy multi-tenant MCP servers that can integrate with external services via OAuth 2.1 and manage API key access for tools.
MCP Plexus extends the capabilities of FastMCP 2.7 to provide a structured environment for creating complex, multi-tenant AI backend systems. It allows defining mutually isolated environments (tenants), each of which can expose customized collections of tools, resources, and prompts to large language models (LLMs) and AI agents.
Key capabilities
- Robust multi-tenant support: Host multiple customers or organizations in a single deployment, with each tenant having independent data and tool access permissions. Tenants are identified by URL path (e.g.,
/{entity_id}/mcp/), and tenant-level MCP session management is supported (currently uses Redis by default). Tenant-level tool visibility and provider configuration are planned features. - Simplified external service integration: Securely connect MCP tools to external services protected by OAuth 2.1 (such as GitHub, Google API, etc.) through built-in process management.
- User-level persistent access: Host applications can register their users with Plexus through a secure endpoint (
/{entity_id}/plexus-auth/register-user), obtainplexus_user_auth_token, and associate host application users with persistent identities within Plexus, thereby persistently storing external OAuth tokens and API keys and reducing repeated authentication. - Tool API key management: Through the
@requires_api_key(provider_name, key_name_display, instructions)decorator, prompt users to submit an API key through a structured MCP error when the key is not stored; keys are encrypted and stored usingPLEXUS_ENCRYPTION_KEY, and decrypted at runtime and injected into tool functions. Users can submit keys through the endpoint/{entity_id}/plexus-services/api-keys. - Standard MCP server capabilities: Full support for defining MCP tools, resources, and prompts using FastMCP's Pythonic decorators and classes (e.g.,
PLEXUS_SERVER_INSTANCE.tool()); native Streamable HTTP transport; access toPlexusContextin tools/resources/prompts (extended fromfastmcp.Context), used for logging, session data, and accessing authenticated clients or API keys. - Configurable storage: By default uses SQLite to persistently store Plexus user authentication tokens, user-level external OAuth tokens, API keys, external OAuth provider configuration, tenant configuration, and user-submitted API keys. MCP session management currently requires Redis (enhanced SQLite session storage is planned).
- (In progress) Internal OAuth 2.1 provider: Includes foundational elements and stub endpoints that make MCP Plexus itself act as an OAuth 2.1 authorization server; full implementation (dynamic client registration, internal client user consent, complete token management) is a future goal.
Usage
Requirements
- Redis (currently required for MCP session management)
- Command-line/terminal access
Installation and setup
- Clone the repository:
git clone https://github.com/Super-I-Tech/mcp_plexus mcp-plexus cd mcp-plexus - Create and activate a virtual environment:
Windows:python -m venv venv.\venv\Scripts\activatemacOS/Linux:source venv/bin/activate - Install dependencies:
pip install -r requirements.txt - Configure environment variables (
.envfile): createmcp-plexus/.envin the project root directory; refer to.env.example. Key variables include:HOST_APP_REGISTRATION_SECRET: critical item. A strong unique key that must be provided when a host application registers users (via theX-Host-App-Secretheader). Be sure to change the default value in production or shared deployments.PLEXUS_ENCRYPTION_KEY: critical item. Fernet key used to encrypt sensitive data such as API keys and external OAuth tokens. Generate it as follows:
Put the output intopython -c "from mcp_plexus.utils import generate_fernet_key; print(generate_fernet_key())".env, keep it safe and back it up; if lost, the encrypted data will be inaccessible.STORAGE_BACKEND: set to"sqlite"(default) or"redis", used for most persistent storage. Note: MCP session management currently must use Redis, regardless of this setting.SQLITE_DB_PATH: SQLite database file path (e.g.,./mcp_plexus_data.sqlite3)。REDIS_HOST、REDIS_PORT、REDIS_DB、REDIS_PASSWORD(optional),REDIS_SSL(optional): Redis connection information (required for MCP sessions).DEBUG_MODE: set toTrueduring development (more detailed logs, Uvicorn reload).PLEXUS_FASTMCP_LOG_LEVEL: FastMCP component log level (e.g.,DEBUG、INFO)。ADMIN_API_KEY: secret key for accessing management endpoints (such as managing tenants and external OAuth providers); a strong value must be set.
Architecture Overview
MCP Plexus runs as an ASGI application (usually with Uvicorn) and acts as an intermediary layer between MCP clients and the underlying FastMCP server instance.
- FastAPI: used for the main web application routing, handling HTTP requests, and providing management API endpoints.
- FastMCP (jlowin/fastmcp): a shared FastMCP instance serves as the core engine, handling MCP protocol messages (tools, resources, prompts) via Streamable HTTP.
- Plexus Core:
- Tenant management: identifies tenants from the URL path and ensures tenant configuration is followed (full configuration in progress; currently database-backed validation).
- Session management (
PlexusSessionManager): manages MCP session data (e.g.,Mcp-Session-Id), currently uses Redis to store session state, associating sessions withentity_idand the availablepersistent_user_id. - Plexus user authentication: handles host application user registration and manages
plexus_user_auth_tokento associate persistent user IDs. - OAuth flow orchestration: manages the OAuth 2.1 authorization code flow for tools that need to access external services, including secure token storage and refresh (refresh in progress).
- API key service: manages secure storage and retrieval of user-provided tool API keys.
PlexusContext: an enhanced context object injected into MCP tools, providingentity_id、persistent_user_id, session data, and helper methods for obtaining an authenticated HTTP client or API key.
- Storage:
- Redis (required for sessions): currently used for temporary MCP session data.
- SQLite (default for persistent data): used to store Plexus user authentication tokens, user-level external OAuth tokens, API keys, external OAuth provider configurations, and tenant metadata.
Use Cases
- SaaS platforms that need to provide isolated AI tool environments for multiple customers or organizations.
- Applications that need to securely connect LLMs or AI agents to OAuth-protected services such as GitHub and Google APIs.
- Host applications that need to persistently store users' external service tokens and reduce repeated logins.
- MCP server deployments that need to securely manage and inject API keys for tools.
Limitations
- MCP session management currently must use Redis; SQLite session storage is a planned enhancement.
- Tenant-level tool visibility and provider configuration are planned features.
- The internal OAuth 2.1 provider is in progress; full implementation (dynamic client registration, user consent, complete token management) is a future goal.
- OAuth token refresh is in progress.
- Other features, charges, prices, platforms, or effects not explicitly stated in the materials are not yet provided.