fix: Hardcode DB config and start server before DB connection
- db.ts: Hardcode 10.0.1.1 (infra VM) to prevent env var issues - index.ts: Start MCP server before DB connection (fixes Claude Code timing) - run.sh/run.js: Add wrapper scripts with embedded env vars - start.sh: Update with correct WireGuard config Fixes task-mcp failing to connect in Claude Code sessions after WireGuard migration. The server must respond to MCP initialize before stdin closes, which requires starting before slow DB ops. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
26
src/index.ts
26
src/index.ts
@@ -5,8 +5,8 @@
|
||||
* Exposes task management tools via Model Context Protocol.
|
||||
* Uses PostgreSQL with pgvector for semantic search.
|
||||
*
|
||||
* Requires SSH tunnel to docker-host:
|
||||
* ssh -L 5432:172.27.0.3:5432 docker-host -N &
|
||||
* Requires SSH tunnel to infra VM on port 5433:
|
||||
* ssh -L 5433:localhost:5432 -i ~/.ssh/hetzner_mash_deploy root@46.224.188.157 -N &
|
||||
*/
|
||||
|
||||
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
||||
@@ -368,16 +368,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||
|
||||
// Main entry point
|
||||
async function main() {
|
||||
// Test database connection
|
||||
const connected = await testConnection();
|
||||
if (!connected) {
|
||||
console.error('Failed to connect to database. Ensure SSH tunnel is active:');
|
||||
console.error(' ssh -L 5432:172.27.0.3:5432 docker-host -N &');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.error('task-mcp: Connected to database');
|
||||
|
||||
// Set up cleanup
|
||||
process.on('SIGINT', async () => {
|
||||
await close();
|
||||
@@ -389,10 +379,20 @@ async function main() {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// Start server
|
||||
// Start server FIRST - respond to MCP protocol immediately
|
||||
// This is critical: Claude Code sends initialize before we finish DB connection
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.error('task-mcp: Server started');
|
||||
|
||||
// Test database connection in background (lazy - will connect on first tool call anyway)
|
||||
testConnection().then((connected) => {
|
||||
if (connected) {
|
||||
console.error('task-mcp: Connected to database');
|
||||
} else {
|
||||
console.error('task-mcp: Warning - database not reachable, will retry on tool calls');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user