Coverage for gco_mcp / run_mcp.py: 100.00%
201 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-28 16:19 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-28 16:19 +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
76from server import mcp # noqa: E402
77from version import get_project_version # noqa: E402
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.crossplane import crossplane_status # noqa: E402, F401
160from tools.dag import dag_run, dag_validate # noqa: E402, F401
161from tools.deps import deps_scan # noqa: E402, F401
162from tools.docs import find_docs # noqa: E402, F401
163from tools.examples import find_examples # noqa: E402, F401
164from tools.gitops import gitops_status # noqa: E402, F401
165from tools.images import ( # noqa: E402, F401
166 images_describe,
167 images_init,
168 images_lifecycle_get,
169 images_lifecycle_set,
170 images_list,
171 images_mirror_plan,
172 images_mirror_status,
173 images_orphans,
174 images_replication_get,
175 images_replication_status,
176 images_replication_sync,
177 images_tags,
178 images_uri,
179)
180from tools.inference import ( # noqa: E402, F401
181 add_inference_region,
182 canary_deploy,
183 chat_inference,
184 configure_mooncake_store,
185 deploy_disaggregated_inference,
186 deploy_inference,
187 inference_health,
188 inference_status,
189 invoke_inference,
190 list_endpoint_models,
191 list_inference_endpoints,
192 mooncake_topology_status,
193 populate_kv_cache,
194 promote_canary,
195 remove_inference_region,
196 rollback_canary,
197 scale_inference,
198 set_mooncake_topology,
199 start_inference,
200 stop_inference,
201 update_inference_image,
202)
203from tools.jobs import ( # noqa: E402, F401
204 check_job_policy,
205 cluster_health,
206 get_job,
207 get_job_events,
208 get_job_logs,
209 get_job_metrics,
210 get_job_pods,
211 get_job_validation_policy,
212 get_pod_logs,
213 list_jobs,
214 queue_status,
215 retry_job,
216 submit_job_api,
217 submit_job_sqs,
218)
219from tools.metrics import ( # noqa: E402, F401
220 metrics_cloudwatch_get,
221 metrics_from_job_logs,
222 metrics_from_shared_storage_file,
223)
224from tools.models import get_model_uri, list_models # noqa: E402, F401
225from tools.monitoring import ( # noqa: E402, F401
226 disable_monitoring,
227 enable_monitoring,
228 monitoring_status,
229 monitoring_user_add,
230 monitoring_users_list,
231)
232from tools.nodepools import ( # noqa: E402, F401
233 nodepools_create_capacity_block,
234 nodepools_create_odcr,
235 nodepools_describe,
236 nodepools_list,
237)
238from tools.queue import queue_get, queue_list, queue_stats, queue_submit # noqa: E402, F401
239from tools.slurm import ( # noqa: E402, F401
240 slurm_accounting,
241 slurm_job,
242 slurm_nodes,
243 slurm_partitions,
244 slurm_queue,
245 slurm_status,
246 slurm_submit,
247)
248from tools.stacks import ( # noqa: E402, F401
249 addons_status,
250 aurora_status,
251 disable_aurora,
252 disable_fsx,
253 disable_valkey,
254 eks_capabilities_status,
255 enable_aurora,
256 enable_fsx,
257 enable_valkey,
258 fsx_status,
259 list_stacks,
260 setup_cluster_access,
261 stack_diff,
262 stack_outputs,
263 stack_status,
264 stack_synth,
265 valkey_status,
266)
267from tools.status import fleet_status # noqa: E402, F401
268from tools.storage import ( # noqa: E402, F401
269 files_access_points,
270 files_get,
271 list_file_systems,
272 list_storage_buckets,
273 list_storage_contents,
274 s3_inventory,
275)
276from tools.tasks import task_status, task_tail # noqa: E402, F401
277from tools.templates import ( # noqa: E402, F401
278 templates_create,
279 templates_get,
280 templates_list,
281 templates_run,
282)
283from tools.webhooks import webhooks_create, webhooks_get, webhooks_list # noqa: E402, F401
285with _contextlib.suppress(ImportError):
286 from tools.capacity import create_reservation, reserve_capacity # noqa: F401
288with _contextlib.suppress(ImportError):
289 from tools.images import images_build, images_mirror, images_push # noqa: F401
291with _contextlib.suppress(ImportError):
292 from tools.images import ( # noqa: F401
293 images_cleanup,
294 images_delete_repo,
295 images_delete_tag,
296 images_prune,
297 )
299with _contextlib.suppress(ImportError):
300 from tools.stacks import addons_install, bootstrap_cdk, deploy_all, deploy_stack # noqa: F401
302with _contextlib.suppress(ImportError):
303 from tools.stacks import destroy_all, destroy_stack # noqa: F401
305# Config-management gated tools — present only when
306# GCO_ENABLE_CONFIG_MANAGEMENT (or GCO_ENABLE_ALL_TOOLS) is set.
307with _contextlib.suppress(ImportError):
308 from tools.stacks import ( # noqa: F401
309 add_deployment_region,
310 list_deployment_regions,
311 remove_deployment_region,
312 set_capacity_advisor_default_model,
313 set_claude_code_default_model,
314 set_codex_default_model,
315 set_codex_reasoning_effort,
316 set_deployment_region,
317 set_eks_endpoint_access,
318 set_mission_default_model,
319 set_opencode_default_model,
320 )
322# Destructive-operations gated tools — present only when
323# GCO_ENABLE_DESTRUCTIVE_OPERATIONS (or GCO_ENABLE_ALL_TOOLS) is set.
324with _contextlib.suppress(ImportError):
325 from tools.capacity import cancel_reservation # noqa: F401
327with _contextlib.suppress(ImportError):
328 from tools.jobs import delete_job
330with _contextlib.suppress(ImportError):
331 from tools.inference import delete_inference
333with _contextlib.suppress(ImportError):
334 from tools.templates import delete_template # noqa: F401
336with _contextlib.suppress(ImportError):
337 from tools.webhooks import delete_webhook # noqa: F401
339with _contextlib.suppress(ImportError):
340 from tools.slurm import slurm_cancel # noqa: F401
342with _contextlib.suppress(ImportError):
343 from tools.models import delete_model # noqa: F401
345with _contextlib.suppress(ImportError):
346 from tools.nodepools import delete_nodepool # noqa: F401
348with _contextlib.suppress(ImportError):
349 from tools.analytics import analytics_user_remove # noqa: F401
351with _contextlib.suppress(ImportError):
352 from tools.monitoring import monitoring_user_remove # noqa: F401
354with _contextlib.suppress(ImportError):
355 from tools.queue import cancel_queue_job # noqa: F401
357with _contextlib.suppress(ImportError):
358 from tools.tasks import task_prune # noqa: F401
360# Model-upload gated tool — present only when GCO_ENABLE_MODEL_UPLOAD
361# (or GCO_ENABLE_ALL_TOOLS) is set.
362with _contextlib.suppress(ImportError):
363 from tools.models import models_upload # noqa: F401
365with _contextlib.suppress(ImportError):
366 from tools.storage import upload_to_regional_bucket # noqa: F401
368# Local-metrics, local-storage, semantic-progress, and Mission tools also use
369# import-time gates. The imports are no-ops when disabled; the explicit reload
370# compatibility blocks below rebind them only during ``importlib.reload``.
371with _contextlib.suppress(ImportError):
372 from tools.metrics import metrics_from_local_file
374with _contextlib.suppress(ImportError):
375 from tools.storage import sync_storage_bucket # noqa: F401
377with _contextlib.suppress(ImportError):
378 from tools.semantic_progress import metrics_semantic_progress
380with _contextlib.suppress(ImportError):
381 from tools.mission import ( # noqa: F401
382 mission_abort,
383 mission_checkpoint,
384 mission_complete,
385 mission_history,
386 mission_iterate,
387 mission_list,
388 mission_memory_search,
389 mission_resume,
390 mission_start,
391 mission_status,
392 )
394with _contextlib.suppress(ImportError):
395 from tools.swarm import ( # noqa: F401
396 swarm_abort,
397 swarm_iterate,
398 swarm_list,
399 swarm_plan,
400 swarm_start,
401 swarm_status,
402 )
404# Explicit reload compatibility for the two gated families in capacity.py.
405# A clean startup has just imported the module under the final environment and
406# must not reload it: doing so used to emit duplicate-component warnings for
407# every unconditional capacity tool.
408if _IS_RELOAD and (
409 _feature_flags.is_enabled(_feature_flags.FLAG_CAPACITY_PURCHASE)
410 or _feature_flags.is_enabled(_feature_flags.FLAG_DESTRUCTIVE_OPERATIONS)
411):
412 from tools import capacity as _cap_mod
414 _importlib.reload(_cap_mod)
415 for _name in ("reserve_capacity", "create_reservation", "cancel_reservation"):
416 if hasattr(_cap_mod, _name):
417 globals()[_name] = getattr(_cap_mod, _name)
419# Reload tools.images when image-publish or destructive flags are set so
420# the gated build/push/delete tools are present after a test
421# ``importlib.reload(run_mcp)`` cycle. Mirrors the reserve_capacity pattern.
422if _IS_RELOAD and (
423 _feature_flags.is_enabled(_feature_flags.FLAG_IMAGE_PUBLISH)
424 or _feature_flags.is_enabled(_feature_flags.FLAG_DESTRUCTIVE_OPERATIONS)
425):
426 from tools import images as _img_mod
428 _importlib.reload(_img_mod)
429 for _name in (
430 "images_build",
431 "images_push",
432 "images_mirror",
433 "images_cleanup",
434 "images_prune",
435 "images_delete_tag",
436 "images_delete_repo",
437 ):
438 if hasattr(_img_mod, _name):
439 globals()[_name] = getattr(_img_mod, _name)
441# Reload tools.stacks when an infrastructure flag or the managed-config
442# flag is set so the gated deploy/destroy/bootstrap and deployment-region
443# tools are present after a test ``importlib.reload(run_mcp)`` cycle.
444# Mirrors the reserve_capacity pattern.
445if _IS_RELOAD and (
446 _feature_flags.is_enabled(_feature_flags.FLAG_INFRASTRUCTURE_DEPLOY)
447 or _feature_flags.is_enabled(_feature_flags.FLAG_INFRASTRUCTURE_DESTROY)
448 or _feature_flags.is_enabled(_feature_flags.FLAG_CONFIG_MANAGEMENT)
449):
450 from tools import stacks as _stacks_mod
452 _importlib.reload(_stacks_mod)
453 for _name in (
454 "deploy_stack",
455 "deploy_all",
456 "bootstrap_cdk",
457 "addons_install",
458 "destroy_stack",
459 "destroy_all",
460 "list_deployment_regions",
461 "add_deployment_region",
462 "remove_deployment_region",
463 "set_deployment_region",
464 "set_eks_endpoint_access",
465 "set_mission_default_model",
466 "set_capacity_advisor_default_model",
467 "set_claude_code_default_model",
468 "set_codex_default_model",
469 "set_codex_reasoning_effort",
470 "set_opencode_default_model",
471 ):
472 if hasattr(_stacks_mod, _name):
473 globals()[_name] = getattr(_stacks_mod, _name)
475# Destructive-operations and model-upload gated reload blocks — mirror the
476# reserve_capacity pattern so flag-driven tests can do ``importlib.reload(
477# run_mcp)`` and have the gated names appear as module-level attributes.
478_DESTRUCTIVE_FLAG_ON = _feature_flags.is_enabled(_feature_flags.FLAG_DESTRUCTIVE_OPERATIONS)
479_MODEL_UPLOAD_FLAG_ON = _feature_flags.is_enabled(_feature_flags.FLAG_MODEL_UPLOAD)
481if _IS_RELOAD and _DESTRUCTIVE_FLAG_ON:
482 from tools import jobs as _jobs_mod
484 _importlib.reload(_jobs_mod)
485 delete_job = _jobs_mod.delete_job
487 from tools import inference as _inf_mod
489 _importlib.reload(_inf_mod)
490 delete_inference = _inf_mod.delete_inference
492 from tools import templates as _tpl_mod
494 _importlib.reload(_tpl_mod)
495 globals()["delete_template"] = _tpl_mod.delete_template
497 from tools import webhooks as _wh_mod
499 _importlib.reload(_wh_mod)
500 globals()["delete_webhook"] = _wh_mod.delete_webhook
502 from tools import nodepools as _np_mod
504 _importlib.reload(_np_mod)
505 globals()["delete_nodepool"] = _np_mod.delete_nodepool
507 from tools import analytics as _an_mod
509 _importlib.reload(_an_mod)
510 globals()["analytics_user_remove"] = _an_mod.analytics_user_remove
512 from tools import queue as _q_mod
514 _importlib.reload(_q_mod)
515 globals()["cancel_queue_job"] = _q_mod.cancel_queue_job
517 from tools import monitoring as _mon_mod
519 _importlib.reload(_mon_mod)
520 globals()["monitoring_user_remove"] = _mon_mod.monitoring_user_remove
522 from tools import tasks as _tasks_mod
524 _importlib.reload(_tasks_mod)
525 globals()["task_prune"] = _tasks_mod.task_prune
527 from tools import slurm as _slurm_mod
529 _importlib.reload(_slurm_mod)
530 globals()["slurm_cancel"] = _slurm_mod.slurm_cancel
532# tools.models is reloaded if either the destructive flag (delete_model)
533# or the model-upload flag (models_upload) is set, so do it once here
534# regardless of which (or both) flipped.
535if _IS_RELOAD and (_DESTRUCTIVE_FLAG_ON or _MODEL_UPLOAD_FLAG_ON):
536 from tools import models as _models_mod
538 _importlib.reload(_models_mod)
539 for _name in ("delete_model", "models_upload"):
540 if hasattr(_models_mod, _name):
541 globals()[_name] = getattr(_models_mod, _name)
543if _IS_RELOAD and (
544 _MODEL_UPLOAD_FLAG_ON or _feature_flags.is_enabled(_feature_flags.FLAG_LOCAL_STORAGE_SYNC)
545):
546 from tools import storage as _storage_mod
548 _importlib.reload(_storage_mod)
549 for _name in ("upload_to_regional_bucket", "sync_storage_bucket"):
550 if hasattr(_storage_mod, _name):
551 globals()[_name] = getattr(_storage_mod, _name)
553if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_LOCAL_METRICS):
554 from tools import metrics as _metrics_mod
556 _importlib.reload(_metrics_mod)
557 metrics_from_local_file = _metrics_mod.metrics_from_local_file
559if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_SEMANTIC_PROGRESS):
560 from tools import semantic_progress as _semantic_progress_mod
562 _importlib.reload(_semantic_progress_mod)
563 metrics_semantic_progress = _semantic_progress_mod.metrics_semantic_progress
565if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_MISSION):
566 from tools import mission as _mission_tools_mod
568 _importlib.reload(_mission_tools_mod)
569 # Unlike the images/models/storage reload blocks above, every name here is
570 # defined under the exact same `is_enabled(FLAG_MISSION)` gate this block
571 # is itself conditioned on, so a `hasattr` guard would never see a miss —
572 # it is a straight rebind.
573 for _name in (
574 "mission_start",
575 "mission_status",
576 "mission_iterate",
577 "mission_checkpoint",
578 "mission_complete",
579 "mission_abort",
580 "mission_resume",
581 "mission_history",
582 "mission_list",
583 "mission_memory_search",
584 ):
585 globals()[_name] = getattr(_mission_tools_mod, _name)
587if _IS_RELOAD and _feature_flags.is_enabled(_feature_flags.FLAG_SWARM):
588 from tools import swarm as _swarm_tools_mod
590 _importlib.reload(_swarm_tools_mod)
591 # Same reasoning as the mission block above: every name is defined under
592 # this same `is_enabled(FLAG_SWARM)` gate, so `hasattr` cannot miss.
593 for _name in (
594 "swarm_start",
595 "swarm_iterate",
596 "swarm_status",
597 "swarm_abort",
598 "swarm_list",
599 "swarm_plan",
600 ):
601 globals()[_name] = getattr(_swarm_tools_mod, _name)
603# --- Re-export resource directory constants for tests ---
604from resources.ci import ( # noqa: E402, F401
605 GITHUB_ACTIONS_DIR,
606 GITHUB_CODEQL_DIR,
607 GITHUB_DIR,
608 GITHUB_ISSUE_TEMPLATE_DIR,
609 GITHUB_KIND_DIR,
610 GITHUB_SCRIPTS_DIR,
611 GITHUB_WORKFLOWS_DIR,
612)
613from resources.docs import DOCS_DIR, EXAMPLES_DIR # noqa: E402, F401
614from resources.infra import DOCKERFILES_DIR, HELM_CHARTS_FILE # noqa: E402, F401
615from resources.k8s import MANIFESTS_DIR # noqa: E402, F401
616from resources.self import _TOOL_GATING_TABLE # noqa: E402
618# Declare every candidate name that is intentionally re-exported for tests and
619# downstream consumers. The final ``__all__`` below filters gated names against
620# both the current environment and actual module globals, so ``from run_mcp
621# import *`` never advertises an unavailable attribute.
622_PUBLIC_EXPORTS = [
623 "DOCKERFILES_DIR",
624 "DOCS_DIR",
625 "EXAMPLES_DIR",
626 "GITHUB_ACTIONS_DIR",
627 "GITHUB_CODEQL_DIR",
628 "GITHUB_DIR",
629 "GITHUB_ISSUE_TEMPLATE_DIR",
630 "GITHUB_KIND_DIR",
631 "GITHUB_SCRIPTS_DIR",
632 "GITHUB_WORKFLOWS_DIR",
633 "HELM_CHARTS_FILE",
634 "MANIFESTS_DIR",
635 "_MCP_SERVER_VERSION",
636 "_PROJECT_VERSION",
637 "_sanitize_arguments",
638 "add_deployment_region",
639 "add_inference_region",
640 "addons_install",
641 "addons_status",
642 "ai_recommend",
643 "analytics_doctor",
644 "analytics_login_url",
645 "analytics_status",
646 "analytics_user_add",
647 "analytics_user_remove",
648 "analytics_users_list",
649 "assume_mcp_role",
650 "audit_logged",
651 "audit_logger",
652 "aurora_status",
653 "bootstrap_cdk",
654 "canary_deploy",
655 "cancel_queue_job",
656 "cancel_reservation",
657 "capacity_history_patterns",
658 "capacity_history_show",
659 "capacity_history_stats",
660 "capacity_predict",
661 "capacity_status",
662 "chat_inference",
663 "check_capacity",
664 "check_job_policy",
665 "cluster_health",
666 "cluster_tunnel_command",
667 "config_get",
668 "configure_mooncake_store",
669 "cost_allocation_activate",
670 "cost_allocation_status",
671 "cost_by_region",
672 "cost_forecast",
673 "cost_k8s_namespaces",
674 "cost_k8s_regions",
675 "cost_k8s_top",
676 "cost_k8s_trend",
677 "cost_report_generate",
678 "cost_report_list",
679 "cost_report_status",
680 "cost_summary",
681 "cost_trend",
682 "cost_workloads",
683 "create_reservation",
684 "crossplane_status",
685 "dag_run",
686 "dag_validate",
687 "delete_inference",
688 "delete_job",
689 "delete_model",
690 "delete_nodepool",
691 "delete_template",
692 "delete_webhook",
693 "deploy_all",
694 "deploy_disaggregated_inference",
695 "deploy_inference",
696 "deploy_stack",
697 "deps_scan",
698 "destroy_all",
699 "destroy_stack",
700 "disable_analytics",
701 "disable_aurora",
702 "disable_fsx",
703 "disable_monitoring",
704 "disable_valkey",
705 "eks_capabilities_status",
706 "emit_startup_log",
707 "enable_analytics",
708 "enable_aurora",
709 "enable_fsx",
710 "enable_monitoring",
711 "enable_valkey",
712 "files_access_points",
713 "files_get",
714 "find_capacity_blocks",
715 "find_capacity_reservations",
716 "find_docs",
717 "find_examples",
718 "fleet_status",
719 "fsx_status",
720 "get_job",
721 "get_job_events",
722 "get_job_logs",
723 "get_job_metrics",
724 "get_job_pods",
725 "get_job_validation_policy",
726 "get_model_uri",
727 "get_pod_logs",
728 "get_project_version",
729 "gitops_status",
730 "images_build",
731 "images_cleanup",
732 "images_delete_repo",
733 "images_delete_tag",
734 "images_describe",
735 "images_init",
736 "images_lifecycle_get",
737 "images_lifecycle_set",
738 "images_list",
739 "images_mirror",
740 "images_mirror_plan",
741 "images_mirror_status",
742 "images_orphans",
743 "images_prune",
744 "images_push",
745 "images_replication_get",
746 "images_replication_status",
747 "images_replication_sync",
748 "images_tags",
749 "images_uri",
750 "inference_health",
751 "inference_status",
752 "instance_info",
753 "invoke_inference",
754 "list_deployment_regions",
755 "list_endpoint_models",
756 "list_file_systems",
757 "list_inference_endpoints",
758 "list_jobs",
759 "list_models",
760 "list_reservations",
761 "list_stacks",
762 "list_storage_buckets",
763 "list_storage_contents",
764 "mcp",
765 "metrics_cloudwatch_get",
766 "metrics_from_job_logs",
767 "metrics_from_local_file",
768 "metrics_from_shared_storage_file",
769 "metrics_semantic_progress",
770 "mission_abort",
771 "mission_checkpoint",
772 "mission_complete",
773 "mission_history",
774 "mission_iterate",
775 "mission_list",
776 "mission_memory_search",
777 "mission_resume",
778 "mission_start",
779 "mission_status",
780 "models_upload",
781 "monitoring_status",
782 "monitoring_user_add",
783 "monitoring_user_remove",
784 "monitoring_users_list",
785 "mooncake_topology_status",
786 "nodepools_create_capacity_block",
787 "nodepools_create_odcr",
788 "nodepools_describe",
789 "nodepools_list",
790 "populate_kv_cache",
791 "promote_canary",
792 "queue_get",
793 "queue_list",
794 "queue_stats",
795 "queue_status",
796 "queue_submit",
797 "recommend_capacity",
798 "recommend_region",
799 "remove_deployment_region",
800 "remove_inference_region",
801 "reservation_check",
802 "reserve_capacity",
803 "retry_job",
804 "rollback_canary",
805 "s3_inventory",
806 "scale_inference",
807 "set_capacity_advisor_default_model",
808 "set_claude_code_default_model",
809 "set_codex_default_model",
810 "set_codex_reasoning_effort",
811 "set_deployment_region",
812 "set_eks_endpoint_access",
813 "set_mission_default_model",
814 "set_mooncake_topology",
815 "set_opencode_default_model",
816 "setup_cluster_access",
817 "slurm_accounting",
818 "slurm_cancel",
819 "slurm_job",
820 "slurm_nodes",
821 "slurm_partitions",
822 "slurm_queue",
823 "slurm_status",
824 "slurm_submit",
825 "spot_prices",
826 "stack_diff",
827 "stack_outputs",
828 "stack_status",
829 "stack_synth",
830 "start_inference",
831 "stop_inference",
832 "submit_job_api",
833 "submit_job_sqs",
834 "swarm_abort",
835 "swarm_iterate",
836 "swarm_list",
837 "swarm_plan",
838 "swarm_start",
839 "swarm_status",
840 "sync_storage_bucket",
841 "task_prune",
842 "task_status",
843 "task_tail",
844 "templates_create",
845 "templates_get",
846 "templates_list",
847 "templates_run",
848 "update_inference_image",
849 "upload_to_regional_bucket",
850 "valkey_status",
851 "webhooks_create",
852 "webhooks_get",
853 "webhooks_list",
854]
856__all__ = [
857 name
858 for name in _PUBLIC_EXPORTS
859 if name in globals()
860 and (name not in _TOOL_GATING_TABLE or _feature_flags.is_enabled(_TOOL_GATING_TABLE[name]))
861]
863# =============================================================================
864# ENTRYPOINT
865# =============================================================================
868def _initialize_runtime() -> None:
869 """Perform external startup effects exactly once per process invocation.
871 Importing ``run_mcp`` is now safe for documentation tooling and tests: it
872 does not emit a startup audit record or mutate the ambient boto3 session by
873 assuming a role. Those effects happen only when the server is actually run.
874 """
875 emit_startup_log()
876 assume_mcp_role()
879def main() -> None:
880 """Start the MCP server after applying runtime identity and audit setup."""
881 _initialize_runtime()
882 mcp.run()
885# Set only after registration/re-export initialization has completed. Python's
886# reload machinery preserves this sentinel in the module dictionary.
887_RUN_MCP_IMPORT_COMPLETE = True
890if __name__ == "__main__":
891 main()