Troubleshooting Guide
Common issues and solutions for local development of the Loan Defenders system.
CORS Configuration Issues
Problem: "I'm sorry, I'm having trouble connecting right now"
Symptoms: - UI displays connection error message - Browser console shows CORS preflight errors - API returns 400 Bad Request on OPTIONS requests
Root Cause: The frontend is running on a port that's not included in the API's CORS allowed origins.
Solution:
-
Check which port your frontend is running on:
-
Edit the root
.envfile and add your port toAPP_CORS_ORIGINS: -
Restart the API server:
-
Verify the API health:
Common Frontend Ports
Vite usually assigns ports sequentially: 5173, 5174, 5175, etc. If one port is in use, it automatically tries the next available port.
Port Already in Use
Problem: "Address already in use" or "Port XXXX is already allocated"
Symptoms:
- Server fails to start
- Error message mentions specific port number
- lsof shows process using the port
Solution:
-
Check which ports are in use:
-
Kill the process using the port:
-
Restart the affected service
Force Kill
Using kill -9 forcefully terminates processes. Only use this if graceful shutdown (kill without -9) doesn't work.
Environment Variables Not Loading
Problem: "AZURE_AI_PROJECT_ENDPOINT not set" or similar environment variable errors
Symptoms: - API fails to start with missing environment variable errors - MCP servers can't connect - Azure authentication fails
Root Cause:
Environment variables are not being loaded from the .env file.
Solution:
-
Verify
.envfile exists in project root: -
If missing, create from template:
-
Edit
.envwith your Azure credentials: -
Verify environment variables are loaded:
Environment Variable Hierarchy
The API loads environment variables in this order:
1. System environment variables (highest priority)
2. Root .env file
3. Default values in code (lowest priority)
Azure Authentication Errors
Problem: "DefaultAzureCredential failed to retrieve a token" or authentication errors
Symptoms: - API starts but fails when processing loan applications - Azure SDK authentication errors in logs - 401 Unauthorized responses from Azure
Solution:
-
Verify Azure CLI is logged in:
-
Test Azure credentials:
-
Check
.envconfiguration: -
For CI/CD environments, set service principal credentials:
DefaultAzureCredential Chain
DefaultAzureCredential tries these authentication methods in order:
1. Environment variables (service principal)
2. Managed identity (Azure hosted)
3. Azure CLI credentials (az login)
4. Visual Studio Code credentials
5. Azure PowerShell credentials
Module Not Found Errors
Problem: "ModuleNotFoundError" or "No module named 'loan_defenders'"
Symptoms:
- Import errors when running Python scripts
- Tests fail with module not found
- uv run commands fail
Solution:
-
Reinstall dependencies:
-
Verify Python path:
-
Check
pyproject.tomlconfiguration: -
For frontend module errors:
Clean Install
If issues persist, perform a complete clean install:
MCP Server Connection Failures
Problem: "Failed to connect to MCP server" or timeouts
Symptoms: - Loan processing hangs or fails - Agent logs show MCP server connection errors - Timeout errors in API logs
Solution:
-
Verify all MCP servers are running:
-
Check MCP server logs for errors:
- Look at the terminal windows where you started the servers
-
Check for startup errors or exceptions
-
Verify MCP server URLs in
.env: -
Test MCP server connectivity:
-
Restart all MCP servers:
# Kill existing processes pkill -f "loan_defenders.tools.mcp_servers" # Start servers in separate terminals uv run python -m loan_defenders.tools.mcp_servers.application_verification.server uv run python -m loan_defenders.tools.mcp_servers.document_processing.server uv run python -m loan_defenders.tools.mcp_servers.financial_calculations.server
MCP Server Dependencies
All three MCP servers must be running before starting the API server. The API won't start if it can't connect to the MCP servers.
Frontend Build Errors
Problem: TypeScript compilation errors or build failures
Symptoms:
- npm run dev fails
- TypeScript type errors in console
- Build hangs or times out
Solution:
-
Clear TypeScript cache:
-
Reinstall dependencies:
-
Check TypeScript configuration:
-
Update dependencies to latest compatible versions:
Slow Agent Response Times
Problem: Agent processing takes 30+ seconds or responses are very slow
Symptoms: - Long wait times during loan processing - UI shows "analyzing" for extended periods - High token usage in logs
Root Cause: Agent personas may be too large or verbose, causing excessive token consumption.
Solution:
-
Check agent persona file sizes:
-
Personas should be 300-500 lines max, not 2000+
-
Review persona content:
- Remove verbose explanations
- Focus on clear directives (WHAT not HOW)
-
Link to external docs instead of inline explanations
-
Monitor token usage in API logs
Token Optimization
Reducing persona files from 2000+ lines to 300-500 focused lines can result in 75% token reduction and 10x faster agent responses.
Database or State Issues
Problem: Session not found, state inconsistencies, or cached data issues
Symptoms: - "Session not found" errors - Loan applications show stale data - Agents process incorrect information
Solution:
-
Clear session data (API maintains in-memory sessions):
-
Clear browser storage:
- Open browser DevTools (F12)
- Application tab → Clear storage
-
Refresh the page
-
Check session timeout configuration in
.env:
Windows-Specific Issues
PowerShell Script Execution Policy
Symptoms:
- PowerShell scripts fail with "cannot be loaded because running scripts is disabled"
- uv commands fail in PowerShell
Solution:
# Check current policy
Get-ExecutionPolicy
# Set policy for current user (recommended)
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# Or bypass for single command
powershell -ExecutionPolicy Bypass -Command "uv sync"
Reference: PowerShell Execution Policies
Path Separators in PowerShell
Windows uses backslashes (\) instead of forward slashes (/):
# Windows PowerShell
cd apps\api
uv run python -m loan_defenders.api.app
# Set PYTHONPATH
$env:PYTHONPATH = "${PWD};$env:PYTHONPATH"
Docker Desktop Not Starting
Symptoms:
- docker commands fail
- "Docker daemon is not running" error
Solution:
1. Start Docker Desktop from Start Menu
2. Wait for Docker to initialize (check system tray icon)
3. If fails, restart Docker Desktop or reboot Windows
4. Verify WSL 2 is enabled: wsl --status
Reference: Docker Desktop for Windows Troubleshooting
VS Code Settings Issues
Terminal Working Directory Error
Symptoms:
- Terminal fails with "directory does not exist" error
- Hardcoded paths like /workspaces/loan-defenders don't work locally
Solution:
VS Code settings should use ${workspaceFolder} variable instead of absolute paths:
// ❌ BAD - Hardcoded path
"terminal.integrated.cwd": "/workspaces/loan-defenders"
// ✅ GOOD - Works everywhere
"terminal.integrated.cwd": "${workspaceFolder}"
Python Interpreter Not Found
Local Dev:
Dev Container Override:
// devcontainer.json
{
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python"
}
}
}
}
Reference: VS Code Variables, Dev Containers Settings
Still Having Issues?
If none of these solutions work:
- Check the logs for detailed error messages:
- API logs in the terminal running
loan_defenders.api.app - MCP server logs in their respective terminals
-
Browser console logs (F12 → Console)
-
Search existing issues: GitHub Issues
-
Create a new issue with:
- Detailed description of the problem
- Steps to reproduce
- Error messages and logs
-
Environment details (OS, Python version, Node version)
-
Join discussions: GitHub Discussions
Platform-Specific Setup Guides
For detailed platform-specific instructions, see:
- Windows Setup: PowerShell Guide, Docker Desktop, uv on Windows
- macOS Setup: Homebrew, Docker Desktop
- Linux Setup: Docker Engine, uv Installation
Useful Debugging Commands
# Check all service health
curl http://localhost:8000/health # API
curl http://localhost:8010/health # MCP Application Verification
curl http://localhost:8011/health # MCP Document Processing
curl http://localhost:8012/health # MCP Financial Calculations
# View running processes
ps aux | grep loan_defenders
ps aux | grep node
# Check port usage (macOS/Linux)
lsof -i :8000
lsof -i :8010-8012
lsof -i :5173
# Check port usage (Windows PowerShell)
netstat -ano | findstr :8000
netstat -ano | findstr :8010
# Test Azure authentication
uv run python -c "from azure.identity import DefaultAzureCredential; print(DefaultAzureCredential().get_token('https://cognitiveservices.azure.com/.default'))"
# Validate environment
cat .env | grep -v "^#" | grep -v "^$" # Unix
Get-Content .env | Where-Object { $_ -notmatch '^#' -and $_ -notmatch '^$' } # PowerShell
# Check Python environment
uv run python --version
uv pip list
# Check Node environment
node --version
npm --version
npm list --depth=0