MCP Composable Integration - Complete Implementation
Overview
Successfully refactored the MCP setup functionality to use the centralized useMcpSetup.js composable, eliminating inline code duplication and adding comprehensive error handling.
Files Modified
1. web/src/composables/useMcpSetup.js (563 lines)
Enhanced with robust error handling for all export functions.
Changes:
-
downloadFile()function:- Added support for both string and Blob content
- Implemented try-catch error handling
- Improved error messages with context
-
downloadAllMcpFiles()function:- Added parameter validation (mcpConfig, agentName)
- Added configuration property validation
- Added JSZip import error handling
- Comprehensive error logging and reporting
- Returns proper error state to caller
-
copyMcpFilesToProject()function:- Added parameter validation
- Added response validation before JSON parsing
- Checks Content-Type header before calling
.json() - Handles missing or empty responses gracefully
- Returns fallback file list on success even if response is empty
Key Error Handling Improvements:
// Check response exists
if (!response) {
throw new Error('No response from server')
}
// Check content type before parsing JSON
const contentType = response.headers.get('content-type')
if (contentType && contentType.includes('application/json')) {
result = await response.json()
}
2. web/src/views/ProjectDetail.vue (1413 lines)
Updated all event handlers to properly use composable functions with error handling.
Changes:
-
downloadMcpFile()handler:- Wrapped in try-catch block
- Displays user-friendly error alerts
- Logs errors to console for debugging
-
handleDownloadAllMcpFiles()handler:- Wrapped in try-catch block
- Properly awaits composable function
- Displays error messages to users
Example Handler:
const handleDownloadAllMcpFiles = async () => {
try {
await downloadAllMcpFiles(mcpConfig.value, mcpSetupAgent.value.name)
} catch (error) {
console.error('Failed to download MCP files:', error)
alert(`Failed to download MCP files: ${error.message}`)
}
}
Problem Resolution
Issue: "Cannot read properties of undefined (reading 'json')"
Root Cause: The copyMcpFilesToProject() function was attempting to call .json() on a response without checking if:
- The response object was defined
- The response had a JSON content-type
Solution:
- Added null/undefined checks for response object
- Check Content-Type header before parsing JSON
- Provide fallback values on successful requests even if response body is empty
- Improved error messages with response text context
Issue: Blob Handling in Download Function
Root Cause: The original downloadFile() function only handled strings, failing when JSZip returned a Blob object.
Solution:
- Added type checking for Blob vs string content
- Handle both types appropriately
- Added error wrapping for debugging
Integration Status
✅ Composable Usage
All MCP configuration is now centralized in useMcpSetup.js:
mcpSettingsJson- VS Code environment variablesmcpCopilotInstructions- Agent identity instructionsmcpPowerShellScript- PowerShell helper functionsmcpBashScript- Bash helper functionsmcpVSCodeJson- VS Code MCP configurationmcpVS2026Json- Visual Studio 2026 full configurationmcpConfig- Bundle of all configurationsdownloadFile- File download utilitydownloadAllMcpFiles- ZIP creation function (with error handling)copyMcpFilesToProject- Direct project file creation (with error handling)
✅ Event Flow
- User clicks "Download All" button in McpSetupModal
- Modal emits
@download-allevent - ProjectDetail.vue catches event in
handleDownloadAllMcpFiles() - Handler calls composable's
downloadAllMcpFiles()function - Function validates input, creates ZIP, handles errors gracefully
✅ Error Handling
All error paths now:
- Log to console for developer debugging
- Display user-friendly alerts
- Prevent silent failures
- Provide actionable error messages
Testing Checklist
- Download individual MCP files (settings, mcp, copilot, powershell, bash)
- Download all MCP files as ZIP
- Copy MCP files directly to project (when backend endpoint implemented)
- Test error handling with invalid inputs
- Test error handling with network failures
- Verify ZIP contains all 6 files + README
- Test in VS Code with extracted files
- Test in Visual Studio 2026 with .mcp.json
Next Steps
Backend Implementation
- Implement
POST /api/projects/{id}/mcp-filesendpoint - Accept file dictionary from request body
- Create files in project directory
- Return success response with file list
UI Enhancements
- Add loading states during download
- Add success/error toast notifications
- Add progress indicator for ZIP generation
- Add "Apply Configuration" button with loading state
Testing
- Test all download scenarios
- Test error scenarios
- Validate ZIP contents
- Test IDE integration (VS Code, VS 2026)
Code Quality Metrics
- Error Handling: Comprehensive try-catch blocks on all async operations
- Validation: Input parameter validation on all functions
- Logging: Console logging for debugging and error tracking
- User Feedback: Alert notifications for user-facing errors
- Type Safety: JSDoc comments on all exported functions
- Backward Compatibility: No breaking changes to existing code
Deployment Notes
This change is fully backward compatible:
- No API contract changes
- No database migrations required
- No configuration changes needed
- Can be deployed independently
The implementation follows Vue 3 Composition API best practices and the project's coding guidelines as specified in vue.instructions.md.