TIMEOUT_FIX_SUMMARY.md•3.58 kB
# RateSpot MCP Server Timeout Fix Summary
## Issue
The RateSpot MCP server was experiencing timeout errors when making API calls with minimal parameters (e.g., just state and zipCode). The error message was:
```
Error fetching mortgage rates: Request timeout after 15000ms
```
## Root Cause Analysis
1. **API Response Time**: The RateSpot API typically takes 15-25 seconds to respond, especially when processing multiple lenders
2. **Timeout Too Short**: The server had a 15-second timeout, which was insufficient for the API's response time
3. **Unnecessary Parameter**: The server was sending a `mortgage_balance` parameter that the API doesn't use (confirmed by comparing with working curl command)
## Solution Implemented
### 1. Increased Timeout Duration
- Changed timeout from 15 seconds to 30 seconds in `makeRateSpotRequest` function
- Added informative error message: "The RateSpot API typically takes 15-25 seconds to respond"
### 2. Removed Unnecessary Parameter
- Removed `mortgage_balance` parameter from API calls in both:
- `get-mortgage-rates` tool
- `compare-loan-products` tool
- The API only needs `down_payment` percentage, not `mortgage_balance`
### 3. Enhanced Error Logging
- Added timeout duration to console logs
- Improved error messages to help with debugging
## Code Changes
### File: `ratespot_mcp_server.ts`
1. **Timeout increase** (line ~340):
```typescript
async function makeRateSpotRequest(params: any, timeoutMs: number = 30000) {
// Changed from 15000 to 30000
```
2. **Better error message**:
```typescript
setTimeout(() => reject(new Error(
`Request timeout after ${timeoutMs}ms. The RateSpot API typically takes 15-25 seconds to respond.`
)), timeoutMs);
```
3. **Removed mortgage_balance** from get-mortgage-rates (line ~570):
```typescript
const queryParams = {
purpose: "purchase",
zipcode: params.zipCode || "90210",
property_value: propertyValue,
down_payment: downPaymentPercent,
// REMOVED: mortgage_balance: mortgageBalancePercent,
credit_score: params.creditScore || 790,
fha: 1,
va: 1,
property_type: params.propertyType || "single_family",
property_use: params.occupancy || "primary"
};
```
4. **Removed mortgage_balance** from compare-loan-products (line ~730):
```typescript
const queryParams = {
purpose: "purchase",
zipcode: currentZip.trim(),
property_value: propertyValue,
down_payment: downPaymentPercent,
// REMOVED: mortgage_balance: mortgageBalancePercent,
credit_score: creditScore,
fha: 1,
va: 1,
property_type: propertyType,
property_use: occupancy
};
```
## Testing Results
### Before Fix
- Minimal parameters (state + zipCode): ❌ Timeout after 15 seconds
- All parameters: ❌ Timeout after 15 seconds
### After Fix
- Minimal parameters: ✅ Success in ~20-22 seconds
- All parameters: ✅ Success in ~17-20 seconds
- With mortgage_balance: ✅ Still works (parameter is ignored by API)
## Verification
Run the test scripts to verify the fix:
```bash
# Test API directly
node test_api_timeout_fix.js
# Test through MCP
node test_timeout_fix_verification.js
```
## Impact
- Users can now successfully query mortgage rates with minimal parameters
- No more timeout errors for normal API usage
- Better error messages if timeouts do occur
- Cleaner API calls without unnecessary parameters
## Recommendations
1. Monitor API response times - if they increase beyond 30 seconds, consider increasing timeout further
2. Consider implementing retry logic for transient failures
3. Add request caching to avoid repeated API calls for same parameters