cas-parser-node-mcp 1.10.0 → 1.10.2
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/code-tool-paths.cjs +4 -2
- package/code-tool-paths.cjs.map +1 -1
- package/code-tool-paths.d.cts +1 -1
- package/code-tool-paths.d.cts.map +1 -1
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +32 -23
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +23 -11
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +4 -1
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +4 -1
- package/docs-search-tool.mjs.map +1 -1
- package/http.d.mts.map +1 -1
- package/http.d.ts.map +1 -1
- package/http.js +41 -2
- package/http.js.map +1 -1
- package/http.mjs +41 -2
- package/http.mjs.map +1 -1
- package/instructions.d.mts.map +1 -1
- package/instructions.d.ts.map +1 -1
- package/instructions.js +10 -24
- package/instructions.js.map +1 -1
- package/instructions.mjs +10 -24
- package/instructions.mjs.map +1 -1
- package/package.json +8 -5
- package/server.d.mts +1 -0
- package/server.d.mts.map +1 -1
- package/server.d.ts +1 -0
- package/server.d.ts.map +1 -1
- package/server.js +2 -1
- package/server.js.map +1 -1
- package/server.mjs +2 -1
- package/server.mjs.map +1 -1
- package/src/code-tool-paths.cts +3 -1
- package/src/code-tool.ts +37 -19
- package/src/docs-search-tool.ts +9 -1
- package/src/http.ts +44 -2
- package/src/instructions.ts +12 -27
- package/src/server.ts +3 -1
- package/src/types.ts +1 -0
- package/types.d.mts +1 -0
- package/types.d.mts.map +1 -1
- package/types.d.ts +1 -0
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/types.mjs.map +1 -1
package/http.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.mjs","sourceRoot":"","sources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AAE,CAAC,CAAC,CAAC;IACnD,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAErB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAAE,EAC/C,UAAU,EACV,IAAI,GAIL,EAAE,EAAE;IACH,MAAM,GAAG,GAAG,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,4CAA4C,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;SAAM,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC,iDAAiD,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/E,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,iDAAiD,IAAI,EAAE,CAAC,CAAC;IACvE,CAAC;AACH,CAAC,CAAC"}
|
package/instructions.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.mts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instructions.d.mts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AAcA,wBAAsB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAmB1F"}
|
package/instructions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AAcA,wBAAsB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAmB1F"}
|
package/instructions.js
CHANGED
|
@@ -6,25 +6,21 @@ const util_1 = require("./util.js");
|
|
|
6
6
|
const logger_1 = require("./logger.js");
|
|
7
7
|
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
8
8
|
const instructionsCache = new Map();
|
|
9
|
-
|
|
10
|
-
const _cacheCleanupInterval = setInterval(() => {
|
|
9
|
+
async function getInstructions(stainlessApiKey) {
|
|
11
10
|
const now = Date.now();
|
|
11
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
12
|
+
const cached = instructionsCache.get(cacheKey);
|
|
13
|
+
if (cached && now - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
14
|
+
return cached.fetchedInstructions;
|
|
15
|
+
}
|
|
16
|
+
// Evict stale entries so the cache doesn't grow unboundedly.
|
|
12
17
|
for (const [key, entry] of instructionsCache) {
|
|
13
18
|
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
14
19
|
instructionsCache.delete(key);
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
|
-
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
18
|
-
// Don't keep the process alive just for cleanup.
|
|
19
|
-
_cacheCleanupInterval.unref();
|
|
20
|
-
async function getInstructions(stainlessApiKey) {
|
|
21
|
-
const cacheKey = stainlessApiKey ?? '';
|
|
22
|
-
const cached = instructionsCache.get(cacheKey);
|
|
23
|
-
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
24
|
-
return cached.fetchedInstructions;
|
|
25
|
-
}
|
|
26
22
|
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
27
|
-
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt:
|
|
23
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: now });
|
|
28
24
|
return fetchedInstructions;
|
|
29
25
|
}
|
|
30
26
|
async function fetchLatestInstructions(stainlessApiKey) {
|
|
@@ -37,20 +33,10 @@ async function fetchLatestInstructions(stainlessApiKey) {
|
|
|
37
33
|
let instructions;
|
|
38
34
|
if (!response.ok) {
|
|
39
35
|
(0, logger_1.getLogger)().warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
40
|
-
instructions =
|
|
41
|
-
|
|
42
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
43
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
44
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
45
|
-
block: it can be as long as you need to get the job done!
|
|
46
|
-
`;
|
|
36
|
+
instructions =
|
|
37
|
+
'\n This is the cas-parser MCP server.\n\n Available tools:\n - search_docs: Search SDK documentation to find the right methods and parameters.\n - execute: Run TypeScript code against a pre-authenticated SDK client. Define an async run(client) function.\n\n Workflow:\n - If unsure about the API, call search_docs first.\n - Write complete solutions in a single execute call when possible. For large datasets, use API filters to narrow results or paginate within a single execute block.\n - If execute returns an error, read the error and fix your code rather than retrying the same approach.\n - Variables do not persist between execute calls. Return or log all data you need.\n - Individual HTTP requests to the API have a 30-second timeout. If a request times out, try a smaller query or add filters.\n - Code execution has a total timeout of approximately 5 minutes. If your code times out, simplify it or break it into smaller steps.\n ';
|
|
47
38
|
}
|
|
48
39
|
instructions ??= (await response.json()).instructions;
|
|
49
|
-
instructions = `
|
|
50
|
-
If needed, you can get the current time by executing Date.now().
|
|
51
|
-
|
|
52
|
-
${instructions}
|
|
53
|
-
`;
|
|
54
40
|
return instructions;
|
|
55
41
|
}
|
|
56
42
|
//# sourceMappingURL=instructions.js.map
|
package/instructions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;AActF,0CAmBC;AA/BD,oCAAiC;AACjC,wCAAqC;AAErC,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAO/D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;AAE7D,KAAK,UAAU,eAAe,CAAC,eAAmC;IACvE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,eAAe,IAAI,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE/C,IAAI,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,SAAS,IAAI,yBAAyB,EAAE,CAAC;QAClE,OAAO,MAAM,CAAC,mBAAmB,CAAC;IACpC,CAAC;IAED,6DAA6D;IAC7D,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;IAED,MAAM,mBAAmB,GAAG,MAAM,uBAAuB,CAAC,eAAe,CAAC,CAAC;IAC3E,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACzE,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,0DAA0D,EACnG;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,IAAA,kBAAS,GAAE,CAAC,IAAI,CACd,8FAA8F,CAC/F,CAAC;QAEF,YAAY;YACV,27BAA27B,CAAC;IACh8B,CAAC;IAED,YAAY,KAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA8B,CAAC,YAAY,CAAC;IAEpF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/instructions.mjs
CHANGED
|
@@ -3,25 +3,21 @@ import { readEnv } from "./util.mjs";
|
|
|
3
3
|
import { getLogger } from "./logger.mjs";
|
|
4
4
|
const INSTRUCTIONS_CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
5
5
|
const instructionsCache = new Map();
|
|
6
|
-
|
|
7
|
-
const _cacheCleanupInterval = setInterval(() => {
|
|
6
|
+
export async function getInstructions(stainlessApiKey) {
|
|
8
7
|
const now = Date.now();
|
|
8
|
+
const cacheKey = stainlessApiKey ?? '';
|
|
9
|
+
const cached = instructionsCache.get(cacheKey);
|
|
10
|
+
if (cached && now - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
11
|
+
return cached.fetchedInstructions;
|
|
12
|
+
}
|
|
13
|
+
// Evict stale entries so the cache doesn't grow unboundedly.
|
|
9
14
|
for (const [key, entry] of instructionsCache) {
|
|
10
15
|
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
11
16
|
instructionsCache.delete(key);
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
|
-
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
15
|
-
// Don't keep the process alive just for cleanup.
|
|
16
|
-
_cacheCleanupInterval.unref();
|
|
17
|
-
export async function getInstructions(stainlessApiKey) {
|
|
18
|
-
const cacheKey = stainlessApiKey ?? '';
|
|
19
|
-
const cached = instructionsCache.get(cacheKey);
|
|
20
|
-
if (cached && Date.now() - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
21
|
-
return cached.fetchedInstructions;
|
|
22
|
-
}
|
|
23
19
|
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
24
|
-
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt:
|
|
20
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: now });
|
|
25
21
|
return fetchedInstructions;
|
|
26
22
|
}
|
|
27
23
|
async function fetchLatestInstructions(stainlessApiKey) {
|
|
@@ -34,20 +30,10 @@ async function fetchLatestInstructions(stainlessApiKey) {
|
|
|
34
30
|
let instructions;
|
|
35
31
|
if (!response.ok) {
|
|
36
32
|
getLogger().warn('Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...');
|
|
37
|
-
instructions =
|
|
38
|
-
|
|
39
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
40
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
41
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
42
|
-
block: it can be as long as you need to get the job done!
|
|
43
|
-
`;
|
|
33
|
+
instructions =
|
|
34
|
+
'\n This is the cas-parser MCP server.\n\n Available tools:\n - search_docs: Search SDK documentation to find the right methods and parameters.\n - execute: Run TypeScript code against a pre-authenticated SDK client. Define an async run(client) function.\n\n Workflow:\n - If unsure about the API, call search_docs first.\n - Write complete solutions in a single execute call when possible. For large datasets, use API filters to narrow results or paginate within a single execute block.\n - If execute returns an error, read the error and fix your code rather than retrying the same approach.\n - Variables do not persist between execute calls. Return or log all data you need.\n - Individual HTTP requests to the API have a 30-second timeout. If a request times out, try a smaller query or add filters.\n - Code execution has a total timeout of approximately 5 minutes. If your code times out, simplify it or break it into smaller steps.\n ';
|
|
44
35
|
}
|
|
45
36
|
instructions ??= (await response.json()).instructions;
|
|
46
|
-
instructions = `
|
|
47
|
-
If needed, you can get the current time by executing Date.now().
|
|
48
|
-
|
|
49
|
-
${instructions}
|
|
50
|
-
`;
|
|
51
37
|
return instructions;
|
|
52
38
|
}
|
|
53
39
|
//# sourceMappingURL=instructions.mjs.map
|
package/instructions.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.mjs","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,OAAO,EAAE;OACX,EAAE,SAAS,EAAE;AAEpB,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAO/D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;AAEpE,
|
|
1
|
+
{"version":3,"file":"instructions.mjs","sourceRoot":"","sources":["src/instructions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,OAAO,EAAE;OACX,EAAE,SAAS,EAAE;AAEpB,MAAM,yBAAyB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAO/D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkC,CAAC;AAEpE,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,eAAmC;IACvE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,QAAQ,GAAG,eAAe,IAAI,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE/C,IAAI,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,SAAS,IAAI,yBAAyB,EAAE,CAAC;QAClE,OAAO,MAAM,CAAC,mBAAmB,CAAC;IACpC,CAAC;IAED,6DAA6D;IAC7D,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;IAED,MAAM,mBAAmB,GAAG,MAAM,uBAAuB,CAAC,eAAe,CAAC,CAAC;IAC3E,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACzE,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,0DAA0D,EACnG;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,SAAS,EAAE,CAAC,IAAI,CACd,8FAA8F,CAC/F,CAAC;QAEF,YAAY;YACV,27BAA27B,CAAC;IACh8B,CAAC;IAED,YAAY,KAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA8B,CAAC,YAAY,CAAC;IAEpF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cas-parser-node-mcp",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "The official MCP Server for the Cas Parser API",
|
|
5
5
|
"author": "Cas Parser <sameer@casparser.in>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -18,9 +18,12 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"cas-parser-node": "^1.10.
|
|
21
|
+
"cas-parser-node": "^1.10.2",
|
|
22
|
+
"ajv": "^8.18.0",
|
|
22
23
|
"@cloudflare/cabidela": "^0.2.4",
|
|
23
|
-
"@
|
|
24
|
+
"@hono/node-server": "^1.19.10",
|
|
25
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
26
|
+
"hono": "^4.12.4",
|
|
24
27
|
"@valtown/deno-http-worker": "^0.0.21",
|
|
25
28
|
"cookie-parser": "^1.4.6",
|
|
26
29
|
"cors": "^2.8.5",
|
|
@@ -215,7 +218,7 @@
|
|
|
215
218
|
"build": "bash ./build",
|
|
216
219
|
"format": "prettier --write --cache --cache-strategy metadata . !dist",
|
|
217
220
|
"tsn": "ts-node -r tsconfig-paths/register",
|
|
218
|
-
"lint": "eslint
|
|
219
|
-
"fix": "eslint --fix
|
|
221
|
+
"lint": "eslint .",
|
|
222
|
+
"fix": "eslint --fix ."
|
|
220
223
|
}
|
|
221
224
|
}
|
package/server.d.mts
CHANGED
|
@@ -13,6 +13,7 @@ export declare function initMcpServer(params: {
|
|
|
13
13
|
clientOptions?: ClientOptions;
|
|
14
14
|
mcpOptions?: McpOptions;
|
|
15
15
|
stainlessApiKey?: string | undefined;
|
|
16
|
+
upstreamClientEnvs?: Record<string, string> | undefined;
|
|
16
17
|
}): Promise<void>;
|
|
17
18
|
/**
|
|
18
19
|
* Selects the tools to include in the MCP Server based on the provided options.
|
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,iBAAiB;OAKxC,EAAE,UAAU,EA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AAE,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
CHANGED
|
@@ -13,6 +13,7 @@ export declare function initMcpServer(params: {
|
|
|
13
13
|
clientOptions?: ClientOptions;
|
|
14
14
|
mcpOptions?: McpOptions;
|
|
15
15
|
stainlessApiKey?: string | undefined;
|
|
16
|
+
upstreamClientEnvs?: Record<string, string> | undefined;
|
|
16
17
|
}): Promise<void>;
|
|
17
18
|
/**
|
|
18
19
|
* Selects the tools to include in the MCP Server based on the provided options.
|
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,iBAAiB;OAKxC,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;
|
|
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,iBAAiB;OAKxC,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;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CACzD,iBAkHA;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,EAAE,CAe3D;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
|
@@ -17,7 +17,7 @@ const instructions_1 = require("./instructions.js");
|
|
|
17
17
|
const methods_1 = require("./methods.js");
|
|
18
18
|
const newMcpServer = async (stainlessApiKey) => new mcp_js_1.McpServer({
|
|
19
19
|
name: 'cas_parser_node_api',
|
|
20
|
-
version: '1.10.
|
|
20
|
+
version: '1.10.2',
|
|
21
21
|
}, {
|
|
22
22
|
instructions: await (0, instructions_1.getInstructions)(stainlessApiKey),
|
|
23
23
|
capabilities: { tools: {}, logging: {} },
|
|
@@ -101,6 +101,7 @@ async function initMcpServer(params) {
|
|
|
101
101
|
reqContext: {
|
|
102
102
|
client,
|
|
103
103
|
stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey,
|
|
104
|
+
upstreamClientEnvs: params.upstreamClientEnvs,
|
|
104
105
|
},
|
|
105
106
|
args,
|
|
106
107
|
});
|
package/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAkCtF,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAkCtF,sCAwHC;AAKD,kCAeC;AAKD,wCAUC;AA1LD,oEAAoE;AACpE,iEAI4C;AAE5C,sEAAwC;AACxC,8CAAuC;AACvC,6EAAgD;AAChD,oDAAiD;AAEjD,0CAAsD;AAG/C,MAAM,YAAY,GAAG,KAAK,EAAE,eAAmC,EAAE,EAAE,CACxE,IAAI,kBAAS,CACX;IACE,IAAI,EAAE,qBAAqB;IAC3B,OAAO,EAAE,QAAQ;CAClB,EACD;IACE,YAAY,EAAE,MAAM,IAAA,8BAAe,EAAC,eAAe,CAAC;IACpD,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;CACzC,CACF,CAAC;AAVS,QAAA,YAAY,gBAUrB;AAEJ;;;GAGG;AACI,KAAK,UAAU,aAAa,CAAC,MAMnC;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,YAAY,kBAAS,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IAEzF,MAAM,UAAU,GACd,CAAC,KAA6C,EAAE,EAAE,CAClD,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QACtC,KAAK,MAAM,CAAC,kBAAkB,CAAC;YAC7B,KAAK;YACL,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SACxB,CAAC,CAAC;IACL,CA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ACV,IAAI,GAKL;IACC,OAAO,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
package/server.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { getInstructions } from "./instructions.mjs";
|
|
|
8
8
|
import { blockedMethodsForCodeTool } from "./methods.mjs";
|
|
9
9
|
export const newMcpServer = async (stainlessApiKey) => new McpServer({
|
|
10
10
|
name: 'cas_parser_node_api',
|
|
11
|
-
version: '1.10.
|
|
11
|
+
version: '1.10.2',
|
|
12
12
|
}, {
|
|
13
13
|
instructions: await getInstructions(stainlessApiKey),
|
|
14
14
|
capabilities: { tools: {}, logging: {} },
|
|
@@ -91,6 +91,7 @@ export async function initMcpServer(params) {
|
|
|
91
91
|
reqContext: {
|
|
92
92
|
client,
|
|
93
93
|
stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey,
|
|
94
|
+
upstreamClientEnvs: params.upstreamClientEnvs,
|
|
94
95
|
},
|
|
95
96
|
args,
|
|
96
97
|
});
|
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,SAAS,MAAM,iBAAiB;OAChC,EAAE,QAAQ,EAAE;OACZ,cAAc;OACd,EAAE,eAAe,EAAE;OAEnB,EAAE,yBAAyB,EAAE;AAGpC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,eAAmC,EAAE,EAAE,CACxE,IAAI,SAAS,CACX;IACE,IAAI,EAAE,qBAAqB;IAC3B,OAAO,EAAE,QAAQ;CAClB,EACD;IACE,YAAY,EAAE,MAAM,eAAe,CAAC,eAAe,CAAC;IACpD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,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
package/src/code-tool-paths.cts
CHANGED
package/src/code-tool.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import url from 'node:url';
|
|
6
|
-
import { newDenoHTTPWorker } from '@valtown/deno-http-worker';
|
|
7
|
-
import { workerPath } from './code-tool-paths.cjs';
|
|
8
3
|
import {
|
|
9
4
|
ContentBlock,
|
|
10
5
|
McpRequestContext,
|
|
@@ -149,19 +144,23 @@ const remoteStainlessHandler = async ({
|
|
|
149
144
|
|
|
150
145
|
const codeModeEndpoint = readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
|
|
151
146
|
|
|
147
|
+
const localClientEnvs = {
|
|
148
|
+
CAS_PARSER_API_KEY: requireValue(
|
|
149
|
+
readEnv('CAS_PARSER_API_KEY') ?? client.apiKey,
|
|
150
|
+
'set CAS_PARSER_API_KEY environment variable or provide apiKey client option',
|
|
151
|
+
),
|
|
152
|
+
CAS_PARSER_BASE_URL: readEnv('CAS_PARSER_BASE_URL') ?? client.baseURL ?? undefined,
|
|
153
|
+
};
|
|
154
|
+
// Merge any upstream client envs from the request header, with upstream values taking precedence.
|
|
155
|
+
const mergedClientEnvs = { ...localClientEnvs, ...reqContext.upstreamClientEnvs };
|
|
156
|
+
|
|
152
157
|
// Setting a Stainless API key authenticates requests to the code tool endpoint.
|
|
153
158
|
const res = await fetch(codeModeEndpoint, {
|
|
154
159
|
method: 'POST',
|
|
155
160
|
headers: {
|
|
156
161
|
...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
|
|
157
162
|
'Content-Type': 'application/json',
|
|
158
|
-
|
|
159
|
-
CAS_PARSER_API_KEY: requireValue(
|
|
160
|
-
readEnv('CAS_PARSER_API_KEY') ?? client.apiKey,
|
|
161
|
-
'set CAS_PARSER_API_KEY environment variable or provide apiKey client option',
|
|
162
|
-
),
|
|
163
|
-
CAS_PARSER_BASE_URL: readEnv('CAS_PARSER_BASE_URL') ?? client.baseURL ?? undefined,
|
|
164
|
-
}),
|
|
163
|
+
'x-stainless-mcp-client-envs': JSON.stringify(mergedClientEnvs),
|
|
165
164
|
},
|
|
166
165
|
body: JSON.stringify({
|
|
167
166
|
project_name: 'cas-parser',
|
|
@@ -172,6 +171,11 @@ const remoteStainlessHandler = async ({
|
|
|
172
171
|
});
|
|
173
172
|
|
|
174
173
|
if (!res.ok) {
|
|
174
|
+
if (res.status === 404 && !reqContext.stainlessApiKey) {
|
|
175
|
+
throw new Error(
|
|
176
|
+
'Could not access code tool for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.',
|
|
177
|
+
);
|
|
178
|
+
}
|
|
175
179
|
throw new Error(
|
|
176
180
|
`${res.status}: ${
|
|
177
181
|
res.statusText
|
|
@@ -199,6 +203,13 @@ const localDenoHandler = async ({
|
|
|
199
203
|
reqContext: McpRequestContext;
|
|
200
204
|
args: unknown;
|
|
201
205
|
}): Promise<ToolCallResult> => {
|
|
206
|
+
const fs = await import('node:fs');
|
|
207
|
+
const path = await import('node:path');
|
|
208
|
+
const url = await import('node:url');
|
|
209
|
+
const { newDenoHTTPWorker } = await import('@valtown/deno-http-worker');
|
|
210
|
+
const { getWorkerPath } = await import('./code-tool-paths.cjs');
|
|
211
|
+
const workerPath = getWorkerPath();
|
|
212
|
+
|
|
202
213
|
const client = reqContext.client;
|
|
203
214
|
const baseURLHostname = new URL(client.baseURL).hostname;
|
|
204
215
|
const { code } = args as { code: string };
|
|
@@ -260,6 +271,9 @@ const localDenoHandler = async ({
|
|
|
260
271
|
printOutput: true,
|
|
261
272
|
spawnOptions: {
|
|
262
273
|
cwd: path.dirname(workerPath),
|
|
274
|
+
// Merge any upstream client envs into the Deno subprocess environment,
|
|
275
|
+
// with the upstream env vars taking precedence.
|
|
276
|
+
env: { ...process.env, ...reqContext.upstreamClientEnvs },
|
|
263
277
|
},
|
|
264
278
|
});
|
|
265
279
|
|
|
@@ -269,13 +283,17 @@ const localDenoHandler = async ({
|
|
|
269
283
|
reject(new Error(`Worker exited with code ${exitCode}`));
|
|
270
284
|
});
|
|
271
285
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
286
|
+
// Strip null/undefined values so that the worker SDK client can fall back to
|
|
287
|
+
// reading from environment variables (including any upstreamClientEnvs).
|
|
288
|
+
const opts: ClientOptions = Object.fromEntries(
|
|
289
|
+
Object.entries({
|
|
290
|
+
baseURL: client.baseURL,
|
|
291
|
+
apiKey: client.apiKey,
|
|
292
|
+
defaultHeaders: {
|
|
293
|
+
'X-Stainless-MCP': 'true',
|
|
294
|
+
},
|
|
295
|
+
}).filter(([_, v]) => v != null),
|
|
296
|
+
) as ClientOptions;
|
|
279
297
|
|
|
280
298
|
const req = worker.request(
|
|
281
299
|
'http://localhost',
|
package/src/docs-search-tool.ts
CHANGED
|
@@ -13,7 +13,8 @@ export const metadata: Metadata = {
|
|
|
13
13
|
|
|
14
14
|
export const tool: Tool = {
|
|
15
15
|
name: 'search_docs',
|
|
16
|
-
description:
|
|
16
|
+
description:
|
|
17
|
+
'Search SDK documentation to find methods, parameters, and usage examples for interacting with the API. Use this before writing code when you need to discover the right approach.',
|
|
17
18
|
inputSchema: {
|
|
18
19
|
type: 'object',
|
|
19
20
|
properties: {
|
|
@@ -73,6 +74,13 @@ export const handler = async ({
|
|
|
73
74
|
},
|
|
74
75
|
'Got error response from docs search tool',
|
|
75
76
|
);
|
|
77
|
+
|
|
78
|
+
if (result.status === 404 && !reqContext.stainlessApiKey) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
'Could not find docs for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.',
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
76
84
|
throw new Error(
|
|
77
85
|
`${result.status}: ${result.statusText} when using doc search tool. Details: ${errorText}`,
|
|
78
86
|
);
|
package/src/http.ts
CHANGED
|
@@ -27,14 +27,56 @@ const newServer = async ({
|
|
|
27
27
|
|
|
28
28
|
const authOptions = parseClientAuthHeaders(req, false);
|
|
29
29
|
|
|
30
|
+
let upstreamClientEnvs: Record<string, string> | undefined;
|
|
31
|
+
const clientEnvsHeader = req.headers['x-stainless-mcp-client-envs'];
|
|
32
|
+
if (typeof clientEnvsHeader === 'string') {
|
|
33
|
+
try {
|
|
34
|
+
const parsed = JSON.parse(clientEnvsHeader);
|
|
35
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
36
|
+
upstreamClientEnvs = parsed;
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
// Ignore malformed header
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Parse x-stainless-mcp-client-permissions header to override permission options
|
|
44
|
+
//
|
|
45
|
+
// Note: Permissions are best-effort and intended to prevent clients from doing unexpected things;
|
|
46
|
+
// they're not a hard security boundary, so we allow arbitrary, client-driven overrides.
|
|
47
|
+
//
|
|
48
|
+
// See the Stainless MCP documentation for more details.
|
|
49
|
+
let effectiveMcpOptions = mcpOptions;
|
|
50
|
+
const clientPermissionsHeader = req.headers['x-stainless-mcp-client-permissions'];
|
|
51
|
+
if (typeof clientPermissionsHeader === 'string') {
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(clientPermissionsHeader);
|
|
54
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
55
|
+
effectiveMcpOptions = {
|
|
56
|
+
...mcpOptions,
|
|
57
|
+
...(typeof parsed.allow_http_gets === 'boolean' && { codeAllowHttpGets: parsed.allow_http_gets }),
|
|
58
|
+
...(Array.isArray(parsed.allowed_methods) && { codeAllowedMethods: parsed.allowed_methods }),
|
|
59
|
+
...(Array.isArray(parsed.blocked_methods) && { codeBlockedMethods: parsed.blocked_methods }),
|
|
60
|
+
};
|
|
61
|
+
getLogger().info(
|
|
62
|
+
{ clientPermissions: parsed },
|
|
63
|
+
'Overriding code execution permissions from x-stainless-mcp-client-permissions header',
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
getLogger().warn({ error }, 'Failed to parse x-stainless-mcp-client-permissions header');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
30
71
|
await initMcpServer({
|
|
31
72
|
server: server,
|
|
32
|
-
mcpOptions:
|
|
73
|
+
mcpOptions: effectiveMcpOptions,
|
|
33
74
|
clientOptions: {
|
|
34
75
|
...clientOptions,
|
|
35
76
|
...authOptions,
|
|
36
77
|
},
|
|
37
78
|
stainlessApiKey: stainlessApiKey,
|
|
79
|
+
upstreamClientEnvs,
|
|
38
80
|
});
|
|
39
81
|
|
|
40
82
|
return server;
|
|
@@ -72,7 +114,7 @@ const del = async (req: express.Request, res: express.Response) => {
|
|
|
72
114
|
};
|
|
73
115
|
|
|
74
116
|
const redactHeaders = (headers: Record<string, any>) => {
|
|
75
|
-
const hiddenHeaders = /auth|cookie|key|token/i;
|
|
117
|
+
const hiddenHeaders = /auth|cookie|key|token|x-stainless-mcp-client-envs/i;
|
|
76
118
|
const filtered = { ...headers };
|
|
77
119
|
Object.keys(filtered).forEach((key) => {
|
|
78
120
|
if (hiddenHeaders.test(key)) {
|
package/src/instructions.ts
CHANGED
|
@@ -12,29 +12,24 @@ interface InstructionsCacheEntry {
|
|
|
12
12
|
|
|
13
13
|
const instructionsCache = new Map<string, InstructionsCacheEntry>();
|
|
14
14
|
|
|
15
|
-
// Periodically evict stale entries so the cache doesn't grow unboundedly.
|
|
16
|
-
const _cacheCleanupInterval = setInterval(() => {
|
|
17
|
-
const now = Date.now();
|
|
18
|
-
for (const [key, entry] of instructionsCache) {
|
|
19
|
-
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
20
|
-
instructionsCache.delete(key);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
24
|
-
|
|
25
|
-
// Don't keep the process alive just for cleanup.
|
|
26
|
-
_cacheCleanupInterval.unref();
|
|
27
|
-
|
|
28
15
|
export async function getInstructions(stainlessApiKey: string | undefined): Promise<string> {
|
|
16
|
+
const now = Date.now();
|
|
29
17
|
const cacheKey = stainlessApiKey ?? '';
|
|
30
18
|
const cached = instructionsCache.get(cacheKey);
|
|
31
19
|
|
|
32
|
-
if (cached &&
|
|
20
|
+
if (cached && now - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
33
21
|
return cached.fetchedInstructions;
|
|
34
22
|
}
|
|
35
23
|
|
|
24
|
+
// Evict stale entries so the cache doesn't grow unboundedly.
|
|
25
|
+
for (const [key, entry] of instructionsCache) {
|
|
26
|
+
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
27
|
+
instructionsCache.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
36
31
|
const fetchedInstructions = await fetchLatestInstructions(stainlessApiKey);
|
|
37
|
-
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt:
|
|
32
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: now });
|
|
38
33
|
return fetchedInstructions;
|
|
39
34
|
}
|
|
40
35
|
|
|
@@ -55,21 +50,11 @@ async function fetchLatestInstructions(stainlessApiKey: string | undefined): Pro
|
|
|
55
50
|
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
56
51
|
);
|
|
57
52
|
|
|
58
|
-
instructions =
|
|
59
|
-
This is the cas-parser MCP server.
|
|
60
|
-
actions. You can use search_docs tool to learn about how to take action with this server. Then,
|
|
61
|
-
you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
|
|
62
|
-
thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
|
|
63
|
-
block: it can be as long as you need to get the job done!
|
|
64
|
-
`;
|
|
53
|
+
instructions =
|
|
54
|
+
'\n This is the cas-parser MCP server.\n\n Available tools:\n - search_docs: Search SDK documentation to find the right methods and parameters.\n - execute: Run TypeScript code against a pre-authenticated SDK client. Define an async run(client) function.\n\n Workflow:\n - If unsure about the API, call search_docs first.\n - Write complete solutions in a single execute call when possible. For large datasets, use API filters to narrow results or paginate within a single execute block.\n - If execute returns an error, read the error and fix your code rather than retrying the same approach.\n - Variables do not persist between execute calls. Return or log all data you need.\n - Individual HTTP requests to the API have a 30-second timeout. If a request times out, try a smaller query or add filters.\n - Code execution has a total timeout of approximately 5 minutes. If your code times out, simplify it or break it into smaller steps.\n ';
|
|
65
55
|
}
|
|
66
56
|
|
|
67
57
|
instructions ??= ((await response.json()) as { instructions: string }).instructions;
|
|
68
|
-
instructions = `
|
|
69
|
-
If needed, you can get the current time by executing Date.now().
|
|
70
|
-
|
|
71
|
-
${instructions}
|
|
72
|
-
`;
|
|
73
58
|
|
|
74
59
|
return instructions;
|
|
75
60
|
}
|
package/src/server.ts
CHANGED
|
@@ -20,7 +20,7 @@ export const newMcpServer = async (stainlessApiKey: string | undefined) =>
|
|
|
20
20
|
new McpServer(
|
|
21
21
|
{
|
|
22
22
|
name: 'cas_parser_node_api',
|
|
23
|
-
version: '1.10.
|
|
23
|
+
version: '1.10.2',
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
26
|
instructions: await getInstructions(stainlessApiKey),
|
|
@@ -37,6 +37,7 @@ export async function initMcpServer(params: {
|
|
|
37
37
|
clientOptions?: ClientOptions;
|
|
38
38
|
mcpOptions?: McpOptions;
|
|
39
39
|
stainlessApiKey?: string | undefined;
|
|
40
|
+
upstreamClientEnvs?: Record<string, string> | undefined;
|
|
40
41
|
}) {
|
|
41
42
|
const server = params.server instanceof McpServer ? params.server.server : params.server;
|
|
42
43
|
|
|
@@ -118,6 +119,7 @@ export async function initMcpServer(params: {
|
|
|
118
119
|
reqContext: {
|
|
119
120
|
client,
|
|
120
121
|
stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey,
|
|
122
|
+
upstreamClientEnvs: params.upstreamClientEnvs,
|
|
121
123
|
},
|
|
122
124
|
args,
|
|
123
125
|
});
|
package/src/types.ts
CHANGED
package/types.d.mts
CHANGED
|
@@ -34,6 +34,7 @@ export type ToolCallResult = {
|
|
|
34
34
|
export type McpRequestContext = {
|
|
35
35
|
client: CasParser;
|
|
36
36
|
stainlessApiKey?: string | undefined;
|
|
37
|
+
upstreamClientEnvs?: Record<string, string> | undefined;
|
|
37
38
|
};
|
|
38
39
|
export type HandlerFunction = ({ reqContext, args, }: {
|
|
39
40
|
reqContext: McpRequestContext;
|