midnight-mcp 0.2.4 → 0.2.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.
package/dist/bin.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
startHttpServer,
|
|
4
4
|
startServer
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-L5CXYFG2.js";
|
|
6
6
|
import {
|
|
7
7
|
setOutputFormat
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-WC2FPYQO.js";
|
|
9
9
|
|
|
10
10
|
// src/bin.ts
|
|
11
11
|
import { config } from "dotenv";
|
|
@@ -13,7 +13,7 @@ import { resolve } from "path";
|
|
|
13
13
|
import yargs from "yargs";
|
|
14
14
|
import { hideBin } from "yargs/helpers";
|
|
15
15
|
config({ path: resolve(process.cwd(), ".env") });
|
|
16
|
-
var CURRENT_VERSION = "0.2.
|
|
16
|
+
var CURRENT_VERSION = "0.2.6";
|
|
17
17
|
process.on("uncaughtException", (error) => {
|
|
18
18
|
console.error("Uncaught exception:", error);
|
|
19
19
|
process.exit(1);
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
validateNumber,
|
|
26
26
|
validateQuery,
|
|
27
27
|
vectorStore
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-WC2FPYQO.js";
|
|
29
29
|
|
|
30
30
|
// src/tools/search/schemas.ts
|
|
31
31
|
import { z } from "zod";
|
|
@@ -353,10 +353,10 @@ async function fetchDocs(input) {
|
|
|
353
353
|
const { path: path2, extractSection } = input;
|
|
354
354
|
let normalizedPath = path2.startsWith("/") ? path2 : `/${path2}`;
|
|
355
355
|
normalizedPath = normalizedPath.replace(/\/$/, "");
|
|
356
|
-
if (/[<>"\s]
|
|
356
|
+
if (/[<>"\s]|\.\.\/|^https?:|^\/\//.test(normalizedPath)) {
|
|
357
357
|
return {
|
|
358
358
|
error: "Invalid path",
|
|
359
|
-
details: ["Path contains invalid characters"],
|
|
359
|
+
details: ["Path contains invalid characters or patterns"],
|
|
360
360
|
suggestion: `Use a clean path like '/develop/faq' or '/getting-started/installation'`
|
|
361
361
|
};
|
|
362
362
|
}
|
|
@@ -667,6 +667,8 @@ USAGE GUIDANCE:
|
|
|
667
667
|
},
|
|
668
668
|
annotations: {
|
|
669
669
|
readOnlyHint: true,
|
|
670
|
+
idempotentHint: true,
|
|
671
|
+
// Same path returns same content
|
|
670
672
|
openWorldHint: true,
|
|
671
673
|
// Fetches from external URL
|
|
672
674
|
title: "\u{1F310} Fetch Live Docs",
|
|
@@ -8730,13 +8732,25 @@ var INTENT_TO_TOOL = [
|
|
|
8730
8732
|
{
|
|
8731
8733
|
patterns: [
|
|
8732
8734
|
"fetch docs",
|
|
8733
|
-
"
|
|
8734
|
-
"
|
|
8735
|
+
"fetch documentation",
|
|
8736
|
+
"fetch the docs",
|
|
8737
|
+
"fetch the latest",
|
|
8738
|
+
"get the docs page",
|
|
8739
|
+
"get latest docs",
|
|
8735
8740
|
"live docs",
|
|
8736
|
-
"docs
|
|
8737
|
-
"
|
|
8738
|
-
"
|
|
8739
|
-
"
|
|
8741
|
+
"real-time docs",
|
|
8742
|
+
"realtime docs",
|
|
8743
|
+
"current docs",
|
|
8744
|
+
"fresh docs",
|
|
8745
|
+
"updated docs",
|
|
8746
|
+
"faq page",
|
|
8747
|
+
"installation page",
|
|
8748
|
+
"getting started page",
|
|
8749
|
+
"/develop/",
|
|
8750
|
+
"/getting-started/",
|
|
8751
|
+
"/compact",
|
|
8752
|
+
"/blog",
|
|
8753
|
+
"/learn/"
|
|
8740
8754
|
],
|
|
8741
8755
|
tool: "midnight-fetch-docs",
|
|
8742
8756
|
reason: "Fetch live documentation directly from docs.midnight.network"
|
|
@@ -9015,14 +9029,21 @@ async function suggestTool(input) {
|
|
|
9015
9029
|
const intentLower = input.intent.toLowerCase();
|
|
9016
9030
|
const matchedTools = [];
|
|
9017
9031
|
for (const mapping of INTENT_TO_TOOL) {
|
|
9018
|
-
const
|
|
9032
|
+
const matchedPatterns = mapping.patterns.filter(
|
|
9019
9033
|
(p) => intentLower.includes(p.toLowerCase())
|
|
9020
|
-
)
|
|
9034
|
+
);
|
|
9035
|
+
const matchCount = matchedPatterns.length;
|
|
9021
9036
|
if (matchCount > 0) {
|
|
9037
|
+
const patternLengthScore = matchedPatterns.reduce(
|
|
9038
|
+
(sum, p) => sum + p.length,
|
|
9039
|
+
0
|
|
9040
|
+
);
|
|
9041
|
+
const matchScore = matchCount * 10 + patternLengthScore;
|
|
9022
9042
|
matchedTools.push({
|
|
9023
9043
|
tool: mapping.tool,
|
|
9024
9044
|
reason: mapping.reason,
|
|
9025
|
-
confidence: matchCount >= 2 ? "high" : "medium"
|
|
9045
|
+
confidence: matchCount >= 2 ? "high" : "medium",
|
|
9046
|
+
matchScore
|
|
9026
9047
|
});
|
|
9027
9048
|
}
|
|
9028
9049
|
}
|
|
@@ -9041,9 +9062,11 @@ async function suggestTool(input) {
|
|
|
9041
9062
|
}
|
|
9042
9063
|
}
|
|
9043
9064
|
const confidenceOrder = { high: 0, medium: 1, low: 2 };
|
|
9044
|
-
matchedTools.sort(
|
|
9045
|
-
|
|
9046
|
-
|
|
9065
|
+
matchedTools.sort((a, b) => {
|
|
9066
|
+
const confDiff = confidenceOrder[a.confidence] - confidenceOrder[b.confidence];
|
|
9067
|
+
if (confDiff !== 0) return confDiff;
|
|
9068
|
+
return b.matchScore - a.matchScore;
|
|
9069
|
+
});
|
|
9047
9070
|
if (matchedTools.length === 0 && matchedCategories.length === 0) {
|
|
9048
9071
|
return {
|
|
9049
9072
|
intent: input.intent,
|
|
@@ -9292,4 +9315,4 @@ export {
|
|
|
9292
9315
|
startServer,
|
|
9293
9316
|
startHttpServer
|
|
9294
9317
|
};
|
|
9295
|
-
//# sourceMappingURL=chunk-
|
|
9318
|
+
//# sourceMappingURL=chunk-L5CXYFG2.js.map
|
|
@@ -1594,7 +1594,7 @@ async function checkGitHubAPI() {
|
|
|
1594
1594
|
}
|
|
1595
1595
|
async function checkVectorStore() {
|
|
1596
1596
|
try {
|
|
1597
|
-
const { vectorStore: vectorStore2 } = await import("./db-
|
|
1597
|
+
const { vectorStore: vectorStore2 } = await import("./db-2KZMPC3W.js");
|
|
1598
1598
|
if (vectorStore2) {
|
|
1599
1599
|
return {
|
|
1600
1600
|
status: "pass",
|
|
@@ -1898,7 +1898,9 @@ function pruneAllCaches() {
|
|
|
1898
1898
|
setInterval(pruneAllCaches, 5 * 60 * 1e3);
|
|
1899
1899
|
|
|
1900
1900
|
// src/utils/hosted-api.ts
|
|
1901
|
-
var API_TIMEOUT =
|
|
1901
|
+
var API_TIMEOUT = 15e3;
|
|
1902
|
+
var MAX_RETRIES = 2;
|
|
1903
|
+
var RETRY_DELAY_MS = 1e3;
|
|
1902
1904
|
function getActionableErrorMessage(status, endpoint, serverMessage) {
|
|
1903
1905
|
const baseMessages = {
|
|
1904
1906
|
400: `Bad request to ${endpoint}. Check your query parameters are valid.`,
|
|
@@ -1932,8 +1934,17 @@ async function parseApiError(response, endpoint) {
|
|
|
1932
1934
|
);
|
|
1933
1935
|
return new Error(actionableMessage);
|
|
1934
1936
|
}
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
+
function isRetryableError2(error) {
|
|
1938
|
+
if (error instanceof Error) {
|
|
1939
|
+
const message = error.message.toLowerCase();
|
|
1940
|
+
return error.name === "AbortError" || message.includes("timeout") || message.includes("network") || message.includes("econnreset") || message.includes("502") || message.includes("503") || message.includes("504") || message.includes("bad gateway") || message.includes("service unavailable") || message.includes("gateway timeout");
|
|
1941
|
+
}
|
|
1942
|
+
return false;
|
|
1943
|
+
}
|
|
1944
|
+
function sleep2(ms) {
|
|
1945
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1946
|
+
}
|
|
1947
|
+
async function makeRequest(url, endpoint, options) {
|
|
1937
1948
|
const controller = new AbortController();
|
|
1938
1949
|
const timeout = setTimeout(() => controller.abort(), API_TIMEOUT);
|
|
1939
1950
|
try {
|
|
@@ -1953,21 +1964,54 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
1953
1964
|
} catch (error) {
|
|
1954
1965
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1955
1966
|
throw new Error(
|
|
1956
|
-
`Request to ${endpoint} timed out after ${API_TIMEOUT / 1e3}s
|
|
1967
|
+
`Request to ${endpoint} timed out after ${API_TIMEOUT / 1e3}s.`
|
|
1957
1968
|
);
|
|
1958
1969
|
}
|
|
1959
|
-
|
|
1960
|
-
|
|
1970
|
+
throw error;
|
|
1971
|
+
} finally {
|
|
1972
|
+
clearTimeout(timeout);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
async function apiRequest(endpoint, options = {}) {
|
|
1976
|
+
const url = `${config.hostedApiUrl}${endpoint}`;
|
|
1977
|
+
let lastError = null;
|
|
1978
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
1979
|
+
try {
|
|
1980
|
+
return await makeRequest(url, endpoint, options);
|
|
1981
|
+
} catch (error) {
|
|
1982
|
+
lastError = error;
|
|
1983
|
+
if (!isRetryableError2(error)) {
|
|
1984
|
+
break;
|
|
1985
|
+
}
|
|
1986
|
+
if (attempt === MAX_RETRIES) {
|
|
1987
|
+
logger.warn(`Hosted API request failed after ${attempt + 1} attempts`, {
|
|
1988
|
+
endpoint,
|
|
1989
|
+
error: String(error)
|
|
1990
|
+
});
|
|
1991
|
+
break;
|
|
1992
|
+
}
|
|
1993
|
+
const delay = RETRY_DELAY_MS * Math.pow(2, attempt);
|
|
1994
|
+
logger.debug(
|
|
1995
|
+
`Retrying hosted API request in ${delay}ms (attempt ${attempt + 1}/${MAX_RETRIES + 1})`,
|
|
1996
|
+
{ endpoint }
|
|
1997
|
+
);
|
|
1998
|
+
await sleep2(delay);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
if (lastError) {
|
|
2002
|
+
if (lastError.message.includes("github.com/Olanetsoft")) {
|
|
2003
|
+
throw lastError;
|
|
1961
2004
|
}
|
|
1962
|
-
if (
|
|
2005
|
+
if (lastError.message.includes("timed out")) {
|
|
1963
2006
|
throw new Error(
|
|
1964
|
-
`
|
|
2007
|
+
`Request to ${endpoint} timed out after ${MAX_RETRIES + 1} attempts. The hosted service may be slow or unavailable. Try a simpler query or set MIDNIGHT_LOCAL=true for local search.`
|
|
1965
2008
|
);
|
|
1966
2009
|
}
|
|
1967
|
-
throw
|
|
1968
|
-
|
|
1969
|
-
|
|
2010
|
+
throw new Error(
|
|
2011
|
+
`Failed to connect to hosted API after ${MAX_RETRIES + 1} attempts: ${lastError.message}. Check your internet connection or set MIDNIGHT_LOCAL=true for local search.`
|
|
2012
|
+
);
|
|
1970
2013
|
}
|
|
2014
|
+
throw new Error("Unknown error in API request");
|
|
1971
2015
|
}
|
|
1972
2016
|
async function searchCompactHosted(query, limit = 10) {
|
|
1973
2017
|
logger.debug("Searching Compact code via hosted API", { query });
|
|
@@ -2025,7 +2069,7 @@ function serialize(data) {
|
|
|
2025
2069
|
}
|
|
2026
2070
|
|
|
2027
2071
|
// src/utils/version.ts
|
|
2028
|
-
var CURRENT_VERSION = "0.2.
|
|
2072
|
+
var CURRENT_VERSION = "0.2.6";
|
|
2029
2073
|
|
|
2030
2074
|
// src/db/vectorStore.ts
|
|
2031
2075
|
var VectorStore = class {
|
|
@@ -2234,4 +2278,4 @@ export {
|
|
|
2234
2278
|
serialize,
|
|
2235
2279
|
CURRENT_VERSION
|
|
2236
2280
|
};
|
|
2237
|
-
//# sourceMappingURL=chunk-
|
|
2281
|
+
//# sourceMappingURL=chunk-WC2FPYQO.js.map
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
promptDefinitions,
|
|
10
10
|
startHttpServer,
|
|
11
11
|
startServer
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-L5CXYFG2.js";
|
|
13
13
|
import {
|
|
14
14
|
logger
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-WC2FPYQO.js";
|
|
16
16
|
export {
|
|
17
17
|
allResources,
|
|
18
18
|
allTools,
|
package/package.json
CHANGED