ADR-003: MCP Common Library with Config-Driven Server Generation¶
Status¶
accepted
Date¶
2025-08-30
Context¶
By v2.0.5, APTL had separate TypeScript MCP servers for Kali and Wazuh.
Their names were mcp-red and mcp-blue.
Both provided agent access to lab containers and the SIEM, but their implementations repeated substantial code.
Problems¶
- Each server repeated SSH connection, session, timeout, and output handling.
- Each entry point repeated configuration loading, server creation, tool registration, and startup.
- Copied comments and SSH prefixes could name the wrong server.
- Tool handlers accepted
args: anyand used internal casts, so TypeScript could not find all argument errors. - Separate HTTP clients handled errors differently.
- A process-wide
NODE_TLS_REJECT_UNAUTHORIZED = '0'disabled TLS verification for all outbound requests.
The early mcp-reverse copy inherited the SSH-prefix problem and the comment APTL Kali Red Team MCP Server.
Another copied server would also copy those defects.
JSON Schema validation remained a runtime boundary, distinct from TypeScript checking.
Scale¶
The decision covered 2–3 existing servers and planned support for at least eight.
The planned targets were Kali, Wazuh, Indexer, reverse engineering, MISP, TheHive, Shuffle, and Suricata.
Those historical counts do not identify the current installed inventory.
ADR-063 later removed TheHive and mcp-casemgmt.
Decision¶
Use mcp/aptl-mcp-common/ as the shared TypeScript library for MCP server behavior.
Configuration selects the target and tools; common owners implement transport and dispatch.
This reduces copied code while keeping server configuration explicit.
Core Components¶
| Component | Original responsibility | Current ownership distinction |
|---|---|---|
PersistentSession |
Long-lived shells, queued commands, delimiters, output bounds, keepalive, and command timeouts | ssh.ts exports the session contract; split session modules implement it |
SSHConnectionManager |
Session pool, lifecycle, and metadata | The SSH manager retains its existing shared ownership |
HTTPClient |
Shared API requests, TLS, and errors | http.ts keeps system-trust, configured-CA, and explicit insecure states distinct |
createMCPServer(config) |
Build tools and handlers from server configuration | server.ts also retains current validation and participant-admission boundaries |
startServer(callerMetaUrl) |
Load the caller's configuration and start its server | index.ts remains the common entry point |
| Argument interfaces | Replace repeated untyped handler arguments with named types | The original 10 SSH and three API handler counts are historical; current signatures are the contract |
| Shell formatters | Format commands for bash, sh, PowerShell, and cmd | shells.ts owns shell-specific environment, directory, and command syntax |
The original entry-point example remains:
The original HTTP decision used a request-scoped HTTPS agent with rejectUnauthorized: false for self-signed lab certificates.
It removed the process-wide TLS override.
This historical rationale does not grant a general current exception to TLS verification.
Amendment (SEC-006 / ADR-034, issue #258, 2026-05-18):
SEC-004's insecure allowance narrows to Wazuh inter-component traffic.
SOC consumers use the CA generated by aptl.core.soc_ca.
verify_ssl=true with ca_cert_path selects a per-instance agent with rejectUnauthorized: true.
Wazuh-targeting mcp-wazuh, mcp-indexer, and mcp-network keep their explicit verify_ssl: false configurations.
Amendment (SEC-009, issue #1767):
mcp-wazuh, mcp-indexer, and mcp-network verify TLS against the lab Wazuh CA.
The common HTTP client refuses verify_ssl: false.
The update selected CA verification for mcp-threatintel, mcp-casemgmt, and mcp-soar.
The later removal of mcp-casemgmt does not reverse the remaining CA requirements.
ADR-034 defines the TLS boundary.
Config-Driven Architecture¶
docker-lab-config.json supplies server identity, target connection details, SSH tools, API endpoint templates, and shell type.
The common factory creates the advertised tools and their handlers.
A new configuration can reuse existing tool types without another transport implementation.
It cannot supply an arbitrary new implementation or bypass validation and admission.
Participant action enforcement explains the later invocation boundary. MCP Reference owns maintained tool and configuration facts. The factory and current source types, rather than an old handler count, determine supported behavior.
Build System¶
The original build used mcp/build-all-mcps.sh to build the common library before dependent servers.
A shared-library change still requires its consumers' verification.
CI owns their complete rebuild and checks.
The MCP operations guide owns supported build tasks.
Consequences¶
Positive¶
- Common transport, entry points, and tool registration avoid repeated fixes.
- Named argument types can find errors during development.
- The recorded migration found the
queryConfig.endpointtoqueryConfig.urlerror. - Configuration reuses common SSH, HTTP, error, and result handling.
- The original SOC servers reused the same pattern.
Negative¶
- All consumers depend on the common library, so a breaking change needs coordinated updates and builds.
- Debugging needs knowledge of the factory and configuration schema.
- The original tree held nine npm packages: one library and eight servers.
- It used the build script rather than Turborepo or Nx for ordering.
- These package counts record that tree, not a current inventory guarantee.
Risks¶
A new tool type or connection method can require common parser, factory, and handler changes. A shared session defect can affect every SSH-based consumer. The existing shared tests and consumer checks must therefore exercise the affected boundary.