UNPKG

dependency-context

Version:

MCP server for providing dependency documentation context to AI assistants

130 lines 5.44 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleDownloadCommand = handleDownloadCommand; exports.displayHelp = displayHelp; const fastmcp_1 = require("fastmcp"); const zod_1 = require("zod"); const path_1 = __importDefault(require("path")); const analyze_1 = require("./tools/analyze"); const search_1 = require("./tools/search"); const download_1 = require("./cli/download"); // Server configuration const PORT = process.env.DC_PORT ? parseInt(process.env.DC_PORT, 10) : 3006; // Check for direct CLI commands const args = process.argv.slice(2); // Function to handle download command function handleDownloadCommand(args) { const projectPath = args[1] ? path_1.default.resolve(args[1]) : process.cwd(); console.log(`Dependency Context - Documentation Downloader`); console.log(`======================================`); // Execute the download function return (0, download_1.downloadRawDependencyDocs)(projectPath); } // Function to display help function displayHelp() { console.log(`Dependency Context - CLI Usage`); console.log(`=======================`); console.log(`Commands:`); console.log(` download [path] Download dependency documentation to a local folder`); console.log(` If path is not specified, current directory is used`); console.log(` Files are saved to: <project>/dependency-context/`); console.log(` --http-stream Start as HTTP streaming server (for MCP)`); console.log(` --help, -h Display this help message`); console.log(``); console.log(`Environment Variables:`); console.log(` GITHUB_TOKEN GitHub token for API access`); console.log(` MODEL_NAME Custom embedding model`); console.log(` MIN_CHUNK_SIZE Minimum chunk size (default: 800)`); console.log(` MAX_CHUNK_SIZE Maximum chunk size (default: 8000)`); console.log(` CHUNKS_RETURNED Number of chunks returned in search (default: 5)`); } // Handle command line arguments (when directly executed) if (require.main === module) { if (args[0] === "download") { // If download command is specified, run in CLI mode handleDownloadCommand(args) .then(() => { // Function handles its own exit codes }) .catch((error) => { console.error("Error:", error.message); process.exit(1); }); } else if (args[0] === "--help" || args[0] === "-h") { // Display help information displayHelp(); process.exit(0); } else { // Start as MCP server const server = new fastmcp_1.FastMCP({ name: "Dependency Documentation Server", version: "1.2.0", }); // Define parameters for the analyze tool using Zod const AnalyzeParamsZod = zod_1.z.object({ project_path: zod_1.z .string() .describe("The absolute path to the project directory"), env_vars: zod_1.z .record(zod_1.z.string()) .optional() .describe("Environment variables to set during analysis"), }); // Register MCP tools server.addTool({ name: "InitializeDependencyIndex", description: "Initializes the dependency index for a project. Analyzes project dependencies, fetches docs, and creates/updates the local vector index.", parameters: AnalyzeParamsZod, execute: analyze_1.analyzeAndIndexDependencies, }); // Define parameters for the search tool using Zod const SearchParamsZod = zod_1.z.object({ project_path: zod_1.z .string() .describe("The absolute path to the project directory"), query: zod_1.z.string().describe("The search query"), repository_context: zod_1.z .string() .optional() .describe("Optional repository name to limit the search to"), env_vars: zod_1.z .record(zod_1.z.string()) .optional() .describe("Environment variables to set during search"), }); server.addTool({ name: "searchDependencyDocs", description: "Performs semantic search over indexed dependency documentation.", parameters: SearchParamsZod, execute: search_1.searchDependencyDocs, }); // Select transport type based on command line arguments const transportType = process.argv.includes("--http-stream") ? "httpStream" : "stdio"; if (transportType === "httpStream") { // Log that the server is starting *before* the await // Start the server server.start({ transportType: "httpStream", httpStream: { endpoint: "/stream", port: PORT, }, }); } else { // // Start the server in stdio mode server.start({ transportType: "stdio", }); } } } //# sourceMappingURL=index.js.map