glaip-sdk 0.0.20__py3-none-any.whl → 0.7.7__py3-none-any.whl

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.
Files changed (216) hide show
  1. glaip_sdk/__init__.py +44 -4
  2. glaip_sdk/_version.py +10 -3
  3. glaip_sdk/agents/__init__.py +27 -0
  4. glaip_sdk/agents/base.py +1250 -0
  5. glaip_sdk/branding.py +15 -6
  6. glaip_sdk/cli/account_store.py +540 -0
  7. glaip_sdk/cli/agent_config.py +2 -6
  8. glaip_sdk/cli/auth.py +271 -45
  9. glaip_sdk/cli/commands/__init__.py +2 -2
  10. glaip_sdk/cli/commands/accounts.py +746 -0
  11. glaip_sdk/cli/commands/agents/__init__.py +119 -0
  12. glaip_sdk/cli/commands/agents/_common.py +561 -0
  13. glaip_sdk/cli/commands/agents/create.py +151 -0
  14. glaip_sdk/cli/commands/agents/delete.py +64 -0
  15. glaip_sdk/cli/commands/agents/get.py +89 -0
  16. glaip_sdk/cli/commands/agents/list.py +129 -0
  17. glaip_sdk/cli/commands/agents/run.py +264 -0
  18. glaip_sdk/cli/commands/agents/sync_langflow.py +72 -0
  19. glaip_sdk/cli/commands/agents/update.py +112 -0
  20. glaip_sdk/cli/commands/common_config.py +104 -0
  21. glaip_sdk/cli/commands/configure.py +734 -143
  22. glaip_sdk/cli/commands/mcps/__init__.py +94 -0
  23. glaip_sdk/cli/commands/mcps/_common.py +459 -0
  24. glaip_sdk/cli/commands/mcps/connect.py +82 -0
  25. glaip_sdk/cli/commands/mcps/create.py +152 -0
  26. glaip_sdk/cli/commands/mcps/delete.py +73 -0
  27. glaip_sdk/cli/commands/mcps/get.py +212 -0
  28. glaip_sdk/cli/commands/mcps/list.py +69 -0
  29. glaip_sdk/cli/commands/mcps/tools.py +235 -0
  30. glaip_sdk/cli/commands/mcps/update.py +190 -0
  31. glaip_sdk/cli/commands/models.py +14 -12
  32. glaip_sdk/cli/commands/shared/__init__.py +21 -0
  33. glaip_sdk/cli/commands/shared/formatters.py +91 -0
  34. glaip_sdk/cli/commands/tools/__init__.py +69 -0
  35. glaip_sdk/cli/commands/tools/_common.py +80 -0
  36. glaip_sdk/cli/commands/tools/create.py +228 -0
  37. glaip_sdk/cli/commands/tools/delete.py +61 -0
  38. glaip_sdk/cli/commands/tools/get.py +103 -0
  39. glaip_sdk/cli/commands/tools/list.py +69 -0
  40. glaip_sdk/cli/commands/tools/script.py +49 -0
  41. glaip_sdk/cli/commands/tools/update.py +102 -0
  42. glaip_sdk/cli/commands/transcripts/__init__.py +90 -0
  43. glaip_sdk/cli/commands/transcripts/_common.py +9 -0
  44. glaip_sdk/cli/commands/transcripts/clear.py +5 -0
  45. glaip_sdk/cli/commands/transcripts/detail.py +5 -0
  46. glaip_sdk/cli/commands/transcripts_original.py +756 -0
  47. glaip_sdk/cli/commands/update.py +164 -23
  48. glaip_sdk/cli/config.py +49 -7
  49. glaip_sdk/cli/constants.py +38 -0
  50. glaip_sdk/cli/context.py +8 -0
  51. glaip_sdk/cli/core/__init__.py +79 -0
  52. glaip_sdk/cli/core/context.py +124 -0
  53. glaip_sdk/cli/core/output.py +851 -0
  54. glaip_sdk/cli/core/prompting.py +649 -0
  55. glaip_sdk/cli/core/rendering.py +187 -0
  56. glaip_sdk/cli/display.py +45 -32
  57. glaip_sdk/cli/entrypoint.py +20 -0
  58. glaip_sdk/cli/hints.py +57 -0
  59. glaip_sdk/cli/io.py +14 -17
  60. glaip_sdk/cli/main.py +344 -167
  61. glaip_sdk/cli/masking.py +21 -33
  62. glaip_sdk/cli/mcp_validators.py +5 -15
  63. glaip_sdk/cli/pager.py +15 -22
  64. glaip_sdk/cli/parsers/__init__.py +1 -3
  65. glaip_sdk/cli/parsers/json_input.py +11 -22
  66. glaip_sdk/cli/resolution.py +5 -10
  67. glaip_sdk/cli/rich_helpers.py +1 -3
  68. glaip_sdk/cli/slash/__init__.py +0 -9
  69. glaip_sdk/cli/slash/accounts_controller.py +580 -0
  70. glaip_sdk/cli/slash/accounts_shared.py +75 -0
  71. glaip_sdk/cli/slash/agent_session.py +65 -29
  72. glaip_sdk/cli/slash/prompt.py +24 -10
  73. glaip_sdk/cli/slash/remote_runs_controller.py +566 -0
  74. glaip_sdk/cli/slash/session.py +827 -232
  75. glaip_sdk/cli/slash/tui/__init__.py +34 -0
  76. glaip_sdk/cli/slash/tui/accounts.tcss +88 -0
  77. glaip_sdk/cli/slash/tui/accounts_app.py +933 -0
  78. glaip_sdk/cli/slash/tui/background_tasks.py +72 -0
  79. glaip_sdk/cli/slash/tui/clipboard.py +147 -0
  80. glaip_sdk/cli/slash/tui/context.py +59 -0
  81. glaip_sdk/cli/slash/tui/keybind_registry.py +235 -0
  82. glaip_sdk/cli/slash/tui/loading.py +58 -0
  83. glaip_sdk/cli/slash/tui/remote_runs_app.py +628 -0
  84. glaip_sdk/cli/slash/tui/terminal.py +402 -0
  85. glaip_sdk/cli/slash/tui/theme/__init__.py +15 -0
  86. glaip_sdk/cli/slash/tui/theme/catalog.py +79 -0
  87. glaip_sdk/cli/slash/tui/theme/manager.py +86 -0
  88. glaip_sdk/cli/slash/tui/theme/tokens.py +55 -0
  89. glaip_sdk/cli/slash/tui/toast.py +123 -0
  90. glaip_sdk/cli/transcript/__init__.py +12 -52
  91. glaip_sdk/cli/transcript/cache.py +258 -60
  92. glaip_sdk/cli/transcript/capture.py +72 -21
  93. glaip_sdk/cli/transcript/history.py +815 -0
  94. glaip_sdk/cli/transcript/launcher.py +1 -3
  95. glaip_sdk/cli/transcript/viewer.py +79 -329
  96. glaip_sdk/cli/update_notifier.py +385 -24
  97. glaip_sdk/cli/validators.py +16 -18
  98. glaip_sdk/client/__init__.py +3 -1
  99. glaip_sdk/client/_schedule_payloads.py +89 -0
  100. glaip_sdk/client/agent_runs.py +147 -0
  101. glaip_sdk/client/agents.py +370 -100
  102. glaip_sdk/client/base.py +78 -35
  103. glaip_sdk/client/hitl.py +136 -0
  104. glaip_sdk/client/main.py +25 -10
  105. glaip_sdk/client/mcps.py +166 -27
  106. glaip_sdk/client/payloads/agent/__init__.py +23 -0
  107. glaip_sdk/client/{_agent_payloads.py → payloads/agent/requests.py} +65 -74
  108. glaip_sdk/client/payloads/agent/responses.py +43 -0
  109. glaip_sdk/client/run_rendering.py +583 -79
  110. glaip_sdk/client/schedules.py +439 -0
  111. glaip_sdk/client/shared.py +21 -0
  112. glaip_sdk/client/tools.py +214 -56
  113. glaip_sdk/client/validators.py +20 -48
  114. glaip_sdk/config/constants.py +11 -0
  115. glaip_sdk/exceptions.py +1 -3
  116. glaip_sdk/hitl/__init__.py +48 -0
  117. glaip_sdk/hitl/base.py +64 -0
  118. glaip_sdk/hitl/callback.py +43 -0
  119. glaip_sdk/hitl/local.py +121 -0
  120. glaip_sdk/hitl/remote.py +523 -0
  121. glaip_sdk/icons.py +9 -3
  122. glaip_sdk/mcps/__init__.py +21 -0
  123. glaip_sdk/mcps/base.py +345 -0
  124. glaip_sdk/models/__init__.py +107 -0
  125. glaip_sdk/models/agent.py +47 -0
  126. glaip_sdk/models/agent_runs.py +117 -0
  127. glaip_sdk/models/common.py +42 -0
  128. glaip_sdk/models/mcp.py +33 -0
  129. glaip_sdk/models/schedule.py +224 -0
  130. glaip_sdk/models/tool.py +33 -0
  131. glaip_sdk/payload_schemas/__init__.py +1 -13
  132. glaip_sdk/payload_schemas/agent.py +1 -3
  133. glaip_sdk/registry/__init__.py +55 -0
  134. glaip_sdk/registry/agent.py +164 -0
  135. glaip_sdk/registry/base.py +139 -0
  136. glaip_sdk/registry/mcp.py +253 -0
  137. glaip_sdk/registry/tool.py +445 -0
  138. glaip_sdk/rich_components.py +58 -2
  139. glaip_sdk/runner/__init__.py +76 -0
  140. glaip_sdk/runner/base.py +84 -0
  141. glaip_sdk/runner/deps.py +112 -0
  142. glaip_sdk/runner/langgraph.py +872 -0
  143. glaip_sdk/runner/logging_config.py +77 -0
  144. glaip_sdk/runner/mcp_adapter/__init__.py +13 -0
  145. glaip_sdk/runner/mcp_adapter/base_mcp_adapter.py +43 -0
  146. glaip_sdk/runner/mcp_adapter/langchain_mcp_adapter.py +257 -0
  147. glaip_sdk/runner/mcp_adapter/mcp_config_builder.py +95 -0
  148. glaip_sdk/runner/tool_adapter/__init__.py +18 -0
  149. glaip_sdk/runner/tool_adapter/base_tool_adapter.py +44 -0
  150. glaip_sdk/runner/tool_adapter/langchain_tool_adapter.py +242 -0
  151. glaip_sdk/schedules/__init__.py +22 -0
  152. glaip_sdk/schedules/base.py +291 -0
  153. glaip_sdk/tools/__init__.py +22 -0
  154. glaip_sdk/tools/base.py +468 -0
  155. glaip_sdk/utils/__init__.py +59 -12
  156. glaip_sdk/utils/a2a/__init__.py +34 -0
  157. glaip_sdk/utils/a2a/event_processor.py +188 -0
  158. glaip_sdk/utils/agent_config.py +4 -14
  159. glaip_sdk/utils/bundler.py +403 -0
  160. glaip_sdk/utils/client.py +111 -0
  161. glaip_sdk/utils/client_utils.py +46 -28
  162. glaip_sdk/utils/datetime_helpers.py +58 -0
  163. glaip_sdk/utils/discovery.py +78 -0
  164. glaip_sdk/utils/display.py +25 -21
  165. glaip_sdk/utils/export.py +143 -0
  166. glaip_sdk/utils/general.py +1 -36
  167. glaip_sdk/utils/import_export.py +15 -16
  168. glaip_sdk/utils/import_resolver.py +524 -0
  169. glaip_sdk/utils/instructions.py +101 -0
  170. glaip_sdk/utils/rendering/__init__.py +115 -1
  171. glaip_sdk/utils/rendering/formatting.py +38 -23
  172. glaip_sdk/utils/rendering/layout/__init__.py +64 -0
  173. glaip_sdk/utils/rendering/{renderer → layout}/panels.py +10 -3
  174. glaip_sdk/utils/rendering/{renderer → layout}/progress.py +73 -12
  175. glaip_sdk/utils/rendering/layout/summary.py +74 -0
  176. glaip_sdk/utils/rendering/layout/transcript.py +606 -0
  177. glaip_sdk/utils/rendering/models.py +18 -8
  178. glaip_sdk/utils/rendering/renderer/__init__.py +9 -51
  179. glaip_sdk/utils/rendering/renderer/base.py +534 -882
  180. glaip_sdk/utils/rendering/renderer/config.py +4 -10
  181. glaip_sdk/utils/rendering/renderer/debug.py +30 -34
  182. glaip_sdk/utils/rendering/renderer/factory.py +138 -0
  183. glaip_sdk/utils/rendering/renderer/stream.py +13 -54
  184. glaip_sdk/utils/rendering/renderer/summary_window.py +79 -0
  185. glaip_sdk/utils/rendering/renderer/thinking.py +273 -0
  186. glaip_sdk/utils/rendering/renderer/toggle.py +182 -0
  187. glaip_sdk/utils/rendering/renderer/tool_panels.py +442 -0
  188. glaip_sdk/utils/rendering/renderer/transcript_mode.py +162 -0
  189. glaip_sdk/utils/rendering/state.py +204 -0
  190. glaip_sdk/utils/rendering/step_tree_state.py +100 -0
  191. glaip_sdk/utils/rendering/steps/__init__.py +34 -0
  192. glaip_sdk/utils/rendering/steps/event_processor.py +778 -0
  193. glaip_sdk/utils/rendering/steps/format.py +176 -0
  194. glaip_sdk/utils/rendering/{steps.py → steps/manager.py} +122 -26
  195. glaip_sdk/utils/rendering/timing.py +36 -0
  196. glaip_sdk/utils/rendering/viewer/__init__.py +21 -0
  197. glaip_sdk/utils/rendering/viewer/presenter.py +184 -0
  198. glaip_sdk/utils/resource_refs.py +29 -26
  199. glaip_sdk/utils/runtime_config.py +425 -0
  200. glaip_sdk/utils/serialization.py +32 -46
  201. glaip_sdk/utils/sync.py +162 -0
  202. glaip_sdk/utils/tool_detection.py +301 -0
  203. glaip_sdk/utils/tool_storage_provider.py +140 -0
  204. glaip_sdk/utils/validation.py +20 -28
  205. {glaip_sdk-0.0.20.dist-info → glaip_sdk-0.7.7.dist-info}/METADATA +78 -23
  206. glaip_sdk-0.7.7.dist-info/RECORD +213 -0
  207. {glaip_sdk-0.0.20.dist-info → glaip_sdk-0.7.7.dist-info}/WHEEL +2 -1
  208. glaip_sdk-0.7.7.dist-info/entry_points.txt +2 -0
  209. glaip_sdk-0.7.7.dist-info/top_level.txt +1 -0
  210. glaip_sdk/cli/commands/agents.py +0 -1412
  211. glaip_sdk/cli/commands/mcps.py +0 -1225
  212. glaip_sdk/cli/commands/tools.py +0 -597
  213. glaip_sdk/cli/utils.py +0 -1330
  214. glaip_sdk/models.py +0 -259
  215. glaip_sdk-0.0.20.dist-info/RECORD +0 -80
  216. glaip_sdk-0.0.20.dist-info/entry_points.txt +0 -3
