aws-notebook-runner-mcp 0.0.1__tar.gz

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.
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ .pytest_cache/
3
+ __pycache__/
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YummyTastyCode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,418 @@
1
+ Metadata-Version: 2.4
2
+ Name: aws-notebook-runner-mcp
3
+ Version: 0.0.1
4
+ Summary: MCP server for guarded AWS notebook execution with EC2/SSM and SageMaker planning
5
+ Project-URL: Homepage, https://github.com/YummyTastyCode/aws-notebook-runner-mcp
6
+ Project-URL: Issues, https://github.com/YummyTastyCode/aws-notebook-runner-mcp/issues
7
+ Author: YummyTastyCode
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: aws,ec2,jupyter,mcp,notebook,sagemaker,ssm
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: mcp<2,>=1.9
21
+ Requires-Dist: nbformat<6,>=5.10
22
+ Provides-Extra: aws
23
+ Requires-Dist: boto3<2,>=1.34; extra == 'aws'
24
+ Requires-Dist: pytz>=2024.1; extra == 'aws'
25
+ Requires-Dist: sagemaker<3,>=2.220; extra == 'aws'
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest<9,>=8; extra == 'test'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # AWS Notebook Runner MCP
31
+
32
+ Run Jupyter notebooks on temporary AWS compute through an MCP server, with
33
+ dry-run planning, guardrails, progress reporting, cost estimates, S3 artifacts,
34
+ and automatic cleanup.
35
+
36
+ This is **not Google Colab automation** and it does not bypass provider limits.
37
+ It is an AI-facing wrapper for AWS notebook execution. The current working
38
+ execution backend is **EC2 + Systems Manager (SSM)**. A SageMaker Notebook Jobs
39
+ backend is included for planning and future execution, but it depends on your
40
+ AWS account quotas.
41
+
42
+ This project is not affiliated with, endorsed by, or sponsored by Amazon Web
43
+ Services. AWS and Amazon SageMaker are trademarks of Amazon.com, Inc. or its
44
+ affiliates.
45
+
46
+ ## What It Can Do
47
+
48
+ - Inspect a local `.ipynb` under an allowlisted local root.
49
+ - Estimate compute cost before launch.
50
+ - Build dry-run plans without starting paid compute.
51
+ - Start a temporary EC2 instance for a notebook run.
52
+ - Execute the notebook through SSM with `nbconvert`.
53
+ - Upload the executed notebook and artifacts to S3.
54
+ - Report progress, elapsed time, ETA, SSM status, EC2 state, artifacts, and
55
+ current compute cost estimate.
56
+ - Terminate the EC2 instance automatically after completion.
57
+ - Refuse paid compute unless both an environment flag and confirmation token are
58
+ provided.
59
+
60
+ ## What It Does Not Do
61
+
62
+ - It does not create or broaden IAM permissions.
63
+ - It does not manage arbitrary AWS resources.
64
+ - It does not open SSH ports.
65
+ - It does not provide exact cell-level progress yet.
66
+ - It does not include memory/filesystem metrics unless you add SSM snapshots or
67
+ CloudWatch Agent support.
68
+ - It does not make AWS quota requests.
69
+
70
+ ## Install
71
+
72
+ From PyPI, after publication:
73
+
74
+ ```bash
75
+ pip install "aws-notebook-runner-mcp[aws]"
76
+ ```
77
+
78
+ From a local checkout:
79
+
80
+ ```bash
81
+ python3 -m venv .venv
82
+ .venv/bin/pip install -e ".[aws,test]"
83
+ ```
84
+
85
+ Run the MCP server:
86
+
87
+ ```bash
88
+ aws-notebook-runner-mcp
89
+ ```
90
+
91
+ ## Required AWS Resources
92
+
93
+ You need:
94
+
95
+ - An S3 bucket/prefix for notebook inputs, outputs, and status files.
96
+ - An IAM user or role for the local MCP server.
97
+ - An EC2 instance role/profile for temporary notebook instances.
98
+ - A default VPC/subnet or explicit subnet id.
99
+ - SSM access; no inbound SSH is required.
100
+
101
+ The tested setup used:
102
+
103
+ ```text
104
+ AWS region: eu-north-1
105
+ S3 root: s3://YOUR_BUCKET/runs
106
+ EC2 instance profile: EC2NotebookRunnerRole
107
+ Instance type: t3.micro
108
+ ```
109
+
110
+ ## IAM: Local MCP User
111
+
112
+ Attach a managed policy to the IAM principal used by your local AWS profile.
113
+ Keep it scoped to your account and bucket where possible.
114
+
115
+ Minimal EC2/SSM/S3 policy shape:
116
+
117
+ ```json
118
+ {
119
+ "Version": "2012-10-17",
120
+ "Statement": [
121
+ {
122
+ "Sid": "PassNotebookRunnerRole",
123
+ "Effect": "Allow",
124
+ "Action": "iam:PassRole",
125
+ "Resource": "arn:aws:iam::123456789012:role/EC2NotebookRunnerRole"
126
+ },
127
+ {
128
+ "Sid": "EC2NotebookRunnerControl",
129
+ "Effect": "Allow",
130
+ "Action": [
131
+ "ec2:RunInstances",
132
+ "ec2:TerminateInstances",
133
+ "ec2:CreateTags",
134
+ "ec2:DescribeInstances",
135
+ "ec2:DescribeInstanceStatus",
136
+ "ec2:DescribeImages",
137
+ "ec2:DescribeSubnets",
138
+ "ec2:DescribeVpcs",
139
+ "ec2:DescribeSecurityGroups"
140
+ ],
141
+ "Resource": "*"
142
+ },
143
+ {
144
+ "Sid": "SSMNotebookRunnerControl",
145
+ "Effect": "Allow",
146
+ "Action": [
147
+ "ssm:SendCommand",
148
+ "ssm:GetCommandInvocation",
149
+ "ssm:DescribeInstanceInformation"
150
+ ],
151
+ "Resource": "*"
152
+ },
153
+ {
154
+ "Sid": "NotebookRunnerS3Access",
155
+ "Effect": "Allow",
156
+ "Action": [
157
+ "s3:GetObject",
158
+ "s3:PutObject",
159
+ "s3:DeleteObject",
160
+ "s3:ListBucket"
161
+ ],
162
+ "Resource": [
163
+ "arn:aws:s3:::YOUR_BUCKET",
164
+ "arn:aws:s3:::YOUR_BUCKET/runs/*"
165
+ ]
166
+ },
167
+ {
168
+ "Sid": "OptionalCloudWatchMetrics",
169
+ "Effect": "Allow",
170
+ "Action": "cloudwatch:GetMetricStatistics",
171
+ "Resource": "*"
172
+ }
173
+ ]
174
+ }
175
+ ```
176
+
177
+ `cloudwatch:GetMetricStatistics` is optional. Without it, status still works,
178
+ but CPU/network/disk I/O metrics are reported as unavailable.
179
+
180
+ ## IAM: EC2 Instance Role
181
+
182
+ Create an EC2 role, for example `EC2NotebookRunnerRole`, with:
183
+
184
+ - Trust policy for `ec2.amazonaws.com`.
185
+ - AWS managed policy: `AmazonSSMManagedInstanceCore`.
186
+ - S3 access to the run prefix.
187
+
188
+ Example inline S3 policy for the EC2 role:
189
+
190
+ ```json
191
+ {
192
+ "Version": "2012-10-17",
193
+ "Statement": [
194
+ {
195
+ "Sid": "NotebookRunnerInstanceS3Access",
196
+ "Effect": "Allow",
197
+ "Action": [
198
+ "s3:GetObject",
199
+ "s3:PutObject",
200
+ "s3:DeleteObject"
201
+ ],
202
+ "Resource": "arn:aws:s3:::YOUR_BUCKET/runs/ec2/*"
203
+ }
204
+ ]
205
+ }
206
+ ```
207
+
208
+ When you create the role through the AWS console, AWS usually creates an
209
+ instance profile with the same name as the role.
210
+
211
+ ## Environment
212
+
213
+ Core settings:
214
+
215
+ ```bash
216
+ export AWS_PROFILE=research
217
+ export AWS_REGION=eu-north-1
218
+ export AWS_NOTEBOOK_RUNNER_ROOT=/absolute/path/to/local/notebooks
219
+ export AWS_NOTEBOOK_S3_ROOT=s3://YOUR_BUCKET/runs
220
+ export AWS_NOTEBOOK_BACKEND=ec2_ssm
221
+ export AWS_NOTEBOOK_ROLE_ARN=arn:aws:iam::123456789012:role/EC2NotebookRunnerRole
222
+ export AWS_NOTEBOOK_ALLOWED_INSTANCE_TYPES=t3.micro,t3.small
223
+ export AWS_NOTEBOOK_DEFAULT_INSTANCE_TYPE=t3.micro
224
+ export AWS_NOTEBOOK_MAX_RUNTIME_SECONDS=1800
225
+ export AWS_NOTEBOOK_MAX_ESTIMATED_COST_USD=1
226
+ ```
227
+
228
+ Paid compute is disabled unless you opt in:
229
+
230
+ ```bash
231
+ export AWS_NOTEBOOK_RUNNER_ENABLE_EXECUTION=true
232
+ ```
233
+
234
+ The MCP caller must also pass:
235
+
236
+ ```text
237
+ confirmation_token = START_PAID_EC2_NOTEBOOK_RUN
238
+ ```
239
+
240
+ SageMaker execution, when quotas are available, uses:
241
+
242
+ ```text
243
+ confirmation_token = START_PAID_SAGEMAKER_NOTEBOOK_JOB
244
+ ```
245
+
246
+ ## MCP Client Configuration
247
+
248
+ Example stdio config:
249
+
250
+ ```json
251
+ {
252
+ "mcpServers": {
253
+ "aws-notebook-runner": {
254
+ "command": "aws-notebook-runner-mcp",
255
+ "env": {
256
+ "AWS_PROFILE": "research",
257
+ "AWS_REGION": "eu-north-1",
258
+ "AWS_NOTEBOOK_RUNNER_ROOT": "/absolute/path/to/notebooks",
259
+ "AWS_NOTEBOOK_S3_ROOT": "s3://YOUR_BUCKET/runs",
260
+ "AWS_NOTEBOOK_BACKEND": "ec2_ssm",
261
+ "AWS_NOTEBOOK_ROLE_ARN": "arn:aws:iam::123456789012:role/EC2NotebookRunnerRole",
262
+ "AWS_NOTEBOOK_ALLOWED_INSTANCE_TYPES": "t3.micro,t3.small",
263
+ "AWS_NOTEBOOK_DEFAULT_INSTANCE_TYPE": "t3.micro",
264
+ "AWS_NOTEBOOK_MAX_RUNTIME_SECONDS": "1800",
265
+ "AWS_NOTEBOOK_MAX_ESTIMATED_COST_USD": "1"
266
+ }
267
+ }
268
+ }
269
+ }
270
+ ```
271
+
272
+ Only add `AWS_NOTEBOOK_RUNNER_ENABLE_EXECUTION=true` when you are ready to allow
273
+ paid compute, and keep the confirmation token gate.
274
+
275
+ ## Tools
276
+
277
+ - `get_runner_status`: local policy and dependency status.
278
+ - `inspect_notebook`: validate and summarize a local notebook.
279
+ - `estimate_notebook_job_cost`: estimate SageMaker or EC2 compute cost.
280
+ - `plan_notebook_job`: dry-run SageMaker plan.
281
+ - `get_sagemaker_notebook_job_spec`: return a SageMaker `NotebookJobStep` spec.
282
+ - `start_sagemaker_notebook_job`: guarded SageMaker execution.
283
+ - `get_sagemaker_job_status`: read SageMaker pipeline execution status.
284
+ - `check_ec2_setup`: read-only EC2/SSM readiness checks.
285
+ - `plan_ec2_smoke_run`: dry-run EC2+SSM plan.
286
+ - `start_ec2_smoke_run`: guarded synchronous EC2+SSM run.
287
+ - `start_ec2_smoke_run_async`: guarded async EC2+SSM run.
288
+ - `get_ec2_smoke_run_status`: EC2/SSM/S3 progress, metrics, artifacts, and cost.
289
+ - `explain_existing_aws_options`: related AWS options and overlap.
290
+
291
+ ## Typical EC2 Workflow
292
+
293
+ 1. Inspect the notebook:
294
+
295
+ ```text
296
+ inspect_notebook(local_path="notebooks/demo.ipynb")
297
+ ```
298
+
299
+ 2. Build a dry-run plan:
300
+
301
+ ```text
302
+ plan_ec2_smoke_run(
303
+ local_path="notebooks/demo.ipynb",
304
+ run_name="demo-run",
305
+ instance_type="t3.micro",
306
+ max_runtime_seconds=900,
307
+ instance_profile_name="EC2NotebookRunnerRole"
308
+ )
309
+ ```
310
+
311
+ 3. Start async execution:
312
+
313
+ ```text
314
+ start_ec2_smoke_run_async(
315
+ local_path="notebooks/demo.ipynb",
316
+ run_name="demo-run",
317
+ confirmation_token="START_PAID_EC2_NOTEBOOK_RUN",
318
+ instance_type="t3.micro",
319
+ max_runtime_seconds=900,
320
+ instance_profile_name="EC2NotebookRunnerRole"
321
+ )
322
+ ```
323
+
324
+ 4. Poll status:
325
+
326
+ ```text
327
+ get_ec2_smoke_run_status(run_name="demo-run")
328
+ ```
329
+
330
+ Status includes:
331
+
332
+ - `progress_summary.summary`, for example:
333
+ `70% executing; elapsed wall 4m 44s, compute 4m 42s, ETA 2m 0s`
334
+ - EC2 instance state.
335
+ - SSM command status.
336
+ - stdout/stderr tail.
337
+ - S3 artifacts.
338
+ - Current compute cost estimate.
339
+
340
+ ## Progress Model
341
+
342
+ Progress is phase-based:
343
+
344
+ ```text
345
+ created -> staged -> launching -> waiting_ssm -> installing -> executing -> uploading -> completed/failed
346
+ ```
347
+
348
+ This is useful for UX and cost guardrails, but it is not exact cell-level
349
+ progress. A notebook that sleeps for five minutes will remain in `executing`
350
+ until it completes unless the notebook itself writes progress markers.
351
+
352
+ ## Cost Model
353
+
354
+ Cost reporting is an estimate:
355
+
356
+ - EC2 compute is estimated from instance type, elapsed compute time, and a
357
+ 60-second minimum.
358
+ - EBS, S3 requests/storage, data transfer, and taxes are not included.
359
+ - Static prices can be overridden:
360
+
361
+ ```bash
362
+ export AWS_NOTEBOOK_PRICE_OVERRIDES_JSON='{"t3.micro": 0.0104, "ml.m5.large": 0.115}'
363
+ ```
364
+
365
+ Always verify official costs in AWS Billing or Cost Explorer.
366
+
367
+ ## SageMaker Notes
368
+
369
+ SageMaker Notebook Jobs are the more managed AWS-native way to run notebooks,
370
+ but new AWS accounts may have a default training-job quota of zero for common
371
+ instance types. In that case, EC2+SSM is a practical fallback.
372
+
373
+ The SageMaker backend is included, but EC2+SSM is the path that has been tested
374
+ end-to-end in this package.
375
+
376
+ ## Troubleshooting
377
+
378
+ `iam:PassRole` denied:
379
+
380
+ The local AWS principal needs permission to pass the EC2 instance role:
381
+
382
+ ```text
383
+ iam:PassRole on arn:aws:iam::<account-id>:role/EC2NotebookRunnerRole
384
+ ```
385
+
386
+ SSM command never starts:
387
+
388
+ - Check that the instance role has `AmazonSSMManagedInstanceCore`.
389
+ - Use an Amazon Linux AMI with SSM Agent.
390
+ - Ensure the subnet has outbound internet access or VPC endpoints for SSM.
391
+
392
+ CloudWatch metrics unavailable:
393
+
394
+ Add `cloudwatch:GetMetricStatistics` to the local AWS principal.
395
+
396
+ SageMaker fails with quota zero:
397
+
398
+ Request quota for the selected instance type, or use the EC2+SSM backend.
399
+
400
+ Inline IAM policy size exceeded:
401
+
402
+ Use customer managed policies attached to the user/role instead of adding more
403
+ inline policies.
404
+
405
+ ## Safety
406
+
407
+ This server is intentionally conservative:
408
+
409
+ - Dry-run tools do not start compute.
410
+ - Execution requires `AWS_NOTEBOOK_RUNNER_ENABLE_EXECUTION=true`.
411
+ - Execution also requires a confirmation token.
412
+ - Instance types are allowlisted.
413
+ - Max runtime and max estimated cost are policy-controlled.
414
+ - EC2 instances are launched with instance-initiated shutdown behavior set to
415
+ terminate.
416
+
417
+ Review IAM, S3 prefixes, instance allowlists, and cost caps before enabling
418
+ execution.