chore: Enhance MCP server execution and compatibility with Cursor mode
- Introduce environment variables for Cursor compatibility in silent-mcp.sh and npx-entry.cjs - Implement process cleanup for existing MCP instances to prevent conflicts - Adjust logging behavior based on execution context to ensure proper message handling - Add test-cursor.sh script to simulate Cursor environment for testing purposes - Refactor stdio-server.ts to manage logging and message flushing based on compatibility mode
This commit is contained in:
@@ -1,14 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Ensure we're running in a clean environment for MCP
|
||||
# Set silent environment variables
|
||||
export LOG_LEVEL=silent
|
||||
export USE_STDIO_TRANSPORT=true
|
||||
|
||||
# Check if we're running from npx or directly
|
||||
# Explicitly mark that we are NOT in Cursor mode
|
||||
export CURSOR_COMPATIBLE=false
|
||||
|
||||
# Flag to prevent recursive execution
|
||||
export SILENT_MCP_RUNNING=true
|
||||
|
||||
# Clean up any existing processes - optional but can help with "already" errors
|
||||
# pkill -f "node.*stdio-server" >/dev/null 2>&1 || true
|
||||
|
||||
# Direct execution - always use local file
|
||||
if [ -f "./dist/stdio-server.js" ]; then
|
||||
# Direct run from project directory - use local file
|
||||
# Keep stdout intact (for JSON-RPC messages) but redirect stderr to /dev/null
|
||||
node ./dist/stdio-server.js 2>/dev/null
|
||||
else
|
||||
# Run using npx
|
||||
npx homeassistant-mcp 2>/dev/null
|
||||
# If no local file, run directly through node using the globally installed package
|
||||
# This avoids calling npx again which would create a loop
|
||||
node $(npm root -g)/homeassistant-mcp/dist/stdio-server.js 2>/dev/null
|
||||
fi
|
||||
Reference in New Issue
Block a user