@@ -0,0 +1,139 @@
1
+ """Abstract base registry for caching platform objects.
2
+
3
+ This module provides the BaseRegistry abstract class that serves as the
4
+ foundation for type-specific registries (AgentRegistry, ToolRegistry, MCPRegistry).
5
+
6
+ The registry pattern provides:
7
+ - In-memory caching to avoid redundant API calls
8
+ - Transparent resolution of various reference types
9
+ - Simple invalidation and cache management
10
+
11
+ Authors:
12
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import logging
18
+ from abc import ABC, abstractmethod
19
+ from typing import Any, Generic, TypeVar
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ T = TypeVar("T")
25
+
26
+
27
+ class BaseRegistry(ABC, Generic[T]):
28
+ """Abstract base registry for caching platform objects.
29
+
30
+ Provides a caching layer between local code and the AIP platform.
31
+ Subclasses implement type-specific resolution logic.
32
+
33
+ The registry follows a simple flow:
34
+ 1. Check if reference is already a platform object → return as-is
35
+ 2. Extract name from reference
36
+ 3. Check cache → return if found
37
+ 4. Resolve via subclass logic → cache and return
38
+
39
+ Attributes:
40
+ _cache: Internal cache mapping names to objects.
41
+
42
+ Example:
43
+ >>> class MyRegistry(BaseRegistry):
44
+ ... def _extract_name(self, ref: Any) -> str:
45
+ ... return ref.name if hasattr(ref, 'name') else str(ref)
46
+ ...
47
+ ... def _resolve_and_cache(self, ref: Any, name: str) -> MyType:
48
+ ... obj = fetch_from_platform(name)
49
+ ... self._cache[name] = obj
50
+ ... return obj
51
+ """
52
+
53
+ def __init__(self) -> None:
54
+ """Initialize the registry with an empty cache."""
55
+ self._cache: dict[str, T] = {}
56
+
57
+ def resolve(self, ref: Any) -> T:
58
+ """Resolve a reference to a platform object.
59
+
60
+ This is the main entry point for the registry. It handles:
61
+ - Cached references (returned from cache)
62
+ - New references (resolved via subclass, then cached)
63
+
64
+ Args:
65
+ ref: A reference to resolve. Can be a class, string name,
66
+ or platform object depending on the registry type.
67
+
68
+ Returns:
69
+ The resolved platform object.
70
+
71
+ Raises:
72
+ ValueError: If the reference cannot be resolved.
73
+ """
74
+ name = self._extract_name(ref)
75
+
76
+ if name in self._cache:
77
+ logger.debug("Cache hit: %s", name)
78
+ return self._cache[name]
79
+
80
+ return self._resolve_and_cache(ref, name)
81
+
82
+ def get(self, name: str) -> T | None:
83
+ """Get a cached object by name.
84
+
85
+ Args:
86
+ name: The name of the object to retrieve.
87
+
88
+ Returns:
89
+ The cached object, or None if not found.
90
+ """
91
+ return self._cache.get(name)
92
+
93
+ def invalidate(self, name: str) -> None:
94
+ """Remove an object from the cache.
95
+
96
+ Use this to force a re-fetch on the next resolve call.
97
+
98
+ Args:
99
+ name: The name of the object to invalidate.
100
+ """
101
+ self._cache.pop(name, None)
102
+ logger.debug("Invalidated cache entry: %s", name)
103
+
104
+ def clear(self) -> None:
105
+ """Clear all cached entries."""
106
+ self._cache.clear()
107
+ logger.debug("Cleared registry cache")
108
+
109
+ @abstractmethod
110
+ def _extract_name(self, ref: Any) -> str:
111
+ """Extract the name from a reference.
112
+
113
+ Args:
114
+ ref: The reference to extract a name from.
115
+
116
+ Returns:
117
+ The extracted name string.
118
+
119
+ Raises:
120
+ ValueError: If name cannot be extracted.
121
+ """
122
+
123
+ @abstractmethod
124
+ def _resolve_and_cache(self, ref: Any, name: str) -> T:
125
+ """Resolve the reference and cache the result.
126
+
127
+ Subclasses implement type-specific resolution logic here.
128
+ This method MUST cache the result in self._cache[name].
129
+
130
+ Args:
131
+ ref: The reference to resolve.
132
+ name: The extracted name for caching.
133
+
134
+ Returns:
135
+ The resolved platform object.
136
+
137
+ Raises:
138
+ ValueError: If resolution fails.
139
+ """
@@ -0,0 +1,253 @@
1
+ """MCP registry for glaip_sdk.
2
+
3
+ This module provides the MCPRegistry that caches MCPs (Model Context Protocols)
4
+ to avoid redundant API calls when deploying agents with MCPs.
5
+
6
+ Authors:
7
+ Christian Trisno Sen Long Chen (christian.t.s.l.chen@gdplabs.id)
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+ from typing import TYPE_CHECKING, Any
14
+
15
+ from glaip_sdk.registry.base import BaseRegistry
16
+ from glaip_sdk.utils.resource_refs import is_uuid
17
+
18
+ if TYPE_CHECKING:
19
+ from glaip_sdk.mcps import MCP
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ class MCPRegistry(BaseRegistry["MCP"]):
25
+ """Registry for MCPs (Model Context Protocols).
26
+
27
+ Resolves MCP references to glaip_sdk.models.MCP objects.
28
+ Caches results to avoid redundant API calls.
29
+
30
+ Handles:
31
+ - glaip_sdk.models.MCP → return as-is (uses mcp.id)
32
+ - String names/IDs → lookup on platform, cache, return MCP
33
+
34
+ Attributes:
35
+ _cache: Internal cache mapping names to MCP objects.
36
+
37
+ Example:
38
+ >>> registry = get_mcp_registry()
39
+ >>> mcp = registry.resolve("arxiv-mcp")
40
+ >>> print(mcp.id)
41
+ """
42
+
43
+ def _extract_name(self, ref: Any) -> str:
44
+ """Extract MCP name from a reference.
45
+
46
+ Args:
47
+ ref: An MCP object, dict, or string name.
48
+
49
+ Returns:
50
+ The extracted MCP name.
51
+
52
+ Raises:
53
+ ValueError: If name cannot be extracted from the reference.
54
+ """
55
+ # String name
56
+ if isinstance(ref, str):
57
+ return ref
58
+
59
+ # Dict from API response - extract name or id
60
+ if isinstance(ref, dict):
61
+ return ref.get("name") or ref.get("id") or ""
62
+
63
+ # Already resolved MCP (glaip_sdk.models.MCP)
64
+ if hasattr(ref, "id") and hasattr(ref, "name") and not isinstance(ref, type):
65
+ return ref.name or ref.id
66
+
67
+ raise ValueError(f"Cannot extract name from: {ref}")
68
+
69
+ def _resolve_and_cache(self, ref: Any, name: str) -> MCP:
70
+ """Resolve MCP reference - find by name/ID or create if needed.
71
+
72
+ Args:
73
+ ref: The MCP reference to resolve.
74
+ name: The extracted MCP name.
75
+
76
+ Returns:
77
+ The resolved glaip_sdk.models.MCP object.
78
+
79
+ Raises:
80
+ ValueError: If the MCP cannot be resolved.
81
+ """
82
+ # MCP object (check if already has ID)
83
+ if hasattr(ref, "id") and hasattr(ref, "name") and not isinstance(ref, type):
84
+ if ref.id is not None:
85
+ # Already resolved MCP with ID - just cache and return
86
+ logger.debug("Caching already resolved MCP: %s", name)
87
+ self._cache[name] = ref
88
+ return ref
89
+
90
+ # MCP without ID - need to look up or create
91
+ return self._lookup_or_create_mcp(ref, name)
92
+
93
+ # Dict from API response - use ID directly if available
94
+ if isinstance(ref, dict):
95
+ mcp_id = ref.get("id")
96
+ if mcp_id:
97
+ from glaip_sdk.mcps.base import MCP # noqa: PLC0415
98
+
99
+ mcp = MCP(id=mcp_id, name=ref.get("name", ""))
100
+ self._cache[name] = mcp
101
+ return mcp
102
+ raise ValueError(f"MCP dict missing 'id': {ref}")
103
+
104
+ # String name - look up on platform
105
+ if isinstance(ref, str):
106
+ return self._lookup_mcp_by_name(name)
107
+
108
+ raise ValueError(f"Could not resolve MCP reference: {ref}")
109
+
110
+ def _lookup_or_create_mcp(self, ref: Any, name: str) -> MCP:
111
+ """Look up or create an MCP from a reference.
112
+
113
+ Args:
114
+ ref: The MCP reference with config details.
115
+ name: The extracted MCP name.
116
+
117
+ Returns:
118
+ The resolved or created glaip_sdk.models.MCP object.
119
+ """
120
+ # Check if this MCP is lookup-only (e.g., from MCP.from_native)
121
+ if getattr(ref, "_lookup_only", False):
122
+ return self._lookup_native_mcp(name)
123
+
124
+ return self._upsert_mcp_from_ref(ref, name)
125
+
126
+ def _lookup_native_mcp(self, name: str) -> MCP:
127
+ """Look up a native MCP that must exist on the platform.
128
+
129
+ Used for MCP.from_native() references that should not be created.
130
+
131
+ Args:
132
+ name: The MCP name to look up.
133
+
134
+ Returns:
135
+ The found MCP.
136
+
137
+ Raises:
138
+ ValueError: If MCP not found or multiple found.
139
+ """
140
+ from glaip_sdk.utils.client import get_client # noqa: PLC0415
141
+
142
+ client = get_client()
143
+ logger.info("Looking up native MCP: %s", name)
144
+
145
+ results = client.find_mcps(name)
146
+ exact_matches = [mcp for mcp in results if getattr(mcp, "name", None) == name]
147
+ if len(exact_matches) == 1:
148
+ mcp = exact_matches[0]
149
+ self._cache[name] = mcp
150
+ return mcp
151
+ if len(exact_matches) > 1:
152
+ raise ValueError(f"Multiple MCPs found with name '{name}'")
153
+ raise ValueError(f"MCP not found on platform: {name}")
154
+
155
+ def _upsert_mcp_from_ref(self, ref: Any, name: str) -> MCP:
156
+ """Create or update an MCP from a reference with config.
157
+
158
+ Args:
159
+ ref: The MCP reference with config details.
160
+ name: The extracted MCP name.
161
+
162
+ Returns:
163
+ The created or updated MCP.
164
+ """
165
+ from glaip_sdk.utils.client import get_client # noqa: PLC0415
166
+
167
+ client = get_client()
168
+ logger.info("Upserting MCP: %s", name)
169
+
170
+ mcp = client.mcps.upsert_mcp(
171
+ name,
172
+ description=getattr(ref, "description", None),
173
+ config=getattr(ref, "config", None),
174
+ transport=getattr(ref, "transport", None),
175
+ metadata=getattr(ref, "metadata", None),
176
+ authentication=getattr(ref, "authentication", None),
177
+ )
178
+ self._cache[name] = mcp
179
+ return mcp
180
+
181
+ def _lookup_mcp_by_name(self, name: str) -> MCP:
182
+ """Look up MCP by name or ID on the platform.
183
+
184
+ Args:
185
+ name: The MCP name or ID to look up.
186
+
187
+ Returns:
188
+ The resolved glaip_sdk.models.MCP object.
189
+
190
+ Raises:
191
+ ValueError: If the MCP cannot be found.
192
+ """
193
+ # Lazy imports to avoid circular dependency
194
+ from glaip_sdk.utils.client import get_client # noqa: PLC0415
195
+
196
+ client = get_client()
197
+ logger.info("Looking up MCP by name: %s", name)
198
+
199
+ # Check if it's a valid UUID
200
+ if is_uuid(name):
201
+ mcp = client.get_mcp_by_id(name)
202
+ if mcp:
203
+ self._cache[name] = mcp
204
+ return mcp
205
+ else:
206
+ results = client.find_mcps(name)
207
+ exact_matches = [mcp for mcp in results if getattr(mcp, "name", None) == name]
208
+ if len(exact_matches) == 1:
209
+ mcp = exact_matches[0]
210
+ self._cache[name] = mcp
211
+ return mcp
212
+ if len(exact_matches) > 1:
213
+ raise ValueError(f"Multiple MCPs found with name '{name}'")
214
+
215
+ raise ValueError(f"MCP not found on platform: {name}")
216
+
217
+
218
+ class _MCPRegistrySingleton:
219
+ """Singleton holder for MCPRegistry to avoid global statement."""
220
+
221
+ _instance: MCPRegistry | None = None
222
+
223
+ @classmethod
224
+ def get_instance(cls) -> MCPRegistry:
225
+ """Get or create the singleton instance.
226
+
227
+ Returns:
228
+ The global MCPRegistry instance.
229
+ """
230
+ if cls._instance is None:
231
+ cls._instance = MCPRegistry()
232
+ return cls._instance
233
+
234
+ @classmethod
235
+ def reset(cls) -> None:
236
+ """Reset the singleton instance (for testing)."""
237
+ cls._instance = None
238
+
239
+
240
+ def get_mcp_registry() -> MCPRegistry:
241
+ """Get the singleton MCPRegistry instance.
242
+
243
+ Returns a global MCPRegistry that caches MCPs across the session.
244
+
245
+ Returns:
246
+ The global MCPRegistry instance.
247
+
248
+ Example:
249
+ >>> from glaip_sdk.registry import get_mcp_registry
250
+ >>> registry = get_mcp_registry()
251
+ >>> mcp = registry.resolve("arxiv-mcp")
252
+ """
253
+ return _MCPRegistrySingleton.get_instance()