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:
12
run.js
Normal file
12
run.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
// Entry point with hardcoded env vars for Claude Code MCP
|
||||||
|
|
||||||
|
process.env.DB_HOST = "10.0.1.1";
|
||||||
|
process.env.DB_PORT = "5432";
|
||||||
|
process.env.DB_NAME = "agiliton";
|
||||||
|
process.env.DB_USER = "agiliton";
|
||||||
|
process.env.DB_PASSWORD = "QtqiwCOAUpQNF6pjzOMAREzUny2bY8V1";
|
||||||
|
process.env.LLM_API_URL = "https://llm.agiliton.cloud";
|
||||||
|
process.env.LLM_API_KEY = "sk-master-91b891c709ade9021a97c9260217ddb277877db652a31dcf";
|
||||||
|
|
||||||
|
await import('./dist/index.js');
|
||||||
12
run.sh
Executable file
12
run.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
echo "task-mcp: run.sh executing with DB_HOST=10.0.1.1" >&2
|
||||||
|
export DB_HOST="10.0.1.1"
|
||||||
|
export DB_PORT="5432"
|
||||||
|
export DB_NAME="agiliton"
|
||||||
|
export DB_USER="agiliton"
|
||||||
|
export DB_PASSWORD="QtqiwCOAUpQNF6pjzOMAREzUny2bY8V1"
|
||||||
|
export LLM_API_URL="https://llm.agiliton.cloud"
|
||||||
|
export LLM_API_KEY="sk-master-91b891c709ade9021a97c9260217ddb277877db652a31dcf"
|
||||||
|
|
||||||
|
cd /Users/christian.gick/Development/Infrastructure/mcp-servers/task-mcp
|
||||||
|
exec /opt/homebrew/bin/node dist/index.js
|
||||||
13
src/db.ts
13
src/db.ts
@@ -1,13 +1,14 @@
|
|||||||
import pg from 'pg';
|
import pg from 'pg';
|
||||||
const { Pool } = pg;
|
const { Pool } = pg;
|
||||||
|
|
||||||
// Configuration - FORCE port 5432 (not 5435 which is litellm)
|
// Configuration - Direct WireGuard connection to INFRA VM PostgreSQL
|
||||||
|
// HARDCODED to prevent any env var override issues
|
||||||
const config = {
|
const config = {
|
||||||
host: process.env.DB_HOST || 'localhost',
|
host: '10.0.1.1', // INFRA VM - agiliton database
|
||||||
port: 5432, // Hardcoded - env was being overridden to 5435 by unknown source
|
port: 5432,
|
||||||
database: process.env.DB_NAME || 'agiliton',
|
database: 'agiliton',
|
||||||
user: process.env.DB_USER || 'agiliton',
|
user: 'agiliton',
|
||||||
password: process.env.DB_PASSWORD || 'QtqiwCOAUpQNF6pjzOMAREzUny2bY8V1',
|
password: 'QtqiwCOAUpQNF6pjzOMAREzUny2bY8V1',
|
||||||
max: 5,
|
max: 5,
|
||||||
idleTimeoutMillis: 30000,
|
idleTimeoutMillis: 30000,
|
||||||
connectionTimeoutMillis: 5000,
|
connectionTimeoutMillis: 5000,
|
||||||
|
|||||||
26
src/index.ts
26
src/index.ts
@@ -5,8 +5,8 @@
|
|||||||
* Exposes task management tools via Model Context Protocol.
|
* Exposes task management tools via Model Context Protocol.
|
||||||
* Uses PostgreSQL with pgvector for semantic search.
|
* Uses PostgreSQL with pgvector for semantic search.
|
||||||
*
|
*
|
||||||
* Requires SSH tunnel to docker-host:
|
* Requires SSH tunnel to infra VM on port 5433:
|
||||||
* ssh -L 5432:172.27.0.3:5432 docker-host -N &
|
* ssh -L 5433:localhost:5432 -i ~/.ssh/hetzner_mash_deploy root@46.224.188.157 -N &
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
||||||
@@ -368,16 +368,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
|
|
||||||
// Main entry point
|
// Main entry point
|
||||||
async function main() {
|
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
|
// Set up cleanup
|
||||||
process.on('SIGINT', async () => {
|
process.on('SIGINT', async () => {
|
||||||
await close();
|
await close();
|
||||||
@@ -389,10 +379,20 @@ async function main() {
|
|||||||
process.exit(0);
|
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();
|
const transport = new StdioServerTransport();
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
console.error('task-mcp: Server started');
|
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) => {
|
main().catch((error) => {
|
||||||
|
|||||||
14
start.sh
14
start.sh
@@ -1,3 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Wrapper script for task-mcp that logs errors
|
# Wrapper script for task-mcp with hardcoded env vars
|
||||||
exec node /Users/christian.gick/Development/Infrastructure/mcp-servers/task-mcp/dist/index.js 2>> /tmp/task-mcp.log
|
export DB_HOST="10.0.1.1"
|
||||||
|
export DB_PORT="5432"
|
||||||
|
export DB_NAME="agiliton"
|
||||||
|
export DB_USER="agiliton"
|
||||||
|
export DB_PASSWORD="QtqiwCOAUpQNF6pjzOMAREzUny2bY8V1"
|
||||||
|
export LLM_API_URL="https://llm.agiliton.cloud"
|
||||||
|
export LLM_API_KEY="sk-master-91b891c709ade9021a97c9260217ddb277877db652a31dcf"
|
||||||
|
|
||||||
|
cd /Users/christian.gick/Development/Infrastructure/mcp-servers/task-mcp
|
||||||
|
export PATH="/opt/homebrew/bin:$PATH"
|
||||||
|
exec node dist/index.js
|
||||||
|
|||||||
Reference in New Issue
Block a user