sourcegraph-mcp-server
Version:
A Model Context Protocol (MCP) server that connects AI assistants to Sourcegraph code search with natural language capabilities
43 lines (42 loc) • 1.97 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mcp_server_js_1 = require("./mcp-server.js");
const dotenv_1 = __importDefault(require("dotenv"));
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
/**
* This file creates an MCP server that communicates over STDIO
* This allows it to be run as a child process by MCP clients
*/
// Load environment variables
dotenv_1.default.config();
async function main() {
try {
// Log startup message to stderr (not stdout which is used for the protocol)
console.error('Starting Sourcegraph MCP Server with STDIO transport...');
console.error(`SOURCEGRAPH_URL: ${process.env.SOURCEGRAPH_URL ? 'Set' : 'NOT SET'}`);
console.error(`SOURCEGRAPH_TOKEN: ${process.env.SOURCEGRAPH_TOKEN ? 'Set (redacted)' : 'NOT SET'}`);
// Create the MCP server
const server = (0, mcp_server_js_1.createServer)();
// Create a STDIO transport from the SDK
const transport = new stdio_js_1.StdioServerTransport();
// Connect the transport to the server
console.error('Connecting to STDIO transport...');
await server.connect(transport);
console.error('Sourcegraph MCP Server running in STDIO mode');
console.error('- Server is waiting for JSONRPC messages on stdin');
console.error('- Tools available: echo, search-code, search-commits, search-diffs, search-github-repos, debug');
}
catch (error) {
// Log error to stderr
console.error('Failed to start MCP server:', error instanceof Error ? error.message : error);
process.exit(1);
}
}
main().catch((error) => {
console.error('Fatal error in main():', error instanceof Error ? error.message : error);
process.exit(1);
});