A multi-tenant MCP (Model Context Protocol) gateway for the Ragie Model Context Protocol server that implements bearer token authentication using WorkOS. This gateway enables secure, organization-based access to Ragie's MCP services through JWT token validation and organization membership verification.
This gateway acts as a secure proxy between AI clients (like Claude, OpenAI, or Anthropic) and the Ragie MCP server. It provides:
- Bearer Token Authentication: JWT token verification via WorkOS JWKS
- Organization-Based Routing: Multi-tenant routing with organization-scoped endpoints
- Organization Membership Validation: Verifies user membership in organizations via WorkOS
- Optional Partition Mapping: Maps organization IDs to Ragie partitions for flexible routing
- Proxy Functionality: Transparent forwarding of authenticated requests to Ragie MCP services
- OAuth Discovery Endpoints: Well-known endpoints for OAuth metadata discovery
- 🔐 Bearer Token Authentication: JWT token verification using WorkOS JWKS
- 🏢 Multi-Tenant Architecture: Organization-based routing and access control
- ✅ Membership Validation: Automatic verification of user membership in organizations
- 🗺️ Flexible Routing: Optional organization-to-partition mapping support
- 🔄 Request Proxying: Seamless forwarding to Ragie MCP services
- 📋 OAuth Discovery: Well-known endpoints for OAuth metadata
- 🚀 Production Ready: Graceful shutdown, error handling, and structured logging
- 🧪 Test Coverage: Comprehensive test suite with Jest
- Node.js 18+
- WorkOS account and application setup
- Ragie API key and MCP server access
Run the gateway directly without installing:
npx @ragieai/mcp-gatewayInstall globally for system-wide access:
npm install -g @ragieai/mcp-gatewayThen run it from anywhere:
mcp-gatewayInstall as a dependency in your project:
npm install @ragieai/mcp-gatewayThen run it with:
npx mcp-gatewayOr add it to your package.json scripts:
{
"scripts": {
"start:gateway": "mcp-gateway"
}
}If you want to contribute or customize the gateway:
# Clone the repository
git clone <repository-url>
cd mcp-gateway
# Install dependencies
npm install
# Copy the environment template
cp env.example .env
# Configure your environment variables in .env (see Configuration section)
# Build the project
npm run buildThe gateway requires several environment variables to be configured. You can set these via:
- Environment variables in your shell
- A
.envfile in the current directory (loaded automatically) - Your deployment platform's environment configuration
BASE_URL: The public URL of your gateway serverRAGIE_API_KEY: Your Ragie API key for accessing MCP servicesRAGIE_MCP_SERVER_URL: The URL of the Ragie MCP serverWORKOS_API_KEY: Your WorkOS API keyWORKOS_AUTHORIZATION_SERVER_URL: Your WorkOS AuthKit authorization server URLWORKOS_CLIENT_ID: Your WorkOS application client ID
PORT: Server port (defaults to 3000)LOG_LEVEL: Logging level - debug, info, warn, or error (defaults to info)NODE_ENV: Environment mode (development, production, etc.)MAPPING_FILE: Path to a JSON file mapping organization IDs to Ragie partitions (optional)STRICT_MAPPING: Enable strict mapping mode - only organizations in the mapping file are allowed (defaults to false, requiresMAPPING_FILE)
BASE_URL=http://localhost:3000
RAGIE_API_KEY=your_ragie_api_key_here
RAGIE_MCP_SERVER_URL=https://api.ragie.ai/mcp/default
WORKOS_API_KEY=your_workos_api_key_here
WORKOS_AUTHORIZATION_SERVER_URL=https://api.workos.com/auth/v1
WORKOS_CLIENT_ID=your_workos_client_id_here
PORT=3000
LOG_LEVEL=info
NODE_ENV=production
# Optional: Organization mapping
MAPPING_FILE=mapping.json
STRICT_MAPPING=falseRun the gateway with default settings:
npx @ragieai/mcp-gatewayThe gateway will start on port 3000 (or the port specified in PORT environment variable).
The gateway supports optional organization-to-partition mapping for flexible routing. Create a JSON mapping file:
{
"org_01K8BHJC61A42KN38TB98HZHTQ": "soc2",
"org_01K8BHJC61A42KN38TB98HZHTQ2": "custom-partition"
}Set the MAPPING_FILE environment variable to enable mapping:
MAPPING_FILE=mapping.json npx @ragieai/mcp-gatewayOr in your .env file:
MAPPING_FILE=mapping.jsonWhen strict mapping is enabled, only organizations defined in the mapping file are allowed. Requests to unmapped organizations will return a 404 error. Set STRICT_MAPPING=true:
MAPPING_FILE=mapping.json STRICT_MAPPING=true npx @ragieai/mcp-gatewayOr in your .env file:
MAPPING_FILE=mapping.json
STRICT_MAPPING=trueBASE_URL=https://gateway.example.com \
RAGIE_API_KEY=your_key \
RAGIE_MCP_SERVER_URL=https://api.ragie.ai/mcp/default \
WORKOS_API_KEY=your_workos_key \
WORKOS_AUTHORIZATION_SERVER_URL=https://api.workos.com/auth/v1 \
WORKOS_CLIENT_ID=your_client_id \
MAPPING_FILE=mapping.json \
STRICT_MAPPING=false \
npx @ragieai/mcp-gatewayGET /.well-known/oauth-protected-resource- Returns OAuth protected resource metadataGET /.well-known/oauth-authorization-server- Returns OAuth authorization server metadata (proxied from WorkOS)
GET /:organizationId/mcp/*- Proxies requests to Ragie MCP server (requires bearer token)
When a mapping is configured, organization IDs are mapped to partitions:
- Without mapping:
/org_123/mcp/...→/mcp/org_123/... - With mapping:
/org_123/mcp/...→/mcp/soc2/...(iforg_123maps tosoc2)
Organization IDs are automatically lowercased when no mapping exists.
- Client obtains JWT: Clients authenticate with WorkOS and receive a JWT bearer token
- Bearer Token: Clients include the token in the
Authorization: Bearer <token>header - Token Verification: The gateway verifies the JWT signature using WorkOS JWKS
- Membership Validation: The gateway verifies the user is an active member of the requested organization
- Request Proxying: Authenticated requests are proxied to the Ragie MCP server with the Ragie API key
- JWT Verification: All bearer tokens are cryptographically verified using WorkOS JWKS
- Organization Membership: Users must be active members of the organization they're accessing
- API Key Injection: Ragie API key is automatically injected in proxied requests
- Error Handling: Proper HTTP status codes and WWW-Authenticate headers for auth failures
- Gateway Class: Main application logic and Express server setup
- Configuration: Environment-based configuration management with Zod validation
- Logger: Structured logging with configurable levels
- Tests: Comprehensive test coverage with mocked dependencies
npm run build- Compile TypeScript to JavaScriptnpm run dev- Start development server with hot reloadingnpm start- Start production server (after build)npm run clean- Clean build artifactsnpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issuesnpm run format- Format code with Prettiernpm test- Run test suitenpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage report
This gateway is designed to work with AI clients that support bearer token authentication. Clients should:
- Authenticate users with WorkOS to obtain JWT tokens
- Include bearer tokens in the
Authorizationheader for all requests - Specify the organization ID in the URL path:
/{organizationId}/mcp/* - Handle 401 responses with WWW-Authenticate headers for authentication errors
- Discover OAuth endpoints via
/.well-known/oauth-protected-resourceif needed
curl -H "Authorization: Bearer <workos-jwt-token>" \
https://gateway.example.com/org_123/mcp/retrieveThe gateway supports multi-tenant access through organization-based routing:
- Each organization has its own endpoint path
- Users must be members of the organization to access its endpoints
- Optional mapping allows organizations to share Ragie partitions
- Strict mapping mode restricts access to only mapped organizations
The gateway can be deployed to any platform that supports Node.js:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
ENV NODE_ENV=production
CMD ["node", "dist/index.js"]- Heroku: Set environment variables in Heroku dashboard and deploy
- AWS Lambda: Use AWS Lambda Node.js runtime with appropriate handler
- Kubernetes: Deploy as a containerized service with ConfigMaps for environment variables
- Railway/Render/Fly.io: Connect your repository and set environment variables
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
For issues and questions, please refer to the project's issue tracker or documentation.