|
| 1 | +// Configuration constants for MCP SSH Manager |
| 2 | + |
| 3 | +// Output limits to prevent Claude Code crashes |
| 4 | +export const OUTPUT_LIMITS = { |
| 5 | + // Maximum length of stdout/stderr in responses (characters) |
| 6 | + MAX_OUTPUT_LENGTH: process.env.MCP_SSH_MAX_OUTPUT_LENGTH |
| 7 | + ? parseInt(process.env.MCP_SSH_MAX_OUTPUT_LENGTH) |
| 8 | + : 10000, |
| 9 | + |
| 10 | + // Maximum length for log file tailing |
| 11 | + MAX_TAIL_LINES: process.env.MCP_SSH_MAX_TAIL_LINES |
| 12 | + ? parseInt(process.env.MCP_SSH_MAX_TAIL_LINES) |
| 13 | + : 100, |
| 14 | + |
| 15 | + // Maximum length for rsync verbose output |
| 16 | + MAX_RSYNC_OUTPUT: process.env.MCP_SSH_MAX_RSYNC_OUTPUT |
| 17 | + ? parseInt(process.env.MCP_SSH_MAX_RSYNC_OUTPUT) |
| 18 | + : 5000, |
| 19 | +}; |
| 20 | + |
| 21 | +// Timeout configuration |
| 22 | +export const TIMEOUTS = { |
| 23 | + // Default command execution timeout (milliseconds) |
| 24 | + DEFAULT_COMMAND_TIMEOUT: process.env.MCP_SSH_DEFAULT_TIMEOUT |
| 25 | + ? parseInt(process.env.MCP_SSH_DEFAULT_TIMEOUT) |
| 26 | + : 120000, // 2 minutes |
| 27 | + |
| 28 | + // Maximum allowed command timeout (milliseconds) |
| 29 | + MAX_COMMAND_TIMEOUT: process.env.MCP_SSH_MAX_TIMEOUT |
| 30 | + ? parseInt(process.env.MCP_SSH_MAX_TIMEOUT) |
| 31 | + : 300000, // 5 minutes |
| 32 | + |
| 33 | + // Connection timeout (milliseconds) |
| 34 | + CONNECTION_TIMEOUT: process.env.MCP_SSH_CONNECTION_TIMEOUT |
| 35 | + ? parseInt(process.env.MCP_SSH_CONNECTION_TIMEOUT) |
| 36 | + : 1800000, // 30 minutes |
| 37 | + |
| 38 | + // Keepalive interval (milliseconds) |
| 39 | + KEEPALIVE_INTERVAL: process.env.MCP_SSH_KEEPALIVE_INTERVAL |
| 40 | + ? parseInt(process.env.MCP_SSH_KEEPALIVE_INTERVAL) |
| 41 | + : 60000, // 1 minute |
| 42 | +}; |
| 43 | + |
| 44 | +// Response formatting |
| 45 | +export const RESPONSE_FORMAT = { |
| 46 | + // Whether to use compact JSON (no formatting) |
| 47 | + COMPACT_JSON: process.env.MCP_SSH_COMPACT_JSON === 'true', |
| 48 | + |
| 49 | + // Whether to include debug information in responses |
| 50 | + INCLUDE_DEBUG_INFO: process.env.MCP_SSH_DEBUG === 'true', |
| 51 | +}; |
| 52 | + |
| 53 | +// Helper function to truncate output |
| 54 | +export function truncateOutput(text, maxLength = OUTPUT_LIMITS.MAX_OUTPUT_LENGTH) { |
| 55 | + if (!text) return ''; |
| 56 | + |
| 57 | + if (text.length <= maxLength) return text; |
| 58 | + |
| 59 | + const truncated = text.length - maxLength; |
| 60 | + return text.substring(0, maxLength) + `\n\n... [${truncated} characters truncated]`; |
| 61 | +} |
| 62 | + |
| 63 | +// Helper function to format JSON response |
| 64 | +export function formatJSONResponse(data) { |
| 65 | + return JSON.stringify( |
| 66 | + data, |
| 67 | + null, |
| 68 | + RESPONSE_FORMAT.COMPACT_JSON ? 0 : 2 |
| 69 | + ); |
| 70 | +} |
0 commit comments