Skip to content

fix: Scaffolding improvements and Redis multi-tenancy support#106

Merged
jdutton merged 1 commit into
mainfrom
fix/scaffolding-adoption-feedback
Dec 5, 2025
Merged

fix: Scaffolding improvements and Redis multi-tenancy support#106
jdutton merged 1 commit into
mainfrom
fix/scaffolding-adoption-feedback

Conversation

@jdutton

@jdutton jdutton commented Nov 29, 2025

Copy link
Copy Markdown
Owner

Summary

This PR addresses scaffolding issues discovered during canary project testing and adds Redis key prefix support for multi-tenant deployments.

Part 1: Scaffolding Fixes

Issue #1: Workspace path aliases breaking module resolution (CRITICAL)

  • Problem: Scaffolded vitest.config.ts included workspace aliases (@mcp-typescript-simple/tools: '../tools/src') that only work in monorepo environments
  • Solution: Removed resolve.alias configuration - packages now resolve from node_modules
  • Impact: Tests and builds now work correctly in standalone scaffolded projects

Issue #2: Cannot scaffold into existing directory

  • Problem: Common workflow blocked: clone GitHub repo → scaffold into it
  • Solution: Accept "." as special case to scaffold into current directory, using directory name as project name
  • Impact: npx create-mcp-typescript-simple@next . --yes now works

Issue #3: Port configuration documentation

  • Problem: Port conflicts can cause test failures, but users don't know how to change ports
  • Solution: Added helpful comments in vitest.system.config.ts explaining port configuration
  • Impact: Users understand how to resolve port conflicts

Issue #4: System tests failing out-of-the-box

  • Problem: Scaffolded projects had system tests failing with CORS errors (14 failed | 2 passed)
  • Root Cause: ALLOWED_ORIGINS set in test environment + NODE_ENV=development instead of 'test'
  • Solution: Removed ALLOWED_ORIGINS from test environment, changed NODE_ENV to 'test'
  • Impact: System tests now pass (16/16) in fresh scaffolds

Code Quality

  • Refactored index.ts to reduce cognitive complexity (extracted helper functions for validation and config)

Part 2: Redis Multi-Tenancy Support

Problem

Multiple MCP apps sharing the same Redis instance had key conflicts:

  • Both mcp-typescript-simple and mcp-typescript-simple-canary write to oauth:client:abc123
  • Required separate Redis instances or databases

Solution

Added REDIS_KEY_PREFIX environment variable with automatic normalization:

  • Implementation: DRY helper functions, updated all 6 Redis stores and factories
  • Backward compatible: Empty prefix by default (existing deployments unaffected)
  • Auto-normalization: mcp-mainmcp-main: (colon separator added automatically)
  • Documentation: Added to all .env templates with default value mcp-persistence

Impact

Can now run multiple MCP apps on same Redis instance:

# Main app
REDIS_KEY_PREFIX=mcp-main
# Keys: mcp-main:oauth:client:, mcp-main:mcp:session:, etc.

# Canary app  
REDIS_KEY_PREFIX=mcp-canary
# Keys: mcp-canary:oauth:client:, mcp-canary:mcp:session:, etc.

Testing

  • ✅ All validation passed (typecheck, lint, build, tests)
  • ✅ Tested scaffolding into new directory
  • ✅ Tested scaffolding into current directory with "."
  • ✅ System tests pass (16/16) in fresh scaffolds
  • ✅ Backward compatible: empty REDIS_KEY_PREFIX works as before

Files Changed: 26

Config & Core:

  • packages/config/src/storage-config.ts - Added REDIS_KEY_PREFIX schema
  • packages/persistence/src/stores/redis/redis-utils.ts - Added DRY helpers

Redis Stores (6 files):

  • Updated all Redis stores to accept keyPrefix parameter

Factories (6 files):

  • Updated all factories to pass keyPrefix from environment

Scaffolding Templates (8 files):

  • Fixed vitest.config.ts, vitest.system.config.ts, vitest-global-setup.ts
  • Added REDIS_KEY_PREFIX to all .env templates

Other:

  • packages/create-mcp-typescript-simple/src/index.ts - Current directory support + refactoring
  • packages/create-mcp-typescript-simple/src/generator.ts - Allow current directory scaffolding
  • CHANGELOG.md - Added v0.9.1-rc.2 release notes

Release Plan

After merge, release as v0.9.1-rc.2 for canary project testing.

🤖 Generated with Claude Code

Scaffolding Fixes (from canary project feedback):
- Remove workspace path aliases from vitest.config.ts template (CRITICAL)
- Add support for scaffolding into current directory with "."
- Add port configuration documentation in vitest.system.config.ts
- Fix system tests failing out-of-the-box (CORS + NODE_ENV issues)
- Refactor index.ts to reduce cognitive complexity

Redis Multi-Tenancy Enhancement:
- Add REDIS_KEY_PREFIX environment variable for multi-app isolation
- Implement normalizeKeyPrefix() helper with automatic colon separator
- Create DRY getRedisKeyPrefix() utility used across all factories
- Update all 6 Redis stores to support key prefixing
- Document in all .env templates with default value 'mcp-persistence'
- Backward compatible: empty prefix by default

Impact:
- Scaffolded projects now have passing tests (16/16)
- Multiple MCP apps can share same Redis instance without conflicts
- Example: REDIS_KEY_PREFIX=mcp-main creates mcp-main:oauth:client: keys

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@jdutton jdutton merged commit 7110af9 into main Dec 5, 2025
6 of 7 checks passed
@jdutton jdutton deleted the fix/scaffolding-adoption-feedback branch December 5, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant