@1mcp/agent 0.34.3 → 0.35.0-beta.1

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 (244) hide show
  1. package/build/admin/assets/admin-console-CX5GzncA.css +1 -0
  2. package/build/admin/assets/admin-console-CkZ5lBKg.js +61 -0
  3. package/build/admin/index.html +13 -0
  4. package/build/commands/admin/admin.d.ts +90 -0
  5. package/build/commands/admin/admin.d.ts.map +1 -0
  6. package/build/commands/admin/admin.js +545 -0
  7. package/build/commands/admin/admin.js.map +1 -0
  8. package/build/commands/admin/index.d.ts +3 -0
  9. package/build/commands/admin/index.d.ts.map +1 -0
  10. package/build/commands/admin/index.js +99 -0
  11. package/build/commands/admin/index.js.map +1 -0
  12. package/build/commands/auth/index.d.ts.map +1 -1
  13. package/build/commands/auth/index.js +24 -5
  14. package/build/commands/auth/index.js.map +1 -1
  15. package/build/commands/auth/login.d.ts +1 -0
  16. package/build/commands/auth/login.d.ts.map +1 -1
  17. package/build/commands/auth/login.js +6 -10
  18. package/build/commands/auth/login.js.map +1 -1
  19. package/build/commands/auth/logout.d.ts +3 -0
  20. package/build/commands/auth/logout.d.ts.map +1 -1
  21. package/build/commands/auth/logout.js +19 -32
  22. package/build/commands/auth/logout.js.map +1 -1
  23. package/build/commands/auth/runtimeTargetContext.d.ts +25 -0
  24. package/build/commands/auth/runtimeTargetContext.d.ts.map +1 -0
  25. package/build/commands/auth/runtimeTargetContext.js +69 -0
  26. package/build/commands/auth/runtimeTargetContext.js.map +1 -0
  27. package/build/commands/auth/status.d.ts +1 -0
  28. package/build/commands/auth/status.d.ts.map +1 -1
  29. package/build/commands/auth/status.js +10 -33
  30. package/build/commands/auth/status.js.map +1 -1
  31. package/build/commands/inspect/index.d.ts.map +1 -1
  32. package/build/commands/inspect/index.js +4 -0
  33. package/build/commands/inspect/index.js.map +1 -1
  34. package/build/commands/inspect/inspect.d.ts +1 -0
  35. package/build/commands/inspect/inspect.d.ts.map +1 -1
  36. package/build/commands/inspect/inspect.js +2 -2
  37. package/build/commands/inspect/inspect.js.map +1 -1
  38. package/build/commands/instructions/index.d.ts.map +1 -1
  39. package/build/commands/instructions/index.js +4 -0
  40. package/build/commands/instructions/index.js.map +1 -1
  41. package/build/commands/instructions/instructions.d.ts +1 -0
  42. package/build/commands/instructions/instructions.d.ts.map +1 -1
  43. package/build/commands/instructions/instructions.js.map +1 -1
  44. package/build/commands/instructions/instructionsUtils.js +1 -1
  45. package/build/commands/instructions/instructionsUtils.js.map +1 -1
  46. package/build/commands/mcp/enable.d.ts +89 -2
  47. package/build/commands/mcp/enable.d.ts.map +1 -1
  48. package/build/commands/mcp/enable.js +555 -35
  49. package/build/commands/mcp/enable.js.map +1 -1
  50. package/build/commands/proxy/index.d.ts +1 -0
  51. package/build/commands/proxy/index.d.ts.map +1 -1
  52. package/build/commands/proxy/index.js +4 -0
  53. package/build/commands/proxy/index.js.map +1 -1
  54. package/build/commands/run/index.d.ts.map +1 -1
  55. package/build/commands/run/index.js +4 -0
  56. package/build/commands/run/index.js.map +1 -1
  57. package/build/commands/run/run.d.ts +1 -0
  58. package/build/commands/run/run.d.ts.map +1 -1
  59. package/build/commands/run/run.js +2 -2
  60. package/build/commands/run/run.js.map +1 -1
  61. package/build/commands/serve/serve.d.ts.map +1 -1
  62. package/build/commands/serve/serve.js +4 -0
  63. package/build/commands/serve/serve.js.map +1 -1
  64. package/build/commands/shared/apiClient.d.ts +5 -1
  65. package/build/commands/shared/apiClient.d.ts.map +1 -1
  66. package/build/commands/shared/apiClient.js +17 -9
  67. package/build/commands/shared/apiClient.js.map +1 -1
  68. package/build/commands/shared/clientSurfaceAttachment.d.ts +14 -0
  69. package/build/commands/shared/clientSurfaceAttachment.d.ts.map +1 -1
  70. package/build/commands/shared/clientSurfaceAttachment.js +51 -9
  71. package/build/commands/shared/clientSurfaceAttachment.js.map +1 -1
  72. package/build/commands/shared/commandRunner.d.ts +3 -1
  73. package/build/commands/shared/commandRunner.d.ts.map +1 -1
  74. package/build/commands/shared/commandRunner.js +59 -2
  75. package/build/commands/shared/commandRunner.js.map +1 -1
  76. package/build/commands/shared/serveTargetResolver.d.ts +14 -1
  77. package/build/commands/shared/serveTargetResolver.d.ts.map +1 -1
  78. package/build/commands/shared/serveTargetResolver.js +145 -3
  79. package/build/commands/shared/serveTargetResolver.js.map +1 -1
  80. package/build/commands/target/index.d.ts +3 -0
  81. package/build/commands/target/index.d.ts.map +1 -0
  82. package/build/commands/target/index.js +171 -0
  83. package/build/commands/target/index.js.map +1 -0
  84. package/build/commands/target/target.d.ts +78 -0
  85. package/build/commands/target/target.d.ts.map +1 -0
  86. package/build/commands/target/target.js +471 -0
  87. package/build/commands/target/target.js.map +1 -0
  88. package/build/constants/mcp.d.ts +1 -1
  89. package/build/constants/mcp.d.ts.map +1 -1
  90. package/build/constants/mcp.js +1 -1
  91. package/build/constants/mcp.js.map +1 -1
  92. package/build/core/capabilities/asyncLoadingOrchestrator.d.ts +6 -14
  93. package/build/core/capabilities/asyncLoadingOrchestrator.d.ts.map +1 -1
  94. package/build/core/capabilities/asyncLoadingOrchestrator.js +24 -17
  95. package/build/core/capabilities/asyncLoadingOrchestrator.js.map +1 -1
  96. package/build/core/capabilities/asyncLoadingOrchestratorEvent.d.ts +6 -0
  97. package/build/core/capabilities/asyncLoadingOrchestratorEvent.d.ts.map +1 -0
  98. package/build/core/capabilities/asyncLoadingOrchestratorEvent.js +7 -0
  99. package/build/core/capabilities/asyncLoadingOrchestratorEvent.js.map +1 -0
  100. package/build/core/capabilities/lazyLoadingOrchestrator.d.ts.map +1 -1
  101. package/build/core/capabilities/lazyLoadingOrchestrator.js +6 -5
  102. package/build/core/capabilities/lazyLoadingOrchestrator.js.map +1 -1
  103. package/build/core/client/clientManager.d.ts +2 -0
  104. package/build/core/client/clientManager.d.ts.map +1 -1
  105. package/build/core/client/clientManager.js +27 -24
  106. package/build/core/client/clientManager.js.map +1 -1
  107. package/build/core/client/connectedClient.d.ts +7 -0
  108. package/build/core/client/connectedClient.d.ts.map +1 -0
  109. package/build/core/client/connectedClient.js +2 -0
  110. package/build/core/client/connectedClient.js.map +1 -0
  111. package/build/core/client/connectionHandler.d.ts +2 -1
  112. package/build/core/client/connectionHandler.d.ts.map +1 -1
  113. package/build/core/client/connectionHandler.js +2 -5
  114. package/build/core/client/connectionHandler.js.map +1 -1
  115. package/build/core/client/transportRecreationState.d.ts +11 -0
  116. package/build/core/client/transportRecreationState.d.ts.map +1 -0
  117. package/build/core/client/transportRecreationState.js +2 -0
  118. package/build/core/client/transportRecreationState.js.map +1 -0
  119. package/build/core/client/transportRecreator.d.ts +2 -0
  120. package/build/core/client/transportRecreator.d.ts.map +1 -1
  121. package/build/core/client/transportRecreator.js +24 -4
  122. package/build/core/client/transportRecreator.js.map +1 -1
  123. package/build/core/loading/parallelExecutor.d.ts +5 -5
  124. package/build/core/loading/parallelExecutor.d.ts.map +1 -1
  125. package/build/core/loading/parallelExecutor.js +31 -33
  126. package/build/core/loading/parallelExecutor.js.map +1 -1
  127. package/build/core/runtime/runtimeIdentityService.d.ts +30 -0
  128. package/build/core/runtime/runtimeIdentityService.d.ts.map +1 -0
  129. package/build/core/runtime/runtimeIdentityService.js +63 -0
  130. package/build/core/runtime/runtimeIdentityService.js.map +1 -0
  131. package/build/core/server/agentConfig.d.ts +4 -0
  132. package/build/core/server/agentConfig.d.ts.map +1 -1
  133. package/build/core/server/agentConfig.js +3 -0
  134. package/build/core/server/agentConfig.js.map +1 -1
  135. package/build/core/tools/handlers/serverManagementHandler.d.ts +7 -7
  136. package/build/core/tools/internal/adapters/helpers/configTransformers.d.ts +2 -2
  137. package/build/core/tools/internal/schemas/discovery.d.ts +1 -1
  138. package/build/core/tools/internal/schemas/index.d.ts +13 -13
  139. package/build/core/tools/internal/schemas/installation.d.ts +7 -7
  140. package/build/core/tools/internal/schemas/management.d.ts +5 -5
  141. package/build/core/types/transport.d.ts +24 -3
  142. package/build/core/types/transport.d.ts.map +1 -1
  143. package/build/core/types/transport.js +7 -2
  144. package/build/core/types/transport.js.map +1 -1
  145. package/build/domains/admin/adminConfiguredServerService.d.ts +275 -0
  146. package/build/domains/admin/adminConfiguredServerService.d.ts.map +1 -0
  147. package/build/domains/admin/adminConfiguredServerService.js +1926 -0
  148. package/build/domains/admin/adminConfiguredServerService.js.map +1 -0
  149. package/build/domains/admin/adminConnectivityChecker.d.ts +7 -0
  150. package/build/domains/admin/adminConnectivityChecker.d.ts.map +1 -0
  151. package/build/domains/admin/adminConnectivityChecker.js +42 -0
  152. package/build/domains/admin/adminConnectivityChecker.js.map +1 -0
  153. package/build/domains/admin/adminDomain.d.ts +29 -0
  154. package/build/domains/admin/adminDomain.d.ts.map +1 -0
  155. package/build/domains/admin/adminDomain.js +39 -0
  156. package/build/domains/admin/adminDomain.js.map +1 -0
  157. package/build/domains/admin/adminIdentityService.d.ts +75 -0
  158. package/build/domains/admin/adminIdentityService.d.ts.map +1 -0
  159. package/build/domains/admin/adminIdentityService.js +321 -0
  160. package/build/domains/admin/adminIdentityService.js.map +1 -0
  161. package/build/domains/admin/adminOperationService.d.ts +202 -0
  162. package/build/domains/admin/adminOperationService.d.ts.map +1 -0
  163. package/build/domains/admin/adminOperationService.js +724 -0
  164. package/build/domains/admin/adminOperationService.js.map +1 -0
  165. package/build/domains/admin/adminPresetService.d.ts +140 -0
  166. package/build/domains/admin/adminPresetService.d.ts.map +1 -0
  167. package/build/domains/admin/adminPresetService.js +248 -0
  168. package/build/domains/admin/adminPresetService.js.map +1 -0
  169. package/build/domains/admin/runtimeScopeAdminLock.d.ts +22 -0
  170. package/build/domains/admin/runtimeScopeAdminLock.d.ts.map +1 -0
  171. package/build/domains/admin/runtimeScopeAdminLock.js +121 -0
  172. package/build/domains/admin/runtimeScopeAdminLock.js.map +1 -0
  173. package/build/domains/config-change/configChange.d.ts +6 -1
  174. package/build/domains/config-change/configChange.d.ts.map +1 -1
  175. package/build/domains/config-change/configChange.js +344 -0
  176. package/build/domains/config-change/configChange.js.map +1 -1
  177. package/build/domains/config-change/types.d.ts +18 -3
  178. package/build/domains/config-change/types.d.ts.map +1 -1
  179. package/build/domains/preset/manager/presetManager.d.ts +1 -0
  180. package/build/domains/preset/manager/presetManager.d.ts.map +1 -1
  181. package/build/domains/preset/manager/presetManager.js +3 -0
  182. package/build/domains/preset/manager/presetManager.js.map +1 -1
  183. package/build/domains/preset/tagAuthoring.d.ts +10 -0
  184. package/build/domains/preset/tagAuthoring.d.ts.map +1 -0
  185. package/build/domains/preset/tagAuthoring.js +94 -0
  186. package/build/domains/preset/tagAuthoring.js.map +1 -0
  187. package/build/domains/runtime-targets/runtimeIdentityVerification.d.ts +51 -0
  188. package/build/domains/runtime-targets/runtimeIdentityVerification.d.ts.map +1 -0
  189. package/build/domains/runtime-targets/runtimeIdentityVerification.js +258 -0
  190. package/build/domains/runtime-targets/runtimeIdentityVerification.js.map +1 -0
  191. package/build/domains/runtime-targets/runtimeTargetStore.d.ts +222 -0
  192. package/build/domains/runtime-targets/runtimeTargetStore.d.ts.map +1 -0
  193. package/build/domains/runtime-targets/runtimeTargetStore.js +1456 -0
  194. package/build/domains/runtime-targets/runtimeTargetStore.js.map +1 -0
  195. package/build/index.d.ts.map +1 -1
  196. package/build/index.js +7 -1
  197. package/build/index.js.map +1 -1
  198. package/build/transport/http/routes/adminRoutes.d.ts +34 -0
  199. package/build/transport/http/routes/adminRoutes.d.ts.map +1 -0
  200. package/build/transport/http/routes/adminRoutes.js +1217 -0
  201. package/build/transport/http/routes/adminRoutes.js.map +1 -0
  202. package/build/transport/http/routes/oauthRoutes.d.ts +2 -0
  203. package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
  204. package/build/transport/http/routes/oauthRoutes.js +5 -185
  205. package/build/transport/http/routes/oauthRoutes.js.map +1 -1
  206. package/build/transport/http/routes/runtimeIdentityRoutes.d.ts +7 -0
  207. package/build/transport/http/routes/runtimeIdentityRoutes.d.ts.map +1 -0
  208. package/build/transport/http/routes/runtimeIdentityRoutes.js +9 -0
  209. package/build/transport/http/routes/runtimeIdentityRoutes.js.map +1 -0
  210. package/build/transport/http/routes/toolRoutes.d.ts.map +1 -1
  211. package/build/transport/http/routes/toolRoutes.js +1 -7
  212. package/build/transport/http/routes/toolRoutes.js.map +1 -1
  213. package/build/transport/http/server.d.ts +3 -0
  214. package/build/transport/http/server.d.ts.map +1 -1
  215. package/build/transport/http/server.js +92 -3
  216. package/build/transport/http/server.js.map +1 -1
  217. package/build/transport/managedStdioStderr.d.ts +40 -0
  218. package/build/transport/managedStdioStderr.d.ts.map +1 -0
  219. package/build/transport/managedStdioStderr.js +198 -0
  220. package/build/transport/managedStdioStderr.js.map +1 -0
  221. package/build/transport/managedStdioStderrEvent.d.ts +6 -0
  222. package/build/transport/managedStdioStderrEvent.d.ts.map +1 -0
  223. package/build/transport/managedStdioStderrEvent.js +7 -0
  224. package/build/transport/managedStdioStderrEvent.js.map +1 -0
  225. package/build/transport/managedStdioStderrMetadata.d.ts +9 -0
  226. package/build/transport/managedStdioStderrMetadata.d.ts.map +1 -0
  227. package/build/transport/managedStdioStderrMetadata.js +2 -0
  228. package/build/transport/managedStdioStderrMetadata.js.map +1 -0
  229. package/build/transport/managedStdioStderrOptions.d.ts +10 -0
  230. package/build/transport/managedStdioStderrOptions.d.ts.map +1 -0
  231. package/build/transport/managedStdioStderrOptions.js +2 -0
  232. package/build/transport/managedStdioStderrOptions.js.map +1 -0
  233. package/build/transport/restartableStdioTransport.d.ts +3 -1
  234. package/build/transport/restartableStdioTransport.d.ts.map +1 -1
  235. package/build/transport/restartableStdioTransport.js +5 -1
  236. package/build/transport/restartableStdioTransport.js.map +1 -1
  237. package/build/transport/transportFactory.d.ts.map +1 -1
  238. package/build/transport/transportFactory.js +21 -3
  239. package/build/transport/transportFactory.js.map +1 -1
  240. package/build/utils/validation/urlDetection.d.ts +13 -2
  241. package/build/utils/validation/urlDetection.d.ts.map +1 -1
  242. package/build/utils/validation/urlDetection.js +37 -6
  243. package/build/utils/validation/urlDetection.js.map +1 -1
  244. package/package.json +22 -9
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>1MCP Admin Console</title>
7
+ <script type="module" crossorigin src="/admin/assets/admin-console-CkZ5lBKg.js"></script>
8
+ <link rel="stylesheet" crossorigin href="/admin/assets/admin-console-CX5GzncA.css">
9
+ </head>
10
+ <body>
11
+ <div id="admin-root"></div>
12
+ </body>
13
+ </html>
@@ -0,0 +1,90 @@
1
+ import { type ServeConfigPaths } from '../../commands/serve/runtimeScope.js';
2
+ import { type ResolvableServeTargetOptions, type ResolvedServeTarget } from '../../commands/shared/serveTargetResolver.js';
3
+ import { RuntimeIdentityService } from '../../core/runtime/runtimeIdentityService.js';
4
+ import { AdminIdentityService } from '../../domains/admin/adminIdentityService.js';
5
+ import { type RuntimeTargetListEntry } from '../../domains/runtime-targets/runtimeTargetStore.js';
6
+ import type { GlobalOptions } from '../../globalOptions.js';
7
+ interface AdminJsonOption {
8
+ json?: boolean;
9
+ }
10
+ interface AdminContextOption {
11
+ context?: string;
12
+ url?: string;
13
+ }
14
+ export interface AdminLoginOptions extends GlobalOptions, AdminJsonOption, AdminContextOption {
15
+ username?: string;
16
+ password?: string;
17
+ }
18
+ export interface AdminBootstrapOptions extends GlobalOptions, AdminJsonOption {
19
+ username?: string;
20
+ password?: string;
21
+ }
22
+ export interface AdminStatusOptions extends GlobalOptions, AdminJsonOption, AdminContextOption {
23
+ }
24
+ export interface AdminLogoutOptions extends GlobalOptions, AdminJsonOption, AdminContextOption {
25
+ forget?: boolean;
26
+ allLocal?: boolean;
27
+ 'all-local'?: boolean;
28
+ }
29
+ interface AdminSessionReference {
30
+ sessionToken: string;
31
+ csrfToken?: string;
32
+ expiresAt?: string;
33
+ }
34
+ interface AdminCredentials {
35
+ username?: string;
36
+ password?: string;
37
+ cancelled?: boolean;
38
+ }
39
+ interface AdminCredentialStore {
40
+ current(): Pick<RuntimeTargetListEntry, 'name'>;
41
+ inspect(name: string): Pick<RuntimeTargetListEntry, 'name' | 'observedIdentity'>;
42
+ setAdminSessionReference(name: string, runtimeScopeId: string, adminSession: AdminSessionReference): void;
43
+ getAdminSessionReference(name: string, runtimeScopeId: string): unknown | undefined;
44
+ clearAdminSessionReference(name: string, runtimeScopeId: string): void;
45
+ clearLocalAdminSessionReferences(): number;
46
+ }
47
+ interface AdminApiClient {
48
+ get<T>(path: string): Promise<{
49
+ ok: boolean;
50
+ status: number;
51
+ data?: T;
52
+ error?: string;
53
+ }>;
54
+ post<T>(path: string, body: unknown): Promise<{
55
+ ok: boolean;
56
+ status: number;
57
+ data?: T;
58
+ error?: string;
59
+ }>;
60
+ }
61
+ export interface AdminCommandDependencies {
62
+ store?: AdminCredentialStore;
63
+ resolveTarget?: (options: ResolvableServeTargetOptions & {
64
+ context: string;
65
+ }) => Promise<ResolvedServeTarget<ResolvableServeTargetOptions & {
66
+ context: string;
67
+ }>>;
68
+ createApiClient?: (baseUrl: string, bearerToken?: string) => AdminApiClient;
69
+ promptForCredentials?: (context: string, existing: Pick<AdminCredentials, 'username' | 'password'>) => Promise<AdminCredentials>;
70
+ }
71
+ export interface AdminBootstrapDependencies {
72
+ resolveConfigPaths?: (options: Pick<AdminBootstrapOptions, 'config' | 'config-dir'>) => ServeConfigPaths;
73
+ createRuntimeIdentityService?: (storageDir: string) => Pick<RuntimeIdentityService, 'getRuntimeIdentity'>;
74
+ createAdminIdentityService?: (options: {
75
+ runtimeScopeId: string;
76
+ storageDir: string;
77
+ }) => Pick<AdminIdentityService, 'bootstrapFirstAdmin'>;
78
+ }
79
+ export declare class AdminCommandError extends Error {
80
+ readonly code: string;
81
+ readonly recoveryCommand?: string | undefined;
82
+ readonly details?: unknown | undefined;
83
+ constructor(code: string, message: string, recoveryCommand?: string | undefined, details?: unknown | undefined);
84
+ }
85
+ export declare function adminBootstrapCommand(options: AdminBootstrapOptions, dependencies?: AdminBootstrapDependencies): Promise<void>;
86
+ export declare function adminLoginCommand(options: AdminLoginOptions, dependencies?: AdminCommandDependencies): Promise<void>;
87
+ export declare function adminStatusCommand(options: AdminStatusOptions, dependencies?: AdminCommandDependencies): Promise<void>;
88
+ export declare function adminLogoutCommand(options: AdminLogoutOptions, dependencies?: AdminCommandDependencies): Promise<void>;
89
+ export {};
90
+ //# sourceMappingURL=admin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../../src/commands/admin/admin.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,545 @@
1
+ import { resolveServeConfigPaths } from '../../commands/serve/runtimeScope.js';
2
+ import { ApiClient } from '../../commands/shared/apiClient.js';
3
+ import { resolveServeTarget, } from '../../commands/shared/serveTargetResolver.js';
4
+ import { MCP_SERVER_VERSION } from '../../constants.js';
5
+ import { RuntimeIdentityService } from '../../core/runtime/runtimeIdentityService.js';
6
+ import { AdminIdentityService } from '../../domains/admin/adminIdentityService.js';
7
+ import { RuntimeTargetStore } from '../../domains/runtime-targets/runtimeTargetStore.js';
8
+ import { stripMcpSuffix } from '../../utils/urlUtils.js';
9
+ import prompts from 'prompts';
10
+ export class AdminCommandError extends Error {
11
+ code;
12
+ recoveryCommand;
13
+ details;
14
+ constructor(code, message, recoveryCommand, details) {
15
+ super(message);
16
+ this.code = code;
17
+ this.recoveryCommand = recoveryCommand;
18
+ this.details = details;
19
+ this.name = 'AdminCommandError';
20
+ }
21
+ }
22
+ export async function adminBootstrapCommand(options, dependencies = {}) {
23
+ const username = requireOption(options.username, 'admin username');
24
+ const password = requireOption(options.password, 'admin password');
25
+ const paths = (dependencies.resolveConfigPaths ?? resolveServeConfigPaths)({
26
+ config: options.config,
27
+ 'config-dir': options['config-dir'],
28
+ });
29
+ const runtimeIdentity = getBootstrapRuntimeIdentity(paths.runtimeScope, dependencies);
30
+ const adminService = dependencies.createAdminIdentityService?.({
31
+ runtimeScopeId: runtimeIdentity.runtimeScopeId,
32
+ storageDir: paths.runtimeScope,
33
+ }) ??
34
+ new AdminIdentityService({
35
+ runtimeScopeId: runtimeIdentity.runtimeScopeId,
36
+ storageDir: paths.runtimeScope,
37
+ });
38
+ const account = await adminService.bootstrapFirstAdmin({ username, password });
39
+ writeAdminSuccess(options, {
40
+ operation: 'admin.bootstrap',
41
+ target: {
42
+ runtimeScopeId: runtimeIdentity.runtimeScopeId,
43
+ runtimeScope: paths.runtimeScope,
44
+ configFilePath: paths.configFilePath,
45
+ },
46
+ result: { account },
47
+ human: `Admin bootstrap created first Admin Account for ${account.username}.\n`,
48
+ });
49
+ }
50
+ export async function adminLoginCommand(options, dependencies = {}) {
51
+ const context = requireCredentialContext(options, dependencies, 'login');
52
+ const target = await resolveAdminTarget(context, options, dependencies);
53
+ const baseUrl = stripMcpSuffix(target.discoveredUrl);
54
+ const client = createClient(dependencies, baseUrl);
55
+ const capabilities = await fetchCapabilities(client, 'admin.login');
56
+ const runtimeScopeId = requireRuntimeScopeId(capabilities);
57
+ const { username, password } = await resolveAdminLoginCredentials(options, context, dependencies);
58
+ const loginEnvelope = await postEnvelope(client, '/admin/cli/v1/session/login', {
59
+ username,
60
+ password,
61
+ });
62
+ if (!loginEnvelope.ok) {
63
+ throw envelopeError(loginEnvelope, 'admin login failed');
64
+ }
65
+ const sessionToken = loginEnvelope.result?.sessionToken;
66
+ if (!sessionToken) {
67
+ throw new AdminCommandError('protocol_invalid_response', 'CLI Admin login response did not include a session');
68
+ }
69
+ const reference = {
70
+ sessionToken,
71
+ csrfToken: loginEnvelope.result?.csrfToken,
72
+ expiresAt: loginEnvelope.result?.expiresAt,
73
+ };
74
+ try {
75
+ (dependencies.store ?? new RuntimeTargetStore()).setAdminSessionReference(context, runtimeScopeId, reference);
76
+ }
77
+ catch (error) {
78
+ await revokeCreatedAdminSession(dependencies, baseUrl, sessionToken);
79
+ throw error;
80
+ }
81
+ const warnings = [...(loginEnvelope.warnings ?? []), ...mutationReadinessWarnings(capabilities)];
82
+ writeAdminSuccess(options, {
83
+ operation: 'admin.login',
84
+ target: targetJson(context, runtimeScopeId, baseUrl),
85
+ warnings,
86
+ result: {
87
+ authenticated: true,
88
+ account: loginEnvelope.result?.account,
89
+ expiresAt: reference.expiresAt,
90
+ },
91
+ human: `Admin login succeeded for ${context}.\n${warnings.map((warning) => `Warning: ${warning.message}\n`).join('')}`,
92
+ });
93
+ }
94
+ export async function adminStatusCommand(options, dependencies = {}) {
95
+ const context = requireCredentialContext(options, dependencies, 'status');
96
+ const store = dependencies.store ?? new RuntimeTargetStore();
97
+ const localRuntimeScopeId = observedRuntimeScopeId(store, context);
98
+ const localReference = localRuntimeScopeId ? store.getAdminSessionReference(context, localRuntimeScopeId) : undefined;
99
+ let target;
100
+ let capabilities;
101
+ let baseUrl;
102
+ try {
103
+ target = await resolveAdminTarget(context, options, dependencies);
104
+ baseUrl = stripMcpSuffix(target.discoveredUrl);
105
+ capabilities = await fetchCapabilities(createClient(dependencies, baseUrl), 'admin.status');
106
+ }
107
+ catch (error) {
108
+ if (isDisabledAdminAdapterError(error) && localRuntimeScopeId) {
109
+ store.clearAdminSessionReference(context, localRuntimeScopeId);
110
+ writeAdminSuccess(options, {
111
+ operation: 'admin.status',
112
+ target: targetJson(context, localRuntimeScopeId, undefined),
113
+ warnings: [],
114
+ result: {
115
+ authenticated: false,
116
+ status: 'unauthenticated',
117
+ localReference: { present: false, runtimeScopeId: localRuntimeScopeId },
118
+ },
119
+ human: `Admin status for ${context}: not authenticated.\n`,
120
+ });
121
+ return;
122
+ }
123
+ if (isProtocolOrCapabilityError(error)) {
124
+ throw error;
125
+ }
126
+ writeAdminSuccess(options, {
127
+ operation: 'admin.status',
128
+ target: targetJson(context, localRuntimeScopeId, undefined),
129
+ warnings: [],
130
+ result: {
131
+ authenticated: false,
132
+ status: 'unknown',
133
+ localReference: { present: localReference !== undefined, runtimeScopeId: localRuntimeScopeId },
134
+ },
135
+ human: `Admin status for ${context}: unknown (runtime could not be verified).\n`,
136
+ });
137
+ return;
138
+ }
139
+ const runtimeScopeId = requireRuntimeScopeId(capabilities);
140
+ const rawReference = store.getAdminSessionReference(context, runtimeScopeId);
141
+ const reference = toAdminSessionReference(rawReference);
142
+ if (!reference?.sessionToken) {
143
+ if (rawReference !== undefined) {
144
+ store.clearAdminSessionReference(context, runtimeScopeId);
145
+ }
146
+ writeAdminSuccess(options, {
147
+ operation: 'admin.status',
148
+ target: targetJson(context, runtimeScopeId, baseUrl),
149
+ warnings: [],
150
+ result: {
151
+ authenticated: false,
152
+ status: 'unauthenticated',
153
+ localReference: { present: false, runtimeScopeId },
154
+ },
155
+ human: `Admin status for ${context}: not logged in.\n`,
156
+ });
157
+ return;
158
+ }
159
+ const client = createClient(dependencies, baseUrl, reference.sessionToken);
160
+ let statusEnvelope;
161
+ try {
162
+ statusEnvelope = await getEnvelope(client, '/admin/cli/v1/session/status');
163
+ }
164
+ catch {
165
+ writeAdminSuccess(options, {
166
+ operation: 'admin.status',
167
+ target: targetJson(context, runtimeScopeId, baseUrl),
168
+ warnings: [],
169
+ result: {
170
+ authenticated: false,
171
+ status: 'unknown',
172
+ localReference: { present: true, runtimeScopeId },
173
+ },
174
+ human: `Admin status for ${context}: unknown (runtime could not be verified).\n`,
175
+ });
176
+ return;
177
+ }
178
+ if (statusEnvelope.ok && statusEnvelope.result?.authenticated) {
179
+ writeAdminSuccess(options, {
180
+ operation: 'admin.status',
181
+ target: targetJson(context, runtimeScopeId, baseUrl),
182
+ warnings: statusEnvelope.warnings,
183
+ result: {
184
+ authenticated: true,
185
+ status: 'authenticated',
186
+ account: statusEnvelope.result.account,
187
+ localReference: { present: true, runtimeScopeId },
188
+ },
189
+ human: `Admin status for ${context}: authenticated.\n`,
190
+ });
191
+ return;
192
+ }
193
+ if (!statusEnvelope.ok && !shouldClearAdminSessionReference(statusEnvelope.error?.code)) {
194
+ const error = envelopeError(statusEnvelope, 'admin status failed');
195
+ if (isProtocolOrCapabilityError(error)) {
196
+ throw error;
197
+ }
198
+ writeAdminSuccess(options, {
199
+ operation: 'admin.status',
200
+ target: targetJson(context, runtimeScopeId, baseUrl),
201
+ warnings: statusEnvelope.warnings,
202
+ result: {
203
+ authenticated: false,
204
+ status: 'unknown',
205
+ localReference: { present: true, runtimeScopeId },
206
+ },
207
+ human: `Admin status for ${context}: unknown (runtime could not be verified).\n`,
208
+ });
209
+ return;
210
+ }
211
+ store.clearAdminSessionReference(context, runtimeScopeId);
212
+ writeAdminSuccess(options, {
213
+ operation: 'admin.status',
214
+ target: targetJson(context, runtimeScopeId, baseUrl),
215
+ warnings: statusEnvelope.warnings,
216
+ result: {
217
+ authenticated: false,
218
+ status: 'unauthenticated',
219
+ localReference: { present: false, runtimeScopeId },
220
+ },
221
+ human: `Admin status for ${context}: not authenticated.\n`,
222
+ });
223
+ }
224
+ export async function adminLogoutCommand(options, dependencies = {}) {
225
+ const context = requireCredentialContext(options, dependencies, 'logout');
226
+ const store = dependencies.store ?? new RuntimeTargetStore();
227
+ if (options.allLocal || options['all-local']) {
228
+ if (context !== 'local') {
229
+ throw new AdminCommandError('credential_all_local_context_required', 'admin logout --all-local can only be used with --context local', '1mcp admin logout --context local --all-local');
230
+ }
231
+ const cleared = store.clearLocalAdminSessionReferences();
232
+ writeAdminSuccess(options, {
233
+ operation: 'admin.logout',
234
+ target: targetJson(context, undefined, undefined),
235
+ warnings: [],
236
+ result: {
237
+ revoked: false,
238
+ forgotLocalReferences: cleared,
239
+ },
240
+ human: cleared === 0
241
+ ? 'No local Admin Session references were found; server-side revocation was not confirmed.\n'
242
+ : `Forgot ${cleared} local Admin Session reference${cleared !== 1 ? 's' : ''}; server-side revocation was not confirmed.\n`,
243
+ });
244
+ return;
245
+ }
246
+ if (options.forget) {
247
+ const runtimeScopeId = observedRuntimeScopeId(store, context);
248
+ if (!runtimeScopeId) {
249
+ throw new AdminCommandError('protocol_invalid_response', 'Cannot forget Admin Session without observed runtime identity');
250
+ }
251
+ store.clearAdminSessionReference(context, runtimeScopeId);
252
+ writeAdminSuccess(options, {
253
+ operation: 'admin.logout',
254
+ target: targetJson(context, runtimeScopeId, undefined),
255
+ warnings: [],
256
+ result: {
257
+ revoked: false,
258
+ forgotLocalReference: true,
259
+ },
260
+ human: `Forgot local Admin Session reference for ${context}; server-side revocation was not confirmed.\n`,
261
+ });
262
+ return;
263
+ }
264
+ const localRuntimeScopeId = observedRuntimeScopeId(store, context);
265
+ const target = await resolveAdminTarget(context, options, dependencies);
266
+ const baseUrl = stripMcpSuffix(target.discoveredUrl);
267
+ let capabilities;
268
+ try {
269
+ capabilities = await fetchCapabilities(createClient(dependencies, baseUrl), 'admin.logout');
270
+ }
271
+ catch (error) {
272
+ if (isDisabledAdminAdapterError(error) && localRuntimeScopeId) {
273
+ store.clearAdminSessionReference(context, localRuntimeScopeId);
274
+ writeAdminSuccess(options, {
275
+ operation: 'admin.logout',
276
+ target: targetJson(context, localRuntimeScopeId, baseUrl),
277
+ warnings: [],
278
+ result: {
279
+ revoked: false,
280
+ forgotLocalReference: true,
281
+ },
282
+ human: `Forgot local Admin Session reference for ${context}; server-side revocation was not confirmed.\n`,
283
+ });
284
+ return;
285
+ }
286
+ throw error;
287
+ }
288
+ const runtimeScopeId = requireRuntimeScopeId(capabilities);
289
+ const reference = toAdminSessionReference(store.getAdminSessionReference(context, runtimeScopeId));
290
+ if (reference?.sessionToken) {
291
+ const client = createClient(dependencies, baseUrl, reference.sessionToken);
292
+ const logoutEnvelope = await postEnvelope(client, '/admin/cli/v1/session/logout', {});
293
+ if (!logoutEnvelope.ok) {
294
+ throw envelopeError(logoutEnvelope, 'admin logout failed');
295
+ }
296
+ }
297
+ store.clearAdminSessionReference(context, runtimeScopeId);
298
+ writeAdminSuccess(options, {
299
+ operation: 'admin.logout',
300
+ target: targetJson(context, runtimeScopeId, baseUrl),
301
+ warnings: [],
302
+ result: {
303
+ revoked: Boolean(reference?.sessionToken),
304
+ forgotLocalReference: true,
305
+ },
306
+ human: `Admin logout completed for ${context}.\n`,
307
+ });
308
+ }
309
+ function getBootstrapRuntimeIdentity(runtimeScope, dependencies) {
310
+ const runtimeIdentityService = dependencies.createRuntimeIdentityService?.(runtimeScope) ??
311
+ new RuntimeIdentityService({ storageDir: runtimeScope });
312
+ return runtimeIdentityService.getRuntimeIdentity({
313
+ externalUrl: 'http://127.0.0.1',
314
+ runtimeVersion: MCP_SERVER_VERSION,
315
+ includeServerTime: false,
316
+ });
317
+ }
318
+ function requireCredentialContext(options, dependencies, command) {
319
+ if (options.url) {
320
+ throw new AdminCommandError('credential_url_unsupported', 'Admin credential commands require a named Runtime Target Context and do not accept --url');
321
+ }
322
+ if (options.context) {
323
+ return options.context;
324
+ }
325
+ const currentName = safeCurrentName(dependencies.store);
326
+ throw new AdminCommandError('credential_context_required', 'Admin credential commands require --context <name>', currentName ? `1mcp admin ${command} --context ${currentName}` : `1mcp admin ${command} --context <name>`);
327
+ }
328
+ function safeCurrentName(store) {
329
+ try {
330
+ return (store ?? new RuntimeTargetStore()).current().name;
331
+ }
332
+ catch {
333
+ return undefined;
334
+ }
335
+ }
336
+ async function resolveAdminTarget(context, options, dependencies) {
337
+ const resolver = dependencies.resolveTarget ?? ((input) => resolveServeTarget(input));
338
+ return resolver({ context, 'config-dir': options['config-dir'] });
339
+ }
340
+ function createClient(dependencies, baseUrl, bearerToken) {
341
+ return dependencies.createApiClient?.(baseUrl, bearerToken) ?? new ApiClient({ baseUrl, bearerToken });
342
+ }
343
+ async function fetchCapabilities(client, requiredOperation) {
344
+ const envelope = await getEnvelope(client, '/admin/cli/v1/capabilities');
345
+ if (!envelope.ok) {
346
+ throw envelopeError(envelope, 'CLI Admin capabilities check failed');
347
+ }
348
+ if (envelope.cliProtocolVersion !== '1') {
349
+ throw new AdminCommandError('protocol_incompatible', 'CLI Admin protocol is not compatible');
350
+ }
351
+ if (!envelope.result) {
352
+ throw new AdminCommandError('protocol_invalid_response', 'CLI Admin capabilities omitted result');
353
+ }
354
+ requireAdminCapability(envelope.result, requiredOperation);
355
+ return envelope.result;
356
+ }
357
+ async function getEnvelope(client, path) {
358
+ const response = await client.get(path);
359
+ if (response.data) {
360
+ return response.data;
361
+ }
362
+ if (!response.ok) {
363
+ if (response.status === 404) {
364
+ throw new AdminCommandError('capability_admin_disabled', 'CLI Admin adapter is not enabled on this runtime');
365
+ }
366
+ throw new AdminCommandError('runtime_unreachable', response.error ?? `Runtime returned HTTP ${response.status}`);
367
+ }
368
+ throw new AdminCommandError('protocol_invalid_response', 'Runtime returned an empty CLI Admin response');
369
+ }
370
+ async function postEnvelope(client, path, body) {
371
+ const response = await client.post(path, body);
372
+ if (response.data) {
373
+ return response.data;
374
+ }
375
+ if (!response.ok) {
376
+ if (response.status === 404) {
377
+ throw new AdminCommandError('capability_admin_disabled', 'CLI Admin adapter is not enabled on this runtime');
378
+ }
379
+ throw new AdminCommandError('runtime_unreachable', response.error ?? `Runtime returned HTTP ${response.status}`);
380
+ }
381
+ throw new AdminCommandError('protocol_invalid_response', 'Runtime returned an empty CLI Admin response');
382
+ }
383
+ async function revokeCreatedAdminSession(dependencies, baseUrl, sessionToken) {
384
+ try {
385
+ await postEnvelope(createClient(dependencies, baseUrl, sessionToken), '/admin/cli/v1/session/logout', {});
386
+ }
387
+ catch {
388
+ // The original local persistence failure is more actionable for the operator.
389
+ }
390
+ }
391
+ function envelopeError(envelope, fallbackMessage) {
392
+ return new AdminCommandError(envelope.error?.code ?? 'internal_error', envelope.error?.message ?? fallbackMessage, envelope.error?.recoveryCommand, envelope.error?.details);
393
+ }
394
+ function requireRuntimeScopeId(capabilities) {
395
+ const runtimeScopeId = (capabilities.runtime ?? capabilities.runtimeIdentity)?.runtimeScopeId;
396
+ if (!runtimeScopeId) {
397
+ throw new AdminCommandError('protocol_invalid_response', 'CLI Admin capabilities omitted runtime identity');
398
+ }
399
+ return runtimeScopeId;
400
+ }
401
+ function requireAdminCapability(capabilities, requiredOperation) {
402
+ if (capabilities.adminSurface?.enabled === false) {
403
+ throw new AdminCommandError('capability_admin_disabled', 'CLI Admin adapter is disabled on this runtime');
404
+ }
405
+ if (requiredOperation === 'admin.login' && capabilities.adminSurface?.status === 'setupRequired') {
406
+ throw new AdminCommandError('capability_admin_setup_required', 'Admin setup is required before CLI Admin login can run');
407
+ }
408
+ if (!capabilities.supportedOperations?.includes(requiredOperation)) {
409
+ throw new AdminCommandError('capability_operation_unsupported', `CLI Admin operation "${requiredOperation}" is not supported by this runtime`);
410
+ }
411
+ }
412
+ function mutationReadinessWarnings(capabilities) {
413
+ if (capabilities.adminMutationsAvailable !== false) {
414
+ return [];
415
+ }
416
+ return [
417
+ {
418
+ code: 'warning_admin_mutations_unavailable',
419
+ message: 'Admin login succeeded, but mutation commands are currently unavailable',
420
+ details: {
421
+ reason: capabilities.adminMutationsUnavailableReason ?? 'unavailable',
422
+ },
423
+ },
424
+ ];
425
+ }
426
+ function isDisabledAdminAdapterError(error) {
427
+ return error instanceof AdminCommandError && error.code === 'capability_admin_disabled';
428
+ }
429
+ function isProtocolOrCapabilityError(error) {
430
+ return (error instanceof AdminCommandError && (error.code.startsWith('protocol_') || error.code.startsWith('capability_')));
431
+ }
432
+ function shouldClearAdminSessionReference(code) {
433
+ return (code === undefined ||
434
+ code.startsWith('auth_session_') ||
435
+ code === 'auth_admin_disabled' ||
436
+ code === 'auth_account_deleted' ||
437
+ code === 'admin_account_not_found' ||
438
+ code === 'capability_admin_disabled');
439
+ }
440
+ function requireOption(value, label) {
441
+ if (!value) {
442
+ throw new AdminCommandError('validation_missing_input', `Missing ${label}`);
443
+ }
444
+ return value;
445
+ }
446
+ async function resolveAdminLoginCredentials(options, context, dependencies) {
447
+ if (options.username && options.password) {
448
+ return {
449
+ username: options.username,
450
+ password: options.password,
451
+ };
452
+ }
453
+ if (options.json || (!dependencies.promptForCredentials && !process.stdin.isTTY)) {
454
+ return {
455
+ username: requireOption(options.username, 'admin username'),
456
+ password: requireOption(options.password, 'admin password'),
457
+ };
458
+ }
459
+ const prompted = await promptForCredentials(context, options, dependencies);
460
+ if (prompted.cancelled) {
461
+ throw new AdminCommandError('validation_missing_input', 'Missing admin credentials');
462
+ }
463
+ return {
464
+ username: requireOption(prompted.username, 'admin username'),
465
+ password: requireOption(prompted.password, 'admin password'),
466
+ };
467
+ }
468
+ async function promptForCredentials(context, options, dependencies) {
469
+ const existing = {
470
+ username: options.username,
471
+ password: options.password,
472
+ };
473
+ if (dependencies.promptForCredentials) {
474
+ return dependencies.promptForCredentials(context, existing);
475
+ }
476
+ const questions = [];
477
+ if (!options.username) {
478
+ questions.push({
479
+ type: 'text',
480
+ name: 'username',
481
+ message: `Admin username for ${context}`,
482
+ });
483
+ }
484
+ if (!options.password) {
485
+ questions.push({
486
+ type: 'password',
487
+ name: 'password',
488
+ message: `Admin password for ${context}`,
489
+ });
490
+ }
491
+ const result = await prompts(questions);
492
+ return {
493
+ username: options.username ?? (typeof result.username === 'string' ? result.username : undefined),
494
+ password: options.password ?? (typeof result.password === 'string' ? result.password : undefined),
495
+ cancelled: (!options.username && result.username === undefined) || (!options.password && result.password === undefined),
496
+ };
497
+ }
498
+ function observedRuntimeScopeId(store, context) {
499
+ try {
500
+ return store.inspect(context).observedIdentity?.runtimeScopeId;
501
+ }
502
+ catch {
503
+ return undefined;
504
+ }
505
+ }
506
+ function toAdminSessionReference(value) {
507
+ if (typeof value !== 'object' || value === null) {
508
+ return undefined;
509
+ }
510
+ const candidate = value;
511
+ if (typeof candidate.sessionToken !== 'string' || candidate.sessionToken.length === 0) {
512
+ return undefined;
513
+ }
514
+ return {
515
+ sessionToken: candidate.sessionToken,
516
+ ...(typeof candidate.csrfToken === 'string' ? { csrfToken: candidate.csrfToken } : {}),
517
+ ...(typeof candidate.expiresAt === 'string' ? { expiresAt: candidate.expiresAt } : {}),
518
+ };
519
+ }
520
+ function writeAdminSuccess(options, input) {
521
+ if (!options.json) {
522
+ process.stdout.write(input.human);
523
+ return;
524
+ }
525
+ process.stdout.write(`${JSON.stringify({
526
+ ok: true,
527
+ cliProtocolVersion: '1',
528
+ requestId: createCliRequestId(),
529
+ target: input.target,
530
+ operation: input.operation,
531
+ warnings: input.warnings ?? [],
532
+ result: input.result,
533
+ })}\n`);
534
+ }
535
+ function targetJson(context, runtimeScopeId, baseUrl) {
536
+ return {
537
+ context,
538
+ ...(runtimeScopeId ? { runtimeScopeId } : {}),
539
+ ...(baseUrl ? { url: baseUrl } : {}),
540
+ };
541
+ }
542
+ function createCliRequestId() {
543
+ return `cli_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
544
+ }
545
+ //# sourceMappingURL=admin.js.map