@imagekit/api-mcp 7.3.0 → 7.4.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/auth.d.mts +6 -0
- package/auth.d.mts.map +1 -0
- package/auth.d.ts +6 -0
- package/auth.d.ts.map +1 -0
- package/{headers.mjs → auth.js} +21 -2
- package/auth.js.map +1 -0
- package/{headers.js → auth.mjs} +16 -6
- package/auth.mjs.map +1 -0
- package/code-tool-paths.cjs +8 -0
- package/code-tool-paths.cjs.map +1 -0
- package/code-tool-paths.d.cts +2 -0
- package/code-tool-paths.d.cts.map +1 -0
- package/code-tool-types.d.mts.map +1 -1
- package/code-tool-types.d.ts.map +1 -1
- package/code-tool-worker.d.mts +5 -0
- package/code-tool-worker.d.mts.map +1 -0
- package/code-tool-worker.d.ts +5 -0
- package/code-tool-worker.d.ts.map +1 -0
- package/code-tool-worker.js +314 -0
- package/code-tool-worker.js.map +1 -0
- package/code-tool-worker.mjs +276 -0
- package/code-tool-worker.mjs.map +1 -0
- package/code-tool.d.mts +11 -2
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +11 -2
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +285 -42
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +253 -43
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +11 -3
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +11 -3
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +58 -5
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +57 -5
- package/docs-search-tool.mjs.map +1 -1
- package/http.d.mts +6 -3
- package/http.d.mts.map +1 -1
- package/http.d.ts +6 -3
- package/http.d.ts.map +1 -1
- package/http.js +130 -28
- package/http.js.map +1 -1
- package/http.mjs +130 -28
- package/http.mjs.map +1 -1
- package/index.js +17 -12
- package/index.js.map +1 -1
- package/index.mjs +17 -12
- package/index.mjs.map +1 -1
- package/instructions.d.mts +5 -0
- package/instructions.d.mts.map +1 -0
- package/instructions.d.ts +5 -0
- package/instructions.d.ts.map +1 -0
- package/instructions.js +61 -0
- package/instructions.js.map +1 -0
- package/instructions.mjs +55 -0
- package/instructions.mjs.map +1 -0
- 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 +2807 -0
- package/local-docs-search.js.map +1 -0
- package/local-docs-search.mjs +2767 -0
- package/local-docs-search.mjs.map +1 -0
- package/logger.d.mts +7 -0
- package/logger.d.mts.map +1 -0
- package/logger.d.ts +7 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +29 -0
- package/logger.js.map +1 -0
- package/logger.mjs +22 -0
- package/logger.mjs.map +1 -0
- package/methods.d.mts +10 -0
- package/methods.d.mts.map +1 -0
- package/methods.d.ts +10 -0
- package/methods.d.ts.map +1 -0
- package/methods.js +349 -0
- package/methods.js.map +1 -0
- package/methods.mjs +345 -0
- package/methods.mjs.map +1 -0
- package/options.d.mts +12 -0
- package/options.d.mts.map +1 -1
- package/options.d.ts +12 -0
- package/options.d.ts.map +1 -1
- package/options.js +81 -12
- package/options.js.map +1 -1
- package/options.mjs +81 -12
- package/options.mjs.map +1 -1
- package/package.json +89 -15
- package/server.d.mts +18 -11
- package/server.d.mts.map +1 -1
- package/server.d.ts +18 -11
- package/server.d.ts.map +1 -1
- package/server.js +89 -49
- package/server.js.map +1 -1
- package/server.mjs +88 -45
- package/server.mjs.map +1 -1
- package/src/{headers.ts → auth.ts} +18 -1
- package/src/code-tool-paths.cts +5 -0
- package/src/code-tool-types.ts +1 -0
- package/src/code-tool-worker.ts +327 -0
- package/src/code-tool.ts +339 -55
- package/src/docs-search-tool.ts +86 -7
- package/src/http.ts +154 -33
- package/src/index.ts +19 -13
- package/src/instructions.ts +83 -0
- package/src/local-docs-search.ts +3380 -0
- package/src/logger.ts +28 -0
- package/src/methods.ts +370 -0
- package/src/options.ts +105 -12
- package/src/server.ts +111 -57
- package/src/stdio.ts +9 -4
- package/src/types.ts +15 -4
- package/src/util.ts +25 -0
- package/stdio.d.mts +2 -1
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts +2 -1
- package/stdio.d.ts.map +1 -1
- package/stdio.js +8 -4
- package/stdio.js.map +1 -1
- package/stdio.mjs +8 -4
- package/stdio.mjs.map +1 -1
- package/types.d.mts +14 -1
- package/types.d.mts.map +1 -1
- package/types.d.ts +14 -1
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/types.mjs.map +1 -1
- package/util.d.mts +4 -0
- package/util.d.mts.map +1 -0
- package/util.d.ts +4 -0
- package/util.d.ts.map +1 -0
- package/util.js +30 -0
- package/util.js.map +1 -0
- package/util.mjs +24 -0
- package/util.mjs.map +1 -0
- package/headers.d.mts +0 -4
- package/headers.d.mts.map +0 -1
- package/headers.d.ts +0 -4
- package/headers.d.ts.map +0 -1
- package/headers.js.map +0 -1
- package/headers.mjs.map +0 -1
package/options.mjs
CHANGED
|
@@ -1,45 +1,107 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
1
2
|
import qs from 'qs';
|
|
2
3
|
import yargs from 'yargs';
|
|
3
4
|
import { hideBin } from 'yargs/helpers';
|
|
4
5
|
import z from 'zod';
|
|
6
|
+
import { readEnv } from "./util.mjs";
|
|
5
7
|
export function parseCLIOptions() {
|
|
6
8
|
const opts = yargs(hideBin(process.argv))
|
|
7
|
-
.option('
|
|
9
|
+
.option('code-allow-http-gets', {
|
|
10
|
+
type: 'boolean',
|
|
11
|
+
description: 'Allow all code tool methods that map to HTTP GET operations. If all code-allow-* flags are unset, then everything is allowed.',
|
|
12
|
+
})
|
|
13
|
+
.option('code-allowed-methods', {
|
|
8
14
|
type: 'string',
|
|
9
15
|
array: true,
|
|
10
|
-
|
|
11
|
-
description: 'Use dynamic tools or all tools',
|
|
16
|
+
description: 'Methods to explicitly allow for code tool. Evaluated as regular expressions against method fully qualified names. If all code-allow-* flags are unset, then everything is allowed.',
|
|
12
17
|
})
|
|
13
|
-
.option('
|
|
18
|
+
.option('code-blocked-methods', {
|
|
14
19
|
type: 'string',
|
|
15
20
|
array: true,
|
|
16
|
-
|
|
17
|
-
description: 'Do not use any dynamic or all tools',
|
|
21
|
+
description: 'Methods to explicitly block for code tool. Evaluated as regular expressions against method fully qualified names. If all code-allow-* flags are unset, then everything is allowed.',
|
|
18
22
|
})
|
|
19
|
-
.option('
|
|
23
|
+
.option('code-execution-mode', {
|
|
20
24
|
type: 'string',
|
|
21
|
-
choices: ['
|
|
22
|
-
default: '
|
|
23
|
-
description:
|
|
25
|
+
choices: ['stainless-sandbox', 'local'],
|
|
26
|
+
default: 'stainless-sandbox',
|
|
27
|
+
description: "Where to run code execution in code tool; 'stainless-sandbox' will execute code in Stainless-hosted sandboxes whereas 'local' will execute code locally on the MCP server machine.",
|
|
28
|
+
})
|
|
29
|
+
.option('custom-instructions-path', {
|
|
30
|
+
type: 'string',
|
|
31
|
+
description: 'Path to custom instructions for the MCP server',
|
|
32
|
+
})
|
|
33
|
+
.option('debug', { type: 'boolean', description: 'Enable debug logging' })
|
|
34
|
+
.option('docs-dir', {
|
|
35
|
+
type: 'string',
|
|
36
|
+
description: 'Path to a directory of local documentation files (markdown/JSON) to include in local docs search.',
|
|
37
|
+
})
|
|
38
|
+
.option('docs-search-mode', {
|
|
39
|
+
type: 'string',
|
|
40
|
+
choices: ['stainless-api', 'local'],
|
|
41
|
+
default: 'stainless-api',
|
|
42
|
+
description: "Where to search documentation; 'stainless-api' uses the Stainless-hosted search API whereas 'local' uses an in-memory search index built from embedded SDK method data and optional local docs files.",
|
|
43
|
+
})
|
|
44
|
+
.option('log-format', {
|
|
45
|
+
type: 'string',
|
|
46
|
+
choices: ['json', 'pretty'],
|
|
47
|
+
description: 'Format for log output; defaults to json unless tty is detected',
|
|
48
|
+
})
|
|
49
|
+
.option('no-tools', {
|
|
50
|
+
type: 'string',
|
|
51
|
+
array: true,
|
|
52
|
+
choices: ['code', 'docs'],
|
|
53
|
+
description: 'Tools to explicitly disable',
|
|
24
54
|
})
|
|
25
55
|
.option('port', {
|
|
26
56
|
type: 'number',
|
|
57
|
+
default: 3000,
|
|
27
58
|
description: 'Port to serve on if using http transport',
|
|
28
59
|
})
|
|
29
|
-
.option('socket', {
|
|
60
|
+
.option('socket', { type: 'string', description: 'Unix socket to serve on if using http transport' })
|
|
61
|
+
.option('stainless-api-key', {
|
|
62
|
+
type: 'string',
|
|
63
|
+
default: readEnv('STAINLESS_API_KEY'),
|
|
64
|
+
description: 'API key for Stainless. Used to authenticate requests to Stainless-hosted tools endpoints.',
|
|
65
|
+
})
|
|
66
|
+
.option('tools', {
|
|
67
|
+
type: 'string',
|
|
68
|
+
array: true,
|
|
69
|
+
choices: ['code', 'docs'],
|
|
70
|
+
description: 'Tools to explicitly enable',
|
|
71
|
+
})
|
|
72
|
+
.option('transport', {
|
|
30
73
|
type: 'string',
|
|
31
|
-
|
|
74
|
+
choices: ['stdio', 'http'],
|
|
75
|
+
default: 'stdio',
|
|
76
|
+
description: 'What transport to use; stdio for local servers or http for remote servers',
|
|
32
77
|
})
|
|
78
|
+
.env('MCP_SERVER')
|
|
79
|
+
.version(true)
|
|
33
80
|
.help();
|
|
34
81
|
const argv = opts.parseSync();
|
|
35
82
|
const shouldIncludeToolType = (toolType) => argv.noTools?.includes(toolType) ? false
|
|
36
83
|
: argv.tools?.includes(toolType) ? true
|
|
37
84
|
: undefined;
|
|
85
|
+
const includeCodeTool = shouldIncludeToolType('code');
|
|
38
86
|
const includeDocsTools = shouldIncludeToolType('docs');
|
|
39
87
|
const transport = argv.transport;
|
|
88
|
+
const logFormat = argv.logFormat ? argv.logFormat
|
|
89
|
+
: process.stderr.isTTY ? 'pretty'
|
|
90
|
+
: 'json';
|
|
40
91
|
return {
|
|
92
|
+
...(includeCodeTool !== undefined && { includeCodeTool }),
|
|
41
93
|
...(includeDocsTools !== undefined && { includeDocsTools }),
|
|
94
|
+
debug: !!argv.debug,
|
|
95
|
+
stainlessApiKey: argv.stainlessApiKey,
|
|
96
|
+
docsSearchMode: argv.docsSearchMode,
|
|
97
|
+
docsDir: argv.docsDir,
|
|
98
|
+
codeAllowHttpGets: argv.codeAllowHttpGets,
|
|
99
|
+
codeAllowedMethods: argv.codeAllowedMethods,
|
|
100
|
+
codeBlockedMethods: argv.codeBlockedMethods,
|
|
101
|
+
codeExecutionMode: argv.codeExecutionMode,
|
|
102
|
+
customInstructionsPath: argv.customInstructionsPath,
|
|
42
103
|
transport,
|
|
104
|
+
logFormat,
|
|
43
105
|
port: argv.port,
|
|
44
106
|
socket: argv.socket,
|
|
45
107
|
};
|
|
@@ -55,11 +117,18 @@ const QueryOptions = z.object({
|
|
|
55
117
|
export function parseQueryOptions(defaultOptions, query) {
|
|
56
118
|
const queryObject = typeof query === 'string' ? qs.parse(query) : query;
|
|
57
119
|
const queryOptions = QueryOptions.parse(queryObject);
|
|
120
|
+
let codeTool = queryOptions.no_tools && queryOptions.no_tools?.includes('code') ? false
|
|
121
|
+
: queryOptions.tools?.includes('code') ? true
|
|
122
|
+
: defaultOptions.includeCodeTool;
|
|
58
123
|
let docsTools = queryOptions.no_tools && queryOptions.no_tools?.includes('docs') ? false
|
|
59
124
|
: queryOptions.tools?.includes('docs') ? true
|
|
60
125
|
: defaultOptions.includeDocsTools;
|
|
61
126
|
return {
|
|
127
|
+
...(codeTool !== undefined && { includeCodeTool: codeTool }),
|
|
62
128
|
...(docsTools !== undefined && { includeDocsTools: docsTools }),
|
|
129
|
+
codeExecutionMode: defaultOptions.codeExecutionMode,
|
|
130
|
+
docsSearchMode: defaultOptions.docsSearchMode,
|
|
131
|
+
docsDir: defaultOptions.docsDir,
|
|
63
132
|
};
|
|
64
133
|
}
|
|
65
134
|
//# sourceMappingURL=options.mjs.map
|
package/options.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","sourceRoot":"","sources":["src/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.mjs","sourceRoot":"","sources":["src/options.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,MAAM,IAAI;OACZ,KAAK,MAAM,OAAO;OAClB,EAAE,OAAO,EAAE,MAAM,eAAe;OAChC,CAAC,MAAM,KAAK;OACZ,EAAE,OAAO,EAAE;AAyBlB,MAAM,UAAU,eAAe;IAC7B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SACtC,MAAM,CAAC,sBAAsB,EAAE;QAC9B,IAAI,EAAE,SAAS;QACf,WAAW,EACT,+HAA+H;KAClI,CAAC;SACD,MAAM,CAAC,sBAAsB,EAAE;QAC9B,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,WAAW,EACT,oLAAoL;KACvL,CAAC;SACD,MAAM,CAAC,sBAAsB,EAAE;QAC9B,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,WAAW,EACT,oLAAoL;KACvL,CAAC;SACD,MAAM,CAAC,qBAAqB,EAAE;QAC7B,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,mBAAmB,EAAE,OAAO,CAAC;QACvC,OAAO,EAAE,mBAAmB;QAC5B,WAAW,EACT,oLAAoL;KACvL,CAAC;SACD,MAAM,CAAC,0BAA0B,EAAE;QAClC,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,gDAAgD;KAC9D,CAAC;SACD,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE,CAAC;SACzE,MAAM,CAAC,UAAU,EAAE;QAClB,IAAI,EAAE,QAAQ;QACd,WAAW,EACT,mGAAmG;KACtG,CAAC;SACD,MAAM,CAAC,kBAAkB,EAAE;QAC1B,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,CAAC,eA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;IAEnC,IAAI,SAAS,GACX,YAAY,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;QACxE,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI;YAC7C,CAAC,CAAC,cAAc,CAAC,gBAAgB,CAAC;IAEpC,OAAO;QACL,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;QAC5D,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC;QAC/D,iBAAiB,EAAE,cAAc,CAAC,iBAAiB;QACnD,cAAc,EAAE,cAAc,CAAC,cAAc;QAC7C,OAAO,EAAE,cAAc,CAAC,OAAO;KAChC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imagekit/api-mcp",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "The official MCP Server for the Image Kit API",
|
|
5
5
|
"author": "Image Kit <developer@imagekit.io>",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -23,18 +23,26 @@
|
|
|
23
23
|
"build": "bash ./build",
|
|
24
24
|
"format": "prettier --write --cache --cache-strategy metadata . !dist",
|
|
25
25
|
"tsn": "ts-node -r tsconfig-paths/register",
|
|
26
|
-
"lint": "eslint
|
|
27
|
-
"fix": "eslint --fix
|
|
26
|
+
"lint": "eslint .",
|
|
27
|
+
"fix": "eslint --fix ."
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@imagekit/nodejs": "^7.
|
|
30
|
+
"@imagekit/nodejs": "^7.4.0",
|
|
31
|
+
"ajv": "^8.18.0",
|
|
31
32
|
"@cloudflare/cabidela": "^0.2.4",
|
|
32
|
-
"@
|
|
33
|
+
"@hono/node-server": "^1.19.10",
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
35
|
+
"hono": "^4.12.4",
|
|
33
36
|
"@valtown/deno-http-worker": "^0.0.21",
|
|
37
|
+
"cookie-parser": "^1.4.6",
|
|
34
38
|
"cors": "^2.8.5",
|
|
35
39
|
"express": "^5.1.0",
|
|
36
40
|
"fuse.js": "^7.1.0",
|
|
41
|
+
"minisearch": "^7.2.0",
|
|
37
42
|
"jq-web": "https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz",
|
|
43
|
+
"pino": "^10.3.1",
|
|
44
|
+
"pino-http": "^11.0.0",
|
|
45
|
+
"pino-pretty": "^13.1.3",
|
|
38
46
|
"qs": "^6.14.1",
|
|
39
47
|
"typescript": "5.8.3",
|
|
40
48
|
"yargs": "^17.7.2",
|
|
@@ -58,6 +66,22 @@
|
|
|
58
66
|
"types": "./index.d.mts",
|
|
59
67
|
"default": "./index.mjs"
|
|
60
68
|
},
|
|
69
|
+
"./auth": {
|
|
70
|
+
"import": "./auth.mjs",
|
|
71
|
+
"require": "./auth.js"
|
|
72
|
+
},
|
|
73
|
+
"./auth.js": {
|
|
74
|
+
"default": "./auth.js"
|
|
75
|
+
},
|
|
76
|
+
"./auth.mjs": {
|
|
77
|
+
"default": "./auth.mjs"
|
|
78
|
+
},
|
|
79
|
+
"./code-tool-paths": {
|
|
80
|
+
"require": "./code-tool-paths.cjs"
|
|
81
|
+
},
|
|
82
|
+
"./code-tool-paths.cjs": {
|
|
83
|
+
"default": "./code-tool-paths.cjs"
|
|
84
|
+
},
|
|
61
85
|
"./code-tool-types": {
|
|
62
86
|
"import": "./code-tool-types.mjs",
|
|
63
87
|
"require": "./code-tool-types.js"
|
|
@@ -68,6 +92,16 @@
|
|
|
68
92
|
"./code-tool-types.mjs": {
|
|
69
93
|
"default": "./code-tool-types.mjs"
|
|
70
94
|
},
|
|
95
|
+
"./code-tool-worker": {
|
|
96
|
+
"import": "./code-tool-worker.mjs",
|
|
97
|
+
"require": "./code-tool-worker.js"
|
|
98
|
+
},
|
|
99
|
+
"./code-tool-worker.js": {
|
|
100
|
+
"default": "./code-tool-worker.js"
|
|
101
|
+
},
|
|
102
|
+
"./code-tool-worker.mjs": {
|
|
103
|
+
"default": "./code-tool-worker.mjs"
|
|
104
|
+
},
|
|
71
105
|
"./code-tool": {
|
|
72
106
|
"import": "./code-tool.mjs",
|
|
73
107
|
"require": "./code-tool.js"
|
|
@@ -88,16 +122,6 @@
|
|
|
88
122
|
"./docs-search-tool.mjs": {
|
|
89
123
|
"default": "./docs-search-tool.mjs"
|
|
90
124
|
},
|
|
91
|
-
"./headers": {
|
|
92
|
-
"import": "./headers.mjs",
|
|
93
|
-
"require": "./headers.js"
|
|
94
|
-
},
|
|
95
|
-
"./headers.js": {
|
|
96
|
-
"default": "./headers.js"
|
|
97
|
-
},
|
|
98
|
-
"./headers.mjs": {
|
|
99
|
-
"default": "./headers.mjs"
|
|
100
|
-
},
|
|
101
125
|
"./http": {
|
|
102
126
|
"import": "./http.mjs",
|
|
103
127
|
"require": "./http.js"
|
|
@@ -118,6 +142,46 @@
|
|
|
118
142
|
"./index.mjs": {
|
|
119
143
|
"default": "./index.mjs"
|
|
120
144
|
},
|
|
145
|
+
"./instructions": {
|
|
146
|
+
"import": "./instructions.mjs",
|
|
147
|
+
"require": "./instructions.js"
|
|
148
|
+
},
|
|
149
|
+
"./instructions.js": {
|
|
150
|
+
"default": "./instructions.js"
|
|
151
|
+
},
|
|
152
|
+
"./instructions.mjs": {
|
|
153
|
+
"default": "./instructions.mjs"
|
|
154
|
+
},
|
|
155
|
+
"./local-docs-search": {
|
|
156
|
+
"import": "./local-docs-search.mjs",
|
|
157
|
+
"require": "./local-docs-search.js"
|
|
158
|
+
},
|
|
159
|
+
"./local-docs-search.js": {
|
|
160
|
+
"default": "./local-docs-search.js"
|
|
161
|
+
},
|
|
162
|
+
"./local-docs-search.mjs": {
|
|
163
|
+
"default": "./local-docs-search.mjs"
|
|
164
|
+
},
|
|
165
|
+
"./logger": {
|
|
166
|
+
"import": "./logger.mjs",
|
|
167
|
+
"require": "./logger.js"
|
|
168
|
+
},
|
|
169
|
+
"./logger.js": {
|
|
170
|
+
"default": "./logger.js"
|
|
171
|
+
},
|
|
172
|
+
"./logger.mjs": {
|
|
173
|
+
"default": "./logger.mjs"
|
|
174
|
+
},
|
|
175
|
+
"./methods": {
|
|
176
|
+
"import": "./methods.mjs",
|
|
177
|
+
"require": "./methods.js"
|
|
178
|
+
},
|
|
179
|
+
"./methods.js": {
|
|
180
|
+
"default": "./methods.js"
|
|
181
|
+
},
|
|
182
|
+
"./methods.mjs": {
|
|
183
|
+
"default": "./methods.mjs"
|
|
184
|
+
},
|
|
121
185
|
"./options": {
|
|
122
186
|
"import": "./options.mjs",
|
|
123
187
|
"require": "./options.js"
|
|
@@ -157,6 +221,16 @@
|
|
|
157
221
|
},
|
|
158
222
|
"./types.mjs": {
|
|
159
223
|
"default": "./types.mjs"
|
|
224
|
+
},
|
|
225
|
+
"./util": {
|
|
226
|
+
"import": "./util.mjs",
|
|
227
|
+
"require": "./util.js"
|
|
228
|
+
},
|
|
229
|
+
"./util.js": {
|
|
230
|
+
"default": "./util.js"
|
|
231
|
+
},
|
|
232
|
+
"./util.mjs": {
|
|
233
|
+
"default": "./util.mjs"
|
|
160
234
|
}
|
|
161
235
|
}
|
|
162
236
|
}
|
package/server.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { ClientOptions } from '@imagekit/nodejs';
|
|
4
|
-
import ImageKit from '@imagekit/nodejs';
|
|
5
4
|
import { McpOptions } from "./options.mjs";
|
|
6
|
-
import { HandlerFunction, McpTool } from "./types.mjs";
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from "./types.mjs";
|
|
6
|
+
export declare const newMcpServer: ({ stainlessApiKey, customInstructionsPath, }: {
|
|
7
|
+
stainlessApiKey?: string | undefined;
|
|
8
|
+
customInstructionsPath?: string | undefined;
|
|
9
|
+
}) => Promise<McpServer>;
|
|
11
10
|
/**
|
|
12
11
|
* Initializes the provided MCP Server with the given tools and handlers.
|
|
13
12
|
* If not provided, the default client, tools and handlers will be used.
|
|
@@ -16,7 +15,14 @@ export declare function initMcpServer(params: {
|
|
|
16
15
|
server: Server | McpServer;
|
|
17
16
|
clientOptions?: ClientOptions;
|
|
18
17
|
mcpOptions?: McpOptions;
|
|
19
|
-
|
|
18
|
+
stainlessApiKey?: string | undefined;
|
|
19
|
+
upstreamClientEnvs?: Record<string, string> | undefined;
|
|
20
|
+
mcpSessionId?: string | undefined;
|
|
21
|
+
mcpClientInfo?: {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
} | undefined;
|
|
25
|
+
}): Promise<void>;
|
|
20
26
|
/**
|
|
21
27
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
22
28
|
*/
|
|
@@ -24,8 +30,9 @@ export declare function selectTools(options?: McpOptions): McpTool[];
|
|
|
24
30
|
/**
|
|
25
31
|
* Runs the provided handler with the given client and arguments.
|
|
26
32
|
*/
|
|
27
|
-
export declare function executeHandler(handler
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
export declare function executeHandler({ handler, reqContext, args, }: {
|
|
34
|
+
handler: HandlerFunction;
|
|
35
|
+
reqContext: McpRequestContext;
|
|
36
|
+
args: Record<string, unknown> | undefined;
|
|
37
|
+
}): Promise<ToolCallResult>;
|
|
31
38
|
//# sourceMappingURL=server.d.mts.map
|
package/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["src/server.ts"],"names":[],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zB,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
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { ClientOptions } from '@imagekit/nodejs';
|
|
4
|
-
import ImageKit from '@imagekit/nodejs';
|
|
5
4
|
import { McpOptions } from "./options.js";
|
|
6
|
-
import { HandlerFunction, McpTool } from "./types.js";
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import { HandlerFunction, McpRequestContext, ToolCallResult, McpTool } from "./types.js";
|
|
6
|
+
export declare const newMcpServer: ({ stainlessApiKey, customInstructionsPath, }: {
|
|
7
|
+
stainlessApiKey?: string | undefined;
|
|
8
|
+
customInstructionsPath?: string | undefined;
|
|
9
|
+
}) => Promise<McpServer>;
|
|
11
10
|
/**
|
|
12
11
|
* Initializes the provided MCP Server with the given tools and handlers.
|
|
13
12
|
* If not provided, the default client, tools and handlers will be used.
|
|
@@ -16,7 +15,14 @@ export declare function initMcpServer(params: {
|
|
|
16
15
|
server: Server | McpServer;
|
|
17
16
|
clientOptions?: ClientOptions;
|
|
18
17
|
mcpOptions?: McpOptions;
|
|
19
|
-
|
|
18
|
+
stainlessApiKey?: string | undefined;
|
|
19
|
+
upstreamClientEnvs?: Record<string, string> | undefined;
|
|
20
|
+
mcpSessionId?: string | undefined;
|
|
21
|
+
mcpClientInfo?: {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
} | undefined;
|
|
25
|
+
}): Promise<void>;
|
|
20
26
|
/**
|
|
21
27
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
22
28
|
*/
|
|
@@ -24,8 +30,9 @@ export declare function selectTools(options?: McpOptions): McpTool[];
|
|
|
24
30
|
/**
|
|
25
31
|
* Runs the provided handler with the given client and arguments.
|
|
26
32
|
*/
|
|
27
|
-
export declare function executeHandler(handler
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
export declare function executeHandler({ handler, reqContext, args, }: {
|
|
34
|
+
handler: HandlerFunction;
|
|
35
|
+
reqContext: McpRequestContext;
|
|
36
|
+
args: Record<string, unknown> | undefined;
|
|
37
|
+
}): Promise<ToolCallResult>;
|
|
31
38
|
//# sourceMappingURL=server.d.ts.map
|
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,kBAAkB;
|
|
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,kBAAkB;OAOzC,EAAE,UAAU,EAAE;OAEd,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE;AAEtE,eAAO,MAAM,YAAY,GAAU,8CAGhC;IACD,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C,uBAUE,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;IACxD,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,aAAa,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CAC/D,iBA0HA;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
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.newMcpServer = void 0;
|
|
8
8
|
exports.initMcpServer = initMcpServer;
|
|
9
9
|
exports.selectTools = selectTools;
|
|
10
10
|
exports.executeHandler = executeHandler;
|
|
@@ -13,18 +13,23 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
|
13
13
|
const nodejs_1 = __importDefault(require("@imagekit/nodejs"));
|
|
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
|
|
16
|
+
const docs_search_tool_2 = require("./docs-search-tool.js");
|
|
17
|
+
const local_docs_search_1 = require("./local-docs-search.js");
|
|
18
|
+
const instructions_1 = require("./instructions.js");
|
|
19
|
+
const methods_1 = require("./methods.js");
|
|
20
|
+
const newMcpServer = async ({ stainlessApiKey, customInstructionsPath, }) => new mcp_js_1.McpServer({
|
|
17
21
|
name: 'imagekit_nodejs_api',
|
|
18
|
-
version: '7.
|
|
19
|
-
}, {
|
|
22
|
+
version: '7.4.0',
|
|
23
|
+
}, {
|
|
24
|
+
instructions: await (0, instructions_1.getInstructions)({ stainlessApiKey, customInstructionsPath }),
|
|
25
|
+
capabilities: { tools: {}, logging: {} },
|
|
26
|
+
});
|
|
20
27
|
exports.newMcpServer = newMcpServer;
|
|
21
|
-
// Create server instance
|
|
22
|
-
exports.server = (0, exports.newMcpServer)();
|
|
23
28
|
/**
|
|
24
29
|
* Initializes the provided MCP Server with the given tools and handlers.
|
|
25
30
|
* If not provided, the default client, tools and handlers will be used.
|
|
26
31
|
*/
|
|
27
|
-
function initMcpServer(params) {
|
|
32
|
+
async function initMcpServer(params) {
|
|
28
33
|
const server = params.server instanceof mcp_js_1.McpServer ? params.server.server : params.server;
|
|
29
34
|
const logAtLevel = (level) => (message, ...rest) => {
|
|
30
35
|
void server.sendLoggingMessage({
|
|
@@ -38,14 +43,38 @@ function initMcpServer(params) {
|
|
|
38
43
|
warn: logAtLevel('warning'),
|
|
39
44
|
error: logAtLevel('error'),
|
|
40
45
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
if (params.mcpOptions?.docsSearchMode === 'local') {
|
|
47
|
+
const docsDir = params.mcpOptions?.docsDir;
|
|
48
|
+
const localSearch = await local_docs_search_1.LocalDocsSearch.create(docsDir ? { docsDir } : undefined);
|
|
49
|
+
(0, docs_search_tool_2.setLocalSearch)(localSearch);
|
|
50
|
+
}
|
|
51
|
+
let _client;
|
|
52
|
+
let _clientError;
|
|
53
|
+
let _logLevel;
|
|
54
|
+
const getClient = () => {
|
|
55
|
+
if (_clientError)
|
|
56
|
+
throw _clientError;
|
|
57
|
+
if (!_client) {
|
|
58
|
+
try {
|
|
59
|
+
_client = new nodejs_1.default({
|
|
60
|
+
logger,
|
|
61
|
+
...params.clientOptions,
|
|
62
|
+
defaultHeaders: {
|
|
63
|
+
...params.clientOptions?.defaultHeaders,
|
|
64
|
+
'X-Stainless-MCP': 'true',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
if (_logLevel) {
|
|
68
|
+
_client = _client.withOptions({ logLevel: _logLevel });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
_clientError = e instanceof Error ? e : new Error(String(e));
|
|
73
|
+
throw _clientError;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return _client;
|
|
77
|
+
};
|
|
49
78
|
const providedTools = selectTools(params.mcpOptions);
|
|
50
79
|
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
51
80
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
@@ -59,28 +88,58 @@ function initMcpServer(params) {
|
|
|
59
88
|
if (!mcpTool) {
|
|
60
89
|
throw new Error(`Unknown tool: ${name}`);
|
|
61
90
|
}
|
|
62
|
-
|
|
91
|
+
let client;
|
|
92
|
+
try {
|
|
93
|
+
client = getClient();
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return {
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
type: 'text',
|
|
100
|
+
text: `Failed to initialize client: ${error instanceof Error ? error.message : String(error)}`,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
isError: true,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return executeHandler({
|
|
107
|
+
handler: mcpTool.handler,
|
|
108
|
+
reqContext: {
|
|
109
|
+
client,
|
|
110
|
+
stainlessApiKey: params.stainlessApiKey ?? params.mcpOptions?.stainlessApiKey,
|
|
111
|
+
upstreamClientEnvs: params.upstreamClientEnvs,
|
|
112
|
+
mcpSessionId: params.mcpSessionId,
|
|
113
|
+
mcpClientInfo: params.mcpClientInfo,
|
|
114
|
+
},
|
|
115
|
+
args,
|
|
116
|
+
});
|
|
63
117
|
});
|
|
64
118
|
server.setRequestHandler(types_js_1.SetLevelRequestSchema, async (request) => {
|
|
65
119
|
const { level } = request.params;
|
|
120
|
+
let logLevel;
|
|
66
121
|
switch (level) {
|
|
67
122
|
case 'debug':
|
|
68
|
-
|
|
123
|
+
logLevel = 'debug';
|
|
69
124
|
break;
|
|
70
125
|
case 'info':
|
|
71
|
-
|
|
126
|
+
logLevel = 'info';
|
|
72
127
|
break;
|
|
73
128
|
case 'notice':
|
|
74
129
|
case 'warning':
|
|
75
|
-
|
|
130
|
+
logLevel = 'warn';
|
|
76
131
|
break;
|
|
77
132
|
case 'error':
|
|
78
|
-
|
|
133
|
+
logLevel = 'error';
|
|
79
134
|
break;
|
|
80
135
|
default:
|
|
81
|
-
|
|
136
|
+
logLevel = 'off';
|
|
82
137
|
break;
|
|
83
138
|
}
|
|
139
|
+
_logLevel = logLevel;
|
|
140
|
+
if (_client) {
|
|
141
|
+
_client = _client.withOptions({ logLevel });
|
|
142
|
+
}
|
|
84
143
|
return {};
|
|
85
144
|
});
|
|
86
145
|
}
|
|
@@ -88,7 +147,13 @@ function initMcpServer(params) {
|
|
|
88
147
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
89
148
|
*/
|
|
90
149
|
function selectTools(options) {
|
|
91
|
-
const includedTools = [
|
|
150
|
+
const includedTools = [];
|
|
151
|
+
if (options?.includeCodeTool ?? true) {
|
|
152
|
+
includedTools.push((0, code_tool_1.codeTool)({
|
|
153
|
+
blockedMethods: (0, methods_1.blockedMethodsForCodeTool)(options),
|
|
154
|
+
codeExecutionMode: options?.codeExecutionMode ?? 'stainless-sandbox',
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
92
157
|
if (options?.includeDocsTools ?? true) {
|
|
93
158
|
includedTools.push(docs_search_tool_1.default);
|
|
94
159
|
}
|
|
@@ -97,32 +162,7 @@ function selectTools(options) {
|
|
|
97
162
|
/**
|
|
98
163
|
* Runs the provided handler with the given client and arguments.
|
|
99
164
|
*/
|
|
100
|
-
async function executeHandler(handler,
|
|
101
|
-
return await handler(
|
|
165
|
+
async function executeHandler({ handler, reqContext, args, }) {
|
|
166
|
+
return await handler({ reqContext, args: args || {} });
|
|
102
167
|
}
|
|
103
|
-
const readEnv = (env) => {
|
|
104
|
-
if (typeof globalThis.process !== 'undefined') {
|
|
105
|
-
return globalThis.process.env?.[env]?.trim();
|
|
106
|
-
}
|
|
107
|
-
else if (typeof globalThis.Deno !== 'undefined') {
|
|
108
|
-
return globalThis.Deno.env?.get?.(env)?.trim();
|
|
109
|
-
}
|
|
110
|
-
return;
|
|
111
|
-
};
|
|
112
|
-
exports.readEnv = readEnv;
|
|
113
|
-
const readEnvOrError = (env) => {
|
|
114
|
-
let envValue = (0, exports.readEnv)(env);
|
|
115
|
-
if (envValue === undefined) {
|
|
116
|
-
throw new Error(`Environment variable ${env} is not set`);
|
|
117
|
-
}
|
|
118
|
-
return envValue;
|
|
119
|
-
};
|
|
120
|
-
exports.readEnvOrError = readEnvOrError;
|
|
121
|
-
const requireValue = (value, description) => {
|
|
122
|
-
if (value === undefined) {
|
|
123
|
-
throw new Error(`Missing required value: ${description}`);
|
|
124
|
-
}
|
|
125
|
-
return value;
|
|
126
|
-
};
|
|
127
|
-
exports.requireValue = requireValue;
|
|
128
168
|
//# sourceMappingURL=server.js.map
|