Implement remote MCP server deployment capabilities
- Add HTTP/JSON-RPC server for remote MCP access - Configure domain and authentication via environment variables - Create comprehensive remote deployment documentation - Support both local (stdio) and remote (HTTP) deployment modes - Add PM2 and Nginx configuration examples - Update README with remote server instructions The server can now be deployed on a VM (e.g., Hetzner) and accessed from Claude Desktop over HTTPS using the configured domain. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
49
src/utils/auth-middleware.ts
Normal file
49
src/utils/auth-middleware.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { logger } from './logger';
|
||||
|
||||
/**
|
||||
* Express middleware for authenticating requests with Bearer tokens
|
||||
*/
|
||||
export function authenticateRequest(authToken?: string) {
|
||||
return (req: Request, res: Response, next: NextFunction): void => {
|
||||
if (!authToken) {
|
||||
// No auth required
|
||||
return next();
|
||||
}
|
||||
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
if (!authHeader) {
|
||||
logger.warn('Missing authorization header', {
|
||||
ip: req.ip,
|
||||
path: req.path,
|
||||
});
|
||||
|
||||
res.status(401).json({
|
||||
error: 'Unauthorized',
|
||||
message: 'Missing authorization header',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Support both "Bearer TOKEN" and just "TOKEN" formats
|
||||
const providedToken = authHeader.startsWith('Bearer ')
|
||||
? authHeader.substring(7)
|
||||
: authHeader;
|
||||
|
||||
if (providedToken !== authToken) {
|
||||
logger.warn('Invalid authentication token', {
|
||||
ip: req.ip,
|
||||
path: req.path,
|
||||
});
|
||||
|
||||
res.status(401).json({
|
||||
error: 'Unauthorized',
|
||||
message: 'Invalid authentication token',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user