Coverage for gco_mcp / run_mcp.py: 100.00%
193 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-09-14 22:07 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-09-14 22:07 +0000
1#!/usr/bin/env python3
2"""
3GCO MCP Server — Exposes the GCO CLI as MCP tools for LLM interaction.
5Run with:
6 python gco_mcp/run_mcp.py
8Add to Kiro MCP config (.kiro/settings/mcp.json):
9 {
10 "mcpServers": {
11 "gco": {
12 "command": "python3",
13 "args": ["gco_mcp/run_mcp.py"],
14 "cwd": "/path/to/GCO"
15 }
16 }
17 }
19This file is a thin entrypoint. The implementation lives under
20``gco_mcp/``; the two package registries are the authoritative module lists:
22 gco_mcp/
23 ├── server.py — FastMCP singleton, transforms, and middleware
24 ├── feature_flags.py — Environment-driven tool gates
25 ├── audit.py — Structured tool/resource/startup audit logging
26 ├── audit_middleware.py — Per-request message and elicitation capture
27 ├── iam.py — Optional startup role assumption
28 ├── cli_runner.py — Bounded gco CLI subprocess wrapper
29 ├── local_data.py — Confined local-path and snapshot helpers
30 ├── mission/ — Goal-directed Mission engine
31 ├── metric_readers/ — Canonical metric-source adapters
32 ├── mission_judge/ — Semantic-progress scorer
33 ├── tools/
34 │ ├── __init__.py — Registers all tool-domain modules
35 │ └── README.md — Complete per-module and per-tool catalog
36 └── resources/
37 ├── __init__.py — Registers every static/live resource module
38 └── README.md — Complete URI-family and module catalog
39"""
41import sys
42from pathlib import Path
44# The file is supported both as ``python gco_mcp/run_mcp.py`` and as
45# ``import gco_mcp.run_mcp``. Alias the two names before importing the shared
46# server so either route observes one module and one FastMCP singleton.
47_THIS_MODULE = sys.modules[__name__]
48if __name__ in {"run_mcp", "__main__"}:
49 sys.modules.setdefault("gco_mcp.run_mcp", _THIS_MODULE)
50if __name__ in {"gco_mcp.run_mcp", "__main__"}:
51 sys.modules.setdefault("run_mcp", _THIS_MODULE)
53# ``importlib.reload`` retains a module's globals. Record whether this is an
54# explicit same-process reload so compatibility rebinds do not re-register
55# every flagged tool during a normal, clean server startup.
56_IS_RELOAD = bool(getattr(_THIS_MODULE, "_RUN_MCP_IMPORT_COMPLETE", False))
58# Direct script execution starts with only gco_mcp/ on sys.path. Add each
59# required root at most once; package imports need no mutation.
60PROJECT_ROOT = Path(__file__).resolve().parent.parent
61MCP_DIR = Path(__file__).resolve().parent
62for _path in (str(PROJECT_ROOT), str(MCP_DIR)):
63 if _path not in sys.path:
64 sys.path.insert(0, _path)
66# --- Re-export everything the existing tests expect on ``run_mcp.*`` ---
68from audit import ( # noqa: E402, F401
69 _MCP_SERVER_VERSION,
70 _sanitize_arguments,
71 audit_logged,
72 audit_logger,
73 emit_startup_log,
74)
75from iam import assume_mcp_role # noqa: E402, F401
76from server import mcp # noqa: E402, F401
77from version import get_project_version # noqa: E402, F401
79# Re-export the project version for tests that check run_mcp._PROJECT_VERSION
80_PROJECT_VERSION = get_project_version()
82# --- Register all tools and resources ---
84from resources import register_all_resources # noqa: E402
85from tools import register_all_tools # noqa: E402
87register_all_tools()
88if _IS_RELOAD:
89 # Static resources already live on the shared FastMCP singleton. Mission
90 # resources are the sole flag-gated family and may need to appear after a
91 # test or embedding process deliberately changes flags and reloads us.
92 from resources import mission as _mission_resources
94 _mission_resources.register(mcp)
95else:
96 register_all_resources()
98# Argument completion (FastMCP 4): answers ``completion/complete`` for the
99# static registry-backed resource templates. Registered after the resource
100# modules so the handler's providers read fully-populated registries;
101# re-registration on reload just replaces the handler.
102from completions import register_completions # noqa: E402
104register_completions(mcp)
106# --- Re-export tool functions for backward compat with existing tests ---
107# Tests call e.g. run_mcp.list_jobs(), so we import them into this namespace.
109# Conditionally re-export reserve_capacity if it was registered.
110# contextlib.suppress is the idiomatic "swallow this exception" form.
111import contextlib as _contextlib # noqa: E402
112import importlib as _importlib # noqa: E402
114import feature_flags as _feature_flags # noqa: E402
115from tools.analytics import ( # noqa: E402, F401
116 analytics_doctor,
117 analytics_login_url,
118 analytics_status,
119 analytics_user_add,
120 analytics_users_list,
121 disable_analytics,
122 enable_analytics,
123)
124from tools.capacity import ( # noqa: E402, F401
125 ai_recommend,
126 capacity_history_patterns,
127 capacity_history_show,
128 capacity_history_stats,
129 capacity_predict,
130 capacity_status,
131 check_capacity,
132 find_capacity_blocks,
133 find_capacity_reservations,
134 instance_info,
135 list_reservations,
136 recommend_capacity,
137 recommend_region,
138 reservation_check,
139 spot_prices,
140)
141from tools.cluster import cluster_tunnel_command # noqa: E402, F401
142from tools.config import config_get # noqa: E402, F401
143from tools.costs import ( # noqa: E402, F401
144 cost_allocation_activate,
145 cost_allocation_status,
146 cost_by_region,
147 cost_forecast,
148 cost_k8s_namespaces,
149 cost_k8s_regions,
150 cost_k8s_top,
151 cost_k8s_trend,
152 cost_report_generate,
153 cost_report_list,
154 cost_report_status,
155 cost_summary,
156 cost_trend,
157 cost_workloads,
158)
159from tools.dag import dag_run, dag_validate # noqa: E402, F401
160from tools.deps import deps_scan # noqa: E402, F401
161from tools.docs import find_docs # noqa: E402, F401
162from tools.examples import find_examples # noqa: E402, F401
163from tools.images import ( # noqa: E402, F401
164 images_describe,
165 images_init,
166 images_lifecycle_get,
167 images_lifecycle_set,
168 images_list,
169 images_mirror_plan,
170 images_mirror_status,
171 images_orphans,
172 images_replication_get,
173 images_replication_status,
174 images_replication_sync,
175 images_tags,
176 images_uri,
177)
178from tools.inference import ( # noqa: E402, F401
179 canary_deploy,
180 chat_inference,
181 configure_mooncake_store,
182 deploy_disaggregated_inference,
183 deploy_inference,
184 inference_health,
185 inference_status,
186 invoke_inference,
187 list_endpoint_models,
188 list_inference_endpoints,
189 mooncake_topology_status,
190 populate_kv_cache,
191 promote_canary,
192 rollback_canary,
193 scale_inference,
194 set_mooncake_topology,
195 start_inference,
196 stop_inference,
197 update_inference_image,
198)
199from tools.jobs import ( # noqa: E402, F401
200 check_job_policy,
201 cluster_health,
202 get_job,
203 get_job_events,
204 get_job_logs,
205 get_job_metrics,
206 get_job_pods,
207 get_job_validation_policy,
208 get_pod_logs,
209 list_jobs,
210 queue_status,
211 retry_job,
212 submit_job_api,
213 submit_job_sqs,
214)
215from tools.metrics import ( # noqa: E402, F401
216 metrics_cloudwatch_get,
217 metrics_from_job_logs,
218 metrics_from_shared_storage_file,
219)
220from tools.models import get_model_uri, list_models # noqa: E402, F401
221from tools.monitoring import ( # noqa: E402, F401
222 disable_monitoring,
223 enable_monitoring,
224 monitoring_status,
225 monitoring_user_add,
226 monitoring_users_list,
227)
228from tools.nodepools import ( # noqa: E402, F401
229 nodepools_create_capacity_block,
230 nodepools_create_odcr,
231 nodepools_describe,
232 nodepools_list,
233)
234from tools.queue import queue_get, queue_list, queue_stats, queue_submit # noqa: E402, F401
235from tools.stacks import ( # noqa: E402, F401
236 addons_status,
237 aurora_status,
238 disable_aurora,
239 disable_fsx,
240 disable_valkey,
241 enable_aurora,
242 enable_fsx,
243 enable_valkey,
244 fsx_status,
245 list_stacks,
246 setup_cluster_access,
247 stack_diff,
248 stack_outputs,
249 stack_status,
250 stack_synth,
251 valkey_status,
252)
253from tools.status import fleet_status # noqa: E402, F401
254from tools.storage import ( # noqa: E402, F401
255 files_access_points,
256 files_get,
257 list_file_systems,
258 list_storage_buckets,
259 list_storage_contents,
260 s3_inventory,
261)
262from tools.tasks import task_status, task_tail # noqa: E402, F401
263from tools.templates import ( # noqa: E402, F401
264 templates_create,
265 templates_get,
266 templates_list,
267 templates_run,
268)
269from tools.webhooks import webhooks_create, webhooks_get, webhooks_list # noqa: E402, F401
271with _contextlib.suppress(ImportError):
272 from tools.capacity import create_reservation, reserve_capacity # noqa: F401
274with _contextlib.suppress(ImportError):
275 from tools.images import images_build, images_mirror, images_push # noqa: F401
277with _contextlib.suppress(ImportError):
278 from tools.images import ( # noqa: F401
279 images_cleanup,
280 images_delete_repo,
281 images_delete_tag,
282 images_prune,
283 )
285with _contextlib.suppress(ImportError):
286 from tools.stacks import addons_install, bootstrap_cdk, deploy_all, deploy_stack # noqa: F401
288with _contextlib.suppress(ImportError):
289 from tools.stacks import destroy_all, destroy_stack # noqa: F401
291# Config-management gated tools — present only when
292# GCO_ENABLE_CONFIG_MANAGEMENT (or GCO_ENABLE_ALL_TOOLS) is set.
293with _contextlib.suppress(ImportError):
294 from tools.stacks import ( # noqa: F401
295 add_deployment_region,
296 list_deployment_regions,
297 remove_deployment_region,
298 set_capacity_advisor_default_model,
299 set_claude_code_default_model,
300 set_codex_default_model,
301 set_codex_reasoning_effort,
302 set_deployment_region,
303 set_eks_endpoint_access,
304 set_mission_default_model,
305 )
307# Destructive-operations gated tools — present only when
308# GCO_ENABLE_DESTRUCTIVE_OPERATIONS (or GCO_ENABLE_ALL_TOOLS) is set.
309with _contextlib.suppress(ImportError):
310 from tools.capacity import cancel_reservation # noqa: F401
312with _contextlib.suppress(ImportError):
313 from tools.jobs import delete_job # noqa: F401
315with _contextlib.suppress(ImportError):
316 from tools.inference import delete_inference # noqa: F401
318with _contextlib.suppress(ImportError):
319 from tools.templates import delete_template # noqa: F401
321with _contextlib.suppress(ImportError):
322 from tools.webhooks import delete_webhook # noqa: F401
324with _contextlib.suppress(ImportError):
325 from tools.models import delete_model # noqa: F401
327with _contextlib.suppress(ImportError):
328 from tools.nodepools import delete_nodepool # noqa: F401
330with _contextlib.suppress(ImportError):
331 from tools.analytics import analytics_user_remove # noqa: F401
333with _contextlib.suppress(ImportError):
334 from tools.monitoring import monitoring_user_remove # noqa: F401
336with _contextlib.suppress(ImportError):
337 from tools.queue import cancel_queue_job # noqa: F401
339with _contextlib.suppress(ImportError):
340 from tools.tasks import task_prune # noqa: F401
342# Model-upload gated tool — present only when GCO_ENABLE_MODEL_UPLOAD
343# (or GCO_ENABLE_ALL_TOOLS) is set.
344with _contextlib.suppress(ImportError):
345 from tools.models import models_upload # noqa: F401
347with _contextlib.suppress(ImportError):
348 from tools.storage import upload_to_regional_bucket # noqa: F401
350# Local-metrics, local-storage, semantic-progress, and Mission tools also use
351# import-time gates. The imports are no-ops when disabled; the explicit reload
352# compatibility blocks below rebind them only during ``importlib.reload``.
353with _contextlib.suppress(ImportError):
354 from tools.metrics import metrics_from_local_file # noqa: F401
356with _contextlib.suppress(ImportError):
357 from tools.storage import sync_storage_bucket # noqa: F401
359with _contextlib.suppress(ImportError):
360 from tools.semantic_progress import metrics_semantic_progress # noqa: F401
362with _contextlib.suppress(ImportError):
363 from tools.mission import ( # noqa: F401
364 mission_abort,
365 mission_checkpoint,
366 mission_complete,
367 mission_history,
368 mission_iterate,
369 mission_list,
370 mission_memory_search,
371 mission_resume,
372 mission_start,
373 mission_status,
374 )
376with _contextlib.suppress(ImportError):
377 from tools.swarm import ( # noqa: F401
378 swarm_abort,
379 swarm_iterate,
380 swarm_list,
381 swarm_plan,
382 swarm_start,
383 swarm_status,
384 )
386# Explicit reload compatibility for the two gated families in capacity.py.
387# A clean startup has just imported the module under the final environment and
388# must not reload it: doing so used to emit duplicate-component warnings for
389# every unconditional capacity tool.
390if _IS_RELOAD and (
391 _feature_flags.is_enabled(_feature_flags.FLAG_CAPACITY_PURCHASE)
392 or _feature_flags.is_enabled(_feature_flags.FLAG_DESTRUCTIVE_OPERATIONS)
393):
394 from tools import capacity as _cap_mod # noqa: E402
396 _importlib.reload(_cap_mod)
397 for _name in ("reserve_capacity", "create_reservation", "cancel_reservation"):
398 if hasattr(_cap_mod, _name):
399 globals()[_name] = getattr(_cap_mod, _name)
401# Reload tools.images when image-publish or destructive flags are set so
402# the gated build/push/delete tools are present after a test
403# ``importlib.reload(run_mcp)`` cycle. Mirrors the reserve_capacity pattern.
404if _IS_RELOAD and (
405 _feature_flags.is_enabled(_feature_flags.FLAG_IMAGE_PUBLISH)
406 or _feature_flags.is_enabled(_feature_flags.FLAG_DESTRUCTIVE_OPERATIONS)
407):
408 from tools import images as _img_mod # noqa: E402
410 _importlib.reload(_img_mod)
411 for _name in (
412 "images_build",
413 "images_push",
414 "images_mirror",
415 "images_cleanup",
416 "images_prune",
417 "images_delete_tag",
418 "images_delete_repo",
419 ):
420 if hasattr(_img_mod, _name):
421 globals()[_name] = getattr(_img_mod, _name)
423# Reload tools.stacks when an infrastructure flag or the managed-config
424# flag is set so the gated deploy/destroy/bootstrap and deployment-region
425# tools are present after a test ``importlib.reload(run_mcp)`` cycle.
426# Mirrors the reserve_capacity pattern.
427if _IS_RELOAD and (
428 _feature_flags.is_enabled(_feature_flags.FLAG_INFRASTRUCTURE_DEPLOY)
429 or _feature_flags.is_enabled(_feature_flags.FLAG_INFRASTRUCTURE_DESTROY)
430 or _feature_flags.is_enabled(_feature_flags.FLAG_CONFIG_MANAGEMENT)
431):
432 from tools import stacks as _stacks_mod # noqa: E402
434 _importlib.reload(_stacks_mod)
435 for _name in (
436 "deploy_stack",
437 "deploy_all",
438 "bootstrap_cdk",
439 "addons_install",
440 "destroy_stack",
441 "destroy_all",
442 "list_deployment_regions",
443 "add_deployment_region",
444 "remove_deployment_region",
445 "set_deployment_region",
446 "set_eks_endpoint_access",
447 "set_mission_default_model",
448 "set_capacity_advisor_default_model",
449 "set_claude_code_default_model",
450 "set_codex_default_model",
451 "set_codex_reasoning_effort",
452 ):
453 if hasattr(_stacks_mod, _name):
454 globals()[_name] = getattr(_stacks_mod, _name)
456# Destructive-operations and model-upload gated reload blocks — mirror the
457# reserve_capacity pattern so flag-driven tests can do ``importlib.reload(
458# run_mcp)`` and have the gated names appear as module-level attributes.
459_DESTRUCTIVE_FLAG_ON = _feature_flags.is_enabled(_feature_flags.FLAG_DESTRUCTIVE_OPERATIONS)
460_MODEL_UPLOAD_FLAG_ON = _feature_flags.is_enabled(_feature_flags.FLAG_MODEL_UPLOAD)
462if _IS_RELOAD and _DESTRUCTIVE_FLAG_ON:
463 from tools import jobs as _jobs_mod # noqa: E402
465 _importlib.reload(_jobs_mod)
466 delete_job = _jobs_mod.delete_job # noqa: F811
468 from tools import inference as _inf_mod # noqa: E402
470 _importlib.reload(_inf_mod)
471 delete_inference = _inf_mod.delete_inference # noqa: F811
473 from tools import templates as _tpl_mod # noqa: E402
475 _importlib.reload(_tpl_mod)
476 globals()["delete_template"] = _tpl_mod.delete_template
478 from tools import webhooks as _wh_mod # noqa: E402
480 _importlib.reload(_wh_mod)
481 globals()["delete_webhook"] = _wh_mod.delete_webhook
483 from tools import nodepools as _np_mod # noqa: E402
485 _importlib.reload(_np_mod)
486 globals()["delete_nodepool"] = _np_mod.delete_nodepool
488 from tools import analytics as _an_mod # noqa: E402
490 _importlib.reload(_an_mod)
491 globals()["analytics_user_remove"] = _an_mod.analytics_user_remove
493 from tools import queue as _q_mod # noqa: E402
495 _importlib.reload(_q_mod)
496 globals()["cancel_queue_job"] = _q_mod.cancel_queue_job
498 from tools import monitoring as _mon_mod # noqa: E402
500 _importlib.reload(_mon_mod)
501 globals()["monitoring_user_remove"] = _mon_mod.monitoring_user_remove
503 from tools import tasks as _tasks_mod # noqa: E402
505 _importlib.reload(_tasks_mod)
506 globals()["task_prune"] = _tasks_mod.task_prune
508# tools.models is reloaded if either the destructive flag (delete_model)
509# or the model-upload flag (models_upload) is set, so do it once here
510# regardless of which (or both) flipped.
511if _IS_RELOAD and (_DESTRUCTIVE_FLAG_ON or _MODEL_UPLOAD_FLAG_ON):
512 from tools import models as _models_mod # noqa: E402
514 _importlib.reload(_models_mod)
515 for _name in ("delete_model", "models_upload"):
516 if hasattr(_models_mod, _name):
517 globals()[_name] = getattr(_models_mod, _name)
519if _IS_RELOAD and (
520 _MODEL_UPLOAD_FLAG_ON or _feature_flags.is_enabled(_feature_flags.FLAG_LOCAL_STORAGE_SYNC)
521):
522 from tools import storage as _storage_mod # noqa: E402
524 _importlib.reload(_storage_mod)
525 for _name in ("upload_to_regional_bucket", "sync_storage_bucket"):
526 if hasattr(_storage_mod, _name):
527 globals()[_name] = getattr(_storage_mod, _name)
529if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_LOCAL_METRICS):
530 from tools import metrics as _metrics_mod # noqa: E402
532 _importlib.reload(_metrics_mod)
533 metrics_from_local_file = _metrics_mod.metrics_from_local_file
535if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_SEMANTIC_PROGRESS):
536 from tools import semantic_progress as _semantic_progress_mod # noqa: E402
538 _importlib.reload(_semantic_progress_mod)
539 metrics_semantic_progress = _semantic_progress_mod.metrics_semantic_progress
541if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_MISSION):
542 from tools import mission as _mission_tools_mod # noqa: E402
544 _importlib.reload(_mission_tools_mod)
545 # Unlike the images/models/storage reload blocks above, every name here is
546 # defined under the exact same `is_enabled(FLAG_MISSION)` gate this block
547 # is itself conditioned on, so a `hasattr` guard would never see a miss —
548 # it is a straight rebind.
549 for _name in (
550 "mission_start",
551 "mission_status",
552 "mission_iterate",
553 "mission_checkpoint",
554 "mission_complete",
555 "mission_abort",
556 "mission_resume",
557 "mission_history",
558 "mission_list",
559 "mission_memory_search",
560 ):
561 globals()[_name] = getattr(_mission_tools_mod, _name)
563if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_SWARM):
564 from tools import swarm as _swarm_tools_mod # noqa: E402
566 _importlib.reload(_swarm_tools_mod)
567 # Same reasoning as the mission block above: every name is defined under
568 # this same `is_enabled(FLAG_SWARM)` gate, so `hasattr` cannot miss.
569 for _name in (
570 "swarm_start",
571 "swarm_iterate",
572 "swarm_status",
573 "swarm_abort",
574 "swarm_list",
575 "swarm_plan",
576 ):
577 globals()[_name] = getattr(_swarm_tools_mod, _name)
579# --- Re-export resource directory constants for tests ---
580from resources.ci import ( # noqa: E402, F401
581 GITHUB_ACTIONS_DIR,
582 GITHUB_CODEQL_DIR,
583 GITHUB_DIR,
584 GITHUB_ISSUE_TEMPLATE_DIR,
585 GITHUB_KIND_DIR,
586 GITHUB_SCRIPTS_DIR,
587 GITHUB_WORKFLOWS_DIR,
588)
589from resources.docs import DOCS_DIR, EXAMPLES_DIR # noqa: E402, F401
590from resources.infra import DOCKERFILES_DIR, HELM_CHARTS_FILE # noqa: E402, F401
591from resources.k8s import MANIFESTS_DIR # noqa: E402, F401
592from resources.self import _TOOL_GATING_TABLE # noqa: E402
594# Declare every candidate name that is intentionally re-exported for tests and
595# downstream consumers. The final ``__all__`` below filters gated names against
596# both the current environment and actual module globals, so ``from run_mcp
597# import *`` never advertises an unavailable attribute.
598_PUBLIC_EXPORTS = [
599 "DOCKERFILES_DIR",
600 "DOCS_DIR",
601 "EXAMPLES_DIR",
602 "GITHUB_ACTIONS_DIR",
603 "GITHUB_CODEQL_DIR",
604 "GITHUB_DIR",
605 "GITHUB_ISSUE_TEMPLATE_DIR",
606 "GITHUB_KIND_DIR",
607 "GITHUB_SCRIPTS_DIR",
608 "GITHUB_WORKFLOWS_DIR",
609 "HELM_CHARTS_FILE",
610 "MANIFESTS_DIR",
611 "_MCP_SERVER_VERSION",
612 "_PROJECT_VERSION",
613 "_sanitize_arguments",
614 "add_deployment_region",
615 "addons_install",
616 "addons_status",
617 "ai_recommend",
618 "analytics_doctor",
619 "analytics_login_url",
620 "analytics_status",
621 "analytics_user_add",
622 "analytics_user_remove",
623 "analytics_users_list",
624 "assume_mcp_role",
625 "audit_logged",
626 "audit_logger",
627 "aurora_status",
628 "bootstrap_cdk",
629 "canary_deploy",
630 "cancel_queue_job",
631 "cancel_reservation",
632 "capacity_history_patterns",
633 "capacity_history_show",
634 "capacity_history_stats",
635 "capacity_predict",
636 "capacity_status",
637 "chat_inference",
638 "check_capacity",
639 "check_job_policy",
640 "cluster_health",
641 "cluster_tunnel_command",
642 "config_get",
643 "configure_mooncake_store",
644 "cost_allocation_activate",
645 "cost_allocation_status",
646 "cost_by_region",
647 "cost_forecast",
648 "cost_k8s_namespaces",
649 "cost_k8s_regions",
650 "cost_k8s_top",
651 "cost_k8s_trend",
652 "cost_report_generate",
653 "cost_report_list",
654 "cost_report_status",
655 "cost_summary",
656 "cost_trend",
657 "cost_workloads",
658 "create_reservation",
659 "dag_run",
660 "dag_validate",
661 "delete_inference",
662 "delete_job",
663 "delete_model",
664 "delete_nodepool",
665 "delete_template",
666 "delete_webhook",
667 "deploy_all",
668 "deploy_disaggregated_inference",
669 "deploy_inference",
670 "deploy_stack",
671 "deps_scan",
672 "destroy_all",
673 "destroy_stack",
674 "disable_analytics",
675 "disable_aurora",
676 "disable_fsx",
677 "disable_monitoring",
678 "disable_valkey",
679 "emit_startup_log",
680 "enable_analytics",
681 "enable_aurora",
682 "enable_fsx",
683 "enable_monitoring",
684 "enable_valkey",
685 "files_access_points",
686 "files_get",
687 "find_capacity_blocks",
688 "find_capacity_reservations",
689 "find_docs",
690 "find_examples",
691 "fleet_status",
692 "fsx_status",
693 "get_job",
694 "get_job_events",
695 "get_job_logs",
696 "get_job_metrics",
697 "get_job_pods",
698 "get_job_validation_policy",
699 "get_model_uri",
700 "get_pod_logs",
701 "get_project_version",
702 "images_build",
703 "images_cleanup",
704 "images_delete_repo",
705 "images_delete_tag",
706 "images_describe",
707 "images_init",
708 "images_lifecycle_get",
709 "images_lifecycle_set",
710 "images_list",
711 "images_mirror",
712 "images_mirror_plan",
713 "images_mirror_status",
714 "images_orphans",
715 "images_prune",
716 "images_push",
717 "images_replication_get",
718 "images_replication_status",
719 "images_replication_sync",
720 "images_tags",
721 "images_uri",
722 "inference_health",
723 "inference_status",
724 "instance_info",
725 "invoke_inference",
726 "list_deployment_regions",
727 "list_endpoint_models",
728 "list_file_systems",
729 "list_inference_endpoints",
730 "list_jobs",
731 "list_models",
732 "list_reservations",
733 "list_stacks",
734 "list_storage_buckets",
735 "list_storage_contents",
736 "mcp",
737 "metrics_cloudwatch_get",
738 "metrics_from_job_logs",
739 "metrics_from_local_file",
740 "metrics_from_shared_storage_file",
741 "metrics_semantic_progress",
742 "mission_abort",
743 "mission_checkpoint",
744 "mission_complete",
745 "mission_history",
746 "mission_iterate",
747 "mission_list",
748 "mission_memory_search",
749 "mission_resume",
750 "mission_start",
751 "mission_status",
752 "models_upload",
753 "monitoring_status",
754 "monitoring_user_add",
755 "monitoring_user_remove",
756 "monitoring_users_list",
757 "mooncake_topology_status",
758 "nodepools_create_capacity_block",
759 "nodepools_create_odcr",
760 "nodepools_describe",
761 "nodepools_list",
762 "populate_kv_cache",
763 "promote_canary",
764 "queue_get",
765 "queue_list",
766 "queue_stats",
767 "queue_status",
768 "queue_submit",
769 "recommend_capacity",
770 "recommend_region",
771 "remove_deployment_region",
772 "reservation_check",
773 "reserve_capacity",
774 "retry_job",
775 "rollback_canary",
776 "s3_inventory",
777 "scale_inference",
778 "set_capacity_advisor_default_model",
779 "set_claude_code_default_model",
780 "set_codex_default_model",
781 "set_codex_reasoning_effort",
782 "set_deployment_region",
783 "set_eks_endpoint_access",
784 "set_mission_default_model",
785 "set_mooncake_topology",
786 "setup_cluster_access",
787 "spot_prices",
788 "stack_diff",
789 "stack_outputs",
790 "stack_status",
791 "stack_synth",
792 "start_inference",
793 "stop_inference",
794 "submit_job_api",
795 "submit_job_sqs",
796 "swarm_abort",
797 "swarm_iterate",
798 "swarm_list",
799 "swarm_plan",
800 "swarm_start",
801 "swarm_status",
802 "sync_storage_bucket",
803 "task_prune",
804 "task_status",
805 "task_tail",
806 "templates_create",
807 "templates_get",
808 "templates_list",
809 "templates_run",
810 "update_inference_image",
811 "upload_to_regional_bucket",
812 "valkey_status",
813 "webhooks_create",
814 "webhooks_get",
815 "webhooks_list",
816]
818__all__ = [
819 name
820 for name in _PUBLIC_EXPORTS
821 if name in globals()
822 and (name not in _TOOL_GATING_TABLE or _feature_flags.is_enabled(_TOOL_GATING_TABLE[name]))
823]
825# =============================================================================
826# ENTRYPOINT
827# =============================================================================
830def _initialize_runtime() -> None:
831 """Perform external startup effects exactly once per process invocation.
833 Importing ``run_mcp`` is now safe for documentation tooling and tests: it
834 does not emit a startup audit record or mutate the ambient boto3 session by
835 assuming a role. Those effects happen only when the server is actually run.
836 """
837 emit_startup_log()
838 assume_mcp_role()
841def main() -> None:
842 """Start the MCP server after applying runtime identity and audit setup."""
843 _initialize_runtime()
844 mcp.run()
847# Set only after registration/re-export initialization has completed. Python's
848# reload machinery preserves this sentinel in the module dictionary.
849_RUN_MCP_IMPORT_COMPLETE = True
852if __name__ == "__main__":
853 main()