@opencodereview/mcp-server 1.0.1 → 1.0.2

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/dist/index.d.ts CHANGED
@@ -1,2 +1,35 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export declare function createSandboxServer(): import("@modelcontextprotocol/sdk/server").Server<{
3
+ method: string;
4
+ params?: {
5
+ [x: string]: unknown;
6
+ _meta?: {
7
+ [x: string]: unknown;
8
+ progressToken?: string | number | undefined;
9
+ "io.modelcontextprotocol/related-task"?: {
10
+ taskId: string;
11
+ } | undefined;
12
+ } | undefined;
13
+ } | undefined;
14
+ }, {
15
+ method: string;
16
+ params?: {
17
+ [x: string]: unknown;
18
+ _meta?: {
19
+ [x: string]: unknown;
20
+ progressToken?: string | number | undefined;
21
+ "io.modelcontextprotocol/related-task"?: {
22
+ taskId: string;
23
+ } | undefined;
24
+ } | undefined;
25
+ } | undefined;
26
+ }, {
27
+ [x: string]: unknown;
28
+ _meta?: {
29
+ [x: string]: unknown;
30
+ progressToken?: string | number | undefined;
31
+ "io.modelcontextprotocol/related-task"?: {
32
+ taskId: string;
33
+ } | undefined;
34
+ } | undefined;
35
+ }>;
package/dist/index.js CHANGED
@@ -1,94 +1,57 @@
1
1
  #!/usr/bin/env node
