@aws/ml-container-creator 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 +202 -0
- package/LICENSE-THIRD-PARTY +68620 -0
- package/NOTICE +2 -0
- package/README.md +106 -0
- package/bin/cli.js +365 -0
- package/config/defaults.json +32 -0
- package/config/presets/transformers-djl.json +26 -0
- package/config/presets/transformers-gpu.json +24 -0
- package/config/presets/transformers-lmi.json +27 -0
- package/package.json +129 -0
- package/servers/README.md +419 -0
- package/servers/base-image-picker/catalogs/model-servers.json +1191 -0
- package/servers/base-image-picker/catalogs/python-slim.json +38 -0
- package/servers/base-image-picker/catalogs/triton-backends.json +51 -0
- package/servers/base-image-picker/catalogs/triton.json +38 -0
- package/servers/base-image-picker/index.js +495 -0
- package/servers/base-image-picker/manifest.json +17 -0
- package/servers/base-image-picker/package.json +15 -0
- package/servers/hyperpod-cluster-picker/LICENSE +202 -0
- package/servers/hyperpod-cluster-picker/index.js +424 -0
- package/servers/hyperpod-cluster-picker/manifest.json +14 -0
- package/servers/hyperpod-cluster-picker/package.json +17 -0
- package/servers/instance-recommender/LICENSE +202 -0
- package/servers/instance-recommender/catalogs/instances.json +852 -0
- package/servers/instance-recommender/index.js +284 -0
- package/servers/instance-recommender/manifest.json +16 -0
- package/servers/instance-recommender/package.json +15 -0
- package/servers/lib/LICENSE +202 -0
- package/servers/lib/bedrock-client.js +160 -0
- package/servers/lib/custom-validators.js +46 -0
- package/servers/lib/dynamic-resolver.js +36 -0
- package/servers/lib/package.json +11 -0
- package/servers/lib/schemas/image-catalog.schema.json +185 -0
- package/servers/lib/schemas/instances.schema.json +124 -0
- package/servers/lib/schemas/manifest.schema.json +64 -0
- package/servers/lib/schemas/model-catalog.schema.json +91 -0
- package/servers/lib/schemas/regions.schema.json +26 -0
- package/servers/lib/schemas/triton-backends.schema.json +51 -0
- package/servers/model-picker/catalogs/jumpstart-public.json +66 -0
- package/servers/model-picker/catalogs/popular-diffusors.json +88 -0
- package/servers/model-picker/catalogs/popular-transformers.json +226 -0
- package/servers/model-picker/index.js +1693 -0
- package/servers/model-picker/manifest.json +18 -0
- package/servers/model-picker/package.json +20 -0
- package/servers/region-picker/LICENSE +202 -0
- package/servers/region-picker/catalogs/regions.json +263 -0
- package/servers/region-picker/index.js +230 -0
- package/servers/region-picker/manifest.json +16 -0
- package/servers/region-picker/package.json +15 -0
- package/src/app.js +1007 -0
- package/src/copy-tpl.js +77 -0
- package/src/lib/accelerator-validator.js +39 -0
- package/src/lib/asset-manager.js +385 -0
- package/src/lib/aws-profile-parser.js +181 -0
- package/src/lib/bootstrap-command-handler.js +1647 -0
- package/src/lib/bootstrap-config.js +238 -0
- package/src/lib/ci-register-helpers.js +124 -0
- package/src/lib/ci-report-helpers.js +158 -0
- package/src/lib/ci-stage-helpers.js +268 -0
- package/src/lib/cli-handler.js +529 -0
- package/src/lib/comment-generator.js +544 -0
- package/src/lib/community-reports-validator.js +91 -0
- package/src/lib/config-manager.js +2106 -0
- package/src/lib/configuration-exporter.js +204 -0
- package/src/lib/configuration-manager.js +695 -0
- package/src/lib/configuration-matcher.js +221 -0
- package/src/lib/cpu-validator.js +36 -0
- package/src/lib/cuda-validator.js +57 -0
- package/src/lib/deployment-config-resolver.js +103 -0
- package/src/lib/deployment-entry-schema.js +125 -0
- package/src/lib/deployment-registry.js +598 -0
- package/src/lib/docker-introspection-validator.js +51 -0
- package/src/lib/engine-prefix-resolver.js +60 -0
- package/src/lib/huggingface-client.js +172 -0
- package/src/lib/key-value-parser.js +37 -0
- package/src/lib/known-flags-validator.js +200 -0
- package/src/lib/manifest-cli.js +280 -0
- package/src/lib/mcp-client.js +303 -0
- package/src/lib/mcp-command-handler.js +532 -0
- package/src/lib/neuron-validator.js +80 -0
- package/src/lib/parameter-schema-validator.js +284 -0
- package/src/lib/prompt-runner.js +1349 -0
- package/src/lib/prompts.js +1138 -0
- package/src/lib/registry-command-handler.js +519 -0
- package/src/lib/registry-loader.js +198 -0
- package/src/lib/rocm-validator.js +80 -0
- package/src/lib/schema-validator.js +157 -0
- package/src/lib/sensitive-redactor.js +59 -0
- package/src/lib/template-engine.js +156 -0
- package/src/lib/template-manager.js +341 -0
- package/src/lib/validation-engine.js +314 -0
- package/src/prompt-adapter.js +63 -0
- package/templates/Dockerfile +300 -0
- package/templates/IAM_PERMISSIONS.md +84 -0
- package/templates/MIGRATION.md +488 -0
- package/templates/PROJECT_README.md +439 -0
- package/templates/TEMPLATE_SYSTEM.md +243 -0
- package/templates/buildspec.yml +64 -0
- package/templates/code/chat_template.jinja +1 -0
- package/templates/code/flask/gunicorn_config.py +35 -0
- package/templates/code/flask/wsgi.py +10 -0
- package/templates/code/model_handler.py +387 -0
- package/templates/code/serve +300 -0
- package/templates/code/serve.py +175 -0
- package/templates/code/serving.properties +105 -0
- package/templates/code/start_server.py +39 -0
- package/templates/code/start_server.sh +39 -0
- package/templates/diffusors/Dockerfile +72 -0
- package/templates/diffusors/patch_image_api.py +35 -0
- package/templates/diffusors/serve +115 -0
- package/templates/diffusors/start_server.sh +114 -0
- package/templates/do/.gitkeep +1 -0
- package/templates/do/README.md +541 -0
- package/templates/do/build +83 -0
- package/templates/do/ci +681 -0
- package/templates/do/clean +811 -0
- package/templates/do/config +260 -0
- package/templates/do/deploy +1560 -0
- package/templates/do/export +306 -0
- package/templates/do/logs +319 -0
- package/templates/do/manifest +12 -0
- package/templates/do/push +119 -0
- package/templates/do/register +580 -0
- package/templates/do/run +113 -0
- package/templates/do/submit +417 -0
- package/templates/do/test +1147 -0
- package/templates/hyperpod/configmap.yaml +24 -0
- package/templates/hyperpod/deployment.yaml +71 -0
- package/templates/hyperpod/pvc.yaml +42 -0
- package/templates/hyperpod/service.yaml +17 -0
- package/templates/nginx-diffusors.conf +74 -0
- package/templates/nginx-predictors.conf +47 -0
- package/templates/nginx-tensorrt.conf +74 -0
- package/templates/requirements.txt +61 -0
- package/templates/sample_model/test_inference.py +123 -0
- package/templates/sample_model/train_abalone.py +252 -0
- package/templates/test/test_endpoint.sh +79 -0
- package/templates/test/test_local_image.sh +80 -0
- package/templates/test/test_model_handler.py +180 -0
- package/templates/triton/Dockerfile +128 -0
- package/templates/triton/config.pbtxt +163 -0
- package/templates/triton/model.py +130 -0
- package/templates/triton/requirements.txt +11 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* HyperPod Cluster Picker MCP Server
|
|
7
|
+
*
|
|
8
|
+
* A bundled MCP server that discovers available SageMaker HyperPod EKS clusters
|
|
9
|
+
* via the AWS SageMaker ListClusters and DescribeCluster APIs.
|
|
10
|
+
*
|
|
11
|
+
* Only clusters that are InService and use EKS orchestration are returned.
|
|
12
|
+
* Slurm-based clusters are excluded.
|
|
13
|
+
*
|
|
14
|
+
* Tool: get_hyperpod_clusters
|
|
15
|
+
* Accepts: { parameters: string[], limit: number, context: object }
|
|
16
|
+
* Returns: { values: Record<string, string>, choices: Record<string, string[]> }
|
|
17
|
+
*
|
|
18
|
+
* Environment variables:
|
|
19
|
+
* AWS_REGION - AWS region for SageMaker API calls (default: us-east-1)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
23
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
24
|
+
import { z } from 'zod'
|
|
25
|
+
import { fileURLToPath } from 'node:url'
|
|
26
|
+
import { resolve } from 'node:path'
|
|
27
|
+
import { readFileSync } from 'node:fs'
|
|
28
|
+
import { homedir } from 'node:os'
|
|
29
|
+
import { DynamicResolver } from '../lib/dynamic-resolver.js'
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Log to stderr so it doesn't interfere with MCP stdio protocol on stdout.
|
|
33
|
+
*/
|
|
34
|
+
function log(message) {
|
|
35
|
+
process.stderr.write(`[hyperpod-cluster-picker] ${message}\n`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a SageMaker client for the given region.
|
|
40
|
+
* Accepts an optional factory function for testability.
|
|
41
|
+
* If no credentials are found with the default provider chain,
|
|
42
|
+
* falls back to the first available AWS profile.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} region - AWS region
|
|
45
|
+
* @param {Function|null} clientFactory - Optional factory (used in tests)
|
|
46
|
+
* @returns {object} SageMaker client
|
|
47
|
+
*/
|
|
48
|
+
function createSageMakerClient(region, clientFactory = null) {
|
|
49
|
+
if (clientFactory) return clientFactory(region)
|
|
50
|
+
return _defaultClientFactory(region)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let _SageMakerClient = null
|
|
54
|
+
let _ListClustersCommand = null
|
|
55
|
+
let _DescribeClusterCommand = null
|
|
56
|
+
let _fromIni = null
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Lazily load the AWS SDK SageMaker client classes.
|
|
60
|
+
* This allows the module to be imported in test environments
|
|
61
|
+
* without requiring @aws-sdk/client-sagemaker to be installed.
|
|
62
|
+
*/
|
|
63
|
+
async function _ensureSdkLoaded() {
|
|
64
|
+
if (_SageMakerClient) return
|
|
65
|
+
const sdk = await import('@aws-sdk/client-sagemaker')
|
|
66
|
+
_SageMakerClient = sdk.SageMakerClient
|
|
67
|
+
_ListClustersCommand = sdk.ListClustersCommand
|
|
68
|
+
_DescribeClusterCommand = sdk.DescribeClusterCommand
|
|
69
|
+
try {
|
|
70
|
+
const credentialProviders = await import('@aws-sdk/credential-providers')
|
|
71
|
+
_fromIni = credentialProviders.fromIni
|
|
72
|
+
} catch {
|
|
73
|
+
// credential-providers not available — profile-based fallback won't work
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function _defaultClientFactory(region) {
|
|
78
|
+
return new _SageMakerClient({ region })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create a SageMaker client using a named AWS profile via fromIni.
|
|
83
|
+
* @param {string} region - AWS region
|
|
84
|
+
* @param {string} profile - AWS profile name
|
|
85
|
+
* @returns {object} SageMaker client
|
|
86
|
+
*/
|
|
87
|
+
function _createClientWithProfile(region, profile) {
|
|
88
|
+
if (!_fromIni) {
|
|
89
|
+
throw new Error('Cannot use profile-based credentials: @aws-sdk/credential-providers not available')
|
|
90
|
+
}
|
|
91
|
+
return new _SageMakerClient({
|
|
92
|
+
region,
|
|
93
|
+
credentials: _fromIni({ profile })
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Detect available AWS profile names from ~/.aws/credentials and ~/.aws/config.
|
|
99
|
+
* @returns {string[]} Array of profile names
|
|
100
|
+
*/
|
|
101
|
+
function _detectAwsProfiles() {
|
|
102
|
+
const profiles = new Set()
|
|
103
|
+
try {
|
|
104
|
+
const credsPath = resolve(homedir(), '.aws/credentials')
|
|
105
|
+
const creds = readFileSync(credsPath, 'utf8')
|
|
106
|
+
for (const match of creds.matchAll(/^\[(.+)\]$/gm)) {
|
|
107
|
+
profiles.add(match[1])
|
|
108
|
+
}
|
|
109
|
+
} catch { /* no credentials file */ }
|
|
110
|
+
try {
|
|
111
|
+
const configPath = resolve(homedir(), '.aws/config')
|
|
112
|
+
const config = readFileSync(configPath, 'utf8')
|
|
113
|
+
for (const match of config.matchAll(/^\[profile\s+(.+)\]$/gm)) {
|
|
114
|
+
profiles.add(match[1])
|
|
115
|
+
}
|
|
116
|
+
} catch { /* no config file */ }
|
|
117
|
+
return [...profiles]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Fetch all HyperPod clusters, filtering to InService + EKS only.
|
|
122
|
+
*
|
|
123
|
+
* @param {object} client - SageMaker client instance
|
|
124
|
+
* @param {object} options - { limit }
|
|
125
|
+
* @returns {Promise<Array<{ clusterName: string, clusterArn: string, status: string, instanceGroups: Array }>>}
|
|
126
|
+
*/
|
|
127
|
+
async function fetchHyperPodClusters(client, { limit = 10 } = {}) {
|
|
128
|
+
const clusters = []
|
|
129
|
+
let nextToken
|
|
130
|
+
|
|
131
|
+
// Paginate through ListClusters
|
|
132
|
+
do {
|
|
133
|
+
const params = { MaxResults: 100 }
|
|
134
|
+
if (nextToken) params.NextToken = nextToken
|
|
135
|
+
|
|
136
|
+
const command = new _ListClustersCommand(params)
|
|
137
|
+
const response = await client.send(command)
|
|
138
|
+
|
|
139
|
+
const summaries = response.ClusterSummaries || []
|
|
140
|
+
for (const summary of summaries) {
|
|
141
|
+
// Filter: InService only
|
|
142
|
+
if (summary.ClusterStatus !== 'InService') continue
|
|
143
|
+
|
|
144
|
+
clusters.push({
|
|
145
|
+
clusterName: summary.ClusterName,
|
|
146
|
+
clusterArn: summary.ClusterArn,
|
|
147
|
+
status: summary.ClusterStatus
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
nextToken = response.NextToken
|
|
152
|
+
} while (nextToken && clusters.length < limit * 3) // over-fetch to account for EKS filtering
|
|
153
|
+
|
|
154
|
+
// Now describe each cluster to check orchestrator type and get instance groups
|
|
155
|
+
const eksClusters = []
|
|
156
|
+
for (const cluster of clusters) {
|
|
157
|
+
if (eksClusters.length >= limit) break
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
const describeCommand = new _DescribeClusterCommand({
|
|
161
|
+
ClusterName: cluster.clusterName
|
|
162
|
+
})
|
|
163
|
+
const detail = await client.send(describeCommand)
|
|
164
|
+
|
|
165
|
+
// Filter: EKS orchestrator only (exclude Slurm)
|
|
166
|
+
const orchestrator = detail.Orchestrator?.Eks ? 'EKS' : 'Slurm'
|
|
167
|
+
if (orchestrator !== 'EKS') continue
|
|
168
|
+
|
|
169
|
+
const instanceGroups = (detail.InstanceGroups || []).map(g => ({
|
|
170
|
+
name: g.InstanceGroupName,
|
|
171
|
+
instanceType: g.InstanceType,
|
|
172
|
+
count: g.CurrentCount ?? g.TargetCount ?? 0
|
|
173
|
+
}))
|
|
174
|
+
|
|
175
|
+
eksClusters.push({
|
|
176
|
+
clusterName: cluster.clusterName,
|
|
177
|
+
clusterArn: cluster.clusterArn,
|
|
178
|
+
status: cluster.status,
|
|
179
|
+
instanceGroups
|
|
180
|
+
})
|
|
181
|
+
} catch (err) {
|
|
182
|
+
log(`Warning: could not describe cluster "${cluster.clusterName}": ${err.message}`)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return eksClusters
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Build the MCP response from a list of discovered clusters.
|
|
191
|
+
*
|
|
192
|
+
* @param {Array} clusters - Array of cluster objects from fetchHyperPodClusters
|
|
193
|
+
* @returns {{ values: object, choices: object, metadata?: object }}
|
|
194
|
+
*/
|
|
195
|
+
function buildResponse(clusters) {
|
|
196
|
+
if (!clusters || clusters.length === 0) {
|
|
197
|
+
return {
|
|
198
|
+
values: {},
|
|
199
|
+
choices: { hyperPodCluster: [] },
|
|
200
|
+
message: 'No InService HyperPod EKS clusters found in the specified region. Verify the region and that you have HyperPod EKS clusters provisioned.'
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const clusterNames = clusters.map(c => c.clusterName)
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
values: { hyperPodCluster: clusterNames[0] },
|
|
208
|
+
choices: { hyperPodCluster: clusterNames },
|
|
209
|
+
metadata: Object.fromEntries(
|
|
210
|
+
clusters.map(c => [c.clusterName, {
|
|
211
|
+
clusterArn: c.clusterArn,
|
|
212
|
+
status: c.status,
|
|
213
|
+
instanceGroups: c.instanceGroups
|
|
214
|
+
}])
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ── ClusterResolver ──────────────────────────────────────────────────────────
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* ClusterResolver — discovers HyperPod EKS clusters via AWS SageMaker APIs.
|
|
223
|
+
*
|
|
224
|
+
* Extends DynamicResolver to fit the shared resolver pattern. Wraps the
|
|
225
|
+
* existing fetchHyperPodClusters logic with credential strategy fallback.
|
|
226
|
+
*/
|
|
227
|
+
class ClusterResolver extends DynamicResolver {
|
|
228
|
+
constructor(options = {}) {
|
|
229
|
+
super()
|
|
230
|
+
this._region = options.region || process.env.AWS_REGION || 'us-east-1'
|
|
231
|
+
this._profile = options.profile || process.env.AWS_PROFILE || null
|
|
232
|
+
this._clientFactory = options.clientFactory || null
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async fetch(key, options = {}) {
|
|
236
|
+
const { limit = 10 } = options
|
|
237
|
+
|
|
238
|
+
await _ensureSdkLoaded()
|
|
239
|
+
|
|
240
|
+
let clusters = null
|
|
241
|
+
let lastError = null
|
|
242
|
+
|
|
243
|
+
// Strategy 1: If a specific profile was requested, use it directly
|
|
244
|
+
if (this._profile) {
|
|
245
|
+
try {
|
|
246
|
+
const client = _createClientWithProfile(this._region, this._profile)
|
|
247
|
+
clusters = await fetchHyperPodClusters(client, { limit })
|
|
248
|
+
} catch (err) {
|
|
249
|
+
log(`Profile "${this._profile}" failed: ${err.message}`)
|
|
250
|
+
lastError = err
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Strategy 2: Try the default credential chain
|
|
255
|
+
if (!clusters) {
|
|
256
|
+
try {
|
|
257
|
+
const client = createSageMakerClient(this._region, this._clientFactory)
|
|
258
|
+
clusters = await fetchHyperPodClusters(client, { limit })
|
|
259
|
+
} catch (err) {
|
|
260
|
+
log(`Default credential chain failed: ${err.message}`)
|
|
261
|
+
lastError = err
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Strategy 3: Detect available AWS profiles and try each
|
|
266
|
+
if (!clusters && _fromIni) {
|
|
267
|
+
const profiles = _detectAwsProfiles()
|
|
268
|
+
for (const p of profiles) {
|
|
269
|
+
try {
|
|
270
|
+
const client = _createClientWithProfile(this._region, p)
|
|
271
|
+
clusters = await fetchHyperPodClusters(client, { limit })
|
|
272
|
+
log(`Profile "${p}" succeeded`)
|
|
273
|
+
break
|
|
274
|
+
} catch (err) {
|
|
275
|
+
log(`Profile "${p}" failed: ${err.message}`)
|
|
276
|
+
lastError = err
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (!clusters) {
|
|
282
|
+
throw lastError || new Error('No AWS credentials available')
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
items: clusters,
|
|
287
|
+
defaultItem: clusters[0] || null
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
supportedKeys() {
|
|
292
|
+
return ['hyperPodCluster']
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Create MCP server
|
|
297
|
+
const server = new McpServer({
|
|
298
|
+
name: 'hyperpod-cluster-picker',
|
|
299
|
+
version: '1.0.0'
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
// Register the get_hyperpod_clusters tool
|
|
303
|
+
server.tool(
|
|
304
|
+
'get_hyperpod_clusters',
|
|
305
|
+
'Discovers available SageMaker HyperPod EKS clusters for deployment target selection',
|
|
306
|
+
{
|
|
307
|
+
parameters: z.array(z.string()).describe('List of parameter names to provide values for'),
|
|
308
|
+
limit: z.number().int().positive().default(10).describe('Maximum number of choices per parameter'),
|
|
309
|
+
context: z.record(z.string(), z.any()).optional().describe('Current configuration context (awsRegion, etc.)')
|
|
310
|
+
},
|
|
311
|
+
async ({ parameters, limit, context }) => {
|
|
312
|
+
// If hyperPodCluster is not requested, return empty
|
|
313
|
+
if (!parameters.includes('hyperPodCluster')) {
|
|
314
|
+
return {
|
|
315
|
+
content: [{
|
|
316
|
+
type: 'text',
|
|
317
|
+
text: JSON.stringify({ values: {}, choices: {} })
|
|
318
|
+
}]
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const region = context?.awsRegion || process.env.AWS_REGION || 'us-east-1'
|
|
323
|
+
const profile = context?.awsProfile || process.env.AWS_PROFILE || null
|
|
324
|
+
log(`Querying HyperPod clusters in region: ${region}${profile ? ` (profile: ${profile})` : ''}`)
|
|
325
|
+
|
|
326
|
+
try {
|
|
327
|
+
await _ensureSdkLoaded()
|
|
328
|
+
|
|
329
|
+
let clusters = null
|
|
330
|
+
let lastError = null
|
|
331
|
+
|
|
332
|
+
// Strategy 1: If a specific profile was requested, use it directly
|
|
333
|
+
if (profile) {
|
|
334
|
+
try {
|
|
335
|
+
log(`Trying explicit profile: ${profile}`)
|
|
336
|
+
const client = _createClientWithProfile(region, profile)
|
|
337
|
+
clusters = await fetchHyperPodClusters(client, { limit })
|
|
338
|
+
} catch (err) {
|
|
339
|
+
log(`Profile "${profile}" failed: ${err.message}`)
|
|
340
|
+
lastError = err
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Strategy 2: Try the default credential chain (env vars, instance profile, etc.)
|
|
345
|
+
if (!clusters) {
|
|
346
|
+
try {
|
|
347
|
+
log('Trying default credential chain')
|
|
348
|
+
const client = createSageMakerClient(region)
|
|
349
|
+
clusters = await fetchHyperPodClusters(client, { limit })
|
|
350
|
+
} catch (err) {
|
|
351
|
+
log(`Default credential chain failed: ${err.message}`)
|
|
352
|
+
lastError = err
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Strategy 3: Detect available AWS profiles and try each
|
|
357
|
+
if (!clusters && _fromIni) {
|
|
358
|
+
const profiles = _detectAwsProfiles()
|
|
359
|
+
if (profiles.length > 0) {
|
|
360
|
+
log(`Default credentials failed, trying ${profiles.length} detected profile(s): ${profiles.join(', ')}`)
|
|
361
|
+
for (const p of profiles) {
|
|
362
|
+
try {
|
|
363
|
+
const client = _createClientWithProfile(region, p)
|
|
364
|
+
clusters = await fetchHyperPodClusters(client, { limit })
|
|
365
|
+
log(`Profile "${p}" succeeded`)
|
|
366
|
+
break
|
|
367
|
+
} catch (err) {
|
|
368
|
+
log(`Profile "${p}" failed: ${err.message}`)
|
|
369
|
+
lastError = err
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// If all strategies failed, throw the last error
|
|
376
|
+
if (!clusters) {
|
|
377
|
+
throw lastError || new Error('No AWS credentials available')
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const result = buildResponse(clusters)
|
|
381
|
+
|
|
382
|
+
if (clusters.length > 0) {
|
|
383
|
+
log(`Found ${clusters.length} HyperPod EKS cluster(s)`)
|
|
384
|
+
} else {
|
|
385
|
+
log('No InService HyperPod EKS clusters found')
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return {
|
|
389
|
+
content: [{
|
|
390
|
+
type: 'text',
|
|
391
|
+
text: JSON.stringify(result)
|
|
392
|
+
}]
|
|
393
|
+
}
|
|
394
|
+
} catch (err) {
|
|
395
|
+
log(`Error querying clusters: ${err.message}`)
|
|
396
|
+
const errorResult = {
|
|
397
|
+
values: {},
|
|
398
|
+
choices: { hyperPodCluster: [] },
|
|
399
|
+
error: err.message,
|
|
400
|
+
message: `Failed to query HyperPod clusters: ${err.message}`
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
content: [{
|
|
404
|
+
type: 'text',
|
|
405
|
+
text: JSON.stringify(errorResult)
|
|
406
|
+
}]
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
// Export for testing
|
|
413
|
+
export { fetchHyperPodClusters, buildResponse, createSageMakerClient, _ensureSdkLoaded, ClusterResolver }
|
|
414
|
+
|
|
415
|
+
// Guard MCP transport — only connect when run as main module
|
|
416
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
417
|
+
const isMain = process.argv[1] && resolve(process.argv[1]) === __filename
|
|
418
|
+
|
|
419
|
+
if (isMain) {
|
|
420
|
+
log('Starting HyperPod Cluster Picker MCP server')
|
|
421
|
+
await _ensureSdkLoaded()
|
|
422
|
+
const transport = new StdioServerTransport()
|
|
423
|
+
await server.connect(transport)
|
|
424
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amzn/ml-container-creator-hyperpod-cluster-picker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP server that discovers available SageMaker HyperPod EKS clusters.",
|
|
5
|
+
"modes": {
|
|
6
|
+
"static": false,
|
|
7
|
+
"smart": false,
|
|
8
|
+
"discover": true
|
|
9
|
+
},
|
|
10
|
+
"catalogs": {},
|
|
11
|
+
"tool": {
|
|
12
|
+
"name": "get_hyperpod_clusters"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amzn/ml-container-creator-hyperpod-cluster-picker",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "MCP server that discovers available SageMaker HyperPod EKS clusters for ML Container Creator deployment target selection.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node test.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@aws-sdk/client-sagemaker": "^3.700.0",
|
|
14
|
+
"@aws-sdk/credential-providers": "^3.700.0",
|
|
15
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|