@nirvana-labs/nirvana-mcp 1.47.0 → 1.48.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/instructions.d.mts +2 -0
- package/instructions.d.mts.map +1 -0
- package/instructions.d.ts +2 -0
- package/instructions.d.ts.map +1 -0
- package/instructions.js +55 -0
- package/instructions.js.map +1 -0
- package/instructions.mjs +52 -0
- package/instructions.mjs.map +1 -0
- package/package.json +12 -2
- package/server.d.mts.map +1 -1
- package/server.d.ts.map +1 -1
- package/server.js +3 -29
- package/server.js.map +1 -1
- package/server.mjs +2 -28
- package/server.mjs.map +1 -1
- package/src/instructions.ts +74 -0
- package/src/server.ts +2 -38
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.mts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AA0BA,wBAAsB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAW1F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AA0BA,wBAAsB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAW1F"}
|
package/instructions.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getInstructions = getInstructions;
|
|
5
|
+
const util_1 = require("./util.js");
|
|
6
|
+
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
7
|
+
const instructionsCache = new Map();
|
|
8
|
+
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
9
|
+
const _cacheCleanupInterval = setInterval(() => {
|
|
10
|
+
const now = Date.now();
|
|
11
|
+
for (const [key, entry] of instructionsCache) {
|
|
12
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
13
|
+
instructionsCache.delete(key);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
17
|
+
// Don't keep the process alive just for cleanup.
|
|
18
|
+
_cacheCleanupInterval.unref();
|
|
19
|
+
async function getInstructions(stainlessApiKey) {
|
|
20
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
21
|
+
const cached = instructionsCache.get(cacheKey);
|
|
22
|
+
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
23
|
+
return cached.fetchedInstructions;
|
|
24
|
+
}
|
|
25
|
+
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
26
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
27
|
+
return fetchedInstructions;
|
|
28
|
+
}
|
|
29
|
+
async function fetchLatestInstructions(stainlessApiKey) {
|
|
30
|
+
// Setting the stainless API key is optional, but may be required
|
|
31
|
+
// to authenticate requests to the Stainless API.
|
|
32
|
+
const response = await fetch((0, util_1.readEnv)('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/nirvana', {
|
|
33
|
+
method: 'GET',
|
|
34
|
+
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
35
|
+
});
|
|
36
|
+
let instructions;
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
39
|
+
instructions = `
|
|
40
|
+
This is the nirvana MCP server. You will use Code Mode to help the user perform
|
|
41
|
+
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
42
|
+
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
43
|
+
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
44
|
+
block: it can be as long as you need to get the job done!
|
|
45
|
+
`;
|
|
46
|
+
}
|
|
47
|
+
instructions ??= (await response.json()).instructions;
|
|
48
|
+
instructions = `
|
|
49
|
+
If needed, you can get the current time by executing Date.now().
|
|
50
|
+
|
|
51
|
+
${instructions}
|
|
52
|
+
`;
|
|
53
|
+
return instructions;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;AA0BtF,0CAWC;AAnCD,oCAAiC;AAEjC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAO/D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;AAEpE,0EAA0E;AAC1E,MAAM,qBAAqB,GAAG,WAAW,CAAC,GAAG,EAAE;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,iBAAiB,EAAE,CAAC;QAC7C,IAAI,GAAG,GAAG,KAAK,CAAC,SAAS,GAAG,yBAAyB,EAAE,CAAC;YACtD,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC,EAAE,yBAAyB,CAAC,CAAC;AAE9B,iDAAiD;AACjD,qBAAqB,CAAC,KAAK,EAAE,CAAC;AAEvB,KAAK,UAAU,eAAe,CAAC,eAAmC;IACvE,MAAM,QAAQ,GAAG,eAAe,IAAI,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE/C,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,yBAAyB,EAAE,CAAC;QACzE,OAAO,MAAM,CAAC,mBAAmB,CAAC;IACpC,CAAC;IAED,MAAM,mBAAmB,GAAG,MAAM,uBAAuB,CAAC,eAAe,CAAC,CAAC;IAC3E,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAChF,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED,KAAK,UAAU,uBAAuB,CAAC,eAAmC;IACxE,iEAAiE;IACjE,iDAAiD;IACjD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,IAAA,cAAO,EAAC,4BAA4B,CAAC,IAAI,uDAAuD,EAChG;QACE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE,GAAG,CAAC,eAAe,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC,EAAE;KACxE,CACF,CAAC;IAEF,IAAI,YAAgC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CACV,8FAA8F,CAC/F,CAAC;QAEF,YAAY,GAAG;;;;;;KAMd,CAAC;IACJ,CAAC;IAED,YAAY,KAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA8B,CAAC,YAAY,CAAC;IACpF,YAAY,GAAG;;;MAGX,YAAY;GACf,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/instructions.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
import { readEnv } from "./util.mjs";
|
|
3
|
+
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
4
|
+
const instructionsCache = new Map();
|
|
5
|
+
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
6
|
+
const _cacheCleanupInterval = setInterval(() => {
|
|
7
|
+
const now = Date.now();
|
|
8
|
+
for (const [key, entry] of instructionsCache) {
|
|
9
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
10
|
+
instructionsCache.delete(key);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
14
|
+
// Don't keep the process alive just for cleanup.
|
|
15
|
+
_cacheCleanupInterval.unref();
|
|
16
|
+
export async function getInstructions(stainlessApiKey) {
|
|
17
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
18
|
+
const cached = instructionsCache.get(cacheKey);
|
|
19
|
+
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
20
|
+
return cached.fetchedInstructions;
|
|
21
|
+
}
|
|
22
|
+
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
23
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
24
|
+
return fetchedInstructions;
|
|
25
|
+
}
|
|
26
|
+
async function fetchLatestInstructions(stainlessApiKey) {
|
|
27
|
+
// Setting the stainless API key is optional, but may be required
|
|
28
|
+
// to authenticate requests to the Stainless API.
|
|
29
|
+
const response = await fetch(readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/nirvana', {
|
|
30
|
+
method: 'GET',
|
|
31
|
+
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
32
|
+
});
|
|
33
|
+
let instructions;
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
36
|
+
instructions = `
|
|
37
|
+
This is the nirvana MCP server. You will use Code Mode to help the user perform
|
|
38
|
+
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
39
|
+
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
40
|
+
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
41
|
+
block: it can be as long as you need to get the job done!
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
instructions ??= (await response.json()).instructions;
|
|
45
|
+
instructions = `
|
|
46
|
+
If needed, you can get the current time by executing Date.now().
|
|
47
|
+
|
|
48
|
+
${instructions}
|
|
49
|
+
`;
|
|
50
|
+
return instructions;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=instructions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.mjs","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,OAAO,EAAE;AAElB,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAO/D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;AAEpE,0EAA0E;AAC1E,MAAM,qBAAqB,GAAG,WAAW,CAAC,GAAG,EAAE;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,iBAAiB,EAAE,CAAC;QAC7C,IAAI,GAAG,GAAG,KAAK,CAAC,SAAS,GAAG,yBAAyB,EAAE,CAAC;YACtD,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;AACH,CAAC,EAAE,yBAAyB,CAAC,CAAC;AAE9B,iDAAiD;AACjD,qBAAqB,CAAC,KAAK,EAAE,CAAC;AAE9B,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,eAAmC;IACvE,MAAM,QAAQ,GAAG,eAAe,IAAI,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE/C,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,yBAAyB,EAAE,CAAC;QACzE,OAAO,MAAM,CAAC,mBAAmB,CAAC;IACpC,CAAC;IAED,MAAM,mBAAmB,GAAG,MAAM,uBAAuB,CAAC,eAAe,CAAC,CAAC;IAC3E,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,mBAAmB,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAChF,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED,KAAK,UAAU,uBAAuB,CAAC,eAAmC;IACxE,iEAAiE;IACjE,iDAAiD;IACjD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,OAAO,CAAC,4BAA4B,CAAC,IAAI,uDAAuD,EAChG;QACE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE,GAAG,CAAC,eAAe,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC,EAAE;KACxE,CACF,CAAC;IAEF,IAAI,YAAgC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CACV,8FAA8F,CAC/F,CAAC;QAEF,YAAY,GAAG;;;;;;KAMd,CAAC;IACJ,CAAC;IAED,YAAY,KAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA8B,CAAC,YAAY,CAAC;IACpF,YAAY,GAAG;;;MAGX,YAAY;GACf,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nirvana-labs/nirvana-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.0",
|
|
4
4
|
"description": "The official MCP Server for the Nirvana Labs API",
|
|
5
5
|
"author": "Nirvana Labs <engineering@nirvanalabs.io>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@nirvana-labs/nirvana": "^1.
|
|
21
|
+
"@nirvana-labs/nirvana": "^1.48.0",
|
|
22
22
|
"@cloudflare/cabidela": "^0.2.4",
|
|
23
23
|
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
24
24
|
"@valtown/deno-http-worker": "^0.0.21",
|
|
@@ -112,6 +112,16 @@
|
|
|
112
112
|
"./index.mjs": {
|
|
113
113
|
"default": "./index.mjs"
|
|
114
114
|
},
|
|
115
|
+
"./instructions": {
|
|
116
|
+
"import": "./instructions.mjs",
|
|
117
|
+
"require": "./instructions.js"
|
|
118
|
+
},
|
|
119
|
+
"./instructions.js": {
|
|
120
|
+
"default": "./instructions.js"
|
|
121
|
+
},
|
|
122
|
+
"./instructions.mjs": {
|
|
123
|
+
"default": "./instructions.mjs"
|
|
124
|
+
},
|
|
115
125
|
"./methods": {
|
|
116
126
|
"import": "./methods.mjs",
|
|
117
127
|
"require": "./methods.js"
|
package/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,uBAAuB;
|
|
1
|
+
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,uBAAuB;OAK9C,EAAE,UAAU,EAAE;OAEd,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE;AAEtE,eAAO,MAAM,YAAY,GAAU,iBAAiB,MAAM,GAAG,SAAS,uBAUnE,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,iBA2EA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAU3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GACL,EAAE;IACD,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1B"}
|
package/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,uBAAuB;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"OAEO,EAAE,MAAM,EAAE,MAAM,2CAA2C;OAC3D,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAM5D,EAAE,aAAa,EAAE,MAAM,uBAAuB;OAK9C,EAAE,UAAU,EAAE;OAEd,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE;AAEtE,eAAO,MAAM,YAAY,GAAU,iBAAiB,MAAM,GAAG,SAAS,uBAUnE,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC,iBA2EA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAU3D;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GACL,EAAE;IACD,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1B"}
|
package/server.js
CHANGED
|
@@ -13,39 +13,13 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
13
13
|
const nirvana_1 = __importDefault(require("@nirvana-labs/nirvana"));
|
|
14
14
|
const code_tool_1 = require("./code-tool.js");
|
|
15
15
|
const docs_search_tool_1 = __importDefault(require("./docs-search-tool.js"));
|
|
16
|
+
const instructions_1 = require("./instructions.js");
|
|
16
17
|
const methods_1 = require("./methods.js");
|
|
17
|
-
const util_1 = require("./util.js");
|
|
18
|
-
async function getInstructions(stainlessApiKey) {
|
|
19
|
-
// Setting the stainless API key is optional, but may be required
|
|
20
|
-
// to authenticate requests to the Stainless API.
|
|
21
|
-
const response = await fetch((0, util_1.readEnv)('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/nirvana', {
|
|
22
|
-
method: 'GET',
|
|
23
|
-
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
24
|
-
});
|
|
25
|
-
let instructions;
|
|
26
|
-
if (!response.ok) {
|
|
27
|
-
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
28
|
-
instructions = `
|
|
29
|
-
This is the nirvana MCP server. You will use Code Mode to help the user perform
|
|
30
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
31
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
32
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
33
|
-
block: it can be as long as you need to get the job done!
|
|
34
|
-
`;
|
|
35
|
-
}
|
|
36
|
-
instructions ??= (await response.json()).instructions;
|
|
37
|
-
instructions = `
|
|
38
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
39
|
-
|
|
40
|
-
${instructions}
|
|
41
|
-
`;
|
|
42
|
-
return instructions;
|
|
43
|
-
}
|
|
44
18
|
const newMcpServer = async (stainlessApiKey) => new mcp_js_1.McpServer({
|
|
45
19
|
name: 'nirvana_labs_nirvana_api',
|
|
46
|
-
version: '1.
|
|
20
|
+
version: '1.48.0',
|
|
47
21
|
}, {
|
|
48
|
-
instructions: await getInstructions(stainlessApiKey),
|
|
22
|
+
instructions: await (0, instructions_1.getInstructions)(stainlessApiKey),
|
|
49
23
|
capabilities: { tools: {}, logging: {} },
|
|
50
24
|
});
|
|
51
25
|
exports.newMcpServer = newMcpServer;
|
package/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAkCtF,sCAgFC;AAKD,kCAUC;AAKD,wCAUC;AA7ID,oEAAoE;AACpE,iEAI4C;AAE5C,oEAAgD;AAChD,8CAAuC;AACvC,6EAAgD;AAChD,oDAAiD;AAEjD,0CAAsD;AAG/C,MAAM,YAAY,GAAG,KAAK,EAAE,eAAmC,EAAE,EAAE,CACxE,IAAI,kBAAS,CACX;IACE,IAAI,EAAE,0BAA0B;IAChC,OAAO,EAAE,QAAQ;CAClB,EACD;IACE,YAAY,EAAE,MAAM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QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,OAAO;gBACV,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;gBACnD,MAAM;YACR;gBACE,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;gBACjD,MAAM;QACV,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,OAAoB;IAC9C,MAAM,aAAa,GAAG;QACpB,IAAA,oBAAQ,EAAC;YACP,cAAc,EAAE,IAAA,mCAAyB,EAAC,OAAO,CAAC;SACnD,CAAC;KACH,CAAC;IACF,IAAI,OAAO,EAAE,gBAAgB,IAAI,IAAI,EAAE,CAAC;QACtC,aAAa,CAAC,IAAI,CAAC,0BAAc,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GAKL;IACC,OAAO,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
package/server.mjs
CHANGED
|
@@ -4,37 +4,11 @@ import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema, }
|
|
|
4
4
|
import NirvanaLabs from '@nirvana-labs/nirvana';
|
|
5
5
|
import { codeTool } from "./code-tool.mjs";
|
|
6
6
|
import docsSearchTool from "./docs-search-tool.mjs";
|
|
7
|
+
import { getInstructions } from "./instructions.mjs";
|
|
7
8
|
import { blockedMethodsForCodeTool } from "./methods.mjs";
|
|
8
|
-
import { readEnv } from "./util.mjs";
|
|
9
|
-
async function getInstructions(stainlessApiKey) {
|
|
10
|
-
// Setting the stainless API key is optional, but may be required
|
|
11
|
-
// to authenticate requests to the Stainless API.
|
|
12
|
-
const response = await fetch(readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/nirvana', {
|
|
13
|
-
method: 'GET',
|
|
14
|
-
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
15
|
-
});
|
|
16
|
-
let instructions;
|
|
17
|
-
if (!response.ok) {
|
|
18
|
-
console.warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
19
|
-
instructions = `
|
|
20
|
-
This is the nirvana MCP server. You will use Code Mode to help the user perform
|
|
21
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
22
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
23
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
24
|
-
block: it can be as long as you need to get the job done!
|
|
25
|
-
`;
|
|
26
|
-
}
|
|
27
|
-
instructions ??= (await response.json()).instructions;
|
|
28
|
-
instructions = `
|
|
29
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
30
|
-
|
|
31
|
-
${instructions}
|
|
32
|
-
`;
|
|
33
|
-
return instructions;
|
|
34
|
-
}
|
|
35
9
|
export const newMcpServer = async (stainlessApiKey) => new McpServer({
|
|
36
10
|
name: 'nirvana_labs_nirvana_api',
|
|
37
|
-
version: '1.
|
|
11
|
+
version: '1.48.0',
|
|
38
12
|
}, {
|
|
39
13
|
instructions: await getInstructions(stainlessApiKey),
|
|
40
14
|
capabilities: { tools: {}, logging: {} },
|
package/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAG/E,EAAE,SAAS,EAAE,MAAM,yCAAyC;OAC5D,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC;OAEpC,WAAW,MAAM,uB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IAAI,GAKL;IACC,OAAO,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { readEnv } from './util';
|
|
4
|
+
|
|
5
|
+
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
6
|
+
|
|
7
|
+
interface InstructionsCacheEntry {
|
|
8
|
+
fetchedInstructions: string;
|
|
9
|
+
fetchedAt: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const instructionsCache = new Map<string, InstructionsCacheEntry>();
|
|
13
|
+
|
|
14
|
+
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
15
|
+
const _cacheCleanupInterval = setInterval(() => {
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
for (const [key, entry] of instructionsCache) {
|
|
18
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
19
|
+
instructionsCache.delete(key);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
23
|
+
|
|
24
|
+
// Don't keep the process alive just for cleanup.
|
|
25
|
+
_cacheCleanupInterval.unref();
|
|
26
|
+
|
|
27
|
+
export async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
28
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
29
|
+
const cached = instructionsCache.get(cacheKey);
|
|
30
|
+
|
|
31
|
+
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
32
|
+
return cached.fetchedInstructions;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
36
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
37
|
+
return fetchedInstructions;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function fetchLatestInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
41
|
+
// Setting the stainless API key is optional, but may be required
|
|
42
|
+
// to authenticate requests to the Stainless API.
|
|
43
|
+
const response = await fetch(
|
|
44
|
+
readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/nirvana',
|
|
45
|
+
{
|
|
46
|
+
method: 'GET',
|
|
47
|
+
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
let instructions: string | undefined;
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
console.warn(
|
|
54
|
+
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
instructions = `
|
|
58
|
+
This is the nirvana MCP server. You will use Code Mode to help the user perform
|
|
59
|
+
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
60
|
+
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
61
|
+
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
62
|
+
block: it can be as long as you need to get the job done!
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
instructions ??= ((await response.json()) as { instructions: string }).instructions;
|
|
67
|
+
instructions = `
|
|
68
|
+
If needed, you can get the current time by executing Date.now().
|
|
69
|
+
|
|
70
|
+
${instructions}
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
return instructions;
|
|
74
|
+
}
|
package/src/server.ts
CHANGED
|
@@ -11,52 +11,16 @@ import { ClientOptions } from '@nirvana-labs/nirvana';
|
|
|
11
11
|
import NirvanaLabs from '@nirvana-labs/nirvana';
|
|
12
12
|
import { codeTool } from './code-tool';
|
|
13
13
|
import docsSearchTool from './docs-search-tool';
|
|
14
|
+
import { getInstructions } from './instructions';
|
|
14
15
|
import { McpOptions } from './options';
|
|
15
16
|
import { blockedMethodsForCodeTool } from './methods';
|
|
16
17
|
import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from './types';
|
|
17
|
-
import { readEnv } from './util';
|
|
18
|
-
|
|
19
|
-
async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
20
|
-
// Setting the stainless API key is optional, but may be required
|
|
21
|
-
// to authenticate requests to the Stainless API.
|
|
22
|
-
const response = await fetch(
|
|
23
|
-
readEnv('CODE_MODE_INSTRUCTIONS_URL') ?? 'https://api.stainless.com/api/ai/instructions/nirvana',
|
|
24
|
-
{
|
|
25
|
-
method: 'GET',
|
|
26
|
-
headers: { ...(stainlessApiKey && { Authorization: stainlessApiKey }) },
|
|
27
|
-
},
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
let instructions: string | undefined;
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
console.warn(
|
|
33
|
-
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
instructions = `
|
|
37
|
-
This is the nirvana MCP server. You will use Code Mode to help the user perform
|
|
38
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
39
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
40
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
41
|
-
block: it can be as long as you need to get the job done!
|
|
42
|
-
`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
instructions ??= ((await response.json()) as { instructions: string }).instructions;
|
|
46
|
-
instructions = `
|
|
47
|
-
The current time in Unix timestamps is ${Date.now()}.
|
|
48
|
-
|
|
49
|
-
${instructions}
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
return instructions;
|
|
53
|
-
}
|
|
54
18
|
|
|
55
19
|
export const newMcpServer = async (stainlessApiKey: string | undefined) =>
|
|
56
20
|
new McpServer(
|
|
57
21
|
{
|
|
58
22
|
name: 'nirvana_labs_nirvana_api',
|
|
59
|
-
version: '1.
|
|
23
|
+
version: '1.48.0',
|
|
60
24
|
},
|
|
61
25
|
{
|
|
62
26
|
instructions: await getInstructions(stainlessApiKey),
|