@esankhan3/code-search-mcp 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/LICENSE +21 -0
- package/README.md +333 -0
- package/dist/core/ast-graph-builder.js +800 -0
- package/dist/core/chunker.js +368 -0
- package/dist/core/claude-runner.js +173 -0
- package/dist/core/config.js +59 -0
- package/dist/core/cross-repo-detector.js +887 -0
- package/dist/core/embedder.js +334 -0
- package/dist/core/env-config.js +86 -0
- package/dist/core/file-walker.js +186 -0
- package/dist/core/git-diff.js +160 -0
- package/dist/core/graph-metrics.js +233 -0
- package/dist/core/indexer.js +552 -0
- package/dist/core/project-graph-builder.js +202 -0
- package/dist/core/query-classifier.js +144 -0
- package/dist/core/query-router.js +210 -0
- package/dist/core/rag-evaluator.js +213 -0
- package/dist/core/repo-profiler.js +383 -0
- package/dist/core/reranker.js +218 -0
- package/dist/core/retriever.js +242 -0
- package/dist/core/semantic-edge-detector.js +147 -0
- package/dist/core/service-mesh-inferrer.js +241 -0
- package/dist/core/structural-hasher.js +316 -0
- package/dist/core/tree-sitter-parser.js +539 -0
- package/dist/core/types.js +0 -0
- package/dist/core/vector-store.js +259 -0
- package/dist/core/workspace-detector.js +481 -0
- package/dist/index.js +177 -0
- package/dist/middleware/auth.js +109 -0
- package/dist/resources/resources.js +79 -0
- package/dist/server.js +242 -0
- package/dist/sources/github-org.js +109 -0
- package/dist/sources/local-path.js +44 -0
- package/dist/tools/graph.js +193 -0
- package/dist/tools/index-tools.js +43 -0
- package/dist/tools/profile.js +88 -0
- package/dist/tools/search.js +84 -0
- package/dist/transports/http-transport.js +162 -0
- package/dist/transports/remote-proxy.js +152 -0
- package/package.json +33 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import {
|
|
4
|
+
CallToolRequestSchema,
|
|
5
|
+
ListToolsRequestSchema,
|
|
6
|
+
ListResourcesRequestSchema,
|
|
7
|
+
ReadResourceRequestSchema
|
|
8
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
9
|
+
class RemoteConnection {
|
|
10
|
+
serverUrl;
|
|
11
|
+
apiKey;
|
|
12
|
+
sessionId = null;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.serverUrl = config.serverUrl.replace(/\/$/, "");
|
|
15
|
+
this.apiKey = config.apiKey;
|
|
16
|
+
}
|
|
17
|
+
/** Send a JSON-RPC request to the remote MCP server */
|
|
18
|
+
async request(method, params = {}, id = 1) {
|
|
19
|
+
const headers = {
|
|
20
|
+
"Content-Type": "application/json",
|
|
21
|
+
"Accept": "application/json, text/event-stream"
|
|
22
|
+
};
|
|
23
|
+
if (this.apiKey) {
|
|
24
|
+
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
25
|
+
}
|
|
26
|
+
if (this.sessionId) {
|
|
27
|
+
headers["mcp-session-id"] = this.sessionId;
|
|
28
|
+
}
|
|
29
|
+
const body = JSON.stringify({
|
|
30
|
+
jsonrpc: "2.0",
|
|
31
|
+
id,
|
|
32
|
+
method,
|
|
33
|
+
params
|
|
34
|
+
});
|
|
35
|
+
const response = await fetch(`${this.serverUrl}/mcp`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers,
|
|
38
|
+
body
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const errBody = await response.text().catch(() => "");
|
|
42
|
+
throw new Error(`Remote server error (${response.status}): ${errBody.slice(0, 300)}`);
|
|
43
|
+
}
|
|
44
|
+
const newSessionId = response.headers.get("mcp-session-id");
|
|
45
|
+
if (newSessionId) {
|
|
46
|
+
this.sessionId = newSessionId;
|
|
47
|
+
}
|
|
48
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
49
|
+
if (contentType.includes("text/event-stream")) {
|
|
50
|
+
const text = await response.text();
|
|
51
|
+
for (const line of text.split("\n")) {
|
|
52
|
+
if (line.startsWith("data: ")) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(line.slice(6));
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw new Error("No valid JSON in SSE response");
|
|
60
|
+
}
|
|
61
|
+
return response.json();
|
|
62
|
+
}
|
|
63
|
+
/** Initialize the remote session */
|
|
64
|
+
async initialize() {
|
|
65
|
+
return this.request("initialize", {
|
|
66
|
+
protocolVersion: "2024-11-05",
|
|
67
|
+
capabilities: {},
|
|
68
|
+
clientInfo: { name: "code-search-mcp-proxy", version: "0.1.0" }
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Check remote server health */
|
|
72
|
+
async health() {
|
|
73
|
+
const res = await fetch(`${this.serverUrl}/health`);
|
|
74
|
+
if (!res.ok) throw new Error(`Health check failed: ${res.status}`);
|
|
75
|
+
return res.json();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function startRemoteProxy(config) {
|
|
79
|
+
const remote = new RemoteConnection(config);
|
|
80
|
+
try {
|
|
81
|
+
const health = await remote.health();
|
|
82
|
+
console.error(`[code-search-mcp] Connected to remote server at ${config.serverUrl}`);
|
|
83
|
+
console.error(`[code-search-mcp] Remote status: ${health.status}, project: ${health.project ?? "unknown"}, index: ${health.indexReady ? "ready" : "not ready"}`);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(`[code-search-mcp] WARNING: Could not reach remote server at ${config.serverUrl}: ${err.message}`);
|
|
86
|
+
console.error(`[code-search-mcp] Proxy will start anyway \u2014 requests will fail until server is available.`);
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
await remote.initialize();
|
|
90
|
+
console.error(`[code-search-mcp] Remote session established`);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.error(`[code-search-mcp] WARNING: Session init failed: ${err.message}. Will retry on first request.`);
|
|
93
|
+
}
|
|
94
|
+
const server = new Server(
|
|
95
|
+
{ name: "code-search-mcp", version: "0.1.0" },
|
|
96
|
+
{ capabilities: { tools: {}, resources: {} } }
|
|
97
|
+
);
|
|
98
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
99
|
+
try {
|
|
100
|
+
const response = await remote.request("tools/list");
|
|
101
|
+
return response.result ?? { tools: [] };
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.error(`[proxy] Failed to list tools: ${err.message}`);
|
|
104
|
+
return { tools: [] };
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
108
|
+
try {
|
|
109
|
+
const response = await remote.request("tools/call", {
|
|
110
|
+
name: request.params.name,
|
|
111
|
+
arguments: request.params.arguments ?? {}
|
|
112
|
+
});
|
|
113
|
+
return response.result ?? {
|
|
114
|
+
content: [{ type: "text", text: "No response from remote server" }],
|
|
115
|
+
isError: true
|
|
116
|
+
};
|
|
117
|
+
} catch (err) {
|
|
118
|
+
return {
|
|
119
|
+
content: [{ type: "text", text: `Remote server error: ${err.message}` }],
|
|
120
|
+
isError: true
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
125
|
+
try {
|
|
126
|
+
const response = await remote.request("resources/list");
|
|
127
|
+
return response.result ?? { resources: [] };
|
|
128
|
+
} catch {
|
|
129
|
+
return { resources: [] };
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
133
|
+
try {
|
|
134
|
+
const response = await remote.request("resources/read", {
|
|
135
|
+
uri: request.params.uri
|
|
136
|
+
});
|
|
137
|
+
return response.result ?? {
|
|
138
|
+
contents: [{ uri: request.params.uri, text: "Not available" }]
|
|
139
|
+
};
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return {
|
|
142
|
+
contents: [{ uri: request.params.uri, text: `Error: ${err.message}` }]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
const transport = new StdioServerTransport();
|
|
147
|
+
await server.connect(transport);
|
|
148
|
+
console.error(`[code-search-mcp] Proxy running (stdio \u2192 ${config.serverUrl})`);
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
startRemoteProxy
|
|
152
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@esankhan3/code-search-mcp",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "MCP server for multi-repo code search — GitHub org or local path, zero config",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"code-search-mcp": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "node build.mjs",
|
|
18
|
+
"dev": "tsc -b --watch"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@lancedb/lancedb": "0.27.2",
|
|
22
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
23
|
+
"graphology": "0.26.0",
|
|
24
|
+
"graphology-communities-louvain": "2.0.2",
|
|
25
|
+
"graphology-metrics": "2.4.0",
|
|
26
|
+
"graphology-types": "0.24.8",
|
|
27
|
+
"tree-sitter-wasms": "0.1.13",
|
|
28
|
+
"web-tree-sitter": "0.26.8"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.15.2"
|
|
32
|
+
}
|
|
33
|
+
}
|