How scitara-cto/dynamic-mcp-server works
Project Type and Purpose
• This is a backend framework—a Node.js/TypeScript server—for hosting Model Context Protocol (MCP) AI tools.
• It provides HTTP transport, API‐key authentication, user management, dynamic tool loading/sharing, and a MongoDB‐backed persistence layer.
• It is extensible: downstream projects can register new handler packages (i.e., plugin modules) and add custom HTTP routes or DB collections.
File Structure
• src/index.ts: entry point that wires up configuration, HTTP server, and MCP server.
• src/config: centralized config loader (e.g., environment, constants).
• src/http: custom HTTP server, routing (health, streamable‐HTTP/MCP endpoint), authentication middleware.
• src/handlers: three core handler packages—user, tool, prompt management—each organized by actions (add, delete, list, update, etc.).
• src/services: business‐logic layer (PromptService, ToolService, EmailService).
• src/db: repository + model layer (Mongoose or equivalent) for User, Tool, Prompt.
• src/mcp: MCP transport server implementation (streamable protocol).
• src/utils: cross‐cutting utilities (logger, etc.).
README for Additional Insights
• Authentication: API‐key lookup in MongoDB.
• Transport: legacy vs. streamable HTTP /mcp endpoint.
• Extensibility: handler packages register tools at runtime.
• Tool argument mapping: templated config.args resolved per invocation.
Main Components and Interactions
a. Components
– Configuration Loader (env, constants)
– HTTP Layer:
• HTTP Server
• Routing Module (health, MCP streams)
• Auth Middleware (API‐key verifier)
– MCP Server (streamable protocol implementation)
– Handler Packages (plugins):
• UserManagementHandler
• ToolManagementHandler
• PromptManagementHandler
• Custom downstream handlers
– Service Layer: PromptService, ToolService, EmailService
– Repository Layer: PromptRepository, ToolRepository, UserRepository
– Data Models: Prompt, Tool, User
– Persistence: MongoDB
– Utility Components: Logger
– External Integrations: e.g., external HTTP APIs for tools (weather, etc.)
b. Relationships / Data Flow
1. Client request → HTTP Server
2. Routing → API Key Auth Middleware
3. Authenticated request → /mcp handler or REST routes
4. /mcp handler dispatches to MCP Server
5. MCP Server invokes relevant Handler Package (based on tool namespace)
6. Handler executes one of its Actions → calls Service
7. Service applies business rules → calls Repository
8. Repository CRUDs MongoDB → returns Models to Service
9. Service returns result up to Handler → MCP Server → HTTP Server → Client
10. For email notifications, Service → EmailService → external SMTP/API
c. Architectural Patterns and Principles
– Layered Architecture (HTTP → Handlers → Services → Repositories → DB)
– Repository Pattern (abstract data access)
– Plugin / Extension Pattern (handler packages as first‐class modules)
– Dependency Injection (config & services wired at startup)
– Single‐Responsibility (each layer has distinct role)
d. Key Technologies
– Node.js with TypeScript
– Custom HTTP server (in src/http)
– Streamable HTTP MCP protocol (src/mcp)
– MongoDB (via Mongoose‐style models)
– Jest for testing
– EmailService for notifications