mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 05:23:08 +00:00
feat: add library usage support for multi-tenant deployments
Enable n8n-mcp to be used as a library dependency for multi-tenant backends: Changes: - Add `types` and `exports` fields to package.json for TypeScript support - Export InstanceContext types and MCP SDK types from src/index.ts - Relax session ID validation to support multi-tenant session strategies - Accept any non-empty string (UUIDv4, instance-prefixed, custom formats) - Maintains backward compatibility with existing UUIDv4 format - Enables mcp-remote and other proxy compatibility - Add comprehensive library usage documentation (docs/LIBRARY_USAGE.md) - Multi-tenant backend examples - API reference for N8NMCPEngine - Security best practices - Deployment guides (Docker, Kubernetes) - Testing strategies Breaking Changes: None - all changes are backward compatible Version: 2.18.9 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -188,11 +188,22 @@ export class SingleSessionHTTPServer {
|
||||
|
||||
/**
|
||||
* Validate session ID format
|
||||
*
|
||||
* Accepts any non-empty string to support various MCP clients:
|
||||
* - UUIDv4 (internal n8n-mcp format)
|
||||
* - instance-{userId}-{hash}-{uuid} (multi-tenant format)
|
||||
* - Custom formats from mcp-remote and other proxies
|
||||
*
|
||||
* Security: Session validation happens via lookup in this.transports,
|
||||
* not format validation. This ensures compatibility with all MCP clients.
|
||||
*
|
||||
* @param sessionId - Session identifier from MCP client
|
||||
* @returns true if valid, false otherwise
|
||||
*/
|
||||
private isValidSessionId(sessionId: string): boolean {
|
||||
// UUID v4 format validation
|
||||
const uuidv4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
return uuidv4Regex.test(sessionId);
|
||||
// Accept any non-empty string as session ID
|
||||
// This ensures compatibility with all MCP clients and proxies
|
||||
return Boolean(sessionId && sessionId.length > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user