@henrylabs/mcp 0.2.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/LICENSE +201 -0
- package/README.md +255 -0
- package/code-tool-paths.cjs +6 -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 +14 -0
- package/code-tool-types.d.mts.map +1 -0
- package/code-tool-types.d.ts +14 -0
- package/code-tool-types.d.ts.map +1 -0
- package/code-tool-types.js +4 -0
- package/code-tool-types.js.map +1 -0
- package/code-tool-types.mjs +3 -0
- package/code-tool-types.mjs.map +1 -0
- 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 +45 -0
- package/code-tool-worker.js.map +1 -0
- package/code-tool-worker.mjs +40 -0
- package/code-tool-worker.mjs.map +1 -0
- package/code-tool.d.mts +12 -0
- package/code-tool.d.mts.map +1 -0
- package/code-tool.d.ts +12 -0
- package/code-tool.d.ts.map +1 -0
- package/code-tool.js +158 -0
- package/code-tool.js.map +1 -0
- package/code-tool.mjs +122 -0
- package/code-tool.mjs.map +1 -0
- package/compat.d.mts +58 -0
- package/compat.d.mts.map +1 -0
- package/compat.d.ts +58 -0
- package/compat.d.ts.map +1 -0
- package/compat.js +387 -0
- package/compat.js.map +1 -0
- package/compat.mjs +378 -0
- package/compat.mjs.map +1 -0
- package/docs-search-tool.d.mts +44 -0
- package/docs-search-tool.d.mts.map +1 -0
- package/docs-search-tool.d.ts +44 -0
- package/docs-search-tool.d.ts.map +1 -0
- package/docs-search-tool.js +43 -0
- package/docs-search-tool.js.map +1 -0
- package/docs-search-tool.mjs +39 -0
- package/docs-search-tool.mjs.map +1 -0
- package/dynamic-tools.d.mts +12 -0
- package/dynamic-tools.d.mts.map +1 -0
- package/dynamic-tools.d.ts +12 -0
- package/dynamic-tools.d.ts.map +1 -0
- package/dynamic-tools.js +135 -0
- package/dynamic-tools.js.map +1 -0
- package/dynamic-tools.mjs +132 -0
- package/dynamic-tools.mjs.map +1 -0
- package/filtering.d.mts +2 -0
- package/filtering.d.mts.map +1 -0
- package/filtering.d.ts +2 -0
- package/filtering.d.ts.map +1 -0
- package/filtering.js +20 -0
- package/filtering.js.map +1 -0
- package/filtering.mjs +13 -0
- package/filtering.mjs.map +1 -0
- package/headers.d.mts +4 -0
- package/headers.d.mts.map +1 -0
- package/headers.d.ts +4 -0
- package/headers.d.ts.map +1 -0
- package/headers.js +13 -0
- package/headers.js.map +1 -0
- package/headers.mjs +9 -0
- package/headers.mjs.map +1 -0
- package/http.d.mts +9 -0
- package/http.d.mts.map +1 -0
- package/http.d.ts +9 -0
- package/http.d.ts.map +1 -0
- package/http.js +108 -0
- package/http.js.map +1 -0
- package/http.mjs +100 -0
- package/http.mjs.map +1 -0
- package/index.d.mts +3 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +91 -0
- package/index.js.map +1 -0
- package/index.mjs +89 -0
- package/index.mjs.map +1 -0
- package/options.d.mts +20 -0
- package/options.d.mts.map +1 -0
- package/options.d.ts +20 -0
- package/options.d.ts.map +1 -0
- package/options.js +424 -0
- package/options.js.map +1 -0
- package/options.mjs +417 -0
- package/options.mjs.map +1 -0
- package/package.json +216 -0
- package/server.d.mts +35 -0
- package/server.d.mts.map +1 -0
- package/server.d.ts +35 -0
- package/server.d.ts.map +1 -0
- package/server.js +175 -0
- package/server.js.map +1 -0
- package/server.mjs +161 -0
- package/server.mjs.map +1 -0
- package/src/code-tool-paths.cts +3 -0
- package/src/code-tool-types.ts +14 -0
- package/src/code-tool-worker.ts +46 -0
- package/src/code-tool.ts +147 -0
- package/src/compat.ts +483 -0
- package/src/docs-search-tool.ts +48 -0
- package/src/dynamic-tools.ts +153 -0
- package/src/filtering.ts +14 -0
- package/src/headers.ts +14 -0
- package/src/http.ts +127 -0
- package/src/index.ts +108 -0
- package/src/options.ts +466 -0
- package/src/server.ts +208 -0
- package/src/stdio.ts +13 -0
- package/src/tools/cart/create-checkout-cart.ts +49 -0
- package/src/tools/cart/items/add-cart-items.ts +93 -0
- package/src/tools/cart/items/clear-cart-items.ts +47 -0
- package/src/tools/cart/items/list-cart-items.ts +47 -0
- package/src/tools/cart/items/remove-cart-items.ts +50 -0
- package/src/tools/checkout/session/confirm-checkout-checkout-session.ts +101 -0
- package/src/tools/checkout/session/create-quote-checkout-session.ts +96 -0
- package/src/tools/checkout/session/list-products-checkout-session.ts +47 -0
- package/src/tools/checkout/session/retrieve-shipping-info-checkout-session.ts +49 -0
- package/src/tools/index.ts +105 -0
- package/src/tools/merchants/check-status-merchants.ts +56 -0
- package/src/tools/merchants/get-shipping-info-merchants.ts +60 -0
- package/src/tools/merchants/list-supported-merchants.ts +52 -0
- package/src/tools/orders/retrieve-status-orders.ts +47 -0
- package/src/tools/products/retrieve-details-products.ts +48 -0
- package/src/tools/products/search-products.ts +78 -0
- package/src/tools/products/variant-check/create-products-variant-check.ts +85 -0
- package/src/tools/products/variant-check/retrieve-status-products-variant-check.ts +50 -0
- package/src/tools/types.ts +103 -0
- package/src/tools/wallet/create-card-collection-wallet.ts +49 -0
- package/src/tools.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/stdio.d.mts +3 -0
- package/stdio.d.mts.map +1 -0
- package/stdio.d.ts +3 -0
- package/stdio.d.ts.map +1 -0
- package/stdio.js +14 -0
- package/stdio.js.map +1 -0
- package/stdio.mjs +10 -0
- package/stdio.mjs.map +1 -0
- package/tools/cart/create-checkout-cart.d.mts +45 -0
- package/tools/cart/create-checkout-cart.d.mts.map +1 -0
- package/tools/cart/create-checkout-cart.d.ts +45 -0
- package/tools/cart/create-checkout-cart.d.ts.map +1 -0
- package/tools/cart/create-checkout-cart.js +44 -0
- package/tools/cart/create-checkout-cart.js.map +1 -0
- package/tools/cart/create-checkout-cart.mjs +40 -0
- package/tools/cart/create-checkout-cart.mjs.map +1 -0
- package/tools/cart/items/add-cart-items.d.mts +45 -0
- package/tools/cart/items/add-cart-items.d.mts.map +1 -0
- package/tools/cart/items/add-cart-items.d.ts +45 -0
- package/tools/cart/items/add-cart-items.d.ts.map +1 -0
- package/tools/cart/items/add-cart-items.js +86 -0
- package/tools/cart/items/add-cart-items.js.map +1 -0
- package/tools/cart/items/add-cart-items.mjs +82 -0
- package/tools/cart/items/add-cart-items.mjs.map +1 -0
- package/tools/cart/items/clear-cart-items.d.mts +45 -0
- package/tools/cart/items/clear-cart-items.d.mts.map +1 -0
- package/tools/cart/items/clear-cart-items.d.ts +45 -0
- package/tools/cart/items/clear-cart-items.d.ts.map +1 -0
- package/tools/cart/items/clear-cart-items.js +42 -0
- package/tools/cart/items/clear-cart-items.js.map +1 -0
- package/tools/cart/items/clear-cart-items.mjs +38 -0
- package/tools/cart/items/clear-cart-items.mjs.map +1 -0
- package/tools/cart/items/list-cart-items.d.mts +45 -0
- package/tools/cart/items/list-cart-items.d.mts.map +1 -0
- package/tools/cart/items/list-cart-items.d.ts +45 -0
- package/tools/cart/items/list-cart-items.d.ts.map +1 -0
- package/tools/cart/items/list-cart-items.js +42 -0
- package/tools/cart/items/list-cart-items.js.map +1 -0
- package/tools/cart/items/list-cart-items.mjs +38 -0
- package/tools/cart/items/list-cart-items.mjs.map +1 -0
- package/tools/cart/items/remove-cart-items.d.mts +45 -0
- package/tools/cart/items/remove-cart-items.d.mts.map +1 -0
- package/tools/cart/items/remove-cart-items.d.ts +45 -0
- package/tools/cart/items/remove-cart-items.d.ts.map +1 -0
- package/tools/cart/items/remove-cart-items.js +45 -0
- package/tools/cart/items/remove-cart-items.js.map +1 -0
- package/tools/cart/items/remove-cart-items.mjs +41 -0
- package/tools/cart/items/remove-cart-items.mjs.map +1 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.d.mts +45 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.d.mts.map +1 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.d.ts +45 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.d.ts.map +1 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.js +94 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.js.map +1 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.mjs +90 -0
- package/tools/checkout/session/confirm-checkout-checkout-session.mjs.map +1 -0
- package/tools/checkout/session/create-quote-checkout-session.d.mts +45 -0
- package/tools/checkout/session/create-quote-checkout-session.d.mts.map +1 -0
- package/tools/checkout/session/create-quote-checkout-session.d.ts +45 -0
- package/tools/checkout/session/create-quote-checkout-session.d.ts.map +1 -0
- package/tools/checkout/session/create-quote-checkout-session.js +91 -0
- package/tools/checkout/session/create-quote-checkout-session.js.map +1 -0
- package/tools/checkout/session/create-quote-checkout-session.mjs +87 -0
- package/tools/checkout/session/create-quote-checkout-session.mjs.map +1 -0
- package/tools/checkout/session/list-products-checkout-session.d.mts +45 -0
- package/tools/checkout/session/list-products-checkout-session.d.mts.map +1 -0
- package/tools/checkout/session/list-products-checkout-session.d.ts +45 -0
- package/tools/checkout/session/list-products-checkout-session.d.ts.map +1 -0
- package/tools/checkout/session/list-products-checkout-session.js +42 -0
- package/tools/checkout/session/list-products-checkout-session.js.map +1 -0
- package/tools/checkout/session/list-products-checkout-session.mjs +38 -0
- package/tools/checkout/session/list-products-checkout-session.mjs.map +1 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.mts +45 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.mts.map +1 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.ts +45 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.d.ts.map +1 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.js +42 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.js.map +1 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.mjs +38 -0
- package/tools/checkout/session/retrieve-shipping-info-checkout-session.mjs.map +1 -0
- package/tools/index.d.mts +10 -0
- package/tools/index.d.mts.map +1 -0
- package/tools/index.d.ts +10 -0
- package/tools/index.d.ts.map +1 -0
- package/tools/index.js +89 -0
- package/tools/index.js.map +1 -0
- package/tools/index.mjs +82 -0
- package/tools/index.mjs.map +1 -0
- package/tools/merchants/check-status-merchants.d.mts +45 -0
- package/tools/merchants/check-status-merchants.d.mts.map +1 -0
- package/tools/merchants/check-status-merchants.d.ts +45 -0
- package/tools/merchants/check-status-merchants.d.ts.map +1 -0
- package/tools/merchants/check-status-merchants.js +48 -0
- package/tools/merchants/check-status-merchants.js.map +1 -0
- package/tools/merchants/check-status-merchants.mjs +44 -0
- package/tools/merchants/check-status-merchants.mjs.map +1 -0
- package/tools/merchants/get-shipping-info-merchants.d.mts +45 -0
- package/tools/merchants/get-shipping-info-merchants.d.mts.map +1 -0
- package/tools/merchants/get-shipping-info-merchants.d.ts +45 -0
- package/tools/merchants/get-shipping-info-merchants.d.ts.map +1 -0
- package/tools/merchants/get-shipping-info-merchants.js +55 -0
- package/tools/merchants/get-shipping-info-merchants.js.map +1 -0
- package/tools/merchants/get-shipping-info-merchants.mjs +51 -0
- package/tools/merchants/get-shipping-info-merchants.mjs.map +1 -0
- package/tools/merchants/list-supported-merchants.d.mts +45 -0
- package/tools/merchants/list-supported-merchants.d.mts.map +1 -0
- package/tools/merchants/list-supported-merchants.d.ts +45 -0
- package/tools/merchants/list-supported-merchants.d.ts.map +1 -0
- package/tools/merchants/list-supported-merchants.js +47 -0
- package/tools/merchants/list-supported-merchants.js.map +1 -0
- package/tools/merchants/list-supported-merchants.mjs +43 -0
- package/tools/merchants/list-supported-merchants.mjs.map +1 -0
- package/tools/orders/retrieve-status-orders.d.mts +45 -0
- package/tools/orders/retrieve-status-orders.d.mts.map +1 -0
- package/tools/orders/retrieve-status-orders.d.ts +45 -0
- package/tools/orders/retrieve-status-orders.d.ts.map +1 -0
- package/tools/orders/retrieve-status-orders.js +42 -0
- package/tools/orders/retrieve-status-orders.js.map +1 -0
- package/tools/orders/retrieve-status-orders.mjs +38 -0
- package/tools/orders/retrieve-status-orders.mjs.map +1 -0
- package/tools/products/retrieve-details-products.d.mts +45 -0
- package/tools/products/retrieve-details-products.d.mts.map +1 -0
- package/tools/products/retrieve-details-products.d.ts +45 -0
- package/tools/products/retrieve-details-products.d.ts.map +1 -0
- package/tools/products/retrieve-details-products.js +43 -0
- package/tools/products/retrieve-details-products.js.map +1 -0
- package/tools/products/retrieve-details-products.mjs +39 -0
- package/tools/products/retrieve-details-products.mjs.map +1 -0
- package/tools/products/search-products.d.mts +45 -0
- package/tools/products/search-products.d.mts.map +1 -0
- package/tools/products/search-products.d.ts +45 -0
- package/tools/products/search-products.d.ts.map +1 -0
- package/tools/products/search-products.js +73 -0
- package/tools/products/search-products.js.map +1 -0
- package/tools/products/search-products.mjs +69 -0
- package/tools/products/search-products.mjs.map +1 -0
- package/tools/products/variant-check/create-products-variant-check.d.mts +45 -0
- package/tools/products/variant-check/create-products-variant-check.d.mts.map +1 -0
- package/tools/products/variant-check/create-products-variant-check.d.ts +45 -0
- package/tools/products/variant-check/create-products-variant-check.d.ts.map +1 -0
- package/tools/products/variant-check/create-products-variant-check.js +79 -0
- package/tools/products/variant-check/create-products-variant-check.js.map +1 -0
- package/tools/products/variant-check/create-products-variant-check.mjs +75 -0
- package/tools/products/variant-check/create-products-variant-check.mjs.map +1 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.d.mts +45 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.d.mts.map +1 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.d.ts +45 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.d.ts.map +1 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.js +43 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.js.map +1 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.mjs +39 -0
- package/tools/products/variant-check/retrieve-status-products-variant-check.mjs.map +1 -0
- package/tools/types.d.mts +51 -0
- package/tools/types.d.mts.map +1 -0
- package/tools/types.d.ts +51 -0
- package/tools/types.d.ts.map +1 -0
- package/tools/types.js +46 -0
- package/tools/types.js.map +1 -0
- package/tools/types.mjs +42 -0
- package/tools/types.mjs.map +1 -0
- package/tools/wallet/create-card-collection-wallet.d.mts +45 -0
- package/tools/wallet/create-card-collection-wallet.d.mts.map +1 -0
- package/tools/wallet/create-card-collection-wallet.d.ts +45 -0
- package/tools/wallet/create-card-collection-wallet.d.ts.map +1 -0
- package/tools/wallet/create-card-collection-wallet.js +44 -0
- package/tools/wallet/create-card-collection-wallet.js.map +1 -0
- package/tools/wallet/create-card-collection-wallet.mjs +40 -0
- package/tools/wallet/create-card-collection-wallet.mjs.map +1 -0
- package/tools.d.mts +2 -0
- package/tools.d.mts.map +1 -0
- package/tools.d.ts +2 -0
- package/tools.d.ts.map +1 -0
- package/tools.js +18 -0
- package/tools.js.map +1 -0
- package/tools.mjs +2 -0
- package/tools.mjs.map +1 -0
package/dynamic-tools.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dynamicTools = dynamicTools;
|
|
4
|
+
const types_1 = require("./tools/types.js");
|
|
5
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
6
|
+
const zod_1 = require("zod");
|
|
7
|
+
const cabidela_1 = require("@cloudflare/cabidela");
|
|
8
|
+
function zodToInputSchema(schema) {
|
|
9
|
+
return {
|
|
10
|
+
type: 'object',
|
|
11
|
+
...(0, zod_to_json_schema_1.zodToJsonSchema)(schema),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A list of tools that expose all the endpoints in the API dynamically.
|
|
16
|
+
*
|
|
17
|
+
* Instead of exposing every endpoint as it's own tool, which uses up too many tokens for LLMs to use at once,
|
|
18
|
+
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
19
|
+
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
20
|
+
*
|
|
21
|
+
* @param endpoints - The endpoints to include in the list.
|
|
22
|
+
*/
|
|
23
|
+
function dynamicTools(endpoints) {
|
|
24
|
+
const listEndpointsSchema = zod_1.z.object({
|
|
25
|
+
search_query: zod_1.z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('An optional search query to filter the endpoints by. Provide a partial name, resource, operation, or tag to filter the endpoints returned.'),
|
|
29
|
+
});
|
|
30
|
+
const listEndpointsTool = {
|
|
31
|
+
metadata: {
|
|
32
|
+
resource: 'dynamic_tools',
|
|
33
|
+
operation: 'read',
|
|
34
|
+
tags: [],
|
|
35
|
+
},
|
|
36
|
+
tool: {
|
|
37
|
+
name: 'list_api_endpoints',
|
|
38
|
+
description: 'List or search for all endpoints in the Henry SDK TypeScript API',
|
|
39
|
+
inputSchema: zodToInputSchema(listEndpointsSchema),
|
|
40
|
+
},
|
|
41
|
+
handler: async (client, args) => {
|
|
42
|
+
const query = args && listEndpointsSchema.parse(args).search_query?.trim();
|
|
43
|
+
const filteredEndpoints = query && query.length > 0 ?
|
|
44
|
+
endpoints.filter((endpoint) => {
|
|
45
|
+
const fieldsToMatch = [
|
|
46
|
+
endpoint.tool.name,
|
|
47
|
+
endpoint.tool.description,
|
|
48
|
+
endpoint.metadata.resource,
|
|
49
|
+
endpoint.metadata.operation,
|
|
50
|
+
...endpoint.metadata.tags,
|
|
51
|
+
];
|
|
52
|
+
return fieldsToMatch.some((field) => field && field.toLowerCase().includes(query.toLowerCase()));
|
|
53
|
+
})
|
|
54
|
+
: endpoints;
|
|
55
|
+
return (0, types_1.asTextContentResult)({
|
|
56
|
+
tools: filteredEndpoints.map(({ tool, metadata }) => ({
|
|
57
|
+
name: tool.name,
|
|
58
|
+
description: tool.description,
|
|
59
|
+
resource: metadata.resource,
|
|
60
|
+
operation: metadata.operation,
|
|
61
|
+
tags: metadata.tags,
|
|
62
|
+
})),
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
const getEndpointSchema = zod_1.z.object({
|
|
67
|
+
endpoint: zod_1.z.string().describe('The name of the endpoint to get the schema for.'),
|
|
68
|
+
});
|
|
69
|
+
const getEndpointTool = {
|
|
70
|
+
metadata: {
|
|
71
|
+
resource: 'dynamic_tools',
|
|
72
|
+
operation: 'read',
|
|
73
|
+
tags: [],
|
|
74
|
+
},
|
|
75
|
+
tool: {
|
|
76
|
+
name: 'get_api_endpoint_schema',
|
|
77
|
+
description: 'Get the schema for an endpoint in the Henry SDK TypeScript API. You can use the schema returned by this tool to invoke an endpoint with the `invoke_api_endpoint` tool.',
|
|
78
|
+
inputSchema: zodToInputSchema(getEndpointSchema),
|
|
79
|
+
},
|
|
80
|
+
handler: async (client, args) => {
|
|
81
|
+
if (!args) {
|
|
82
|
+
throw new Error('No endpoint provided');
|
|
83
|
+
}
|
|
84
|
+
const endpointName = getEndpointSchema.parse(args).endpoint;
|
|
85
|
+
const endpoint = endpoints.find((e) => e.tool.name === endpointName);
|
|
86
|
+
if (!endpoint) {
|
|
87
|
+
throw new Error(`Endpoint ${endpointName} not found`);
|
|
88
|
+
}
|
|
89
|
+
return (0, types_1.asTextContentResult)(endpoint.tool);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
const invokeEndpointSchema = zod_1.z.object({
|
|
93
|
+
endpoint_name: zod_1.z.string().describe('The name of the endpoint to invoke.'),
|
|
94
|
+
args: zod_1.z
|
|
95
|
+
.record(zod_1.z.string(), zod_1.z.any())
|
|
96
|
+
.describe('The arguments to pass to the endpoint. This must match the schema returned by the `get_api_endpoint_schema` tool.'),
|
|
97
|
+
});
|
|
98
|
+
const invokeEndpointTool = {
|
|
99
|
+
metadata: {
|
|
100
|
+
resource: 'dynamic_tools',
|
|
101
|
+
operation: 'write',
|
|
102
|
+
tags: [],
|
|
103
|
+
},
|
|
104
|
+
tool: {
|
|
105
|
+
name: 'invoke_api_endpoint',
|
|
106
|
+
description: 'Invoke an endpoint in the Henry SDK TypeScript API. Note: use the `list_api_endpoints` tool to get the list of endpoints and `get_api_endpoint_schema` tool to get the schema for an endpoint.',
|
|
107
|
+
inputSchema: zodToInputSchema(invokeEndpointSchema),
|
|
108
|
+
},
|
|
109
|
+
handler: async (client, args) => {
|
|
110
|
+
if (!args) {
|
|
111
|
+
throw new Error('No endpoint provided');
|
|
112
|
+
}
|
|
113
|
+
const { success, data, error } = invokeEndpointSchema.safeParse(args);
|
|
114
|
+
if (!success) {
|
|
115
|
+
throw new Error(`Invalid arguments for endpoint. ${error?.format()}`);
|
|
116
|
+
}
|
|
117
|
+
const { endpoint_name, args: endpointArgs } = data;
|
|
118
|
+
const endpoint = endpoints.find((e) => e.tool.name === endpoint_name);
|
|
119
|
+
if (!endpoint) {
|
|
120
|
+
throw new Error(`Endpoint ${endpoint_name} not found. Use the \`list_api_endpoints\` tool to get the list of available endpoints.`);
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
// Try to validate the arguments for a better error message
|
|
124
|
+
const cabidela = new cabidela_1.Cabidela(endpoint.tool.inputSchema, { fullErrors: true });
|
|
125
|
+
cabidela.validate(endpointArgs);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new Error(`Invalid arguments for endpoint ${endpoint_name}:\n${error}`);
|
|
129
|
+
}
|
|
130
|
+
return await endpoint.handler(client, endpointArgs);
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
return [getEndpointTool, listEndpointsTool, invokeEndpointTool];
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=dynamic-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-tools.js","sourceRoot":"","sources":["src/dynamic-tools.ts"],"names":[],"mappings":";;AAsBA,oCAkIC;AAvJD,4CAA8E;AAC9E,2DAAqD;AACrD,6BAAwB;AACxB,mDAAgD;AAEhD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AE,GAAG,IAAI,CAAC;YAEnD,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;YACtE,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CACb,YAAY,aAAa,yFAAyF,CACnH,CAAC;YACJ,CAAC;YAED,IAAI,CAAC;gBACH,2DAA2D;gBAC3D,MAAM,QAAQ,GAAG,IAAI,mBAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/E,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAClC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,kCAAkC,aAAa,MAAM,KAAK,EAAE,CAAC,CAAC;YAChF,CAAC;YAED,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACtD,CAAC;KACF,CAAC;IAEF,OAAO,CAAC,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { asTextContentResult } from "./tools/types.mjs";
|
|
2
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { Cabidela } from '@cloudflare/cabidela';
|
|
5
|
+
function zodToInputSchema(schema) {
|
|
6
|
+
return {
|
|
7
|
+
type: 'object',
|
|
8
|
+
...zodToJsonSchema(schema),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A list of tools that expose all the endpoints in the API dynamically.
|
|
13
|
+
*
|
|
14
|
+
* Instead of exposing every endpoint as it's own tool, which uses up too many tokens for LLMs to use at once,
|
|
15
|
+
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
16
|
+
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
17
|
+
*
|
|
18
|
+
* @param endpoints - The endpoints to include in the list.
|
|
19
|
+
*/
|
|
20
|
+
export function dynamicTools(endpoints) {
|
|
21
|
+
const listEndpointsSchema = z.object({
|
|
22
|
+
search_query: z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe('An optional search query to filter the endpoints by. Provide a partial name, resource, operation, or tag to filter the endpoints returned.'),
|
|
26
|
+
});
|
|
27
|
+
const listEndpointsTool = {
|
|
28
|
+
metadata: {
|
|
29
|
+
resource: 'dynamic_tools',
|
|
30
|
+
operation: 'read',
|
|
31
|
+
tags: [],
|
|
32
|
+
},
|
|
33
|
+
tool: {
|
|
34
|
+
name: 'list_api_endpoints',
|
|
35
|
+
description: 'List or search for all endpoints in the Henry SDK TypeScript API',
|
|
36
|
+
inputSchema: zodToInputSchema(listEndpointsSchema),
|
|
37
|
+
},
|
|
38
|
+
handler: async (client, args) => {
|
|
39
|
+
const query = args && listEndpointsSchema.parse(args).search_query?.trim();
|
|
40
|
+
const filteredEndpoints = query && query.length > 0 ?
|
|
41
|
+
endpoints.filter((endpoint) => {
|
|
42
|
+
const fieldsToMatch = [
|
|
43
|
+
endpoint.tool.name,
|
|
44
|
+
endpoint.tool.description,
|
|
45
|
+
endpoint.metadata.resource,
|
|
46
|
+
endpoint.metadata.operation,
|
|
47
|
+
...endpoint.metadata.tags,
|
|
48
|
+
];
|
|
49
|
+
return fieldsToMatch.some((field) => field && field.toLowerCase().includes(query.toLowerCase()));
|
|
50
|
+
})
|
|
51
|
+
: endpoints;
|
|
52
|
+
return asTextContentResult({
|
|
53
|
+
tools: filteredEndpoints.map(({ tool, metadata }) => ({
|
|
54
|
+
name: tool.name,
|
|
55
|
+
description: tool.description,
|
|
56
|
+
resource: metadata.resource,
|
|
57
|
+
operation: metadata.operation,
|
|
58
|
+
tags: metadata.tags,
|
|
59
|
+
})),
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
const getEndpointSchema = z.object({
|
|
64
|
+
endpoint: z.string().describe('The name of the endpoint to get the schema for.'),
|
|
65
|
+
});
|
|
66
|
+
const getEndpointTool = {
|
|
67
|
+
metadata: {
|
|
68
|
+
resource: 'dynamic_tools',
|
|
69
|
+
operation: 'read',
|
|
70
|
+
tags: [],
|
|
71
|
+
},
|
|
72
|
+
tool: {
|
|
73
|
+
name: 'get_api_endpoint_schema',
|
|
74
|
+
description: 'Get the schema for an endpoint in the Henry SDK TypeScript API. You can use the schema returned by this tool to invoke an endpoint with the `invoke_api_endpoint` tool.',
|
|
75
|
+
inputSchema: zodToInputSchema(getEndpointSchema),
|
|
76
|
+
},
|
|
77
|
+
handler: async (client, args) => {
|
|
78
|
+
if (!args) {
|
|
79
|
+
throw new Error('No endpoint provided');
|
|
80
|
+
}
|
|
81
|
+
const endpointName = getEndpointSchema.parse(args).endpoint;
|
|
82
|
+
const endpoint = endpoints.find((e) => e.tool.name === endpointName);
|
|
83
|
+
if (!endpoint) {
|
|
84
|
+
throw new Error(`Endpoint ${endpointName} not found`);
|
|
85
|
+
}
|
|
86
|
+
return asTextContentResult(endpoint.tool);
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
const invokeEndpointSchema = z.object({
|
|
90
|
+
endpoint_name: z.string().describe('The name of the endpoint to invoke.'),
|
|
91
|
+
args: z
|
|
92
|
+
.record(z.string(), z.any())
|
|
93
|
+
.describe('The arguments to pass to the endpoint. This must match the schema returned by the `get_api_endpoint_schema` tool.'),
|
|
94
|
+
});
|
|
95
|
+
const invokeEndpointTool = {
|
|
96
|
+
metadata: {
|
|
97
|
+
resource: 'dynamic_tools',
|
|
98
|
+
operation: 'write',
|
|
99
|
+
tags: [],
|
|
100
|
+
},
|
|
101
|
+
tool: {
|
|
102
|
+
name: 'invoke_api_endpoint',
|
|
103
|
+
description: 'Invoke an endpoint in the Henry SDK TypeScript API. Note: use the `list_api_endpoints` tool to get the list of endpoints and `get_api_endpoint_schema` tool to get the schema for an endpoint.',
|
|
104
|
+
inputSchema: zodToInputSchema(invokeEndpointSchema),
|
|
105
|
+
},
|
|
106
|
+
handler: async (client, args) => {
|
|
107
|
+
if (!args) {
|
|
108
|
+
throw new Error('No endpoint provided');
|
|
109
|
+
}
|
|
110
|
+
const { success, data, error } = invokeEndpointSchema.safeParse(args);
|
|
111
|
+
if (!success) {
|
|
112
|
+
throw new Error(`Invalid arguments for endpoint. ${error?.format()}`);
|
|
113
|
+
}
|
|
114
|
+
const { endpoint_name, args: endpointArgs } = data;
|
|
115
|
+
const endpoint = endpoints.find((e) => e.tool.name === endpoint_name);
|
|
116
|
+
if (!endpoint) {
|
|
117
|
+
throw new Error(`Endpoint ${endpoint_name} not found. Use the \`list_api_endpoints\` tool to get the list of available endpoints.`);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
// Try to validate the arguments for a better error message
|
|
121
|
+
const cabidela = new Cabidela(endpoint.tool.inputSchema, { fullErrors: true });
|
|
122
|
+
cabidela.validate(endpointArgs);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new Error(`Invalid arguments for endpoint ${endpoint_name}:\n${error}`);
|
|
126
|
+
}
|
|
127
|
+
return await endpoint.handler(client, endpointArgs);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
return [getEndpointTool, listEndpointsTool, invokeEndpointTool];
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=dynamic-tools.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-tools.mjs","sourceRoot":"","sources":["src/dynamic-tools.ts"],"names":[],"mappings":"OACO,EAAY,mBAAmB,EAAkB;OACjD,EAAE,eAAe,EAAE,MAAM,oBAAoB;OAC7C,EAAE,CAAC,EAAE,MAAM,KAAK;OAChB,EAAE,QAAQ,EAAE,MAAM,sBAAsB;AAE/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I,CAAC;YAEnD,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC;YACtE,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CACb,YAAY,aAAa,yFAAyF,CACnH,CAAC;YACJ,CAAC;YAED,IAAI,CAAC;gBACH,2DAA2D;gBAC3D,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/E,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAClC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,kCAAkC,aAAa,MAAM,KAAK,EAAE,CAAC,CAAC;YAChF,CAAC;YAED,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACtD,CAAC;KACF,CAAC;IAEF,OAAO,CAAC,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AAClE,CAAC"}
|
package/filtering.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.d.mts","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":"AAGA,wBAAsB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAM5F"}
|
package/filtering.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":"AAGA,wBAAsB,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAM5F"}
|
package/filtering.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.maybeFilter = maybeFilter;
|
|
7
|
+
// @ts-nocheck
|
|
8
|
+
const jq_web_1 = __importDefault(require("jq-web"));
|
|
9
|
+
async function maybeFilter(jqFilter, response) {
|
|
10
|
+
if (jqFilter && typeof jqFilter === 'string') {
|
|
11
|
+
return await jq(response, jqFilter);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return response;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function jq(json, jqFilter) {
|
|
18
|
+
return (await jq_web_1.default).json(json, jqFilter);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=filtering.js.map
|
package/filtering.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.js","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":";;;;;AAGA,kCAMC;AATD,cAAc;AACd,oDAA4B;AAErB,KAAK,UAAU,WAAW,CAAC,QAA6B,EAAE,QAAa;IAC5E,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC,IAAS,EAAE,QAAgB;IAC3C,OAAO,CAAC,MAAM,gBAAM,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC"}
|
package/filtering.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import initJq from 'jq-web';
|
|
2
|
+
export async function maybeFilter(jqFilter, response) {
|
|
3
|
+
if (jqFilter && typeof jqFilter === 'string') {
|
|
4
|
+
return await jq(response, jqFilter);
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
return response;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
async function jq(json, jqFilter) {
|
|
11
|
+
return (await initJq).json(json, jqFilter);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=filtering.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.mjs","sourceRoot":"","sources":["src/filtering.ts"],"names":[],"mappings":"OACO,MAAM,MAAM,QAAQ;AAE3B,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAA6B,EAAE,QAAa;IAC5E,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC7C,OAAO,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC,IAAS,EAAE,QAAgB;IAC3C,OAAO,CAAC,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAC7C,CAAC"}
|
package/headers.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.d.mts","sourceRoot":"","sources":["src/headers.ts"],"names":[],"mappings":"OAEO,EAAE,eAAe,EAAE,MAAM,WAAW;OACpC,EAAE,aAAa,EAAE,MAAM,gBAAgB;AAE9C,eAAO,MAAM,gBAAgB,GAAI,KAAK,eAAe,KAAG,OAAO,CAAC,aAAa,CAQ5E,CAAC"}
|
package/headers.d.ts
ADDED
package/headers.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["src/headers.ts"],"names":[],"mappings":"OAEO,EAAE,eAAe,EAAE,MAAM,WAAW;OACpC,EAAE,aAAa,EAAE,MAAM,gBAAgB;AAE9C,eAAO,MAAM,gBAAgB,GAAI,KAAK,eAAe,KAAG,OAAO,CAAC,aAAa,CAQ5E,CAAC"}
|
package/headers.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parseAuthHeaders = void 0;
|
|
5
|
+
const parseAuthHeaders = (req) => {
|
|
6
|
+
const apiKey = Array.isArray(req.headers['x-api-key']) ? req.headers['x-api-key'][0] : req.headers['x-api-key'];
|
|
7
|
+
const accessToken = Array.isArray(req.headers['x-access-token']) ?
|
|
8
|
+
req.headers['x-access-token'][0]
|
|
9
|
+
: req.headers['x-access-token'];
|
|
10
|
+
return { apiKey, accessToken };
|
|
11
|
+
};
|
|
12
|
+
exports.parseAuthHeaders = parseAuthHeaders;
|
|
13
|
+
//# sourceMappingURL=headers.js.map
|
package/headers.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["src/headers.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAK/E,MAAM,gBAAgB,GAAG,CAAC,GAAoB,EAA0B,EAAE;IAC/E,MAAM,MAAM,GACV,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACnG,MAAM,WAAW,GACf,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC5C,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACjC,CAAC,CAAC;AARW,QAAA,gBAAgB,oBAQ3B"}
|
package/headers.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
export const parseAuthHeaders = (req) => {
|
|
3
|
+
const apiKey = Array.isArray(req.headers['x-api-key']) ? req.headers['x-api-key'][0] : req.headers['x-api-key'];
|
|
4
|
+
const accessToken = Array.isArray(req.headers['x-access-token']) ?
|
|
5
|
+
req.headers['x-access-token'][0]
|
|
6
|
+
: req.headers['x-access-token'];
|
|
7
|
+
return { apiKey, accessToken };
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=headers.mjs.map
|
package/headers.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.mjs","sourceRoot":"","sources":["src/headers.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAKtF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAoB,EAA0B,EAAE;IAC/E,MAAM,MAAM,GACV,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACnG,MAAM,WAAW,GACf,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC5C,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AACjC,CAAC,CAAC"}
|
package/http.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { McpOptions } from "./options.mjs";
|
|
3
|
+
import { ClientOptions } from "./server.mjs";
|
|
4
|
+
export declare const streamableHTTPApp: ({ clientOptions, mcpOptions, }: {
|
|
5
|
+
clientOptions?: ClientOptions;
|
|
6
|
+
mcpOptions?: McpOptions;
|
|
7
|
+
}) => express.Express;
|
|
8
|
+
export declare const launchStreamableHTTPServer: (options: McpOptions, port: number | string | undefined) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=http.d.mts.map
|
package/http.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.mts","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"OAKO,OAAO,MAAM,SAAS;OAEtB,EAAE,UAAU,EAAqB;OACjC,EAAE,aAAa,EAA+B;AAwFrD,eAAO,MAAM,iBAAiB,GAAI,gCAG/B;IACD,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,KAAG,OAAO,CAAC,OAUX,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAU,SAAS,UAAU,EAAE,MAAM,MAAM,GAAG,MAAM,GAAG,SAAS,kBAYtG,CAAC"}
|
package/http.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { McpOptions } from "./options.js";
|
|
3
|
+
import { ClientOptions } from "./server.js";
|
|
4
|
+
export declare const streamableHTTPApp: ({ clientOptions, mcpOptions, }: {
|
|
5
|
+
clientOptions?: ClientOptions;
|
|
6
|
+
mcpOptions?: McpOptions;
|
|
7
|
+
}) => express.Express;
|
|
8
|
+
export declare const launchStreamableHTTPServer: (options: McpOptions, port: number | string | undefined) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=http.d.ts.map
|
package/http.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":"OAKO,OAAO,MAAM,SAAS;OAEtB,EAAE,UAAU,EAAqB;OACjC,EAAE,aAAa,EAA+B;AAwFrD,eAAO,MAAM,iBAAiB,GAAI,gCAG/B;IACD,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,KAAG,OAAO,CAAC,OAUX,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAU,SAAS,UAAU,EAAE,MAAM,MAAM,GAAG,MAAM,GAAG,SAAS,kBAYtG,CAAC"}
|
package/http.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.launchStreamableHTTPServer = exports.streamableHTTPApp = void 0;
|
|
8
|
+
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
9
|
+
const express_1 = __importDefault(require("express"));
|
|
10
|
+
const v3_1 = require("zod-validation-error/v3");
|
|
11
|
+
const options_1 = require("./options.js");
|
|
12
|
+
const server_1 = require("./server.js");
|
|
13
|
+
const headers_1 = require("./headers.js");
|
|
14
|
+
const newServer = ({ clientOptions, mcpOptions: defaultMcpOptions, req, res, }) => {
|
|
15
|
+
const server = (0, server_1.newMcpServer)();
|
|
16
|
+
let mcpOptions;
|
|
17
|
+
try {
|
|
18
|
+
mcpOptions = (0, options_1.parseQueryOptions)(defaultMcpOptions, req.query);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
res.status(400).json({
|
|
22
|
+
jsonrpc: '2.0',
|
|
23
|
+
error: {
|
|
24
|
+
code: -32000,
|
|
25
|
+
message: `Invalid request: ${(0, v3_1.fromError)(error)}`,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const authOptions = (0, headers_1.parseAuthHeaders)(req);
|
|
32
|
+
(0, server_1.initMcpServer)({
|
|
33
|
+
server: server,
|
|
34
|
+
clientOptions: {
|
|
35
|
+
...clientOptions,
|
|
36
|
+
...authOptions,
|
|
37
|
+
},
|
|
38
|
+
mcpOptions,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
res.status(401).json({
|
|
43
|
+
jsonrpc: '2.0',
|
|
44
|
+
error: {
|
|
45
|
+
code: -32000,
|
|
46
|
+
message: 'Unauthorized',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return server;
|
|
52
|
+
};
|
|
53
|
+
const post = (options) => async (req, res) => {
|
|
54
|
+
const server = newServer({ ...options, req, res });
|
|
55
|
+
// If we return null, we already set the authorization error.
|
|
56
|
+
if (server === null)
|
|
57
|
+
return;
|
|
58
|
+
const transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
|
59
|
+
// Stateless server
|
|
60
|
+
sessionIdGenerator: undefined,
|
|
61
|
+
});
|
|
62
|
+
await server.connect(transport);
|
|
63
|
+
await transport.handleRequest(req, res, req.body);
|
|
64
|
+
};
|
|
65
|
+
const get = async (req, res) => {
|
|
66
|
+
res.status(405).json({
|
|
67
|
+
jsonrpc: '2.0',
|
|
68
|
+
error: {
|
|
69
|
+
code: -32000,
|
|
70
|
+
message: 'Method not supported',
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const del = async (req, res) => {
|
|
75
|
+
res.status(405).json({
|
|
76
|
+
jsonrpc: '2.0',
|
|
77
|
+
error: {
|
|
78
|
+
code: -32000,
|
|
79
|
+
message: 'Method not supported',
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const streamableHTTPApp = ({ clientOptions = {}, mcpOptions = {}, }) => {
|
|
84
|
+
const app = (0, express_1.default)();
|
|
85
|
+
app.set('query parser', 'extended');
|
|
86
|
+
app.use(express_1.default.json());
|
|
87
|
+
app.get('/', get);
|
|
88
|
+
app.post('/', post({ clientOptions, mcpOptions }));
|
|
89
|
+
app.delete('/', del);
|
|
90
|
+
return app;
|
|
91
|
+
};
|
|
92
|
+
exports.streamableHTTPApp = streamableHTTPApp;
|
|
93
|
+
const launchStreamableHTTPServer = async (options, port) => {
|
|
94
|
+
const app = (0, exports.streamableHTTPApp)({ mcpOptions: options });
|
|
95
|
+
const server = app.listen(port);
|
|
96
|
+
const address = server.address();
|
|
97
|
+
if (typeof address === 'string') {
|
|
98
|
+
console.error(`MCP Server running on streamable HTTP at ${address}`);
|
|
99
|
+
}
|
|
100
|
+
else if (address !== null) {
|
|
101
|
+
console.error(`MCP Server running on streamable HTTP on port ${address.port}`);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.error(`MCP Server running on streamable HTTP on port ${port}`);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.launchStreamableHTTPServer = launchStreamableHTTPServer;
|
|
108
|
+
//# sourceMappingURL=http.js.map
|
package/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["src/http.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAGtF,0FAAmG;AAEnG,sDAA8B;AAC9B,gDAAoD;AACpD,0CAA0D;AAC1D,wCAAsE;AACtE,0CAA6C;AAE7C,MAAM,SAAS,GAAG,CAAC,EACjB,aAAa,EACb,UAAU,EAAE,iBAAiB,EAC7B,GAAG,EACH,GAAG,GAMJ,EAAo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C;IACnD,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAErB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAhBW,QAAA,iBAAiB,qBAgB5B;AAEK,MAAM,0BAA0B,GAAG,KAAK,EAAE,OAAmB,EAAE,IAAiC,EAAE,EAAE;IACzG,MAAM,GAAG,GAAG,IAAA,yBAAiB,EAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,4CAA4C,OAAO,EAAE,CAAC,CAAC;IACvE,CAAC;SAAM,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,CAAC,iDAAiD,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,iDAAiD,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,0BAA0B,8BAYrC"}
|
package/http.mjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { fromError } from 'zod-validation-error/v3';
|
|
5
|
+
import { parseQueryOptions } from "./options.mjs";
|
|
6
|
+
import { initMcpServer, newMcpServer } from "./server.mjs";
|
|
7
|
+
import { parseAuthHeaders } from "./headers.mjs";
|
|
8
|
+
const newServer = ({ clientOptions, mcpOptions: defaultMcpOptions, req, res, }) => {
|
|
9
|
+
const server = newMcpServer();
|
|
10
|
+
let mcpOptions;
|
|
11
|
+
try {
|
|
12
|
+
mcpOptions = parseQueryOptions(defaultMcpOptions, req.query);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
res.status(400).json({
|
|
16
|
+
jsonrpc: '2.0',
|
|
17
|
+
error: {
|
|
18
|
+
code: -32000,
|
|
19
|
+
message: `Invalid request: ${fromError(error)}`,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const authOptions = parseAuthHeaders(req);
|
|
26
|
+
initMcpServer({
|
|
27
|
+
server: server,
|
|
28
|
+
clientOptions: {
|
|
29
|
+
...clientOptions,
|
|
30
|
+
...authOptions,
|
|
31
|
+
},
|
|
32
|
+
mcpOptions,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
res.status(401).json({
|
|
37
|
+
jsonrpc: '2.0',
|
|
38
|
+
error: {
|
|
39
|
+
code: -32000,
|
|
40
|
+
message: 'Unauthorized',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return server;
|
|
46
|
+
};
|
|
47
|
+
const post = (options) => async (req, res) => {
|
|
48
|
+
const server = newServer({ ...options, req, res });
|
|
49
|
+
// If we return null, we already set the authorization error.
|
|
50
|
+
if (server === null)
|
|
51
|
+
return;
|
|
52
|
+
const transport = new StreamableHTTPServerTransport({
|
|
53
|
+
// Stateless server
|
|
54
|
+
sessionIdGenerator: undefined,
|
|
55
|
+
});
|
|
56
|
+
await server.connect(transport);
|
|
57
|
+
await transport.handleRequest(req, res, req.body);
|
|
58
|
+
};
|
|
59
|
+
const get = async (req, res) => {
|
|
60
|
+
res.status(405).json({
|
|
61
|
+
jsonrpc: '2.0',
|
|
62
|
+
error: {
|
|
63
|
+
code: -32000,
|
|
64
|
+
message: 'Method not supported',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const del = async (req, res) => {
|
|
69
|
+
res.status(405).json({
|
|
70
|
+
jsonrpc: '2.0',
|
|
71
|
+
error: {
|
|
72
|
+
code: -32000,
|
|
73
|
+
message: 'Method not supported',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export const streamableHTTPApp = ({ clientOptions = {}, mcpOptions = {}, }) => {
|
|
78
|
+
const app = express();
|
|
79
|
+
app.set('query parser', 'extended');
|
|
80
|
+
app.use(express.json());
|
|
81
|
+
app.get('/', get);
|
|
82
|
+
app.post('/', post({ clientOptions, mcpOptions }));
|
|
83
|
+
app.delete('/', del);
|
|
84
|
+
return app;
|
|
85
|
+
};
|
|
86
|
+
export const launchStreamableHTTPServer = async (options, port) => {
|
|
87
|
+
const app = streamableHTTPApp({ mcpOptions: options });
|
|
88
|
+
const server = app.listen(port);
|
|
89
|
+
const address = server.address();
|
|
90
|
+
if (typeof address === 'string') {
|
|
91
|
+
console.error(`MCP Server running on streamable HTTP at ${address}`);
|
|
92
|
+
}
|
|
93
|
+
else if (address !== null) {
|
|
94
|
+
console.error(`MCP Server running on streamable HTTP on port ${address.port}`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.error(`MCP Server running on streamable HTTP on port ${port}`);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=http.mjs.map
|