@henrylabs/mcp 0.15.0 → 0.18.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/README.md +13 -334
- package/code-tool.d.mts +2 -44
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts +2 -44
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +7 -3
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +7 -3
- package/code-tool.mjs.map +1 -1
- package/docs-search-tool.d.mts +3 -3
- package/docs-search-tool.d.mts.map +1 -1
- package/docs-search-tool.d.ts +3 -3
- package/docs-search-tool.d.ts.map +1 -1
- package/docs-search-tool.js +1 -1
- package/docs-search-tool.js.map +1 -1
- package/docs-search-tool.mjs +1 -1
- package/http.d.mts.map +1 -1
- package/http.d.ts.map +1 -1
- package/http.js +1 -18
- package/http.js.map +1 -1
- package/http.mjs +1 -18
- package/http.mjs.map +1 -1
- package/index.js +4 -40
- package/index.js.map +1 -1
- package/index.mjs +4 -40
- package/index.mjs.map +1 -1
- package/options.d.mts +0 -9
- package/options.d.mts.map +1 -1
- package/options.d.ts +0 -9
- package/options.d.ts.map +1 -1
- package/options.js +4 -359
- package/options.js.map +1 -1
- package/options.mjs +4 -359
- package/options.mjs.map +1 -1
- package/package.json +9 -49
- package/server.d.mts +3 -8
- package/server.d.mts.map +1 -1
- package/server.d.ts +3 -8
- package/server.d.ts.map +1 -1
- package/server.js +12 -65
- package/server.js.map +1 -1
- package/server.mjs +11 -62
- package/server.mjs.map +1 -1
- package/src/code-tool.ts +7 -3
- package/src/docs-search-tool.ts +1 -1
- package/src/http.ts +1 -19
- package/src/index.ts +5 -52
- package/src/options.ts +5 -386
- package/src/server.ts +12 -72
- package/src/stdio.ts +2 -3
- package/src/{tools/types.ts → types.ts} +1 -1
- package/stdio.d.mts +1 -2
- package/stdio.d.mts.map +1 -1
- package/stdio.d.ts +1 -2
- package/stdio.d.ts.map +1 -1
- package/stdio.js +2 -2
- package/stdio.js.map +1 -1
- package/stdio.mjs +2 -2
- package/stdio.mjs.map +1 -1
- package/{tools/types.d.mts → types.d.mts} +1 -1
- package/types.d.mts.map +1 -0
- package/{tools/types.d.ts → types.d.ts} +1 -1
- package/types.d.ts.map +1 -0
- package/types.js.map +1 -0
- package/types.mjs.map +1 -0
- package/compat.d.mts +0 -58
- package/compat.d.mts.map +0 -1
- package/compat.d.ts +0 -58
- package/compat.d.ts.map +0 -1
- package/compat.js +0 -387
- package/compat.js.map +0 -1
- package/compat.mjs +0 -378
- package/compat.mjs.map +0 -1
- package/dynamic-tools.d.mts +0 -12
- package/dynamic-tools.d.mts.map +0 -1
- package/dynamic-tools.d.ts +0 -12
- package/dynamic-tools.d.ts.map +0 -1
- package/dynamic-tools.js +0 -135
- package/dynamic-tools.js.map +0 -1
- package/dynamic-tools.mjs +0 -132
- package/dynamic-tools.mjs.map +0 -1
- package/filtering.d.mts +0 -3
- package/filtering.d.mts.map +0 -1
- package/filtering.d.ts +0 -3
- package/filtering.d.ts.map +0 -1
- package/filtering.js +0 -24
- package/filtering.js.map +0 -1
- package/filtering.mjs +0 -16
- package/filtering.mjs.map +0 -1
- package/src/compat.ts +0 -483
- package/src/dynamic-tools.ts +0 -153
- package/src/filtering.ts +0 -18
- package/src/tools/cart/create-cart-checkout.ts +0 -60
- package/src/tools/cart/items/add-cart-items.ts +0 -100
- package/src/tools/cart/items/clear-cart-items.ts +0 -54
- package/src/tools/cart/items/list-cart-items.ts +0 -54
- package/src/tools/cart/items/remove-cart-items.ts +0 -57
- package/src/tools/index.ts +0 -87
- package/src/tools/orders/retrieve-status-orders.ts +0 -54
- package/src/tools/products/retrieve-product-details.ts +0 -48
- package/src/tools/products/search-products.ts +0 -110
- package/src/tools/wallet/collect-payment-details.ts +0 -56
- package/src/tools.ts +0 -1
- package/tools/cart/create-cart-checkout.d.mts +0 -51
- package/tools/cart/create-cart-checkout.d.mts.map +0 -1
- package/tools/cart/create-cart-checkout.d.ts +0 -51
- package/tools/cart/create-cart-checkout.d.ts.map +0 -1
- package/tools/cart/create-cart-checkout.js +0 -60
- package/tools/cart/create-cart-checkout.js.map +0 -1
- package/tools/cart/create-cart-checkout.mjs +0 -53
- package/tools/cart/create-cart-checkout.mjs.map +0 -1
- package/tools/cart/items/add-cart-items.d.mts +0 -51
- package/tools/cart/items/add-cart-items.d.mts.map +0 -1
- package/tools/cart/items/add-cart-items.d.ts +0 -51
- package/tools/cart/items/add-cart-items.d.ts.map +0 -1
- package/tools/cart/items/add-cart-items.js +0 -98
- package/tools/cart/items/add-cart-items.js.map +0 -1
- package/tools/cart/items/add-cart-items.mjs +0 -91
- package/tools/cart/items/add-cart-items.mjs.map +0 -1
- package/tools/cart/items/clear-cart-items.d.mts +0 -51
- package/tools/cart/items/clear-cart-items.d.mts.map +0 -1
- package/tools/cart/items/clear-cart-items.d.ts +0 -51
- package/tools/cart/items/clear-cart-items.d.ts.map +0 -1
- package/tools/cart/items/clear-cart-items.js +0 -54
- package/tools/cart/items/clear-cart-items.js.map +0 -1
- package/tools/cart/items/clear-cart-items.mjs +0 -47
- package/tools/cart/items/clear-cart-items.mjs.map +0 -1
- package/tools/cart/items/list-cart-items.d.mts +0 -51
- package/tools/cart/items/list-cart-items.d.mts.map +0 -1
- package/tools/cart/items/list-cart-items.d.ts +0 -51
- package/tools/cart/items/list-cart-items.d.ts.map +0 -1
- package/tools/cart/items/list-cart-items.js +0 -54
- package/tools/cart/items/list-cart-items.js.map +0 -1
- package/tools/cart/items/list-cart-items.mjs +0 -47
- package/tools/cart/items/list-cart-items.mjs.map +0 -1
- package/tools/cart/items/remove-cart-items.d.mts +0 -51
- package/tools/cart/items/remove-cart-items.d.mts.map +0 -1
- package/tools/cart/items/remove-cart-items.d.ts +0 -51
- package/tools/cart/items/remove-cart-items.d.ts.map +0 -1
- package/tools/cart/items/remove-cart-items.js +0 -57
- package/tools/cart/items/remove-cart-items.js.map +0 -1
- package/tools/cart/items/remove-cart-items.mjs +0 -50
- package/tools/cart/items/remove-cart-items.mjs.map +0 -1
- package/tools/index.d.mts +0 -10
- package/tools/index.d.mts.map +0 -1
- package/tools/index.d.ts +0 -10
- package/tools/index.d.ts.map +0 -1
- package/tools/index.js +0 -71
- package/tools/index.js.map +0 -1
- package/tools/index.mjs +0 -64
- package/tools/index.mjs.map +0 -1
- package/tools/orders/retrieve-status-orders.d.mts +0 -51
- package/tools/orders/retrieve-status-orders.d.mts.map +0 -1
- package/tools/orders/retrieve-status-orders.d.ts +0 -51
- package/tools/orders/retrieve-status-orders.d.ts.map +0 -1
- package/tools/orders/retrieve-status-orders.js +0 -54
- package/tools/orders/retrieve-status-orders.js.map +0 -1
- package/tools/orders/retrieve-status-orders.mjs +0 -47
- package/tools/orders/retrieve-status-orders.mjs.map +0 -1
- package/tools/products/retrieve-product-details.d.mts +0 -51
- package/tools/products/retrieve-product-details.d.mts.map +0 -1
- package/tools/products/retrieve-product-details.d.ts +0 -51
- package/tools/products/retrieve-product-details.d.ts.map +0 -1
- package/tools/products/retrieve-product-details.js +0 -49
- package/tools/products/retrieve-product-details.js.map +0 -1
- package/tools/products/retrieve-product-details.mjs +0 -42
- package/tools/products/retrieve-product-details.mjs.map +0 -1
- package/tools/products/search-products.d.mts +0 -51
- package/tools/products/search-products.d.mts.map +0 -1
- package/tools/products/search-products.d.ts +0 -51
- package/tools/products/search-products.d.ts.map +0 -1
- package/tools/products/search-products.js +0 -110
- package/tools/products/search-products.js.map +0 -1
- package/tools/products/search-products.mjs +0 -103
- package/tools/products/search-products.mjs.map +0 -1
- package/tools/types.d.mts.map +0 -1
- package/tools/types.d.ts.map +0 -1
- package/tools/types.js.map +0 -1
- package/tools/types.mjs.map +0 -1
- package/tools/wallet/collect-payment-details.d.mts +0 -51
- package/tools/wallet/collect-payment-details.d.mts.map +0 -1
- package/tools/wallet/collect-payment-details.d.ts +0 -51
- package/tools/wallet/collect-payment-details.d.ts.map +0 -1
- package/tools/wallet/collect-payment-details.js +0 -56
- package/tools/wallet/collect-payment-details.js.map +0 -1
- package/tools/wallet/collect-payment-details.mjs +0 -49
- package/tools/wallet/collect-payment-details.mjs.map +0 -1
- package/tools.d.mts +0 -2
- package/tools.d.mts.map +0 -1
- package/tools.d.ts +0 -2
- package/tools.d.ts.map +0 -1
- package/tools.js +0 -18
- package/tools.js.map +0 -1
- package/tools.mjs +0 -2
- package/tools.mjs.map +0 -1
- /package/{tools/types.js → types.js} +0 -0
- /package/{tools/types.mjs → types.mjs} +0 -0
package/server.js
CHANGED
|
@@ -4,25 +4,18 @@ 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.readEnvOrError = exports.readEnv = exports.server = exports.newMcpServer =
|
|
7
|
+
exports.readEnvOrError = exports.readEnv = exports.server = exports.newMcpServer = void 0;
|
|
8
8
|
exports.initMcpServer = initMcpServer;
|
|
9
9
|
exports.selectTools = selectTools;
|
|
10
10
|
exports.executeHandler = executeHandler;
|
|
11
11
|
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
12
|
-
const tools_1 = require("./tools.js");
|
|
13
12
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
14
13
|
const sdk_1 = __importDefault(require("@henrylabs/sdk"));
|
|
15
|
-
const compat_1 = require("./compat.js");
|
|
16
|
-
const dynamic_tools_1 = require("./dynamic-tools.js");
|
|
17
14
|
const code_tool_1 = require("./code-tool.js");
|
|
18
15
|
const docs_search_tool_1 = __importDefault(require("./docs-search-tool.js"));
|
|
19
|
-
var compat_2 = require("./compat.js");
|
|
20
|
-
Object.defineProperty(exports, "ClientType", { enumerable: true, get: function () { return compat_2.ClientType; } });
|
|
21
|
-
var tools_2 = require("./tools.js");
|
|
22
|
-
Object.defineProperty(exports, "endpoints", { enumerable: true, get: function () { return tools_2.endpoints; } });
|
|
23
16
|
const newMcpServer = () => new mcp_js_1.McpServer({
|
|
24
17
|
name: 'henrylabs_sdk_api',
|
|
25
|
-
version: '0.
|
|
18
|
+
version: '0.18.0',
|
|
26
19
|
}, { capabilities: { tools: {}, logging: {} } });
|
|
27
20
|
exports.newMcpServer = newMcpServer;
|
|
28
21
|
// Create server instance
|
|
@@ -33,23 +26,6 @@ exports.server = (0, exports.newMcpServer)();
|
|
|
33
26
|
*/
|
|
34
27
|
function initMcpServer(params) {
|
|
35
28
|
const server = params.server instanceof mcp_js_1.McpServer ? params.server.server : params.server;
|
|
36
|
-
const mcpOptions = params.mcpOptions ?? {};
|
|
37
|
-
let providedEndpoints = null;
|
|
38
|
-
let endpointMap = null;
|
|
39
|
-
const initTools = async (implementation) => {
|
|
40
|
-
if (implementation && (!mcpOptions.client || mcpOptions.client === 'infer')) {
|
|
41
|
-
mcpOptions.client =
|
|
42
|
-
implementation.name.toLowerCase().includes('claude') ? 'claude'
|
|
43
|
-
: implementation.name.toLowerCase().includes('cursor') ? 'cursor'
|
|
44
|
-
: undefined;
|
|
45
|
-
mcpOptions.capabilities = {
|
|
46
|
-
...(mcpOptions.client && compat_1.knownClients[mcpOptions.client]),
|
|
47
|
-
...mcpOptions.capabilities,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
providedEndpoints ?? (providedEndpoints = await selectTools(tools_1.endpoints, mcpOptions));
|
|
51
|
-
endpointMap ?? (endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint])));
|
|
52
|
-
};
|
|
53
29
|
const logAtLevel = (level) => (message, ...rest) => {
|
|
54
30
|
void server.sendLoggingMessage({
|
|
55
31
|
level,
|
|
@@ -71,24 +47,20 @@ function initMcpServer(params) {
|
|
|
71
47
|
'X-Stainless-MCP': 'true',
|
|
72
48
|
},
|
|
73
49
|
});
|
|
50
|
+
const providedTools = selectTools(params.mcpOptions);
|
|
51
|
+
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
74
52
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
75
|
-
if (providedEndpoints === null) {
|
|
76
|
-
await initTools(server.getClientVersion());
|
|
77
|
-
}
|
|
78
53
|
return {
|
|
79
|
-
tools:
|
|
54
|
+
tools: providedTools.map((mcpTool) => mcpTool.tool),
|
|
80
55
|
};
|
|
81
56
|
});
|
|
82
57
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
83
|
-
if (endpointMap === null) {
|
|
84
|
-
await initTools(server.getClientVersion());
|
|
85
|
-
}
|
|
86
58
|
const { name, arguments: args } = request.params;
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
59
|
+
const mcpTool = toolMap[name];
|
|
60
|
+
if (!mcpTool) {
|
|
89
61
|
throw new Error(`Unknown tool: ${name}`);
|
|
90
62
|
}
|
|
91
|
-
return executeHandler(
|
|
63
|
+
return executeHandler(mcpTool.handler, client, args);
|
|
92
64
|
});
|
|
93
65
|
server.setRequestHandler(types_js_1.SetLevelRequestSchema, async (request) => {
|
|
94
66
|
const { level } = request.params;
|
|
@@ -116,42 +88,17 @@ function initMcpServer(params) {
|
|
|
116
88
|
/**
|
|
117
89
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
118
90
|
*/
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
let includedTools = filteredEndpoints.slice();
|
|
122
|
-
if (includedTools.length > 0) {
|
|
123
|
-
if (options?.includeDynamicTools) {
|
|
124
|
-
includedTools = (0, dynamic_tools_1.dynamicTools)(includedTools);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
if (options?.includeAllTools) {
|
|
129
|
-
includedTools = endpoints.slice();
|
|
130
|
-
}
|
|
131
|
-
else if (options?.includeDynamicTools) {
|
|
132
|
-
includedTools = (0, dynamic_tools_1.dynamicTools)(endpoints);
|
|
133
|
-
}
|
|
134
|
-
else if (options?.includeCodeTools) {
|
|
135
|
-
includedTools = [await (0, code_tool_1.codeTool)()];
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
includedTools = endpoints.slice();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
91
|
+
function selectTools(options) {
|
|
92
|
+
const includedTools = [(0, code_tool_1.codeTool)()];
|
|
141
93
|
if (options?.includeDocsTools ?? true) {
|
|
142
94
|
includedTools.push(docs_search_tool_1.default);
|
|
143
95
|
}
|
|
144
|
-
|
|
145
|
-
return (0, compat_1.applyCompatibilityTransformations)(includedTools, capabilities);
|
|
96
|
+
return includedTools;
|
|
146
97
|
}
|
|
147
98
|
/**
|
|
148
99
|
* Runs the provided handler with the given client and arguments.
|
|
149
100
|
*/
|
|
150
|
-
async function executeHandler(
|
|
151
|
-
const options = { ...compat_1.defaultClientCapabilities, ...compatibilityOptions };
|
|
152
|
-
if (!options.validJson && args) {
|
|
153
|
-
args = (0, compat_1.parseEmbeddedJSON)(args, tool.inputSchema);
|
|
154
|
-
}
|
|
101
|
+
async function executeHandler(handler, client, args) {
|
|
155
102
|
return await handler(client, args || {});
|
|
156
103
|
}
|
|
157
104
|
const readEnv = (env) => {
|
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;;;;;;AAmCtF,sCAyEC;AAKD,kCAMC;AAKD,wCAMC;AA/HD,oEAAoE;AACpE,iEAI4C;AAE5C,yDAAsC;AACtC,8CAAuC;AACvC,6EAAgD;AAOzC,MAAM,YAAY,GAAG,GAAG,EAAE,CAC/B,IAAI,kBAAS,CACX;IACE,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,QAAQ;CAClB,EACD,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC7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AC,CAAC;IAC5B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB"}
|
package/server.mjs
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { endpoints, query } from "./tools.mjs";
|
|
4
3
|
import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
4
|
import HenrySDK from '@henrylabs/sdk';
|
|
6
|
-
import { applyCompatibilityTransformations, defaultClientCapabilities, knownClients, parseEmbeddedJSON, } from "./compat.mjs";
|
|
7
|
-
import { dynamicTools } from "./dynamic-tools.mjs";
|
|
8
5
|
import { codeTool } from "./code-tool.mjs";
|
|
9
6
|
import docsSearchTool from "./docs-search-tool.mjs";
|
|
10
|
-
export { ClientType } from "./compat.mjs";
|
|
11
|
-
export { endpoints } from "./tools.mjs";
|
|
12
7
|
export const newMcpServer = () => new McpServer({
|
|
13
8
|
name: 'henrylabs_sdk_api',
|
|
14
|
-
version: '0.
|
|
9
|
+
version: '0.18.0',
|
|
15
10
|
}, { capabilities: { tools: {}, logging: {} } });
|
|
16
11
|
// Create server instance
|
|
17
12
|
export const server = newMcpServer();
|
|
@@ -21,23 +16,6 @@ export const server = newMcpServer();
|
|
|
21
16
|
*/
|
|
22
17
|
export function initMcpServer(params) {
|
|
23
18
|
const server = params.server instanceof McpServer ? params.server.server : params.server;
|
|
24
|
-
const mcpOptions = params.mcpOptions ?? {};
|
|
25
|
-
let providedEndpoints = null;
|
|
26
|
-
let endpointMap = null;
|
|
27
|
-
const initTools = async (implementation) => {
|
|
28
|
-
if (implementation && (!mcpOptions.client || mcpOptions.client === 'infer')) {
|
|
29
|
-
mcpOptions.client =
|
|
30
|
-
implementation.name.toLowerCase().includes('claude') ? 'claude'
|
|
31
|
-
: implementation.name.toLowerCase().includes('cursor') ? 'cursor'
|
|
32
|
-
: undefined;
|
|
33
|
-
mcpOptions.capabilities = {
|
|
34
|
-
...(mcpOptions.client && knownClients[mcpOptions.client]),
|
|
35
|
-
...mcpOptions.capabilities,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
providedEndpoints ?? (providedEndpoints = await selectTools(endpoints, mcpOptions));
|
|
39
|
-
endpointMap ?? (endpointMap = Object.fromEntries(providedEndpoints.map((endpoint) => [endpoint.tool.name, endpoint])));
|
|
40
|
-
};
|
|
41
19
|
const logAtLevel = (level) => (message, ...rest) => {
|
|
42
20
|
void server.sendLoggingMessage({
|
|
43
21
|
level,
|
|
@@ -59,24 +37,20 @@ export function initMcpServer(params) {
|
|
|
59
37
|
'X-Stainless-MCP': 'true',
|
|
60
38
|
},
|
|
61
39
|
});
|
|
40
|
+
const providedTools = selectTools(params.mcpOptions);
|
|
41
|
+
const toolMap = Object.fromEntries(providedTools.map((mcpTool) => [mcpTool.tool.name, mcpTool]));
|
|
62
42
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
63
|
-
if (providedEndpoints === null) {
|
|
64
|
-
await initTools(server.getClientVersion());
|
|
65
|
-
}
|
|
66
43
|
return {
|
|
67
|
-
tools:
|
|
44
|
+
tools: providedTools.map((mcpTool) => mcpTool.tool),
|
|
68
45
|
};
|
|
69
46
|
});
|
|
70
47
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
71
|
-
if (endpointMap === null) {
|
|
72
|
-
await initTools(server.getClientVersion());
|
|
73
|
-
}
|
|
74
48
|
const { name, arguments: args } = request.params;
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
49
|
+
const mcpTool = toolMap[name];
|
|
50
|
+
if (!mcpTool) {
|
|
77
51
|
throw new Error(`Unknown tool: ${name}`);
|
|
78
52
|
}
|
|
79
|
-
return executeHandler(
|
|
53
|
+
return executeHandler(mcpTool.handler, client, args);
|
|
80
54
|
});
|
|
81
55
|
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
|
|
82
56
|
const { level } = request.params;
|
|
@@ -104,42 +78,17 @@ export function initMcpServer(params) {
|
|
|
104
78
|
/**
|
|
105
79
|
* Selects the tools to include in the MCP Server based on the provided options.
|
|
106
80
|
*/
|
|
107
|
-
export
|
|
108
|
-
const
|
|
109
|
-
let includedTools = filteredEndpoints.slice();
|
|
110
|
-
if (includedTools.length > 0) {
|
|
111
|
-
if (options?.includeDynamicTools) {
|
|
112
|
-
includedTools = dynamicTools(includedTools);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
if (options?.includeAllTools) {
|
|
117
|
-
includedTools = endpoints.slice();
|
|
118
|
-
}
|
|
119
|
-
else if (options?.includeDynamicTools) {
|
|
120
|
-
includedTools = dynamicTools(endpoints);
|
|
121
|
-
}
|
|
122
|
-
else if (options?.includeCodeTools) {
|
|
123
|
-
includedTools = [await codeTool()];
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
includedTools = endpoints.slice();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
81
|
+
export function selectTools(options) {
|
|
82
|
+
const includedTools = [codeTool()];
|
|
129
83
|
if (options?.includeDocsTools ?? true) {
|
|
130
84
|
includedTools.push(docsSearchTool);
|
|
131
85
|
}
|
|
132
|
-
|
|
133
|
-
return applyCompatibilityTransformations(includedTools, capabilities);
|
|
86
|
+
return includedTools;
|
|
134
87
|
}
|
|
135
88
|
/**
|
|
136
89
|
* Runs the provided handler with the given client and arguments.
|
|
137
90
|
*/
|
|
138
|
-
export async function executeHandler(
|
|
139
|
-
const options = { ...defaultClientCapabilities, ...compatibilityOptions };
|
|
140
|
-
if (!options.validJson && args) {
|
|
141
|
-
args = parseEmbeddedJSON(args, tool.inputSchema);
|
|
142
|
-
}
|
|
91
|
+
export async function executeHandler(handler, client, args) {
|
|
143
92
|
return await handler(client, args || {});
|
|
144
93
|
}
|
|
145
94
|
export const readEnv = (env) => {
|
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,
|
|
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,QAAQ,MAAM,gBAAgB;OAC9B,EAAE,QAAQ,EAAE;OACZ,cAAc;AAOrB,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE,CAC/B,IAAI,SAAS,CACX;IACE,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,QAAQ;CAClB,EACD,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAC7C,CAAC;AAEJ,yBAAyB;AACzB,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAI7B;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,YAAY,SAAS,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;S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AAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAwB,EACxB,MAAgB,EAChB,IAAyC;IAEzC,OAAO,MAAM,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAsB,EAAE;IACzD,IAAI,OAAQ,UAAkB,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;QACvD,OAAQ,UAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IACxD,CAAC;SAAM,IAAI,OAAQ,UAAkB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC3D,OAAQ,UAAkB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO;AACT,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAU,EAAE;IACpD,IAAI,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,aAAa,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
package/src/code-tool.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { Metadata, ToolCallResult, asTextContentResult } from './
|
|
3
|
+
import { McpTool, Metadata, ToolCallResult, asTextContentResult } from './types';
|
|
4
4
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { readEnv } from './server';
|
|
6
6
|
import { WorkerSuccess } from './code-tool-types';
|
|
@@ -13,7 +13,7 @@ import { WorkerSuccess } from './code-tool-types';
|
|
|
13
13
|
*
|
|
14
14
|
* @param endpoints - The endpoints to include in the list.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export function codeTool(): McpTool {
|
|
17
17
|
const metadata: Metadata = { resource: 'all', operation: 'write', tags: [] };
|
|
18
18
|
const tool: Tool = {
|
|
19
19
|
name: 'execute',
|
|
@@ -35,10 +35,14 @@ export async function codeTool() {
|
|
|
35
35
|
headers: {
|
|
36
36
|
...(stainlessAPIKey && { Authorization: stainlessAPIKey }),
|
|
37
37
|
'Content-Type': 'application/json',
|
|
38
|
-
client_envs: JSON.stringify({
|
|
38
|
+
client_envs: JSON.stringify({
|
|
39
|
+
HENRY_SDK_API_KEY: readEnv('HENRY_SDK_API_KEY'),
|
|
40
|
+
HENRY_SDK_BASE_URL: readEnv('HENRY_SDK_BASE_URL'),
|
|
41
|
+
}),
|
|
39
42
|
},
|
|
40
43
|
body: JSON.stringify({
|
|
41
44
|
project_name: 'henry-sdk',
|
|
45
|
+
client_opts: { environment: (readEnv('HENRY_SDK_ENVIRONMENT') || undefined) as any },
|
|
42
46
|
code,
|
|
43
47
|
}),
|
|
44
48
|
});
|
package/src/docs-search-tool.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { Metadata, asTextContentResult } from './
|
|
3
|
+
import { Metadata, asTextContentResult } from './types';
|
|
4
4
|
|
|
5
5
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
|
package/src/http.ts
CHANGED
|
@@ -4,38 +4,21 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
|
|
|
4
4
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
5
5
|
|
|
6
6
|
import express from 'express';
|
|
7
|
-
import {
|
|
8
|
-
import { McpOptions, parseQueryOptions } from './options';
|
|
7
|
+
import { McpOptions } from './options';
|
|
9
8
|
import { ClientOptions, initMcpServer, newMcpServer } from './server';
|
|
10
9
|
import { parseAuthHeaders } from './headers';
|
|
11
10
|
|
|
12
11
|
const newServer = ({
|
|
13
12
|
clientOptions,
|
|
14
|
-
mcpOptions: defaultMcpOptions,
|
|
15
13
|
req,
|
|
16
14
|
res,
|
|
17
15
|
}: {
|
|
18
16
|
clientOptions: ClientOptions;
|
|
19
|
-
mcpOptions: McpOptions;
|
|
20
17
|
req: express.Request;
|
|
21
18
|
res: express.Response;
|
|
22
19
|
}): McpServer | null => {
|
|
23
20
|
const server = newMcpServer();
|
|
24
21
|
|
|
25
|
-
let mcpOptions: McpOptions;
|
|
26
|
-
try {
|
|
27
|
-
mcpOptions = parseQueryOptions(defaultMcpOptions, req.query);
|
|
28
|
-
} catch (error) {
|
|
29
|
-
res.status(400).json({
|
|
30
|
-
jsonrpc: '2.0',
|
|
31
|
-
error: {
|
|
32
|
-
code: -32000,
|
|
33
|
-
message: `Invalid request: ${fromError(error)}`,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
22
|
try {
|
|
40
23
|
const authOptions = parseAuthHeaders(req);
|
|
41
24
|
initMcpServer({
|
|
@@ -44,7 +27,6 @@ const newServer = ({
|
|
|
44
27
|
...clientOptions,
|
|
45
28
|
...authOptions,
|
|
46
29
|
},
|
|
47
|
-
mcpOptions,
|
|
48
30
|
});
|
|
49
31
|
} catch (error) {
|
|
50
32
|
res.status(401).json({
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { selectTools } from './server';
|
|
4
|
-
import { Endpoint, endpoints } from './tools';
|
|
5
4
|
import { McpOptions, parseCLIOptions } from './options';
|
|
6
5
|
import { launchStdioServer } from './stdio';
|
|
7
6
|
import { launchStreamableHTTPServer } from './http';
|
|
7
|
+
import type { McpTool } from './types';
|
|
8
8
|
|
|
9
9
|
async function main() {
|
|
10
10
|
const options = parseOptionsOrError();
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
listAllTools();
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const selectedTools = await selectToolsOrError(endpoints, options);
|
|
12
|
+
const selectedTools = await selectToolsOrError(options);
|
|
18
13
|
|
|
19
14
|
console.error(
|
|
20
15
|
`MCP Server starting with ${selectedTools.length} tools:`,
|
|
@@ -23,7 +18,7 @@ async function main() {
|
|
|
23
18
|
|
|
24
19
|
switch (options.transport) {
|
|
25
20
|
case 'stdio':
|
|
26
|
-
await launchStdioServer(
|
|
21
|
+
await launchStdioServer();
|
|
27
22
|
break;
|
|
28
23
|
case 'http':
|
|
29
24
|
await launchStreamableHTTPServer(options, options.port ?? options.socket);
|
|
@@ -47,9 +42,9 @@ function parseOptionsOrError() {
|
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
44
|
|
|
50
|
-
async function selectToolsOrError(
|
|
45
|
+
async function selectToolsOrError(options: McpOptions): Promise<McpTool[]> {
|
|
51
46
|
try {
|
|
52
|
-
const includedTools =
|
|
47
|
+
const includedTools = selectTools(options);
|
|
53
48
|
if (includedTools.length === 0) {
|
|
54
49
|
console.error('No tools match the provided filters.');
|
|
55
50
|
process.exit(1);
|
|
@@ -64,45 +59,3 @@ async function selectToolsOrError(endpoints: Endpoint[], options: McpOptions): P
|
|
|
64
59
|
process.exit(1);
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
|
-
|
|
68
|
-
function listAllTools() {
|
|
69
|
-
if (endpoints.length === 0) {
|
|
70
|
-
console.log('No tools available.');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
console.log('Available tools:\n');
|
|
74
|
-
|
|
75
|
-
// Group endpoints by resource
|
|
76
|
-
const resourceGroups = new Map<string, typeof endpoints>();
|
|
77
|
-
|
|
78
|
-
for (const endpoint of endpoints) {
|
|
79
|
-
const resource = endpoint.metadata.resource;
|
|
80
|
-
if (!resourceGroups.has(resource)) {
|
|
81
|
-
resourceGroups.set(resource, []);
|
|
82
|
-
}
|
|
83
|
-
resourceGroups.get(resource)!.push(endpoint);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Sort resources alphabetically
|
|
87
|
-
const sortedResources = Array.from(resourceGroups.keys()).sort();
|
|
88
|
-
|
|
89
|
-
// Display hierarchically by resource
|
|
90
|
-
for (const resource of sortedResources) {
|
|
91
|
-
console.log(`Resource: ${resource}`);
|
|
92
|
-
|
|
93
|
-
const resourceEndpoints = resourceGroups.get(resource)!;
|
|
94
|
-
// Sort endpoints by tool name
|
|
95
|
-
resourceEndpoints.sort((a, b) => a.tool.name.localeCompare(b.tool.name));
|
|
96
|
-
|
|
97
|
-
for (const endpoint of resourceEndpoints) {
|
|
98
|
-
const {
|
|
99
|
-
tool,
|
|
100
|
-
metadata: { operation, tags },
|
|
101
|
-
} = endpoint;
|
|
102
|
-
|
|
103
|
-
console.log(` - ${tool.name} (${operation}) ${tags.length > 0 ? `tags: ${tags.join(', ')}` : ''}`);
|
|
104
|
-
console.log(` Description: ${tool.description}`);
|
|
105
|
-
}
|
|
106
|
-
console.log('');
|
|
107
|
-
}
|
|
108
|
-
}
|