@mduenas/codegraph 0.4.0 → 0.5.0
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/bin/codegraph.js +45 -4
- package/dist/bin/codegraph.js.map +1 -1
- package/dist/db/schema.sql +149 -0
- package/dist/installer/banner.d.ts +1 -1
- package/dist/installer/banner.d.ts.map +1 -1
- package/dist/installer/banner.js +40 -8
- package/dist/installer/banner.js.map +1 -1
- package/dist/installer/index.d.ts +2 -2
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +43 -35
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/prompts.d.ts +5 -0
- package/dist/installer/prompts.d.ts.map +1 -1
- package/dist/installer/prompts.js +23 -0
- package/dist/installer/prompts.js.map +1 -1
- package/dist/mcp/http-transport.d.ts +89 -0
- package/dist/mcp/http-transport.d.ts.map +1 -0
- package/dist/mcp/http-transport.js +323 -0
- package/dist/mcp/http-transport.js.map +1 -0
- package/dist/mcp/index.d.ts +29 -2
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +35 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/transport.d.ts +37 -3
- package/dist/mcp/transport.d.ts.map +1 -1
- package/dist/mcp/transport.js +4 -2
- package/dist/mcp/transport.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/installer/prompts.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/installer/prompts.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCH,8CAqBC;AAKD,sDAmBC;AAKD,0CAiBC;AAKD,sCAYC;AAlHD,mDAAqC;AACrC,qCAAiC;AAKjC;;GAEG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,GAAG,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;IAE5C,OAAO,MAAM,KAAK,GAAG,CAAC;AACxB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,aAAa,CAAC,OAAe,EAAE,aAAsB,IAAI;IAC7E,MAAM,EAAE,GAAG,eAAe,EAAE,CAAC;IAE7B,MAAM,UAAU,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,EAAE,EAAE,KAAK,OAAO,KAAK,UAAU,KAAK,CAAC,CAAC;IAClE,EAAE,CAAC,KAAK,EAAE,CAAC;IAEX,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QAClB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP HTTP Transport
|
|
3
|
+
*
|
|
4
|
+
* Handles JSON-RPC 2.0 communication over HTTP for MCP protocol.
|
|
5
|
+
* Used for GitHub Copilot and other HTTP-based MCP clients.
|
|
6
|
+
*/
|
|
7
|
+
import { ITransport, MessageHandler, JsonRpcResponse } from './transport';
|
|
8
|
+
/**
|
|
9
|
+
* HTTP Transport Configuration
|
|
10
|
+
*/
|
|
11
|
+
export interface HttpTransportConfig {
|
|
12
|
+
/** Port to listen on (default: 3000) */
|
|
13
|
+
port?: number;
|
|
14
|
+
/** Host to bind to (default: 'localhost') */
|
|
15
|
+
host?: string;
|
|
16
|
+
/** Allowed CORS origins (default: '*') */
|
|
17
|
+
corsOrigins?: string | string[];
|
|
18
|
+
/** Endpoint path (default: '/mcp') */
|
|
19
|
+
endpoint?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* HTTP Transport for MCP
|
|
23
|
+
*
|
|
24
|
+
* Provides HTTP/JSON-RPC transport for MCP protocol.
|
|
25
|
+
* Supports CORS for browser-based clients.
|
|
26
|
+
*/
|
|
27
|
+
export declare class HttpTransport implements ITransport {
|
|
28
|
+
private server;
|
|
29
|
+
private messageHandler;
|
|
30
|
+
private pendingResponses;
|
|
31
|
+
private config;
|
|
32
|
+
constructor(config?: HttpTransportConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Start the HTTP server
|
|
35
|
+
*/
|
|
36
|
+
start(handler: MessageHandler): void;
|
|
37
|
+
/**
|
|
38
|
+
* Stop the HTTP server
|
|
39
|
+
*/
|
|
40
|
+
stop(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Send a JSON-RPC response
|
|
43
|
+
* For HTTP transport, this sends the response to the pending HTTP request
|
|
44
|
+
*/
|
|
45
|
+
send(response: JsonRpcResponse): void;
|
|
46
|
+
/**
|
|
47
|
+
* Send a notification
|
|
48
|
+
* Note: In HTTP transport, notifications are typically not used
|
|
49
|
+
* as the client initiates all requests
|
|
50
|
+
*/
|
|
51
|
+
notify(method: string, _params?: unknown): void;
|
|
52
|
+
/**
|
|
53
|
+
* Send a success result
|
|
54
|
+
*/
|
|
55
|
+
sendResult(id: string | number, result: unknown): void;
|
|
56
|
+
/**
|
|
57
|
+
* Send an error response
|
|
58
|
+
*/
|
|
59
|
+
sendError(id: string | number | null, code: number, message: string, data?: unknown): void;
|
|
60
|
+
/**
|
|
61
|
+
* Handle incoming HTTP request
|
|
62
|
+
*/
|
|
63
|
+
private handleRequest;
|
|
64
|
+
/**
|
|
65
|
+
* Read request body as string
|
|
66
|
+
*/
|
|
67
|
+
private readBody;
|
|
68
|
+
/**
|
|
69
|
+
* Set CORS headers on response
|
|
70
|
+
*/
|
|
71
|
+
private setCorsHeaders;
|
|
72
|
+
/**
|
|
73
|
+
* Send HTTP response with JSON body
|
|
74
|
+
*/
|
|
75
|
+
private sendHttpResponse;
|
|
76
|
+
/**
|
|
77
|
+
* Check if message is a valid JSON-RPC 2.0 message
|
|
78
|
+
*/
|
|
79
|
+
private isValidMessage;
|
|
80
|
+
/**
|
|
81
|
+
* Get the server address info
|
|
82
|
+
*/
|
|
83
|
+
getAddress(): {
|
|
84
|
+
host: string;
|
|
85
|
+
port: number;
|
|
86
|
+
endpoint: string;
|
|
87
|
+
} | null;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=http-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-transport.d.ts","sourceRoot":"","sources":["../../src/mcp/http-transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,UAAU,EACV,cAAc,EAEd,eAAe,EAGhB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAUD;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,UAAU;IAC9C,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,gBAAgB,CAAoD;IAC5E,OAAO,CAAC,MAAM,CAAgC;gBAElC,MAAM,GAAE,mBAAwB;IAS5C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAiBpC;;OAEG;IACH,IAAI,IAAI,IAAI;IAQZ;;;OAGG;IACH,IAAI,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAarC;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI;IAM/C;;OAEG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAQtD;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAc1F;;OAEG;YACW,aAAa;IAkI3B;;OAEG;IACH,OAAO,CAAC,QAAQ;IAShB;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IASxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAQtB;;OAEG;IACH,UAAU,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAQtE"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP HTTP Transport
|
|
4
|
+
*
|
|
5
|
+
* Handles JSON-RPC 2.0 communication over HTTP for MCP protocol.
|
|
6
|
+
* Used for GitHub Copilot and other HTTP-based MCP clients.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.HttpTransport = void 0;
|
|
43
|
+
const http = __importStar(require("http"));
|
|
44
|
+
const transport_1 = require("./transport");
|
|
45
|
+
/**
|
|
46
|
+
* HTTP Transport for MCP
|
|
47
|
+
*
|
|
48
|
+
* Provides HTTP/JSON-RPC transport for MCP protocol.
|
|
49
|
+
* Supports CORS for browser-based clients.
|
|
50
|
+
*/
|
|
51
|
+
class HttpTransport {
|
|
52
|
+
server = null;
|
|
53
|
+
messageHandler = null;
|
|
54
|
+
pendingResponses = new Map();
|
|
55
|
+
config;
|
|
56
|
+
constructor(config = {}) {
|
|
57
|
+
this.config = {
|
|
58
|
+
port: config.port ?? 3000,
|
|
59
|
+
host: config.host ?? 'localhost',
|
|
60
|
+
corsOrigins: config.corsOrigins ?? '*',
|
|
61
|
+
endpoint: config.endpoint ?? '/mcp',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Start the HTTP server
|
|
66
|
+
*/
|
|
67
|
+
start(handler) {
|
|
68
|
+
this.messageHandler = handler;
|
|
69
|
+
this.server = http.createServer(async (req, res) => {
|
|
70
|
+
await this.handleRequest(req, res);
|
|
71
|
+
});
|
|
72
|
+
this.server.listen(this.config.port, this.config.host, () => {
|
|
73
|
+
// Server started - log to stderr to not interfere with potential stdio
|
|
74
|
+
console.error(`[codegraph] MCP HTTP server listening on http://${this.config.host}:${this.config.port}${this.config.endpoint}`);
|
|
75
|
+
});
|
|
76
|
+
this.server.on('error', (err) => {
|
|
77
|
+
console.error(`[codegraph] HTTP server error: ${err.message}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Stop the HTTP server
|
|
82
|
+
*/
|
|
83
|
+
stop() {
|
|
84
|
+
if (this.server) {
|
|
85
|
+
this.server.close();
|
|
86
|
+
this.server = null;
|
|
87
|
+
}
|
|
88
|
+
this.pendingResponses.clear();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Send a JSON-RPC response
|
|
92
|
+
* For HTTP transport, this sends the response to the pending HTTP request
|
|
93
|
+
*/
|
|
94
|
+
send(response) {
|
|
95
|
+
if (response.id === null) {
|
|
96
|
+
// Notifications don't have responses in HTTP context
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const pending = this.pendingResponses.get(response.id);
|
|
100
|
+
if (pending) {
|
|
101
|
+
this.sendHttpResponse(pending.res, 200, response);
|
|
102
|
+
this.pendingResponses.delete(response.id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Send a notification
|
|
107
|
+
* Note: In HTTP transport, notifications are typically not used
|
|
108
|
+
* as the client initiates all requests
|
|
109
|
+
*/
|
|
110
|
+
notify(method, _params) {
|
|
111
|
+
// HTTP transport doesn't support server-initiated notifications
|
|
112
|
+
// This would require SSE or WebSocket for bidirectional communication
|
|
113
|
+
console.error(`[codegraph] HTTP transport cannot send notifications: ${method}`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Send a success result
|
|
117
|
+
*/
|
|
118
|
+
sendResult(id, result) {
|
|
119
|
+
this.send({
|
|
120
|
+
jsonrpc: '2.0',
|
|
121
|
+
id,
|
|
122
|
+
result,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Send an error response
|
|
127
|
+
*/
|
|
128
|
+
sendError(id, code, message, data) {
|
|
129
|
+
if (id === null) {
|
|
130
|
+
// Can't send error response without an id
|
|
131
|
+
console.error(`[codegraph] Cannot send error without request id: ${message}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this.send({
|
|
135
|
+
jsonrpc: '2.0',
|
|
136
|
+
id,
|
|
137
|
+
error: { code, message, data },
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Handle incoming HTTP request
|
|
142
|
+
*/
|
|
143
|
+
async handleRequest(req, res) {
|
|
144
|
+
// Set CORS headers
|
|
145
|
+
this.setCorsHeaders(res);
|
|
146
|
+
// Handle preflight OPTIONS request
|
|
147
|
+
if (req.method === 'OPTIONS') {
|
|
148
|
+
res.writeHead(204);
|
|
149
|
+
res.end();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Only accept POST to the MCP endpoint
|
|
153
|
+
const url = new URL(req.url || '/', `http://${req.headers.host}`);
|
|
154
|
+
if (req.method !== 'POST' || url.pathname !== this.config.endpoint) {
|
|
155
|
+
this.sendHttpResponse(res, 404, {
|
|
156
|
+
jsonrpc: '2.0',
|
|
157
|
+
id: null,
|
|
158
|
+
error: {
|
|
159
|
+
code: transport_1.ErrorCodes.InvalidRequest,
|
|
160
|
+
message: `Not found. Use POST ${this.config.endpoint}`,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// Check content type
|
|
166
|
+
const contentType = req.headers['content-type'];
|
|
167
|
+
if (!contentType || !contentType.includes('application/json')) {
|
|
168
|
+
this.sendHttpResponse(res, 400, {
|
|
169
|
+
jsonrpc: '2.0',
|
|
170
|
+
id: null,
|
|
171
|
+
error: {
|
|
172
|
+
code: transport_1.ErrorCodes.ParseError,
|
|
173
|
+
message: 'Content-Type must be application/json',
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
// Read request body
|
|
179
|
+
let body = '';
|
|
180
|
+
try {
|
|
181
|
+
body = await this.readBody(req);
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
this.sendHttpResponse(res, 400, {
|
|
185
|
+
jsonrpc: '2.0',
|
|
186
|
+
id: null,
|
|
187
|
+
error: {
|
|
188
|
+
code: transport_1.ErrorCodes.ParseError,
|
|
189
|
+
message: 'Failed to read request body',
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
// Parse JSON
|
|
195
|
+
let parsed;
|
|
196
|
+
try {
|
|
197
|
+
parsed = JSON.parse(body);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
this.sendHttpResponse(res, 400, {
|
|
201
|
+
jsonrpc: '2.0',
|
|
202
|
+
id: null,
|
|
203
|
+
error: {
|
|
204
|
+
code: transport_1.ErrorCodes.ParseError,
|
|
205
|
+
message: 'Parse error: invalid JSON',
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
// Validate JSON-RPC structure
|
|
211
|
+
if (!this.isValidMessage(parsed)) {
|
|
212
|
+
this.sendHttpResponse(res, 400, {
|
|
213
|
+
jsonrpc: '2.0',
|
|
214
|
+
id: null,
|
|
215
|
+
error: {
|
|
216
|
+
code: transport_1.ErrorCodes.InvalidRequest,
|
|
217
|
+
message: 'Invalid Request: not a valid JSON-RPC 2.0 message',
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const message = parsed;
|
|
223
|
+
// Check if it's a request (has id) or notification
|
|
224
|
+
if ('id' in message) {
|
|
225
|
+
// Store pending response for later
|
|
226
|
+
this.pendingResponses.set(message.id, {
|
|
227
|
+
res,
|
|
228
|
+
timestamp: Date.now(),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
// Handle the message
|
|
232
|
+
if (this.messageHandler) {
|
|
233
|
+
try {
|
|
234
|
+
await this.messageHandler(message);
|
|
235
|
+
// If it was a notification (no id), send empty 204 response
|
|
236
|
+
if (!('id' in message)) {
|
|
237
|
+
res.writeHead(204);
|
|
238
|
+
res.end();
|
|
239
|
+
}
|
|
240
|
+
// For requests, the response is sent via send/sendResult/sendError
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
if ('id' in message) {
|
|
244
|
+
this.sendError(message.id, transport_1.ErrorCodes.InternalError, `Internal error: ${err instanceof Error ? err.message : String(err)}`);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
res.writeHead(500);
|
|
248
|
+
res.end();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
this.sendHttpResponse(res, 500, {
|
|
254
|
+
jsonrpc: '2.0',
|
|
255
|
+
id: 'id' in message ? message.id : null,
|
|
256
|
+
error: {
|
|
257
|
+
code: transport_1.ErrorCodes.InternalError,
|
|
258
|
+
message: 'No message handler configured',
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Read request body as string
|
|
265
|
+
*/
|
|
266
|
+
readBody(req) {
|
|
267
|
+
return new Promise((resolve, reject) => {
|
|
268
|
+
const chunks = [];
|
|
269
|
+
req.on('data', (chunk) => chunks.push(chunk));
|
|
270
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
|
|
271
|
+
req.on('error', reject);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Set CORS headers on response
|
|
276
|
+
*/
|
|
277
|
+
setCorsHeaders(res) {
|
|
278
|
+
const origins = this.config.corsOrigins;
|
|
279
|
+
const originHeader = Array.isArray(origins) ? origins.join(', ') : origins;
|
|
280
|
+
res.setHeader('Access-Control-Allow-Origin', originHeader);
|
|
281
|
+
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
282
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
283
|
+
res.setHeader('Access-Control-Max-Age', '86400');
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Send HTTP response with JSON body
|
|
287
|
+
*/
|
|
288
|
+
sendHttpResponse(res, statusCode, body) {
|
|
289
|
+
const json = JSON.stringify(body);
|
|
290
|
+
res.writeHead(statusCode, {
|
|
291
|
+
'Content-Type': 'application/json',
|
|
292
|
+
'Content-Length': Buffer.byteLength(json),
|
|
293
|
+
});
|
|
294
|
+
res.end(json);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Check if message is a valid JSON-RPC 2.0 message
|
|
298
|
+
*/
|
|
299
|
+
isValidMessage(msg) {
|
|
300
|
+
if (typeof msg !== 'object' || msg === null)
|
|
301
|
+
return false;
|
|
302
|
+
const obj = msg;
|
|
303
|
+
if (obj.jsonrpc !== '2.0')
|
|
304
|
+
return false;
|
|
305
|
+
if (typeof obj.method !== 'string')
|
|
306
|
+
return false;
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Get the server address info
|
|
311
|
+
*/
|
|
312
|
+
getAddress() {
|
|
313
|
+
if (!this.server)
|
|
314
|
+
return null;
|
|
315
|
+
return {
|
|
316
|
+
host: this.config.host,
|
|
317
|
+
port: this.config.port,
|
|
318
|
+
endpoint: this.config.endpoint,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
exports.HttpTransport = HttpTransport;
|
|
323
|
+
//# sourceMappingURL=http-transport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B,CAAC,CAAC;QAC7E,GAAG,CAAC,SAAS,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,GAAwB,EAAE,UAAkB,EAAE,IAAqB;QAC1F,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAClC,GAAG,CAAC,SAAS,CAAC,UAAU,EAAE;YACxB,cAAc,EAAE,kBAAkB;YAClC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;SAC1C,CAAC,CAAC;QACH,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,GAAY;QACjC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QAC1D,MAAM,GAAG,GAAG,GAA8B,CAAC;QAC3C,IAAI,GAAG,CAAC,OAAO,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QACxC,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;SAC/B,CAAC;IACJ,CAAC;CACF;AAtSD,sCAsSC"}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -10,23 +10,49 @@
|
|
|
10
10
|
* ```typescript
|
|
11
11
|
* import { MCPServer } from 'codegraph';
|
|
12
12
|
*
|
|
13
|
+
* // Stdio transport (default, for Claude Code)
|
|
13
14
|
* const server = new MCPServer('/path/to/project');
|
|
14
15
|
* await server.start();
|
|
16
|
+
*
|
|
17
|
+
* // HTTP transport (for GitHub Copilot)
|
|
18
|
+
* const httpServer = new MCPServer('/path/to/project', {
|
|
19
|
+
* transport: 'http',
|
|
20
|
+
* port: 3000,
|
|
21
|
+
* });
|
|
22
|
+
* await httpServer.start();
|
|
15
23
|
* ```
|
|
16
24
|
*/
|
|
25
|
+
/**
|
|
26
|
+
* MCP Server Configuration
|
|
27
|
+
*/
|
|
28
|
+
export interface MCPServerConfig {
|
|
29
|
+
/** Transport type: 'stdio' (default) or 'http' */
|
|
30
|
+
transport?: 'stdio' | 'http';
|
|
31
|
+
/** HTTP port (only for http transport, default: 3000) */
|
|
32
|
+
port?: number;
|
|
33
|
+
/** HTTP host (only for http transport, default: 'localhost') */
|
|
34
|
+
host?: string;
|
|
35
|
+
/** CORS origins (only for http transport, default: '*') */
|
|
36
|
+
corsOrigins?: string | string[];
|
|
37
|
+
}
|
|
17
38
|
/**
|
|
18
39
|
* MCP Server for CodeGraph
|
|
19
40
|
*
|
|
20
41
|
* Implements the Model Context Protocol to expose CodeGraph
|
|
21
42
|
* functionality as tools that can be called by AI assistants.
|
|
43
|
+
*
|
|
44
|
+
* Supports multiple transport mechanisms:
|
|
45
|
+
* - stdio: For direct process communication (Claude Code)
|
|
46
|
+
* - http: For HTTP-based clients (GitHub Copilot)
|
|
22
47
|
*/
|
|
23
48
|
export declare class MCPServer {
|
|
24
49
|
private transport;
|
|
50
|
+
private transportType;
|
|
25
51
|
private cg;
|
|
26
52
|
private toolHandler;
|
|
27
53
|
private projectPath;
|
|
28
54
|
private initError;
|
|
29
|
-
constructor(projectPath?: string);
|
|
55
|
+
constructor(projectPath?: string, config?: MCPServerConfig);
|
|
30
56
|
/**
|
|
31
57
|
* Start the MCP server
|
|
32
58
|
*
|
|
@@ -59,6 +85,7 @@ export declare class MCPServer {
|
|
|
59
85
|
*/
|
|
60
86
|
private handleToolsCall;
|
|
61
87
|
}
|
|
62
|
-
export { StdioTransport } from './transport';
|
|
88
|
+
export { ITransport, StdioTransport } from './transport';
|
|
89
|
+
export { HttpTransport, HttpTransportConfig } from './http-transport';
|
|
63
90
|
export { tools, ToolHandler } from './tools';
|
|
64
91
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/mcp/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAoBH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACjC;AAED;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,SAAS,CAAuB;gBAE5B,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,GAAE,eAAoB;IAe9D;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;OAEG;YACW,mBAAmB;IAiBjC;;OAEG;IACH,IAAI,IAAI,IAAI;IAcZ;;OAEG;YACW,aAAa;IA6C3B;;OAEG;YACW,gBAAgB;IAkC9B;;OAEG;YACW,eAAe;IAM7B;;OAEG;YACW,eAAe;CA+C9B;AAGD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/mcp/index.js
CHANGED
|
@@ -11,17 +11,26 @@
|
|
|
11
11
|
* ```typescript
|
|
12
12
|
* import { MCPServer } from 'codegraph';
|
|
13
13
|
*
|
|
14
|
+
* // Stdio transport (default, for Claude Code)
|
|
14
15
|
* const server = new MCPServer('/path/to/project');
|
|
15
16
|
* await server.start();
|
|
17
|
+
*
|
|
18
|
+
* // HTTP transport (for GitHub Copilot)
|
|
19
|
+
* const httpServer = new MCPServer('/path/to/project', {
|
|
20
|
+
* transport: 'http',
|
|
21
|
+
* port: 3000,
|
|
22
|
+
* });
|
|
23
|
+
* await httpServer.start();
|
|
16
24
|
* ```
|
|
17
25
|
*/
|
|
18
26
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
28
|
};
|
|
21
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.ToolHandler = exports.tools = exports.StdioTransport = exports.MCPServer = void 0;
|
|
30
|
+
exports.ToolHandler = exports.tools = exports.HttpTransport = exports.StdioTransport = exports.MCPServer = void 0;
|
|
23
31
|
const index_1 = __importDefault(require("../index"));
|
|
24
32
|
const transport_1 = require("./transport");
|
|
33
|
+
const http_transport_1 = require("./http-transport");
|
|
25
34
|
const tools_1 = require("./tools");
|
|
26
35
|
/**
|
|
27
36
|
* MCP Server Info
|
|
@@ -39,16 +48,31 @@ const PROTOCOL_VERSION = '2024-11-05';
|
|
|
39
48
|
*
|
|
40
49
|
* Implements the Model Context Protocol to expose CodeGraph
|
|
41
50
|
* functionality as tools that can be called by AI assistants.
|
|
51
|
+
*
|
|
52
|
+
* Supports multiple transport mechanisms:
|
|
53
|
+
* - stdio: For direct process communication (Claude Code)
|
|
54
|
+
* - http: For HTTP-based clients (GitHub Copilot)
|
|
42
55
|
*/
|
|
43
56
|
class MCPServer {
|
|
44
57
|
transport;
|
|
58
|
+
transportType;
|
|
45
59
|
cg = null;
|
|
46
60
|
toolHandler = null;
|
|
47
61
|
projectPath;
|
|
48
62
|
initError = null;
|
|
49
|
-
constructor(projectPath) {
|
|
63
|
+
constructor(projectPath, config = {}) {
|
|
50
64
|
this.projectPath = projectPath || null;
|
|
51
|
-
this.
|
|
65
|
+
this.transportType = config.transport || 'stdio';
|
|
66
|
+
if (this.transportType === 'http') {
|
|
67
|
+
this.transport = new http_transport_1.HttpTransport({
|
|
68
|
+
port: config.port,
|
|
69
|
+
host: config.host,
|
|
70
|
+
corsOrigins: config.corsOrigins,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.transport = new transport_1.StdioTransport();
|
|
75
|
+
}
|
|
52
76
|
}
|
|
53
77
|
/**
|
|
54
78
|
* Start the MCP server
|
|
@@ -91,7 +115,11 @@ class MCPServer {
|
|
|
91
115
|
this.cg = null;
|
|
92
116
|
}
|
|
93
117
|
this.transport.stop();
|
|
94
|
-
process
|
|
118
|
+
// Only exit process for stdio transport (where stdin close means we should exit)
|
|
119
|
+
// HTTP transport should stop gracefully without terminating the process
|
|
120
|
+
if (this.transportType === 'stdio') {
|
|
121
|
+
process.exit(0);
|
|
122
|
+
}
|
|
95
123
|
}
|
|
96
124
|
/**
|
|
97
125
|
* Handle incoming JSON-RPC messages
|
|
@@ -198,9 +226,11 @@ class MCPServer {
|
|
|
198
226
|
}
|
|
199
227
|
}
|
|
200
228
|
exports.MCPServer = MCPServer;
|
|
201
|
-
// Export for use in CLI
|
|
229
|
+
// Export for use in CLI and external consumers
|
|
202
230
|
var transport_2 = require("./transport");
|
|
203
231
|
Object.defineProperty(exports, "StdioTransport", { enumerable: true, get: function () { return transport_2.StdioTransport; } });
|
|
232
|
+
var http_transport_2 = require("./http-transport");
|
|
233
|
+
Object.defineProperty(exports, "HttpTransport", { enumerable: true, get: function () { return http_transport_2.HttpTransport; } });
|
|
204
234
|
var tools_2 = require("./tools");
|
|
205
235
|
Object.defineProperty(exports, "tools", { enumerable: true, get: function () { return tools_2.tools; } });
|
|
206
236
|
Object.defineProperty(exports, "ToolHandler", { enumerable: true, get: function () { return tools_2.ToolHandler; } });
|
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;AAEH,qDAAiC;AACjC,2CAA0G;AAC1G,qDAAiD;AACjD,mCAA6C;AAE7C;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAgBtC;;;;;;;;;GASG;AACH,MAAa,SAAS;IACZ,SAAS,CAAa;IACtB,aAAa,CAAmB;IAChC,EAAE,GAAqB,IAAI,CAAC;IAC5B,WAAW,GAAuB,IAAI,CAAC;IACvC,WAAW,CAAgB;IAC3B,SAAS,GAAkB,IAAI,CAAC;IAExC,YAAY,WAAoB,EAAE,SAA0B,EAAE;QAC5D,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,IAAI,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC;QAEjD,IAAI,IAAI,CAAC,aAAa,KAAK,MAAM,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,GAAG,IAAI,8BAAa,CAAC;gBACjC,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;g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