@codesherlock/codesherlock-alpha-mcp-server 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +9 -0
- package/README.md +185 -0
- package/build/handlers/analyzeCommitHandler.d.ts +55 -0
- package/build/handlers/analyzeCommitHandler.d.ts.map +1 -0
- package/build/handlers/analyzeCommitHandler.js +345 -0
- package/build/handlers/analyzeCommitHandler.js.map +1 -0
- package/build/handlers/events.d.ts +7 -0
- package/build/handlers/events.d.ts.map +1 -0
- package/build/handlers/events.js +15 -0
- package/build/handlers/events.js.map +1 -0
- package/build/handlers/resources.d.ts +10 -0
- package/build/handlers/resources.d.ts.map +1 -0
- package/build/handlers/resources.js +14 -0
- package/build/handlers/resources.js.map +1 -0
- package/build/handlers/tools.d.ts +6 -0
- package/build/handlers/tools.d.ts.map +1 -0
- package/build/handlers/tools.js +24 -0
- package/build/handlers/tools.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +82 -0
- package/build/index.js.map +1 -0
- package/build/schemas/toolSchemas.d.ts +40 -0
- package/build/schemas/toolSchemas.d.ts.map +1 -0
- package/build/schemas/toolSchemas.js +42 -0
- package/build/schemas/toolSchemas.js.map +1 -0
- package/build/services/backendApiService.d.ts +81 -0
- package/build/services/backendApiService.d.ts.map +1 -0
- package/build/services/backendApiService.js +211 -0
- package/build/services/backendApiService.js.map +1 -0
- package/build/services/commitReviewService.d.ts +61 -0
- package/build/services/commitReviewService.d.ts.map +1 -0
- package/build/services/commitReviewService.js +306 -0
- package/build/services/commitReviewService.js.map +1 -0
- package/build/services/gitService.d.ts +120 -0
- package/build/services/gitService.d.ts.map +1 -0
- package/build/services/gitService.js +360 -0
- package/build/services/gitService.js.map +1 -0
- package/build/services/loggingService.d.ts +64 -0
- package/build/services/loggingService.d.ts.map +1 -0
- package/build/services/loggingService.js +185 -0
- package/build/services/loggingService.js.map +1 -0
- package/build/services/zipService.d.ts +9 -0
- package/build/services/zipService.d.ts.map +1 -0
- package/build/services/zipService.js +47 -0
- package/build/services/zipService.js.map +1 -0
- package/build/tests/backendApiService.test.d.ts +2 -0
- package/build/tests/backendApiService.test.d.ts.map +1 -0
- package/build/tests/backendApiService.test.js +109 -0
- package/build/tests/backendApiService.test.js.map +1 -0
- package/build/tests/commitReviewService.test.d.ts +2 -0
- package/build/tests/commitReviewService.test.d.ts.map +1 -0
- package/build/tests/commitReviewService.test.js +118 -0
- package/build/tests/commitReviewService.test.js.map +1 -0
- package/build/tests/loggingService.test.d.ts +2 -0
- package/build/tests/loggingService.test.d.ts.map +1 -0
- package/build/tests/loggingService.test.js +156 -0
- package/build/tests/loggingService.test.js.map +1 -0
- package/build/tests/setup.test.d.ts +2 -0
- package/build/tests/setup.test.d.ts.map +1 -0
- package/build/tests/setup.test.js +7 -0
- package/build/tests/setup.test.js.map +1 -0
- package/build/utils/analysisFormatter.d.ts +40 -0
- package/build/utils/analysisFormatter.d.ts.map +1 -0
- package/build/utils/analysisFormatter.js +97 -0
- package/build/utils/analysisFormatter.js.map +1 -0
- package/build/utils/errorExtractor.d.ts +36 -0
- package/build/utils/errorExtractor.d.ts.map +1 -0
- package/build/utils/errorExtractor.js +178 -0
- package/build/utils/errorExtractor.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register all resources with the MCP server
|
|
3
|
+
*
|
|
4
|
+
* Note: Resources are optional. In this setup, we don't expose any resources
|
|
5
|
+
* because the AI doesn't need to read data directly - it only needs to call tools.
|
|
6
|
+
* Tools internally orchestrate Git operations and backend API calls.
|
|
7
|
+
*/
|
|
8
|
+
export function registerResources(server) {
|
|
9
|
+
// No resources needed for this use case
|
|
10
|
+
// Tools handle all the orchestration internally
|
|
11
|
+
// Resources handler registered (no resources defined)
|
|
12
|
+
// Logging is handled via Application Insights only
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/handlers/resources.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAiB;IAC/C,wCAAwC;IACxC,gDAAgD;IAChD,sDAAsD;IACtD,mDAAmD;AACvD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/handlers/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAOpE;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,QAsB9C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GitService } from "../services/gitService.js";
|
|
2
|
+
import { BackendApiService } from "../services/backendApiService.js";
|
|
3
|
+
import { CommitReviewService } from "../services/commitReviewService.js";
|
|
4
|
+
import { AnalyzeCommitInputSchema, AnalyzeCommitOutputSchema } from "../schemas/toolSchemas.js";
|
|
5
|
+
import { createAnalyzeCommitHandler } from "./analyzeCommitHandler.js";
|
|
6
|
+
/**
|
|
7
|
+
* Register all tools with the MCP server
|
|
8
|
+
*/
|
|
9
|
+
export function registerTools(server) {
|
|
10
|
+
const gitService = new GitService();
|
|
11
|
+
const backendApiService = new BackendApiService(process.env.BACKEND_API_URL || "", process.env.MCP_API_KEY);
|
|
12
|
+
const commitReviewService = new CommitReviewService(backendApiService);
|
|
13
|
+
/**
|
|
14
|
+
* Tool: Analyze Commit
|
|
15
|
+
* Complete flow: Get Git data → Send to backend → Return results
|
|
16
|
+
*/
|
|
17
|
+
server.registerTool("analyze_commit", {
|
|
18
|
+
title: "Analyze Commit",
|
|
19
|
+
description: "Analyze a Git commit or uncommitted changes by fetching diff and sending to backend for analysis",
|
|
20
|
+
inputSchema: AnalyzeCommitInputSchema,
|
|
21
|
+
outputSchema: AnalyzeCommitOutputSchema,
|
|
22
|
+
}, createAnalyzeCommitHandler(gitService, commitReviewService, backendApiService));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/handlers/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAChG,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEvE;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAiB;IAC3C,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;IACpC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAC3C,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE,EACjC,OAAO,CAAC,GAAG,CAAC,WAAW,CAC1B,CAAC;IACF,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IAEvE;;;OAGG;IACH,MAAM,CAAC,YAAY,CACf,gBAAgB,EAChB;QACI,KAAK,EAAE,gBAAgB;QACvB,WAAW,EAAE,kGAAkG;QAC/G,WAAW,EAAE,wBAAwB;QACrC,YAAY,EAAE,yBAAyB;KAC1C,EACD,0BAA0B,CAAC,UAAU,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,CACjF,CAAC;AACN,CAAC"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { registerTools } from "./handlers/tools.js";
|
|
5
|
+
import { logger } from "./services/loggingService.js";
|
|
6
|
+
import dotenv from "dotenv";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
import { dirname, join, resolve } from "path";
|
|
9
|
+
// Resolve .env file path relative to project root
|
|
10
|
+
// This works both in development (src/) and production (build/)
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = dirname(__filename);
|
|
13
|
+
// Go up from src/ or build/ to project root
|
|
14
|
+
const projectRoot = resolve(__dirname, "..");
|
|
15
|
+
const envPath = join(projectRoot, ".env");
|
|
16
|
+
// Load environment variables with explicit path
|
|
17
|
+
dotenv.config({ path: envPath });
|
|
18
|
+
/**
|
|
19
|
+
* CodeSherlock MCP Server
|
|
20
|
+
* A TypeScript-based Model Context Protocol server with modular architecture
|
|
21
|
+
*/
|
|
22
|
+
const appInsightsConnectionString = process.env.APPLICATIONINSIGHTS_CONNECTION_STRING;
|
|
23
|
+
// Initialize Application Insights and setup console suppression
|
|
24
|
+
// This must complete before creating the server
|
|
25
|
+
async function initializeLogging() {
|
|
26
|
+
await logger.initialize(appInsightsConnectionString);
|
|
27
|
+
// Note: We don't suppress stdout/stderr streams as MCP SDK uses them for protocol communication
|
|
28
|
+
const noOp = () => { };
|
|
29
|
+
if (logger.isEnabled()) {
|
|
30
|
+
// Only suppress console if Application Insights is initializeds
|
|
31
|
+
console.log = noOp;
|
|
32
|
+
console.error = noOp;
|
|
33
|
+
console.warn = noOp;
|
|
34
|
+
console.info = noOp;
|
|
35
|
+
console.debug = noOp;
|
|
36
|
+
console.trace = noOp;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Wait for logging initialization to complete
|
|
40
|
+
await initializeLogging();
|
|
41
|
+
// Create MCP server instance
|
|
42
|
+
const server = new McpServer({
|
|
43
|
+
name: "codesherlock-mcp-server",
|
|
44
|
+
version: "1.0.0",
|
|
45
|
+
});
|
|
46
|
+
logger.logInfo("MCP Server instance created", {
|
|
47
|
+
serverName: "codesherlock-mcp-server",
|
|
48
|
+
version: "1.0.0",
|
|
49
|
+
});
|
|
50
|
+
// Register all handlers
|
|
51
|
+
registerTools(server);
|
|
52
|
+
// registerResources(server);
|
|
53
|
+
// registerEventHandlers(server);
|
|
54
|
+
logger.logInfo("All handlers registered successfully");
|
|
55
|
+
/**
|
|
56
|
+
* Start the server
|
|
57
|
+
*/
|
|
58
|
+
async function main() {
|
|
59
|
+
const transport = new StdioServerTransport();
|
|
60
|
+
await server.connect(transport);
|
|
61
|
+
logger.logInfo("Server started successfully", {
|
|
62
|
+
transport: "stdio",
|
|
63
|
+
timestamp: new Date().toISOString(),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Graceful shutdown handler
|
|
67
|
+
process.on("SIGINT", async () => {
|
|
68
|
+
logger.logInfo("Shutting down server...");
|
|
69
|
+
await logger.flush();
|
|
70
|
+
process.exit(0);
|
|
71
|
+
});
|
|
72
|
+
process.on("SIGTERM", async () => {
|
|
73
|
+
logger.logInfo("Shutting down server...");
|
|
74
|
+
await logger.flush();
|
|
75
|
+
process.exit(0);
|
|
76
|
+
});
|
|
77
|
+
main().catch(async (error) => {
|
|
78
|
+
logger.logError("Fatal error in main()", error);
|
|
79
|
+
await logger.flush();
|
|
80
|
+
process.exit(1);
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,O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MAAM,CAAC,QAAQ,CAAC,uBAAuB,EAAE,KAAc,CAAC,CAAC;IACzD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const AnalyzeCommitInputSchema: {
|
|
3
|
+
uncommitted: z.ZodBoolean;
|
|
4
|
+
directory: z.ZodString;
|
|
5
|
+
factor: z.ZodEnum<["power_analysis", "owasp", "cwe"]>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Comprehensive output schema that handles all error scenarios from the FastAPI backend:
|
|
9
|
+
* - HTTP errors (401, 404, 422, 500)
|
|
10
|
+
* - WebSocket errors with status_code and error_message
|
|
11
|
+
* - Validation errors (missing files.json, invalid JSON, invalid file structure, etc.)
|
|
12
|
+
* - Authentication errors
|
|
13
|
+
* - Usage limit errors
|
|
14
|
+
* - Git errors
|
|
15
|
+
* - Internal server errors
|
|
16
|
+
*/
|
|
17
|
+
export declare const AnalyzeCommitOutputSchema: {
|
|
18
|
+
success: z.ZodBoolean;
|
|
19
|
+
analysisId: z.ZodOptional<z.ZodString>;
|
|
20
|
+
status: z.ZodOptional<z.ZodString>;
|
|
21
|
+
statusCode: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
errorType: z.ZodOptional<z.ZodEnum<["authentication_error", "validation_error", "not_found_error", "git_error", "websocket_error", "api_error", "internal_error", "usage_limit_error", "repository_error"]>>;
|
|
23
|
+
results: z.ZodOptional<z.ZodAny>;
|
|
24
|
+
message: z.ZodOptional<z.ZodString>;
|
|
25
|
+
error: z.ZodOptional<z.ZodString>;
|
|
26
|
+
errorDetails: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
userMessage: z.ZodOptional<z.ZodString>;
|
|
28
|
+
technicalDetails: z.ZodOptional<z.ZodString>;
|
|
29
|
+
retryable: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
userMessage?: string | undefined;
|
|
32
|
+
technicalDetails?: string | undefined;
|
|
33
|
+
retryable?: boolean | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
userMessage?: string | undefined;
|
|
36
|
+
technicalDetails?: string | undefined;
|
|
37
|
+
retryable?: boolean | undefined;
|
|
38
|
+
}>>;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=toolSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolSchemas.d.ts","sourceRoot":"","sources":["../../src/schemas/toolSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,eAAO,MAAM,wBAAwB;;;;CAIpC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;CAwBrC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export const AnalyzeCommitInputSchema = {
|
|
3
|
+
uncommitted: z.boolean().describe("value will be false for commit analysis and true for unstaged changes"),
|
|
4
|
+
directory: z.string().describe("Path to the Git repository root"),
|
|
5
|
+
factor: z.enum(["power_analysis", "owasp", "cwe"]).describe("Analysis factor: power_analysis, owasp, or cwe"),
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Comprehensive output schema that handles all error scenarios from the FastAPI backend:
|
|
9
|
+
* - HTTP errors (401, 404, 422, 500)
|
|
10
|
+
* - WebSocket errors with status_code and error_message
|
|
11
|
+
* - Validation errors (missing files.json, invalid JSON, invalid file structure, etc.)
|
|
12
|
+
* - Authentication errors
|
|
13
|
+
* - Usage limit errors
|
|
14
|
+
* - Git errors
|
|
15
|
+
* - Internal server errors
|
|
16
|
+
*/
|
|
17
|
+
export const AnalyzeCommitOutputSchema = {
|
|
18
|
+
success: z.boolean().describe("Whether the commit analysis was successful"),
|
|
19
|
+
analysisId: z.string().optional().describe("Analysis ID returned from the backend (if successful)"),
|
|
20
|
+
status: z.string().optional().describe("Status string (e.g., 'complete', 'pending', 'failed')"),
|
|
21
|
+
statusCode: z.number().optional().describe("HTTP status code for error scenarios. Common values: 401 (authentication), 404 (not found), 422 (validation), 500 (internal error)"),
|
|
22
|
+
errorType: z.enum([
|
|
23
|
+
"authentication_error",
|
|
24
|
+
"validation_error",
|
|
25
|
+
"not_found_error",
|
|
26
|
+
"git_error",
|
|
27
|
+
"websocket_error",
|
|
28
|
+
"api_error",
|
|
29
|
+
"internal_error",
|
|
30
|
+
"usage_limit_error",
|
|
31
|
+
"repository_error"
|
|
32
|
+
]).optional().describe("Categorized error type for better error handling and user experience"),
|
|
33
|
+
results: z.any().optional().describe("Analysis results array (present when success is true)"),
|
|
34
|
+
message: z.string().optional().describe("Success or informational message"),
|
|
35
|
+
error: z.string().optional().describe("Error message (present when success is false)"),
|
|
36
|
+
errorDetails: z.object({
|
|
37
|
+
userMessage: z.string().optional().describe("User-friendly error message that can be displayed to end users"),
|
|
38
|
+
technicalDetails: z.string().optional().describe("Technical error details for debugging purposes"),
|
|
39
|
+
retryable: z.boolean().optional().describe("Whether the error is retryable (true for transient errors like network issues, false for validation/authentication errors)"),
|
|
40
|
+
}).optional().describe("Detailed error information including user-friendly message and retry guidance"),
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=toolSchemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolSchemas.js","sourceRoot":"","sources":["../../src/schemas/toolSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACpC,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,uEAAuE,CAAC;IAC1G,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,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C;QAC7G,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC;QAClG,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,4HAA4H,CAAC;KAC3K,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,+EAA+E,CAAC;CAC1G,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
/**
|
|
3
|
+
* Backend API Service
|
|
4
|
+
* Handles HTTP API calls and WebSocket connections for commit review
|
|
5
|
+
*/
|
|
6
|
+
export declare class BackendApiService {
|
|
7
|
+
private baseUrl;
|
|
8
|
+
private wsBaseUrl;
|
|
9
|
+
private apiKey?;
|
|
10
|
+
constructor(baseUrl: string, apiKey?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Submit commit review to backend
|
|
13
|
+
*/
|
|
14
|
+
submitCommitReview(params: CommitReviewParams): Promise<ApiResponse>;
|
|
15
|
+
/**
|
|
16
|
+
* WebSocket connection for real-time commit analysis
|
|
17
|
+
*/
|
|
18
|
+
connectWebSocket(userId: string, onMessage: (data: WebSocketMessage) => void, onError?: (error: Error) => void, onClose?: (code: number, reason: string) => void): Promise<WebSocket>;
|
|
19
|
+
sendDiff(diff: string, metadata?: DiffMetadata): Promise<ApiResponse>;
|
|
20
|
+
getAnalysisResults(analysisId: string): Promise<AnalysisResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Get user information from secure route
|
|
23
|
+
* Uses API key authentication to fetch authenticated user details
|
|
24
|
+
* @returns User information including user_id and username
|
|
25
|
+
*/
|
|
26
|
+
getUserFromSecureRoute(): Promise<User>;
|
|
27
|
+
}
|
|
28
|
+
export interface CommitReviewParams {
|
|
29
|
+
factor: "power_analysis" | "owasp" | "cwe";
|
|
30
|
+
user_id: string;
|
|
31
|
+
repo_name: string;
|
|
32
|
+
username: string;
|
|
33
|
+
commit_id: string;
|
|
34
|
+
files_json: any;
|
|
35
|
+
organization_name?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface WebSocketMessage {
|
|
38
|
+
status_code: number;
|
|
39
|
+
error_message?: string;
|
|
40
|
+
content?: {
|
|
41
|
+
analysis_type?: string;
|
|
42
|
+
analysis?: any;
|
|
43
|
+
language?: string;
|
|
44
|
+
file_name?: string;
|
|
45
|
+
is_complete?: boolean;
|
|
46
|
+
status?: string;
|
|
47
|
+
};
|
|
48
|
+
analysis_id?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface DiffMetadata {
|
|
51
|
+
directory?: string;
|
|
52
|
+
factor?: "power_analysis" | "owasp" | "cwe";
|
|
53
|
+
commitHash?: string;
|
|
54
|
+
author?: string;
|
|
55
|
+
timestamp?: string;
|
|
56
|
+
uncommitted?: boolean;
|
|
57
|
+
repoName?: string;
|
|
58
|
+
branch?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ApiResponse {
|
|
61
|
+
success: boolean;
|
|
62
|
+
message?: string;
|
|
63
|
+
data?: any;
|
|
64
|
+
analysisId?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface AnalysisResult {
|
|
67
|
+
id: string;
|
|
68
|
+
status: "pending" | "completed" | "failed";
|
|
69
|
+
results?: any;
|
|
70
|
+
error?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* User interface returned from secure_route endpoint
|
|
74
|
+
*/
|
|
75
|
+
export interface User {
|
|
76
|
+
userid: string;
|
|
77
|
+
username: string;
|
|
78
|
+
email?: string;
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=backendApiService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backendApiService.d.ts","sourceRoot":"","sources":["../../src/services/backendApiService.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAK3B;;;GAGG;AACH,qBAAa,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AG,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC3C,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
import JSZip from "jszip";
|
|
3
|
+
import { File, Blob } from "node:buffer";
|
|
4
|
+
import { logger } from "./loggingService.js";
|
|
5
|
+
/**
|
|
6
|
+
* Backend API Service
|
|
7
|
+
* Handles HTTP API calls and WebSocket connections for commit review
|
|
8
|
+
*/
|
|
9
|
+
export class BackendApiService {
|
|
10
|
+
baseUrl;
|
|
11
|
+
wsBaseUrl;
|
|
12
|
+
apiKey;
|
|
13
|
+
constructor(baseUrl, apiKey) {
|
|
14
|
+
this.baseUrl = baseUrl;
|
|
15
|
+
this.wsBaseUrl = baseUrl.replace(/^http/, "ws");
|
|
16
|
+
this.apiKey = apiKey;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Submit commit review to backend
|
|
20
|
+
*/
|
|
21
|
+
async submitCommitReview(params) {
|
|
22
|
+
try {
|
|
23
|
+
const url = `${this.baseUrl}/v2/commit-review/${params.factor}`;
|
|
24
|
+
const formData = new FormData();
|
|
25
|
+
formData.append("user_id", params.user_id);
|
|
26
|
+
formData.append("repo_name", params.repo_name);
|
|
27
|
+
formData.append("commit_id", params.commit_id);
|
|
28
|
+
formData.append("username", params.username);
|
|
29
|
+
formData.append("factor", params.factor);
|
|
30
|
+
// Build ZIP
|
|
31
|
+
const zip = new JSZip();
|
|
32
|
+
zip.file("files.json", params.files_json);
|
|
33
|
+
const filesBuffer = await zip.generateAsync({ type: "nodebuffer" });
|
|
34
|
+
// Convert Buffer → Blob → File
|
|
35
|
+
const blob = new Blob([filesBuffer], { type: "application/zip" });
|
|
36
|
+
formData.append("files_zip", new File([blob], "files.zip", { type: "application/zip" }));
|
|
37
|
+
if (params.organization_name) {
|
|
38
|
+
formData.append("organization_name", params.organization_name);
|
|
39
|
+
}
|
|
40
|
+
const response = await fetch(url, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
...(this.apiKey ? { "X-CS-MCP-API-Key": this.apiKey } : {})
|
|
44
|
+
},
|
|
45
|
+
body: formData
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
let errorDetail = "Unknown error";
|
|
49
|
+
try {
|
|
50
|
+
// Try to parse JSON error response (FastAPI typically returns {detail: "message"})
|
|
51
|
+
const errorJson = await response.json();
|
|
52
|
+
errorDetail = errorJson.detail || errorJson.error || errorJson.message || JSON.stringify(errorJson);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// If not JSON, use text response
|
|
56
|
+
const errorText = await response.text();
|
|
57
|
+
errorDetail = errorText || `HTTP ${response.status}`;
|
|
58
|
+
}
|
|
59
|
+
logger.logError(`HTTP error! status: ${response.status}, detail: ${errorDetail}`);
|
|
60
|
+
// Create error with status code in message for extraction
|
|
61
|
+
const error = new Error(`HTTP error! status: ${response.status}, detail: ${errorDetail}`);
|
|
62
|
+
error.statusCode = response.status;
|
|
63
|
+
error.errorDetail = errorDetail;
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
// Handle 202 Accepted response (FastAPI returns this for background processing)
|
|
67
|
+
if (response.status === 202) {
|
|
68
|
+
let data = {};
|
|
69
|
+
try {
|
|
70
|
+
// Try to parse JSON response (FastAPI may return JSON with message)
|
|
71
|
+
const contentType = response.headers.get("content-type");
|
|
72
|
+
if (contentType && contentType.includes("application/json")) {
|
|
73
|
+
data = await response.json();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// If not JSON, read as text
|
|
77
|
+
const text = await response.text();
|
|
78
|
+
data = { message: text || "Commit review request received. Processing in the background." };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// If parsing fails, use default message
|
|
83
|
+
data = { message: "Commit review request received. Processing in the background." };
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
success: true,
|
|
87
|
+
data,
|
|
88
|
+
analysisId: data.analysis_id ? String(data.analysis_id) : undefined,
|
|
89
|
+
message: data.message || "Commit review submitted successfully"
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Handle other success responses (200, etc.)
|
|
93
|
+
let data = {};
|
|
94
|
+
try {
|
|
95
|
+
data = await response.json();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// If JSON parsing fails, create a default response
|
|
99
|
+
logger.logWarning("Failed to parse JSON response, using default", { status: String(response.status) });
|
|
100
|
+
data = { message: "Commit review submitted successfully" };
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
success: true,
|
|
104
|
+
data,
|
|
105
|
+
analysisId: data.analysis_id ? String(data.analysis_id) : undefined,
|
|
106
|
+
message: data.message || "Commit review submitted successfully"
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
logger.logError("Error submitting commit review", error);
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* WebSocket connection for real-time commit analysis
|
|
116
|
+
*/
|
|
117
|
+
connectWebSocket(userId, onMessage, onError, onClose) {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
try {
|
|
120
|
+
const wsUrl = `${this.wsBaseUrl}/v2/ws/${userId}`;
|
|
121
|
+
logger.logInfo("Connecting to WebSocket", { wsUrl, userId });
|
|
122
|
+
const ws = new WebSocket(wsUrl);
|
|
123
|
+
ws.on("open", () => {
|
|
124
|
+
logger.logInfo("WebSocket connection opened", { userId });
|
|
125
|
+
resolve(ws);
|
|
126
|
+
});
|
|
127
|
+
ws.on("message", (data) => {
|
|
128
|
+
try {
|
|
129
|
+
const message = JSON.parse(data.toString());
|
|
130
|
+
onMessage(message);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
logger.logError("Error parsing WebSocket message", error);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
ws.on("error", (error) => {
|
|
137
|
+
logger.logError("WebSocket error", error, { userId });
|
|
138
|
+
onError?.(error);
|
|
139
|
+
reject(error);
|
|
140
|
+
});
|
|
141
|
+
ws.on("close", (code, reason) => {
|
|
142
|
+
const reasonStr = reason.toString();
|
|
143
|
+
// logger.logInfo("WebSocket closed", { userId, code, reason: reasonStr });
|
|
144
|
+
onClose?.(code, reasonStr);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
logger.logError("Error creating WebSocket connection", error);
|
|
149
|
+
reject(error);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async sendDiff(diff, metadata) {
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
message: "Diff received (legacy method)"
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async getAnalysisResults(analysisId) {
|
|
160
|
+
throw new Error("Not implemented");
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get user information from secure route
|
|
164
|
+
* Uses API key authentication to fetch authenticated user details
|
|
165
|
+
* @returns User information including user_id and username
|
|
166
|
+
*/
|
|
167
|
+
async getUserFromSecureRoute() {
|
|
168
|
+
try {
|
|
169
|
+
const url = `${this.baseUrl}/v2/secure_route`;
|
|
170
|
+
if (!this.apiKey) {
|
|
171
|
+
throw new Error("API key is required for secure route authentication");
|
|
172
|
+
}
|
|
173
|
+
const response = await fetch(url, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
headers: {
|
|
176
|
+
"X-CS-MCP-API-Key": this.apiKey,
|
|
177
|
+
"Content-Type": "application/json"
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
let errorDetail = "Unknown error";
|
|
182
|
+
try {
|
|
183
|
+
// Try to parse JSON error response (FastAPI typically returns {detail: "message"})
|
|
184
|
+
const errorJson = await response.json();
|
|
185
|
+
errorDetail = errorJson.detail || JSON.stringify(errorJson);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
// If not JSON, use text response
|
|
189
|
+
const errorText = await response.text();
|
|
190
|
+
errorDetail = errorText || `HTTP ${response.status}`;
|
|
191
|
+
}
|
|
192
|
+
logger.logError(`HTTP error! status: ${response.status}, detail: ${errorDetail}`);
|
|
193
|
+
if (response.status === 401) {
|
|
194
|
+
throw new Error(errorDetail || "Authentication required. Please provide a valid API key.");
|
|
195
|
+
}
|
|
196
|
+
else if (response.status === 404) {
|
|
197
|
+
throw new Error(errorDetail || "User not found.");
|
|
198
|
+
}
|
|
199
|
+
throw new Error(errorDetail || `HTTP error! status: ${response.status}`);
|
|
200
|
+
}
|
|
201
|
+
const user = await response.json();
|
|
202
|
+
logger.logInfo("User retrieved from secure route", { user_id: user.userid });
|
|
203
|
+
return user;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
logger.logError("Error fetching user from secure route", error);
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=backendApiService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backendApiService.js","sourceRoot":"","sources":["../../src/services/backendApiService.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAClB,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,MAAM,CAAU;IAExB,YAAY,OAAe,EAAE,MAAe;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBAAkB,CAAC,MAA0B;QAC/C,IAAI,CAAC;YACD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,qBAAqB,MAAM,CAAC,MAAM,EAAE,CAAC;YAEhE,MAA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-0,0 +1,61 @@
|
|
|
1
|
+
import { BackendApiService } from "./backendApiService.js";
|
|
2
|
+
import { FileChange } from "./gitService.js";
|
|
3
|
+
/**
|
|
4
|
+
* Commit Review Service
|
|
5
|
+
* Handles the full flow of submitting commit review and receiving results via WebSocket
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommitReviewService {
|
|
8
|
+
private backendApiService;
|
|
9
|
+
constructor(backendApiService: BackendApiService);
|
|
10
|
+
/**
|
|
11
|
+
* Submit commit review and wait for analysis results via WebSocket
|
|
12
|
+
* @param params - Commit review parameters
|
|
13
|
+
* @returns Analysis results
|
|
14
|
+
*/
|
|
15
|
+
submitAndWaitForResults(params: CommitReviewSubmitParams): Promise<CommitReviewResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Connect to WebSocket and collect analysis results
|
|
18
|
+
* Handles edge cases:
|
|
19
|
+
* - Timeout scenarios (backend takes too long)
|
|
20
|
+
* - Empty results (no files to analyze)
|
|
21
|
+
* - Partial results (some files succeed, others fail)
|
|
22
|
+
* - WebSocket completion without explicit completion signal
|
|
23
|
+
* @param userId - User ID for WebSocket connection
|
|
24
|
+
* @param timeoutMs - Maximum time to wait for results (default: 10 minutes)
|
|
25
|
+
* @returns Array of analysis results
|
|
26
|
+
*/
|
|
27
|
+
private collectResultsViaWebSocket;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Commit review submit parameters
|
|
31
|
+
*/
|
|
32
|
+
export interface CommitReviewSubmitParams {
|
|
33
|
+
factor: "power_analysis" | "owasp" | "cwe";
|
|
34
|
+
user_id: string;
|
|
35
|
+
repo_name: string;
|
|
36
|
+
commit_id: string;
|
|
37
|
+
username: string;
|
|
38
|
+
file_changes: FileChange[];
|
|
39
|
+
organization_name?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Analysis result item
|
|
43
|
+
*/
|
|
44
|
+
export interface AnalysisResultItem {
|
|
45
|
+
analysis: any;
|
|
46
|
+
language?: string;
|
|
47
|
+
file_name: string;
|
|
48
|
+
analysisId: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Commit review result
|
|
52
|
+
*/
|
|
53
|
+
export interface CommitReviewResult {
|
|
54
|
+
[key: string]: unknown;
|
|
55
|
+
success: boolean;
|
|
56
|
+
analysisId?: string;
|
|
57
|
+
message?: string;
|
|
58
|
+
results?: AnalysisResultItem[];
|
|
59
|
+
error?: string;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=commitReviewService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitReviewService.d.ts","sourceRoot":"","sources":["../../src/services/commitReviewService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,iBAAiB,CAAoB;gBAEjC,iBAAiB,EAAE,iBAAiB;IAIhD;;;;OAIG;IACG,uBAAuB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAgH5F;;;;;;;;;;OAUG;YACW,0BAA0B;CAiM3C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACrC,MAAM,EAAE,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB"}
|