@esankhan3/code-search-mcp 0.4.4 → 0.4.6

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.
@@ -8,8 +8,10 @@ async function startHttpTransport(opts) {
8
8
  const authenticate = createAuthMiddleware(config);
9
9
  const startedAt = Date.now();
10
10
  const sessions = /* @__PURE__ */ new Map();
11
- const SESSION_TTL_MS = 30 * 60 * 1e3;
12
- const MAX_SESSIONS = 100;
11
+ const ttlMin = parseInt(process.env.CODE_SEARCH_SESSION_TTL_MINUTES ?? "", 10);
12
+ const SESSION_TTL_MS = (Number.isFinite(ttlMin) && ttlMin > 0 ? ttlMin : 120) * 60 * 1e3;
13
+ const maxEnv = parseInt(process.env.CODE_SEARCH_MAX_SESSIONS ?? "", 10);
14
+ const MAX_SESSIONS = Number.isFinite(maxEnv) && maxEnv > 0 ? maxEnv : 100;
13
15
  setInterval(() => {
14
16
  const now = Date.now();
15
17
  for (const [id, session] of sessions) {
@@ -123,8 +125,8 @@ async function startHttpTransport(opts) {
123
125
  return;
124
126
  }
125
127
  if (sessionId && !sessions.has(sessionId)) {
126
- res.writeHead(400, { "Content-Type": "application/json" });
127
- res.end(JSON.stringify({ error: "Invalid session ID. Session may have expired." }));
128
+ res.writeHead(404, { "Content-Type": "application/json" });
129
+ res.end(JSON.stringify({ error: "Session expired or unknown \u2014 reinitialize." }));
128
130
  return;
129
131
  }
130
132
  if (sessions.size >= MAX_SESSIONS) {
@@ -162,11 +164,12 @@ async function startHttpTransport(opts) {
162
164
  if (req.method === "GET") {
163
165
  const sessionId = req.headers["mcp-session-id"];
164
166
  if (sessionId && sessions.has(sessionId)) {
167
+ sessions.get(sessionId).lastActivity = Date.now();
165
168
  await sessions.get(sessionId).transport.handleRequest(req, res);
166
169
  return;
167
170
  }
168
- res.writeHead(400, { "Content-Type": "application/json" });
169
- res.end(JSON.stringify({ error: "Session ID required for GET requests" }));
171
+ res.writeHead(sessionId ? 404 : 400, { "Content-Type": "application/json" });
172
+ res.end(JSON.stringify({ error: sessionId ? "Session expired or unknown \u2014 reinitialize." : "Session ID required for GET requests" }));
170
173
  return;
171
174
  }
172
175
  if (req.method === "DELETE") {
@@ -15,7 +15,7 @@ class RemoteConnection {
15
15
  this.apiKey = config.apiKey;
16
16
  }
17
17
  /** Send a JSON-RPC request to the remote MCP server */
18
- async request(method, params = {}, id = 1) {
18
+ async request(method, params = {}, id = 1, _retried = false) {
19
19
  const headers = {
20
20
  "Content-Type": "application/json",
21
21
  "Accept": "application/json, text/event-stream"
@@ -38,6 +38,11 @@ class RemoteConnection {
38
38
  body
39
39
  });
40
40
  if (!response.ok) {
41
+ if ((response.status === 404 || response.status === 400) && this.sessionId && method !== "initialize" && !_retried) {
42
+ this.sessionId = null;
43
+ await this.initialize();
44
+ return this.request(method, params, id, true);
45
+ }
41
46
  const errBody = await response.text().catch(() => "");
42
47
  throw new Error(`Remote server error (${response.status}): ${errBody.slice(0, 300)}`);
43
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esankhan3/code-search-mcp",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "MCP server for multi-repo code search — GitHub org or local path, zero config",
5
5
  "type": "module",
6
6
  "license": "MIT",