2
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { createServer } from "./server.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
- import { scanDirectorySchema, scanDiffSchema, handleScanDirectory, handleScanDiff, } from "./tools/scan.js";
6
- import { explainIssueSchema, handleExplainIssue, } from "./tools/explain.js";
7
- import { healCodeSchema, handleHealCode, } from "./tools/heal.js";
8
- const server = new Server({ name: "open-code-review", version: "1.0.0" }, { capabilities: { tools: {} } });
9
- server.setRequestHandler(ListToolsRequestSchema, async () => ({
10
- tools: [
11
- {
12
- name: "scan_directory",
13
- description: "Scan a directory for AI-generated code quality issues. Detects hallucinated imports, phantom packages, stale APIs, security anti-patterns, and more. Supports TypeScript, JavaScript, Python, Java, Go, and Kotlin.",
14
- inputSchema: {
15
- type: "object",
16
- properties: {
17
- path: { type: "string", description: "Directory path to scan" },
18
- level: { type: "string", enum: ["L1", "L2", "L3"], default: "L1", description: "SLA level: L1 (fast structural), L2 (standard + local AI), L3 (deep + remote AI)" },
19
- languages: { type: "string", description: "Comma-separated languages (e.g. 'typescript,python'). Auto-detect if omitted." },
20
- },
21
- required: ["path"],
22
- },
23
- },
24
- {
25
- name: "scan_diff",
26
- description: "Scan git diff between two branches for code quality issues. Ideal for PR/MR review — only analyzes changed files and lines.",
27
- inputSchema: {
28
- type: "object",
29
- properties: {
30
- base: { type: "string", description: "Base branch (e.g. 'origin/main')" },
31
- head: { type: "string", description: "Head branch (e.g. 'HEAD')" },
32
- path: { type: "string", description: "Repository path" },
33
- level: { type: "string", enum: ["L1", "L2", "L3"], default: "L1", description: "SLA level" },
34
- },
35
- required: ["base", "head", "path"],
36
- },
37
- },
38
- {
39
- name: "explain_issue",
40
- description: "Explain a code quality issue detected by OCR. Returns detailed explanation, category context, and fix guidance for the AI agent to act on.",
41
- inputSchema: {
42
- type: "object",
43
- properties: {
44
- issue: { type: "string", description: "The issue description to explain" },
45
- file: { type: "string", description: "File path where the issue was found" },
46
- line: { type: "number", description: "Line number" },
47
- severity: { type: "string", description: "Severity: critical/high/medium/low/info" },
48
- category: { type: "string", description: "Issue category" },
49
- suggestion: { type: "string", description: "Auto-generated fix suggestion" },
50
- },
51
- required: ["issue"],
52
- },
53
- },
54
- {
55
- name: "heal_code",
56
- description: "Load a file's source code and prepare a repair prompt for the AI agent. The agent (you) should then apply the fix based on the issue description and suggestion. Returns the file content along with the repair context.",
57
- inputSchema: {
58
- type: "object",
59
- properties: {
60
- path: { type: "string", description: "File path to heal" },
61
- issue: { type: "string", description: "Issue description to fix" },
62
- suggestion: { type: "string", description: "Suggested fix from OCR scan" },
63
- },
64
- required: ["path", "issue"],
65
- },
66
- },
67
- ],
68
- }));
69
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
70
- const { name, arguments: args } = request.params;
71
- switch (name) {
72
- case "scan_directory": {
73
- const parsed = scanDirectorySchema.parse(args);
74
- return handleScanDirectory(parsed);
75
- }
76
- case "scan_diff": {
77
- const parsed = scanDiffSchema.parse(args);
78
- return handleScanDiff(parsed);
79
- }
80
- case "explain_issue": {
81
- const parsed = explainIssueSchema.parse(args);
82
- return handleExplainIssue(parsed);
83
- }
84
- case "heal_code": {
85
- const parsed = healCodeSchema.parse(args);
86
- return handleHealCode(parsed);
87
- }
88
- default:
89
- throw new Error(`Unknown tool: ${name}`);
4
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
5
+ const server = createServer();
6
+ export function createSandboxServer() {
7
+ return server;
8
+ }
9
+ const transport = process.env.TRANSPORT || "stdio";
10
+ if (process.env.NODE_ENV !== "test" && process.env.SMITHERY !== "true") {
11
+ if (transport === "http") {
12
+ import("node:http").then(({ createServer }) => {
13
+ const httpServer = createServer(async (req, res) => {
14
+ // Only handle /mcp path
15
+ if (req.url !== "/mcp") {
16
+ res.writeHead(404);
17
+ res.end("Not Found. MCP endpoint is at /mcp");
18
+ return;
19
+ }
20
+ // Collect request body for POST requests
21
+ const bodyChunks = [];
22
+ req.on("data", (chunk) => bodyChunks.push(chunk));
23
+ req.on("end", async () => {
24
+ let parsedBody;
25
+ if (req.method === "POST" && bodyChunks.length > 0) {
26
+ try {
27
+ parsedBody = JSON.parse(Buffer.concat(bodyChunks).toString());
28
+ }
29
+ catch {
30
+ parsedBody = undefined;
31
+ }
32
+ }
33
+ const httpTransport = new StreamableHTTPServerTransport({
34
+ sessionIdGenerator: undefined,
35
+ });
36
+ httpTransport.onclose = () => {
37
+ // Session closed
38
+ };
39
+ await server.connect(httpTransport);
40
+ await httpTransport.handleRequest(req, res, parsedBody);
41
+ });
42
+ });
43
+ const port = parseInt(process.env.PORT || "3000", 10);
44
+ httpServer.listen(port, () => {
45
+ console.error(`MCP HTTP server listening on http://localhost:${port}/mcp`);
46
+ });
47
+ });
90
48
  }
91
- });
92
- const transport = new StdioServerTransport();
93
- await server.connect(transport);
49
+ else {
50
+ const stdioTransport = new StdioServerTransport();
51
+ server.connect(stdioTransport).catch((err) => {
52
+ console.error("Failed to connect MCP server:", err);
53
+ process.exit(1);
54
+ });
55
+ }
56
+ }
94
57
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,EAC9C,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;AAEF,MAAM,CAAC,iBAAiB,CACtB,sBAAsB,EACtB,KAAK,IAAI,EAAE,CAAC,CAAC;IACX,KAAK,EAAE;QACL;YACE,IAAI,EAAE,gBAAgB;YACtB,WAAW,EAAE,qNAAqN;YAClO,WAAW,EAAE;gBACX,IAAI,EAAE,QAAiB;gBACvB,UAAU,EAAE;oBACV,IAAI,EAAE,EAAE,IA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,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC;YACtD,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;gBAC3B,OAAO,CAAC,KAAK,CAAC,iDAAiD,IAAI,MAAM,CAAC,CAAC;YAC7E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,cAAc,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAClD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACpD,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAC;YACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ export declare function createServer(): Server;
package/dist/server.js ADDED
@@ -0,0 +1,121 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
3
+ import { scanDirectorySchema, scanDiffSchema, handleScanDirectory, handleScanDiff, } from "./tools/scan.js";
4
+ import { explainIssueSchema, handleExplainIssue, } from "./tools/explain.js";
5
+ import { healCodeSchema, handleHealCode, } from "./tools/heal.js";
6
+ export function createServer() {
7
+ const server = new Server({ name: "open-code-review", version: "1.0.0" }, { capabilities: { tools: {} } });
8
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
9
+ tools: [
10
+ {
11
+ name: "scan_directory",
12
+ description: "Scan a directory for AI-generated code quality issues. Detects hallucinated imports, phantom packages, stale APIs, security anti-patterns, and more. Supports TypeScript, JavaScript, Python, Java, Go, and Kotlin.",
13
+ inputSchema: {
14
+ type: "object",
15
+ properties: {
16
+ path: { type: "string", description: "Directory path to scan" },
17
+ level: {
18
+ type: "string",
19
+ enum: ["L1", "L2", "L3"],
20
+ default: "L1",
21
+ description: "SLA level: L1 (fast structural), L2 (standard + local AI), L3 (deep + remote AI)",
22
+ },
23
+ languages: {
24
+ type: "string",
25
+ description: "Comma-separated languages (e.g. 'typescript,python'). Auto-detect if omitted.",
26
+ },
27
+ },
28
+ required: ["path"],
29
+ },
30
+ },
31
+ {
32
+ name: "scan_diff",
33
+ description: "Scan git diff between two branches for code quality issues. Ideal for PR/MR review — only analyzes changed files and lines.",
34
+ inputSchema: {
35
+ type: "object",
36
+ properties: {
37
+ base: { type: "string", description: "Base branch (e.g. 'origin/main')" },
38
+ head: { type: "string", description: "Head branch (e.g. 'HEAD')" },
39
+ path: { type: "string", description: "Repository path" },
40
+ level: {
41
+ type: "string",
42
+ enum: ["L1", "L2", "L3"],
43
+ default: "L1",
44
+ description: "SLA level",
45
+ },
46
+ },
47
+ required: ["base", "head", "path"],
48
+ },
49
+ },
50
+ {
51
+ name: "explain_issue",
52
+ description: "Explain a code quality issue detected by OCR. Returns detailed explanation, category context, and fix guidance for the AI agent to act on.",
53
+ inputSchema: {
54
+ type: "object",
55
+ properties: {
56
+ issue: {
57
+ type: "string",
58
+ description: "The issue description to explain",
59
+ },
60
+ file: {
61
+ type: "string",
62
+ description: "File path where the issue was found",
63
+ },
64
+ line: { type: "number", description: "Line number" },
65
+ severity: {
66
+ type: "string",
67
+ description: "Severity: critical/high/medium/low/info",
68
+ },
69
+ category: { type: "string", description: "Issue category" },
70
+ suggestion: {
71
+ type: "string",
72
+ description: "Auto-generated fix suggestion",
73
+ },
74
+ },
75
+ required: ["issue"],
76
+ },
77
+ },
78
+ {
79
+ name: "heal_code",
80
+ description: "Load a file's source code and prepare a repair prompt for the AI agent. The agent (you) should then apply the fix based on the issue description and suggestion. Returns the file content along with the repair context.",
81
+ inputSchema: {
82
+ type: "object",
83
+ properties: {
84
+ path: { type: "string", description: "File path to heal" },
85
+ issue: { type: "string", description: "Issue description to fix" },
86
+ suggestion: {
87
+ type: "string",
88
+ description: "Suggested fix from OCR scan",
89
+ },
90
+ },
91
+ required: ["path", "issue"],
92
+ },
93
+ },
94
+ ],
95
+ }));
96
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
97
+ const { name, arguments: args } = request.params;
98
+ switch (name) {
99
+ case "scan_directory": {
100
+ const parsed = scanDirectorySchema.parse(args);
101
+ return handleScanDirectory(parsed);
102
+ }
103
+ case "scan_diff": {
104
+ const parsed = scanDiffSchema.parse(args);
105
+ return handleScanDiff(parsed);
106
+ }
107
+ case "explain_issue": {
108
+ const parsed = explainIssueSchema.parse(args);
109
+ return handleExplainIssue(parsed);
110
+ }
111
+ case "heal_code": {
112
+ const parsed = healCodeSchema.parse(args);
113
+ return handleHealCode(parsed);
114
+ }
115
+ default:
116
+ throw new Error(`Unknown tool: ${name}`);
117
+ }
118
+ });
119
+ return server;
120
+ }
121
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,OAAO,EAAE,EAC9C,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;IAEF,MAAM,CAAC,iBA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CAAC,CAAC;gBACtB,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC/C,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;YACrC,CAAC;YACD,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC1C,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;YAChC,CAAC;YACD,KAAK,eAAe,CAAC,CAAC,CAAC;gBACrB,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC9C,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC;YACD,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC1C,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;YAChC,CAAC;YACD;gBACE,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ fetch(request: Request): Promise<Response>;
3
+ };
4
+ export default _default;
package/dist/worker.js ADDED
@@ -0,0 +1,123 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
3
+ import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
4
+ import { z } from "zod";
5
+ // ── explain_issue tool (no fs dependency) ──
6
+ const CATEGORY_EXPLANATIONS = {
7
+ "hallucinated-import": "The code imports a package that does not exist in the npm registry. This is a common AI hallucination — the model invented a plausible-sounding package name that has never been published. Remove the import and replace with a real package, or implement the functionality inline.",
8
+ "phantom-package": "A dependency is declared in package.json but never actually imported or used anywhere in the source code. This bloats the install size and may indicate an AI added an unnecessary dependency.",
9
+ "stale-api": "The code calls an API or uses a function signature that has been deprecated or removed in the current version of the library. Check the library's changelog and migration guide for the replacement.",
10
+ "context-break": "The code contains logic that appears inconsistent with the surrounding context — possibly caused by an AI losing track of what it was building mid-generation. Review the surrounding code for coherence.",
11
+ duplication: "Significant code duplication detected. This may indicate the AI copy-pasted code blocks without abstracting shared logic. Consider extracting a shared function or utility.",
12
+ "security-pattern": "A potential security anti-pattern was detected (e.g., hardcoded secrets, eval usage, SQL injection risk, path traversal). This requires immediate review.",
13
+ overengineering: "The code is unnecessarily complex for what it does. AI models tend to add extra abstraction layers, generic types, or design patterns that aren't needed. Simplify the implementation.",
14
+ };
15
+ const explainIssueSchema = z.object({
16
+ issue: z.string().describe("The issue description to explain"),
17
+ file: z.string().optional().describe("File path where the issue was found"),
18
+ line: z.number().optional().describe("Line number where the issue was found"),
19
+ severity: z
20
+ .string()
21
+ .optional()
22
+ .describe("Issue severity (critical/high/medium/low/info)"),
23
+ category: z.string().optional().describe("Issue category"),
24
+ suggestion: z
25
+ .string()
26
+ .optional()
27
+ .describe("Auto-generated fix suggestion"),
28
+ });
29
+ async function handleExplainIssue(args) {
30
+ const categoryExplanation = args.category
31
+ ? CATEGORY_EXPLANATIONS[args.category]
32
+ : null;
33
+ const explanation = {
34
+ issue: args.issue,
35
+ file: args.file ?? null,
36
+ line: args.line ?? null,
37
+ severity: args.severity ?? null,
38
+ category: args.category ?? null,
39
+ suggestion: args.suggestion ?? null,
40
+ categoryExplanation,
41
+ analysis: `This is a ${args.severity ?? "unknown"} severity issue in the "${args.category ?? "uncategorized"}" category. ${categoryExplanation ?? "Review the flagged code and consider the suggestion for resolution."}`,
42
+ };
43
+ return {
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: JSON.stringify(explanation, null, 2),
48
+ },
49
+ ],
50
+ };
51
+ }
52
+ // ── MCP Server setup ──
53
+ function createCloudflareServer() {
54
+ const server = new Server({ name: "open-code-review", version: "1.0.0" }, { capabilities: { tools: {} } });
55
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
56
+ tools: [
57
+ {
58
+ name: "explain_issue",
59
+ description: "Explain a code quality issue detected by Open Code Review (OCR). Returns detailed explanation, category context, and fix guidance for the AI agent to act on.",
60
+ inputSchema: {
61
+ type: "object",
62
+ properties: {
63
+ issue: {
64
+ type: "string",
65
+ description: "The issue description to explain",
66
+ },
67
+ file: {
68
+ type: "string",
69
+ description: "File path where the issue was found",
70
+ },
71
+ line: { type: "number", description: "Line number" },
72
+ severity: {
73
+ type: "string",
74
+ description: "Severity: critical/high/medium/low/info",
75
+ },
76
+ category: { type: "string", description: "Issue category" },
77
+ suggestion: {
78
+ type: "string",
79
+ description: "Auto-generated fix suggestion",
80
+ },
81
+ },
82
+ required: ["issue"],
83
+ },
84
+ },
85
+ ],
86
+ }));
87
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
88
+ const { name, arguments: args } = request.params;
89
+ switch (name) {
90
+ case "explain_issue": {
91
+ const parsed = explainIssueSchema.parse(args);
92
+ return handleExplainIssue(parsed);
93
+ }
94
+ default:
95
+ throw new Error(`Unknown tool: ${name}`);
96
+ }
97
+ });
98
+ return server;
99
+ }
100
+ // ── Worker fetch handler ──
101
+ const mcpServer = createCloudflareServer();
102
+ export default {
103
+ async fetch(request) {
104
+ const url = new URL(request.url);
105
+ // Health check
106
+ if (url.pathname === "/health") {
107
+ return new Response(JSON.stringify({ status: "ok", service: "open-code-review-mcp" }), {
108
+ headers: { "Content-Type": "application/json" },
109
+ });
110
+ }
111
+ // MCP endpoint
112
+ if (url.pathname === "/mcp") {
113
+ const transport = new WebStandardStreamableHTTPServerTransport({
114
+ sessionIdGenerator: undefined,
115
+ });
116
+ transport.onclose = () => { };
117
+ await mcpServer.connect(transport);
118
+ return transport.handleRequest(request);
119
+ }
120
+ return new Response("Not Found. MCP endpoint is at /mcp", { status: 404 });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GAAG,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC/B,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,EAAE;gBACrF,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;aAChD,CAAC,CAAC;QACL,CAAC;QAED,eAAe;QACf,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YAC5B,MAAM,SAAS,GAAG,IAAI,wCAAwC,CAAC;gBAC7D,kBAAkB,EAAE,SAAS;aAC9B,CAAC,CAAC;YAEH,SAAS,CAAC,OAAO,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;YAE7B,MAAM,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACnC,OAAO,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;QAED,OAAO,IAAI,QAAQ,CAAC,oCAAoC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencodereview/mcp-server",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "MCP Server for Open Code Review - AI code quality gate for Claude Desktop, Cursor, Windsurf, VS Code Copilot",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",