Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class CodeContextServer {

this.setupToolHandlers();

// Error handling
this.server.onerror = (error) => console.error("[MCP Error]", error);
// Error handling - comment out to avoid JSON parsing conflicts
// this.server.onerror = (error) => console.error("[MCP Error]", error);
process.on("SIGINT", async () => {
await this.server.close();
process.exit(0);
Expand All @@ -47,7 +47,7 @@ class CodeContextServer {
tools: [
{
name: ToolName.QUERY_REPO,
description: "Queries a git repository using semantic and keyword search. Use keywords and file patterns if you want to targer specific files or terms",
description: "Queries a git repository using semantic and keyword search. Use keywords and file patterns if you want to target specific files or terms",
inputSchema: zodToJsonSchema(QueryRepoSchema),
},
],
Expand Down Expand Up @@ -94,7 +94,7 @@ class CodeContextServer {
],
};
} catch (error) {
console.error("Error in query_repo:", error);
// console.error("Error in query_repo:", error);
return {
content: [
{
Expand All @@ -113,9 +113,12 @@ class CodeContextServer {
async run() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
console.error("Code Context MCP server running on stdio");
// console.error("Code Context MCP server running on stdio");
}
}

const server = new CodeContextServer();
server.run().catch(console.error);
server.run().catch((_error) => {
// Silent error handling to avoid JSON parsing conflicts
process.exit(1);
});
12 changes: 7 additions & 5 deletions start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ const NODE_ENV = process.env.NODE_ENV || 'development';
}
});

process.stderr.write(`Starting Code Context MCP Server\n`);
process.stderr.write(`Data Directory: ${DATA_DIR}\n`);
process.stderr.write(`Repo Config: ${REPO_CONFIG_DIR}\n`);
process.stderr.write(`Node Environment: ${NODE_ENV}\n\n`);
// Log to a file instead of stderr to avoid JSON parsing conflicts
// Uncomment these lines if you need debug output, but redirect to a log file
// process.stderr.write(`Starting Code Context MCP Server\n`);
// process.stderr.write(`Data Directory: ${DATA_DIR}\n`);
// process.stderr.write(`Repo Config: ${REPO_CONFIG_DIR}\n`);
// process.stderr.write(`Node Environment: ${NODE_ENV}\n\n`);

const checkOllama = () => {
try {
const result = spawn('pgrep', ['ollama'], { stdio: 'pipe' });
result.on('exit', (code) => {
if (code !== 0) {
process.stderr.write('Starting Ollama...\n');
// process.stderr.write('Starting Ollama...\n');
spawn('ollama', ['serve'], { detached: true, stdio: 'ignore' }).unref();
setTimeout(() => startMcpServer(), 3000);
} else {
Expand Down
30 changes: 30 additions & 0 deletions wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node

import {writeFileSync, appendFileSync} from 'fs';

const LOG_FILE = process.env.LOG_FILE || '/tmp/mcp-code-context.log';

const safeLog = (level: string, ...args: any[]) => {
if (!LOG_FILE) return;
try {
appendFileSync(LOG_FILE, `[${level}] ${new Date().toISOString()} ${args.join(' ')}\n`);
} catch (e) {
}
};

const createLogger = (level: string) => (...args: any[]) => safeLog(level, ...args);

console.log = createLogger('LOG');
console.error = createLogger('ERROR');
console.warn = console.info = console.debug = console.log;

try {
writeFileSync(LOG_FILE, `[INIT] ${new Date().toISOString()} Code Context MCP Server starting\n`);
} catch (e) {
}

import('./index.js').then(() => {
}).catch(error => {
safeLog('FATAL', error);
process.exit(1);
});