@henrylabs/mcp 0.26.0 → 1.1.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/README.md +1 -3
- 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-worker.d.mts.map +1 -1
- package/code-tool-worker.d.ts.map +1 -1
- package/code-tool-worker.js +14 -25
- package/code-tool-worker.js.map +1 -1
- package/code-tool-worker.mjs +14 -25
- package/code-tool-worker.mjs.map +1 -1
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +32 -28
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +23 -16
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +2 -0
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +2 -0
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +36 -5
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +35 -5
- 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 +43 -3
- package/http.js.map +1 -1
- package/http.mjs +43 -3
- package/http.mjs.map +1 -1
- package/instructions.d.mts +4 -1
- package/instructions.d.mts.map +1 -1
- package/instructions.d.ts +4 -1
- package/instructions.d.ts.map +1 -1
- package/instructions.js +30 -25
- package/instructions.js.map +1 -1
- package/instructions.mjs +27 -25
- package/instructions.mjs.map +1 -1
- package/local-docs-search.d.mts +28 -0
- package/local-docs-search.d.mts.map +1 -0
- package/local-docs-search.d.ts +28 -0
- package/local-docs-search.d.ts.map +1 -0
- package/local-docs-search.js +493 -0
- package/local-docs-search.js.map +1 -0
- package/local-docs-search.mjs +453 -0
- package/local-docs-search.mjs.map +1 -0
- package/methods.d.mts.map +1 -1
- package/methods.d.ts.map +1 -1
- package/methods.js +51 -117
- package/methods.js.map +1 -1
- package/methods.mjs +51 -117
- package/methods.mjs.map +1 -1
- package/options.d.mts +3 -0
- package/options.d.mts.map +1 -1
- package/options.d.ts +3 -0
- package/options.d.ts.map +1 -1
- package/options.js +19 -0
- package/options.js.map +1 -1
- package/options.mjs +19 -0
- package/options.mjs.map +1 -1
- package/package.json +20 -6
- package/server.d.mts +5 -1
- package/server.d.mts.map +1 -1
- package/server.d.ts +5 -1
- package/server.d.ts.map +1 -1
- package/server.js +11 -5
- package/server.js.map +1 -1
- package/server.mjs +11 -5
- package/server.mjs.map +1 -1
- package/src/code-tool-paths.cts +3 -1
- package/src/code-tool-worker.ts +14 -25
- package/src/code-tool.ts +30 -22
- package/src/docs-search-tool.ts +58 -11
- package/src/http.ts +46 -3
- package/src/instructions.ts +34 -26
- package/src/local-docs-search.ts +544 -0
- package/src/methods.ts +51 -117
- package/src/options.ts +24 -0
- package/src/server.ts +19 -5
- package/src/stdio.ts +4 -1
- package/src/types.ts +1 -0
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts.map +1 -1
- package/stdio.js +4 -1
- package/stdio.js.map +1 -1
- package/stdio.mjs +4 -1
- package/stdio.mjs.map +1 -1
- 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/src/http.ts
CHANGED
|
@@ -23,18 +23,61 @@ const newServer = async ({
|
|
|
23
23
|
res: express.Response;
|
|
24
24
|
}): Promise<McpServer | null> => {
|
|
25
25
|
const stainlessApiKey = getStainlessApiKey(req, mcpOptions);
|
|
26
|
-
const
|
|
26
|
+
const customInstructionsPath = mcpOptions.customInstructionsPath;
|
|
27
|
+
const server = await newMcpServer({ stainlessApiKey, customInstructionsPath });
|
|
27
28
|
|
|
28
29
|
const authOptions = parseClientAuthHeaders(req, false);
|
|
29
30
|
|
|
31
|
+
let upstreamClientEnvs: Record<string, string> | undefined;
|
|
32
|
+
const clientEnvsHeader = req.headers['x-stainless-mcp-client-envs'];
|
|
33
|
+
if (typeof clientEnvsHeader === 'string') {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(clientEnvsHeader);
|
|
36
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
37
|
+
upstreamClientEnvs = parsed;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// Ignore malformed header
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Parse x-stainless-mcp-client-permissions header to override permission options
|
|
45
|
+
//
|
|
46
|
+
// Note: Permissions are best-effort and intended to prevent clients from doing unexpected things;
|
|
47
|
+
// they're not a hard security boundary, so we allow arbitrary, client-driven overrides.
|
|
48
|
+
//
|
|
49
|
+
// See the Stainless MCP documentation for more details.
|
|
50
|
+
let effectiveMcpOptions = mcpOptions;
|
|
51
|
+
const clientPermissionsHeader = req.headers['x-stainless-mcp-client-permissions'];
|
|
52
|
+
if (typeof clientPermissionsHeader === 'string') {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(clientPermissionsHeader);
|
|
55
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
56
|
+
effectiveMcpOptions = {
|
|
57
|
+
...mcpOptions,
|
|
58
|
+
...(typeof parsed.allow_http_gets === 'boolean' && { codeAllowHttpGets: parsed.allow_http_gets }),
|
|
59
|
+
...(Array.isArray(parsed.allowed_methods) && { codeAllowedMethods: parsed.allowed_methods }),
|
|
60
|
+
...(Array.isArray(parsed.blocked_methods) && { codeBlockedMethods: parsed.blocked_methods }),
|
|
61
|
+
};
|
|
62
|
+
getLogger().info(
|
|
63
|
+
{ clientPermissions: parsed },
|
|
64
|
+
'Overriding code execution permissions from x-stainless-mcp-client-permissions header',
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
getLogger().warn({ error }, 'Failed to parse x-stainless-mcp-client-permissions header');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
30
72
|
await initMcpServer({
|
|
31
73
|
server: server,
|
|
32
|
-
mcpOptions:
|
|
74
|
+
mcpOptions: effectiveMcpOptions,
|
|
33
75
|
clientOptions: {
|
|
34
76
|
...clientOptions,
|
|
35
77
|
...authOptions,
|
|
36
78
|
},
|
|
37
79
|
stainlessApiKey: stainlessApiKey,
|
|
80
|
+
upstreamClientEnvs,
|
|
38
81
|
});
|
|
39
82
|
|
|
40
83
|
return server;
|
|
@@ -72,7 +115,7 @@ const del = async (req: express.Request, res: express.Response) => {
|
|
|
72
115
|
};
|
|
73
116
|
|
|
74
117
|
const redactHeaders = (headers: Record<string, any>) => {
|
|
75
|
-
const hiddenHeaders = /auth|cookie|key|token/i;
|
|
118
|
+
const hiddenHeaders = /auth|cookie|key|token|x-stainless-mcp-client-envs/i;
|
|
76
119
|
const filtered = { ...headers };
|
|
77
120
|
Object.keys(filtered).forEach((key) => {
|
|
78
121
|
if (hiddenHeaders.test(key)) {
|
package/src/instructions.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
+
import fs from 'fs/promises';
|
|
3
4
|
import { readEnv } from './util';
|
|
4
5
|
import { getLogger } from './logger';
|
|
5
6
|
|
|
@@ -12,33 +13,50 @@ interface InstructionsCacheEntry {
|
|
|
12
13
|
|
|
13
14
|
const instructionsCache = new Map<string, InstructionsCacheEntry>();
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
export async function getInstructions({
|
|
17
|
+
stainlessApiKey,
|
|
18
|
+
customInstructionsPath,
|
|
19
|
+
}: {
|
|
20
|
+
stainlessApiKey?: string | undefined;
|
|
21
|
+
customInstructionsPath?: string | undefined;
|
|
22
|
+
}): Promise<string> {
|
|
17
23
|
const now = Date.now();
|
|
24
|
+
const cacheKey = customInstructionsPath ?? stainlessApiKey ?? '';
|
|
25
|
+
const cached = instructionsCache.get(cacheKey);
|
|
26
|
+
|
|
27
|
+
if (cached && now - cached.fetchedAt <= INSTRUCTIONS_CACHE_TTL_MS) {
|
|
28
|
+
return cached.fetchedInstructions;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Evict stale entries so the cache doesn't grow unboundedly.
|
|
18
32
|
for (const [key, entry] of instructionsCache) {
|
|
19
33
|
if (now - entry.fetchedAt > INSTRUCTIONS_CACHE_TTL_MS) {
|
|
20
34
|
instructionsCache.delete(key);
|
|
21
35
|
}
|
|
22
36
|
}
|
|
23
|
-
}, INSTRUCTIONS_CACHE_TTL_MS);
|
|
24
|
-
|
|
25
|
-
// Don't keep the process alive just for cleanup.
|
|
26
|
-
_cacheCleanupInterval.unref();
|
|
27
37
|
|
|
28
|
-
|
|
29
|
-
const cacheKey = stainlessApiKey ?? '';
|
|
30
|
-
const cached = instructionsCache.get(cacheKey);
|
|
38
|
+
let fetchedInstructions: string;
|
|
31
39
|
|
|
32
|
-
if (
|
|
33
|
-
|
|
40
|
+
if (customInstructionsPath) {
|
|
41
|
+
fetchedInstructions = await fetchLatestInstructionsFromFile(customInstructionsPath);
|
|
42
|
+
} else {
|
|
43
|
+
fetchedInstructions = await fetchLatestInstructionsFromApi(stainlessApiKey);
|
|
34
44
|
}
|
|
35
45
|
|
|
36
|
-
|
|
37
|
-
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: Date.now() });
|
|
46
|
+
instructionsCache.set(cacheKey, { fetchedInstructions, fetchedAt: now });
|
|
38
47
|
return fetchedInstructions;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
async function
|
|
50
|
+
async function fetchLatestInstructionsFromFile(path: string): Promise<string> {
|
|
51
|
+
try {
|
|
52
|
+
return await fs.readFile(path, 'utf-8');
|
|
53
|
+
} catch (error) {
|
|
54
|
+
getLogger().error({ error, path }, 'Error fetching instructions from file');
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function fetchLatestInstructionsFromApi(stainlessApiKey: string | undefined): Promise<string> {
|
|
42
60
|
// Setting the stainless API key is optional, but may be required
|
|
43
61
|
// to authenticate requests to the Stainless API.
|
|
44
62
|
const response = await fetch(
|
|
@@ -55,21 +73,11 @@ async function fetchLatestInstructions(stainlessApiKey: string | undefined): Pro
|
|
|
55
73
|
'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...',
|
|
56
74
|
);
|
|
57
75
|
|
|
58
|
-
instructions =
|
|
59
|
-
This is the henry-sdk 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
|
-
`;
|
|
76
|
+
instructions =
|
|
77
|
+
'\n This is the henry-sdk 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
78
|
}
|
|
66
79
|
|
|
67
80
|
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
81
|
|
|
74
82
|
return instructions;
|
|
75
83
|
}
|