Skip to content

Commit 767df79

Browse files
john-walkoeclaude
andcommitted
COMPREHENSIVE FIX: Prevent ALL INFO/WARN/ERROR messages from corrupting API key files
Bug: All echo statements in prompt_and_validate_*_key() functions were going to stdout and being captured by $(command) substitution, resulting in corrupted key files containing error messages + actual keys. Fix: Redirect ALL informational messages to stderr (>&2). Only actual API keys should go to stdout. Files affected: - prompt_and_validate_uspto_key(): 11 echo statements fixed - prompt_and_validate_mistral_key(): 11 echo statements fixed Impact: Cross-MCP key detection now works perfectly. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent c23cbcb commit 767df79

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

deploy/Validation-Helpers.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ prompt_and_validate_uspto_key() {
268268

269269
# STEP 1: Check if key already exists in secure storage
270270
if check_existing_uspto_key; then
271-
echo "INFO: Checking existing USPTO API key from another USPTO MCP installation..."
271+
echo "INFO: Checking existing USPTO API key from another USPTO MCP installation..." >&2
272272

273273
# Try to load the existing key
274274
local existing_key=$(load_existing_uspto_key)
@@ -278,22 +278,22 @@ prompt_and_validate_uspto_key() {
278278

279279
# Ask user if they want to use it
280280
if prompt_use_existing_key "USPTO" "$masked_key"; then
281-
echo "SUCCESS: Using existing USPTO API key from secure storage"
281+
echo "SUCCESS: Using existing USPTO API key from secure storage" >&2
282282
echo "$existing_key"
283283
return 0
284284
else
285-
echo "INFO: You chose to enter a new USPTO API key"
286-
echo "WARN: This will OVERWRITE the existing key for ALL USPTO MCPs"
285+
echo "INFO: You chose to enter a new USPTO API key" >&2
286+
echo "WARN: This will OVERWRITE the existing key for ALL USPTO MCPs" >&2
287287
read -p "Are you sure you want to continue? (y/N): " CONFIRM_OVERWRITE
288288
if [[ ! "$CONFIRM_OVERWRITE" =~ ^[Yy]$ ]]; then
289-
echo "INFO: Keeping existing key"
289+
echo "INFO: Keeping existing key" >&2
290290
echo "$existing_key"
291291
return 0
292292
fi
293293
fi
294294
else
295-
echo "WARN: Existing key file found but could not load (may be corrupted)"
296-
echo "INFO: You will need to enter a new key"
295+
echo "WARN: Existing key file found but could not load (may be corrupted)" >&2
296+
echo "INFO: You will need to enter a new key" >&2
297297
fi
298298
fi
299299

@@ -304,9 +304,9 @@ prompt_and_validate_uspto_key() {
304304
read_api_key_secure "Enter your USPTO API key" key
305305

306306
if [[ -z "$key" ]]; then
307-
echo "ERROR: USPTO API key cannot be empty"
307+
echo "ERROR: USPTO API key cannot be empty" >&2
308308
if [[ $attempt -lt $max_attempts ]]; then
309-
echo "INFO: Attempt $attempt of $max_attempts"
309+
echo "INFO: Attempt $attempt of $max_attempts" >&2
310310
fi
311311
continue
312312
fi
@@ -318,15 +318,15 @@ prompt_and_validate_uspto_key() {
318318
echo "$key"
319319
return 0
320320
else
321-
echo "$VALIDATION_RESULT"
321+
echo "$VALIDATION_RESULT" >&2
322322
if [[ $attempt -lt $max_attempts ]]; then
323-
echo "WARN: Attempt $attempt of $max_attempts - please try again"
324-
echo "INFO: USPTO API key format: 30 lowercase letters (a-z)"
323+
echo "WARN: Attempt $attempt of $max_attempts - please try again" >&2
324+
echo "INFO: USPTO API key format: 30 lowercase letters (a-z)" >&2
325325
fi
326326
fi
327327
done
328328

329-
echo "ERROR: Failed to provide valid USPTO API key after $max_attempts attempts"
329+
echo "ERROR: Failed to provide valid USPTO API key after $max_attempts attempts" >&2
330330
return 1
331331
}
332332

@@ -338,7 +338,7 @@ prompt_and_validate_mistral_key() {
338338

339339
# STEP 1: Check if key already exists in secure storage
340340
if check_existing_mistral_key; then
341-
echo "INFO: Checking existing Mistral API key from another USPTO MCP installation..."
341+
echo "INFO: Checking existing Mistral API key from another USPTO MCP installation..." >&2
342342

343343
# Try to load the existing key
344344
local existing_key=$(load_existing_mistral_key)
@@ -348,22 +348,22 @@ prompt_and_validate_mistral_key() {
348348

349349
# Ask user if they want to use it
350350
if prompt_use_existing_key "Mistral" "$masked_key"; then
351-
echo "SUCCESS: Using existing Mistral API key from secure storage"
351+
echo "SUCCESS: Using existing Mistral API key from secure storage" >&2
352352
echo "$existing_key"
353353
return 0
354354
else
355-
echo "INFO: You chose to enter a new Mistral API key"
356-
echo "WARN: This will OVERWRITE the existing key for ALL USPTO MCPs"
355+
echo "INFO: You chose to enter a new Mistral API key" >&2
356+
echo "WARN: This will OVERWRITE the existing key for ALL USPTO MCPs" >&2
357357
read -p "Are you sure you want to continue? (y/N): " CONFIRM_OVERWRITE
358358
if [[ ! "$CONFIRM_OVERWRITE" =~ ^[Yy]$ ]]; then
359-
echo "INFO: Keeping existing key"
359+
echo "INFO: Keeping existing key" >&2
360360
echo "$existing_key"
361361
return 0
362362
fi
363363
fi
364364
else
365-
echo "WARN: Existing key file found but could not load (may be corrupted)"
366-
echo "INFO: You will need to enter a new key"
365+
echo "WARN: Existing key file found but could not load (may be corrupted)" >&2
366+
echo "INFO: You will need to enter a new key" >&2
367367
fi
368368
fi
369369

@@ -379,7 +379,7 @@ prompt_and_validate_mistral_key() {
379379

380380
# Empty is OK (optional)
381381
if [[ -z "$key" ]]; then
382-
echo "INFO: Skipping Mistral API key"
382+
echo "INFO: Skipping Mistral API key" >&2
383383
echo "" # Return empty string
384384
return 0
385385
fi
@@ -391,15 +391,15 @@ prompt_and_validate_mistral_key() {
391391
echo "$key"
392392
return 0
393393
else
394-
echo "$VALIDATION_RESULT"
394+
echo "$VALIDATION_RESULT" >&2
395395
if [[ $attempt -lt $max_attempts ]]; then
396-
echo "WARN: Attempt $attempt of $max_attempts - please try again"
397-
echo "INFO: Mistral API key format: 32 alphanumeric characters (a-z, A-Z, 0-9)"
396+
echo "WARN: Attempt $attempt of $max_attempts - please try again" >&2
397+
echo "INFO: Mistral API key format: 32 alphanumeric characters (a-z, A-Z, 0-9)" >&2
398398
fi
399399
fi
400400
done
401401

402-
echo "ERROR: Failed to provide valid Mistral API key after $max_attempts attempts"
402+
echo "ERROR: Failed to provide valid Mistral API key after $max_attempts attempts" >&2
403403
return 1
404404
}
405405

0 commit comments

Comments
 (0)