@@ -41,6 +41,26 @@ interface TestConnectionResult {
4141 warnings ?: string [ ]
4242}
4343
44+ /**
45+ * Extracts a user-friendly error message from connection errors.
46+ * Keeps diagnostic info (timeout, DNS, HTTP status) but strips
47+ * verbose internals (Zod details, full response bodies, stack traces).
48+ */
49+ function sanitizeConnectionError ( error : unknown ) : string {
50+ if ( ! ( error instanceof Error ) ) {
51+ return 'Unknown connection error'
52+ }
53+
54+ const msg = error . message
55+
56+ if ( msg . length > 200 ) {
57+ const firstLine = msg . split ( '\n' ) [ 0 ]
58+ return firstLine . length > 200 ? `${ firstLine . slice ( 0 , 200 ) } ...` : firstLine
59+ }
60+
61+ return msg
62+ }
63+
4464/**
4565 * POST - Test connection to an MCP server before registering it
4666 */
@@ -137,8 +157,7 @@ export const POST = withMcpAuth('write')(
137157 } catch ( toolError ) {
138158 logger . warn ( `[${ requestId } ] Connection established but could not list tools:` , toolError )
139159 result . success = false
140- const errorMessage = toolError instanceof Error ? toolError . message : 'Unknown error'
141- result . error = `Connection established but could not list tools: ${ errorMessage } `
160+ result . error = 'Connection established but could not list tools'
142161 result . warnings = result . warnings || [ ]
143162 result . warnings . push (
144163 'Server connected but tool listing failed - connection may be incomplete'
@@ -163,11 +182,7 @@ export const POST = withMcpAuth('write')(
163182 logger . warn ( `[${ requestId } ] MCP server test failed:` , error )
164183
165184 result . success = false
166- if ( error instanceof Error ) {
167- result . error = error . message
168- } else {
169- result . error = 'Unknown connection error'
170- }
185+ result . error = sanitizeConnectionError ( error )
171186 } finally {
172187 if ( client ) {
173188 try {
0 commit comments