@openziti/ziti-mcp-server 0.1.0

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 (210) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +868 -0
  3. package/dist/auth/client-credentials-flow.d.ts +21 -0
  4. package/dist/auth/client-credentials-flow.js +63 -0
  5. package/dist/auth/client-credentials-flow.js.map +1 -0
  6. package/dist/auth/device-auth-flow.d.ts +47 -0
  7. package/dist/auth/device-auth-flow.js +291 -0
  8. package/dist/auth/device-auth-flow.js.map +1 -0
  9. package/dist/clients/base.d.ts +74 -0
  10. package/dist/clients/base.js +109 -0
  11. package/dist/clients/base.js.map +1 -0
  12. package/dist/clients/claude.d.ts +22 -0
  13. package/dist/clients/claude.js +40 -0
  14. package/dist/clients/claude.js.map +1 -0
  15. package/dist/clients/cursor.d.ts +22 -0
  16. package/dist/clients/cursor.js +39 -0
  17. package/dist/clients/cursor.js.map +1 -0
  18. package/dist/clients/index.d.ts +33 -0
  19. package/dist/clients/index.js +39 -0
  20. package/dist/clients/index.js.map +1 -0
  21. package/dist/clients/types.d.ts +70 -0
  22. package/dist/clients/types.js +2 -0
  23. package/dist/clients/types.js.map +1 -0
  24. package/dist/clients/utils.d.ts +22 -0
  25. package/dist/clients/utils.js +46 -0
  26. package/dist/clients/utils.js.map +1 -0
  27. package/dist/clients/vscode.d.ts +76 -0
  28. package/dist/clients/vscode.js +159 -0
  29. package/dist/clients/vscode.js.map +1 -0
  30. package/dist/clients/windsurf.d.ts +22 -0
  31. package/dist/clients/windsurf.js +39 -0
  32. package/dist/clients/windsurf.js.map +1 -0
  33. package/dist/commands/init.d.ts +45 -0
  34. package/dist/commands/init.js +133 -0
  35. package/dist/commands/init.js.map +1 -0
  36. package/dist/commands/logout.d.ts +12 -0
  37. package/dist/commands/logout.js +90 -0
  38. package/dist/commands/logout.js.map +1 -0
  39. package/dist/commands/run.d.ts +15 -0
  40. package/dist/commands/run.js +94 -0
  41. package/dist/commands/run.js.map +1 -0
  42. package/dist/commands/session.d.ts +12 -0
  43. package/dist/commands/session.js +99 -0
  44. package/dist/commands/session.js.map +1 -0
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.js +105 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/server.d.ts +67 -0
  49. package/dist/server.js +171 -0
  50. package/dist/server.js.map +1 -0
  51. package/dist/tools/api-sessions.d.ts +3 -0
  52. package/dist/tools/api-sessions.js +86 -0
  53. package/dist/tools/api-sessions.js.map +1 -0
  54. package/dist/tools/auth-policies.d.ts +3 -0
  55. package/dist/tools/auth-policies.js +347 -0
  56. package/dist/tools/auth-policies.js.map +1 -0
  57. package/dist/tools/authenticators.d.ts +3 -0
  58. package/dist/tools/authenticators.js +183 -0
  59. package/dist/tools/authenticators.js.map +1 -0
  60. package/dist/tools/certificate-authorities.d.ts +3 -0
  61. package/dist/tools/certificate-authorities.js +288 -0
  62. package/dist/tools/certificate-authorities.js.map +1 -0
  63. package/dist/tools/config-types.d.ts +3 -0
  64. package/dist/tools/config-types.js +194 -0
  65. package/dist/tools/config-types.js.map +1 -0
  66. package/dist/tools/configs.d.ts +3 -0
  67. package/dist/tools/configs.js +203 -0
  68. package/dist/tools/configs.js.map +1 -0
  69. package/dist/tools/controller-settings.d.ts +3 -0
  70. package/dist/tools/controller-settings.js +219 -0
  71. package/dist/tools/controller-settings.js.map +1 -0
  72. package/dist/tools/controllers.d.ts +3 -0
  73. package/dist/tools/controllers.js +89 -0
  74. package/dist/tools/controllers.js.map +1 -0
  75. package/dist/tools/edge-router-policies.d.ts +3 -0
  76. package/dist/tools/edge-router-policies.js +262 -0
  77. package/dist/tools/edge-router-policies.js.map +1 -0
  78. package/dist/tools/edge-routers.d.ts +3 -0
  79. package/dist/tools/edge-routers.js +381 -0
  80. package/dist/tools/edge-routers.js.map +1 -0
  81. package/dist/tools/enrollments.d.ts +3 -0
  82. package/dist/tools/enrollments.js +187 -0
  83. package/dist/tools/enrollments.js.map +1 -0
  84. package/dist/tools/external-jwt-signers.d.ts +3 -0
  85. package/dist/tools/external-jwt-signers.js +242 -0
  86. package/dist/tools/external-jwt-signers.js.map +1 -0
  87. package/dist/tools/identities.d.ts +3 -0
  88. package/dist/tools/identities.js +741 -0
  89. package/dist/tools/identities.js.map +1 -0
  90. package/dist/tools/identity-types.d.ts +3 -0
  91. package/dist/tools/identity-types.js +58 -0
  92. package/dist/tools/identity-types.js.map +1 -0
  93. package/dist/tools/index.d.ts +3 -0
  94. package/dist/tools/index.js +101 -0
  95. package/dist/tools/index.js.map +1 -0
  96. package/dist/tools/posture-checks.d.ts +3 -0
  97. package/dist/tools/posture-checks.js +254 -0
  98. package/dist/tools/posture-checks.js.map +1 -0
  99. package/dist/tools/routers.d.ts +3 -0
  100. package/dist/tools/routers.js +169 -0
  101. package/dist/tools/routers.js.map +1 -0
  102. package/dist/tools/service-edge-router-policies.d.ts +3 -0
  103. package/dist/tools/service-edge-router-policies.js +282 -0
  104. package/dist/tools/service-edge-router-policies.js.map +1 -0
  105. package/dist/tools/service-policies.d.ts +3 -0
  106. package/dist/tools/service-policies.js +311 -0
  107. package/dist/tools/service-policies.js.map +1 -0
  108. package/dist/tools/services.d.ts +3 -0
  109. package/dist/tools/services.js +403 -0
  110. package/dist/tools/services.js.map +1 -0
  111. package/dist/tools/sessions.d.ts +3 -0
  112. package/dist/tools/sessions.js +86 -0
  113. package/dist/tools/sessions.js.map +1 -0
  114. package/dist/tools/terminators.d.ts +3 -0
  115. package/dist/tools/terminators.js +187 -0
  116. package/dist/tools/terminators.js.map +1 -0
  117. package/dist/tools/transit-routers.d.ts +3 -0
  118. package/dist/tools/transit-routers.js +169 -0
  119. package/dist/tools/transit-routers.js.map +1 -0
  120. package/dist/utils/analytics.d.ts +75 -0
  121. package/dist/utils/analytics.js +191 -0
  122. package/dist/utils/analytics.js.map +1 -0
  123. package/dist/utils/auth0-client.d.ts +27 -0
  124. package/dist/utils/auth0-client.js +67 -0
  125. package/dist/utils/auth0-client.js.map +1 -0
  126. package/dist/utils/authenticated-client.d.ts +6 -0
  127. package/dist/utils/authenticated-client.js +55 -0
  128. package/dist/utils/authenticated-client.js.map +1 -0
  129. package/dist/utils/config.d.ts +65 -0
  130. package/dist/utils/config.js +80 -0
  131. package/dist/utils/config.js.map +1 -0
  132. package/dist/utils/constants.d.ts +15 -0
  133. package/dist/utils/constants.js +17 -0
  134. package/dist/utils/constants.js.map +1 -0
  135. package/dist/utils/controller-client/client/client.gen.d.ts +2 -0
  136. package/dist/utils/controller-client/client/client.gen.js +229 -0
  137. package/dist/utils/controller-client/client/client.gen.js.map +1 -0
  138. package/dist/utils/controller-client/client/index.d.ts +8 -0
  139. package/dist/utils/controller-client/client/index.js +7 -0
  140. package/dist/utils/controller-client/client/index.js.map +1 -0
  141. package/dist/utils/controller-client/client/types.gen.d.ts +117 -0
  142. package/dist/utils/controller-client/client/types.gen.js +3 -0
  143. package/dist/utils/controller-client/client/types.gen.js.map +1 -0
  144. package/dist/utils/controller-client/client/utils.gen.d.ts +33 -0
  145. package/dist/utils/controller-client/client/utils.gen.js +232 -0
  146. package/dist/utils/controller-client/client/utils.gen.js.map +1 -0
  147. package/dist/utils/controller-client/client.gen.d.ts +12 -0
  148. package/dist/utils/controller-client/client.gen.js +6 -0
  149. package/dist/utils/controller-client/client.gen.js.map +1 -0
  150. package/dist/utils/controller-client/core/auth.gen.d.ts +18 -0
  151. package/dist/utils/controller-client/core/auth.gen.js +15 -0
  152. package/dist/utils/controller-client/core/auth.gen.js.map +1 -0
  153. package/dist/utils/controller-client/core/bodySerializer.gen.d.ts +25 -0
  154. package/dist/utils/controller-client/core/bodySerializer.gen.js +58 -0
  155. package/dist/utils/controller-client/core/bodySerializer.gen.js.map +1 -0
  156. package/dist/utils/controller-client/core/params.gen.d.ts +43 -0
  157. package/dist/utils/controller-client/core/params.gen.js +101 -0
  158. package/dist/utils/controller-client/core/params.gen.js.map +1 -0
  159. package/dist/utils/controller-client/core/pathSerializer.gen.d.ts +33 -0
  160. package/dist/utils/controller-client/core/pathSerializer.gen.js +115 -0
  161. package/dist/utils/controller-client/core/pathSerializer.gen.js.map +1 -0
  162. package/dist/utils/controller-client/core/queryKeySerializer.gen.d.ts +18 -0
  163. package/dist/utils/controller-client/core/queryKeySerializer.gen.js +100 -0
  164. package/dist/utils/controller-client/core/queryKeySerializer.gen.js.map +1 -0
  165. package/dist/utils/controller-client/core/serverSentEvents.gen.d.ts +71 -0
  166. package/dist/utils/controller-client/core/serverSentEvents.gen.js +136 -0
  167. package/dist/utils/controller-client/core/serverSentEvents.gen.js.map +1 -0
  168. package/dist/utils/controller-client/core/types.gen.d.ts +78 -0
  169. package/dist/utils/controller-client/core/types.gen.js +3 -0
  170. package/dist/utils/controller-client/core/types.gen.js.map +1 -0
  171. package/dist/utils/controller-client/core/utils.gen.d.ts +19 -0
  172. package/dist/utils/controller-client/core/utils.gen.js +88 -0
  173. package/dist/utils/controller-client/core/utils.gen.js.map +1 -0
  174. package/dist/utils/controller-client/index.d.ts +2 -0
  175. package/dist/utils/controller-client/index.js +3 -0
  176. package/dist/utils/controller-client/index.js.map +1 -0
  177. package/dist/utils/controller-client/sdk.gen.d.ts +1302 -0
  178. package/dist/utils/controller-client/sdk.gen.js +4436 -0
  179. package/dist/utils/controller-client/sdk.gen.js.map +1 -0
  180. package/dist/utils/controller-client/types.gen.d.ts +9170 -0
  181. package/dist/utils/controller-client/types.gen.js +3 -0
  182. package/dist/utils/controller-client/types.gen.js.map +1 -0
  183. package/dist/utils/glob.d.ts +75 -0
  184. package/dist/utils/glob.js +110 -0
  185. package/dist/utils/glob.js.map +1 -0
  186. package/dist/utils/http-utility.d.ts +5 -0
  187. package/dist/utils/http-utility.js +68 -0
  188. package/dist/utils/http-utility.js.map +1 -0
  189. package/dist/utils/keychain.d.ts +129 -0
  190. package/dist/utils/keychain.js +193 -0
  191. package/dist/utils/keychain.js.map +1 -0
  192. package/dist/utils/logger.d.ts +4 -0
  193. package/dist/utils/logger.js +28 -0
  194. package/dist/utils/logger.js.map +1 -0
  195. package/dist/utils/package.d.ts +3 -0
  196. package/dist/utils/package.js +9 -0
  197. package/dist/utils/package.js.map +1 -0
  198. package/dist/utils/scopes.d.ts +12 -0
  199. package/dist/utils/scopes.js +19 -0
  200. package/dist/utils/scopes.js.map +1 -0
  201. package/dist/utils/terminal.d.ts +35 -0
  202. package/dist/utils/terminal.js +409 -0
  203. package/dist/utils/terminal.js.map +1 -0
  204. package/dist/utils/tools.d.ts +63 -0
  205. package/dist/utils/tools.js +149 -0
  206. package/dist/utils/tools.js.map +1 -0
  207. package/dist/utils/types.d.ts +55 -0
  208. package/dist/utils/types.js +3 -0
  209. package/dist/utils/types.js.map +1 -0
  210. package/package.json +89 -0
@@ -0,0 +1,45 @@
1
+ import type { ClientType } from '../clients/types.js';
2
+ /**
3
+ * Command options for the init command
4
+ */
5
+ export interface InitOptions {
6
+ client: ClientType;
7
+ scopes?: string[];
8
+ tools: string[];
9
+ readOnly?: boolean;
10
+ zitiControllerHost?: string;
11
+ idpDomain?: string;
12
+ idpClientId?: string;
13
+ idpClientSecret?: string;
14
+ }
15
+ /**
16
+ * Initializes the OpenZiti MCP server with the specified client, tools and scopes.
17
+ *
18
+ * This function orchestrates the complete initialization process by:
19
+ * 1. Resolving and validating requested scopes
20
+ * 2. Obtaining authorization through the device flow
21
+ * 3. Configuring the selected client (Claude, Windsurf, Cursor, or VS Code)
22
+ *
23
+ * @param {InitOptions} options - Configuration options including:
24
+ * - client: The target client type to configure ('claude', 'windsurf', or 'cursor')
25
+ * - scopes: Optional scope patterns for authorization (will prompt if omitted)
26
+ * - tools: Tool patterns to enable (e.g., ['ziti_list_*'])
27
+ *
28
+ * @returns {Promise<void>} A promise that resolves when initialization is complete
29
+ *
30
+ * @throws {Error} If authorization fails or client configuration encounters an error
31
+ *
32
+ * @example
33
+ * // Initialize with Claude client and all tools
34
+ * await init({ client: 'claude', tools: ['*'] });
35
+ *
36
+ * @example
37
+ * // Initialize with Windsurf client and specific tools
38
+ * await init({
39
+ * client: 'windsurf',
40
+ * tools: ['ziti_list_*', 'list_get_*'],
41
+ * scopes: ['read:*']
42
+ * });
43
+ */
44
+ declare const init: (options: InitOptions) => Promise<void>;
45
+ export default init;
@@ -0,0 +1,133 @@
1
+ import { clients } from '../clients/index.js';
2
+ import { log, logError } from '../utils/logger.js';
3
+ import { requestAuthorization } from '../auth/device-auth-flow.js';
4
+ import { requestClientCredentialsAuthorization } from '../auth/client-credentials-flow.js';
5
+ import { promptForScopeSelection } from '../utils/terminal.js';
6
+ import { getAllScopes } from '../utils/scopes.js';
7
+ import { Glob } from '../utils/glob.js';
8
+ import chalk from 'chalk';
9
+ import trackEvent from '../utils/analytics.js';
10
+ /**
11
+ * Resolves scope patterns to actual scope values
12
+ *
13
+ * @param {string[] | undefined} scopePatterns - Scope patterns from command line
14
+ * @returns {Promise<string[]>} - The selected scopes
15
+ */
16
+ async function resolveScopes(scopePatterns) {
17
+ // If no scopes provided, prompt user for selection
18
+ if (!scopePatterns?.length) {
19
+ return promptForScopeSelection();
20
+ }
21
+ const allAvailableScopes = getAllScopes();
22
+ const matchedScopes = new Set();
23
+ const invalidScopes = new Set();
24
+ // Match patterns against available scopes
25
+ for (const pattern of scopePatterns) {
26
+ let foundMatch = false;
27
+ const glob = new Glob(pattern);
28
+ for (const scope of allAvailableScopes) {
29
+ if (glob.matches(scope)) {
30
+ matchedScopes.add(scope);
31
+ foundMatch = true;
32
+ }
33
+ }
34
+ // Track non-wildcard patterns that didn't match anything
35
+ if (!glob.hasWildcards() && !foundMatch) {
36
+ invalidScopes.add(pattern);
37
+ }
38
+ }
39
+ // Handle invalid scopes
40
+ if (invalidScopes.size > 0) {
41
+ const errorMessage = `Error: The following scopes are not valid: ${Array.from(invalidScopes).join(', ')}`;
42
+ logError(errorMessage);
43
+ logError(chalk.yellow(`Valid scopes are: ${allAvailableScopes.join(', ')}`));
44
+ process.exit(1);
45
+ }
46
+ // Handle matched scopes
47
+ const matchedScopesArray = Array.from(matchedScopes);
48
+ if (matchedScopesArray.length === 0) {
49
+ log(chalk.yellow('No scopes matched the provided patterns, proceeding to scope selection.'));
50
+ return promptForScopeSelection();
51
+ }
52
+ return promptForScopeSelection(matchedScopesArray);
53
+ }
54
+ /**
55
+ * Configures the specified client with options
56
+ *
57
+ * @param {ClientType} clientType - Type of the client to configure
58
+ * @param {InitOptions} options - Configuration options
59
+ */
60
+ async function configureClient(clientType, options) {
61
+ const manager = clients[clientType];
62
+ if (!manager) {
63
+ logError(`Invalid client type specified: ${clientType}`);
64
+ logError(`Available clients are: ${Object.keys(clients).join(', ')}`);
65
+ process.exit(1);
66
+ }
67
+ log(`Configuring ${manager.displayName} as client...`);
68
+ const clientOptions = {
69
+ tools: options.tools,
70
+ readOnly: options.readOnly,
71
+ };
72
+ await manager.configure(clientOptions);
73
+ }
74
+ /**
75
+ * Initializes the OpenZiti MCP server with the specified client, tools and scopes.
76
+ *
77
+ * This function orchestrates the complete initialization process by:
78
+ * 1. Resolving and validating requested scopes
79
+ * 2. Obtaining authorization through the device flow
80
+ * 3. Configuring the selected client (Claude, Windsurf, Cursor, or VS Code)
81
+ *
82
+ * @param {InitOptions} options - Configuration options including:
83
+ * - client: The target client type to configure ('claude', 'windsurf', or 'cursor')
84
+ * - scopes: Optional scope patterns for authorization (will prompt if omitted)
85
+ * - tools: Tool patterns to enable (e.g., ['ziti_list_*'])
86
+ *
87
+ * @returns {Promise<void>} A promise that resolves when initialization is complete
88
+ *
89
+ * @throws {Error} If authorization fails or client configuration encounters an error
90
+ *
91
+ * @example
92
+ * // Initialize with Claude client and all tools
93
+ * await init({ client: 'claude', tools: ['*'] });
94
+ *
95
+ * @example
96
+ * // Initialize with Windsurf client and specific tools
97
+ * await init({
98
+ * client: 'windsurf',
99
+ * tools: ['ziti_list_*', 'list_get_*'],
100
+ * scopes: ['read:*']
101
+ * });
102
+ */
103
+ const init = async (options) => {
104
+ log('Initializing OpenZiti MCP server...');
105
+ log(`Configuring server with selected tools: ${options.tools.join(', ')}`);
106
+ if (options.readOnly) {
107
+ log('Running in read-only mode - only read operations will be available');
108
+ }
109
+ trackEvent.trackInit(options.client);
110
+ // Check if client credentials parameters are provided for Private Cloud authentication
111
+ const { zitiControllerHost, idpDomain, idpClientId, idpClientSecret } = options;
112
+ if (zitiControllerHost && idpDomain && idpClientId && idpClientSecret) {
113
+ // Client credentials flow for Private Cloud
114
+ log('Using client credentials flow for authentication');
115
+ await requestClientCredentialsAuthorization({
116
+ zitiControllerHost: zitiControllerHost,
117
+ idpDomain: idpDomain,
118
+ idpClientId: idpClientId,
119
+ idpClientSecret: idpClientSecret,
120
+ });
121
+ }
122
+ else {
123
+ // Device authorization flow for public cloud
124
+ log('Using device authorization flow for authentication');
125
+ // Handle scope resolution
126
+ const selectedScopes = await resolveScopes(options.scopes);
127
+ await requestAuthorization(selectedScopes);
128
+ }
129
+ // Configure the requested client
130
+ await configureClient(options.client, options);
131
+ };
132
+ export default init;
133
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,qCAAqC,EAAE,MAAM,oCAAoC,CAAC;AAC3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAiB/C;;;;;GAKG;AACH,KAAK,UAAU,aAAa,CAAC,aAAwB;IACnD,mDAAmD;IACnD,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,CAAC;IAErC,uFAAuF;IACvF,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAEhF,IAAI,kBAAkB,IAAI,SAAS,IAAI,WAAW,IAAI,eAAe,EAAE,CAAC;QACtE,4CAA4C;QAC5C,GAAG,CAAC,kDAAkD,CAAC,CAAC;QAExD,MAAM,qCAAqC,CAAC;YAC1C,kBAAkB,EAAE,kBAAkB;YACtC,SAAS,EAAE,SAAS;YACpB,WAAW,EAAE,WAAW;YACxB,eAAe,EAAE,eAAe;SACjC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,6CAA6C;QAC7C,GAAG,CAAC,oDAAoD,CAAC,CAAC;QAE1D,0BAA0B;QAC1B,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAE3D,MAAM,oBAAoB,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;IAED,iCAAiC;IACjC,MAAM,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Command options for the logout command
3
+ */
4
+ export type LogoutOptions = Record<string, never>;
5
+ /**
6
+ * Removes all OpenZiti MCP related tokens from the system keychain
7
+ *
8
+ * @param {LogoutOptions} _options - Command options from commander (unused)
9
+ * @returns A promise that resolves when logout is complete
10
+ */
11
+ declare function logout(_options?: LogoutOptions): Promise<void>;
12
+ export default logout;
@@ -0,0 +1,90 @@
1
+ import chalk from 'chalk';
2
+ import { log, logError } from '../utils/logger.js';
3
+ import { cliOutput } from '../utils/terminal.js';
4
+ import { keychain, KeychainItem } from '../utils/keychain.js';
5
+ import { revokeRefreshToken } from '../auth/device-auth-flow.js';
6
+ /**
7
+ * Maps technical keychain item names to user-friendly descriptions
8
+ * @param item - The keychain item key
9
+ * @returns A user-friendly description of the item
10
+ */
11
+ const getItemDescription = (item) => {
12
+ const descriptions = {
13
+ [KeychainItem.TOKEN]: 'access token',
14
+ [KeychainItem.REFRESH_TOKEN]: 'refresh token',
15
+ [KeychainItem.ZITI_CONTROLLER_HOST]: 'Ziti Controller host',
16
+ [KeychainItem.DOMAIN]: 'domain information',
17
+ [KeychainItem.TOKEN_EXPIRES_AT]: 'token expiration',
18
+ };
19
+ return descriptions[item] ?? item;
20
+ };
21
+ /**
22
+ * Creates a formatted message for successful token removal
23
+ * @param successfulItems - Array of successfully removed items
24
+ * @returns A formatted success message
25
+ */
26
+ const createSuccessMessage = (successfulItems) => {
27
+ if (successfulItems.length === 0)
28
+ return '';
29
+ const tokenNames = successfulItems.map((result) => getItemDescription(result.item));
30
+ return `${chalk.green('✓')} Successfully removed ${tokenNames.join(', ')} from your system keychain.\n`;
31
+ };
32
+ /**
33
+ * Creates a formatted message for items that failed to be removed
34
+ * @param failedItems - Array of items that failed to be removed
35
+ * @returns A formatted error message
36
+ */
37
+ const createErrorMessage = (failedItems) => {
38
+ if (failedItems.length === 0)
39
+ return '';
40
+ const errorLines = failedItems.map((result) => `${chalk.red('✗')} ${getItemDescription(result.item)}: ${result.error?.message ?? 'Unknown error'}`);
41
+ return [
42
+ `${chalk.yellow('!')} Some credentials could not be removed and may require manual cleanup:`,
43
+ ...errorLines,
44
+ `\n${chalk.blue('i')} To manually remove credentials, use your system's keychain manager and search for 'ziti-mcp'.`,
45
+ ].join('\n');
46
+ };
47
+ /**
48
+ * Categorizes deletion results into successful and failed operations
49
+ * @param results - Array of keychain operation results
50
+ * @returns Object containing arrays of successful and failed operations
51
+ */
52
+ const categorizeResults = (results) => {
53
+ return {
54
+ successful: results.filter((result) => result.success),
55
+ failed: results.filter((result) => !result.success),
56
+ };
57
+ };
58
+ /**
59
+ * Removes all OpenZiti MCP related tokens from the system keychain
60
+ *
61
+ * @param {LogoutOptions} _options - Command options from commander (unused)
62
+ * @returns A promise that resolves when logout is complete
63
+ */
64
+ async function logout(_options) {
65
+ try {
66
+ log('Removing OpenZiti tokens from keychain');
67
+ cliOutput(`\n${chalk.blue('i')} Clearing authentication data...\n`);
68
+ log('Revoke refresh token if present');
69
+ await revokeRefreshToken();
70
+ // Delete all items from the keychain
71
+ const deletionResults = await keychain.clearAll();
72
+ const { successful, failed } = categorizeResults(deletionResults);
73
+ if (successful.length > 0) {
74
+ cliOutput(createSuccessMessage(successful));
75
+ }
76
+ else if (deletionResults.length === failed.length) {
77
+ cliOutput(`${chalk.yellow('!')} No OpenZiti MCP authentication data was found in your system keychain.\n`);
78
+ }
79
+ if (failed.length > 0) {
80
+ cliOutput(createErrorMessage(failed));
81
+ }
82
+ }
83
+ catch (error) {
84
+ logError('Error during logout:', error);
85
+ cliOutput(`\n${chalk.red('✗')} Failed to clear authentication data. ${error instanceof Error ? error.message : ''}\n`);
86
+ process.exit(1);
87
+ }
88
+ }
89
+ export default logout;
90
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAgC,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAU,EAAE;IAClD,MAAM,YAAY,GAA2B;QAC3C,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,cAAc;QACpC,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,eAAe;QAC7C,CAAC,YAAY,CAAC,oBAAoB,CAAC,EAAE,sBAAsB;QAC3D,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,o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C,EAAE,IAAI,CAC5G,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Command options for the run command
3
+ */
4
+ export interface RunOptions {
5
+ tools: string[];
6
+ readOnly?: boolean;
7
+ }
8
+ /**
9
+ * Main function to start server
10
+ *
11
+ * @param {RunOptions} options - Command options
12
+ * @returns {Promise<void>}
13
+ */
14
+ declare const run: (options: RunOptions) => Promise<void>;
15
+ export default run;
@@ -0,0 +1,94 @@
1
+ import { startServer } from '../server.js';
2
+ import trackEvent from '../utils/analytics.js';
3
+ import { log, logError, logInfo } from '../utils/logger.js';
4
+ import * as os from 'os';
5
+ import { keychain } from '../utils/keychain.js';
6
+ import { isTokenExpired } from '../auth/device-auth-flow.js';
7
+ import chalk from 'chalk';
8
+ /**
9
+ * Validates authorization preconditions before starting the server
10
+ *
11
+ * This function provides user-friendly validation with detailed CLI output
12
+ * and actionable guidance for resolving authentication issues. It forms the
13
+ * first layer of the MCP server's validation architecture:
14
+ *
15
+ * 1. Initial validation (here): Provides rich user feedback during startup
16
+ * 2. Server startup validation: Secondary checkpoint in `server.ts`
17
+ * 3. Continuous validation: During tool calls via the `validateConfig()` function
18
+ *
19
+ * Each layer serves a distinct purpose, creating a balance between security
20
+ * and developer experience. This function focuses on DX with detailed,
21
+ * human-readable feedback, while later validation layers provide ongoing
22
+ * security with more technical checks.
23
+ *
24
+ * @returns {Promise<boolean>} True if authorization is valid, false otherwise
25
+ */
26
+ const validateAuthorization = async () => {
27
+ // Check if token exists
28
+ const token = await keychain.getToken();
29
+ if (!token) {
30
+ logError(`${chalk.red('Authorization Error:')} No valid authorization token found`);
31
+ logError(`${chalk.bold('Recommended actions:')}`);
32
+ logError(`1. Run ${chalk.cyan('npx @openziti/openziti-mcp-server init')} to authorize with your OpenZiti Controller`);
33
+ logError(`2. Use ${chalk.cyan('npx @openziti/openziti-mcp-server session')} to check your current session status`);
34
+ return false;
35
+ }
36
+ // Check if token is expired
37
+ const expired = await isTokenExpired();
38
+ if (expired) {
39
+ const expiresAt = await keychain.getTokenExpiresAt();
40
+ const expiryDate = expiresAt ? new Date(expiresAt).toLocaleString() : 'unknown';
41
+ logError(`${chalk.red('Authorization Error:')} Token has expired (on ${expiryDate})`);
42
+ logError(`${chalk.bold('Recommended actions:')}`);
43
+ logError(`1. Run ${chalk.cyan('npx @openziti/openziti-mcp-server init')} to refresh your authorization`);
44
+ logError(`2. Use ${chalk.cyan('npx @openziti/openziti-mcp-server session')} to check your current session details`);
45
+ return false;
46
+ }
47
+ // Check if domain exists
48
+ const domain = await keychain.getDomain();
49
+ if (!domain) {
50
+ logError(`${chalk.red('Authorization Error:')} No OpenZiti Controller host found in configuration`);
51
+ logError(`${chalk.bold('Recommended actions:')}`);
52
+ logError(`1. Run ${chalk.cyan('npx @openziti/openziti-mcp-server init')} to authorize with your OpenZiti Controller`);
53
+ logError(`2. Use ${chalk.cyan('npx @openziti/openziti-mcp-server session')} to check your current configuration`);
54
+ return false;
55
+ }
56
+ return true;
57
+ };
58
+ /**
59
+ * Main function to start server
60
+ *
61
+ * @param {RunOptions} options - Command options
62
+ * @returns {Promise<void>}
63
+ */
64
+ const run = async (options) => {
65
+ try {
66
+ if (!process.env.HOME) {
67
+ process.env.HOME = os.homedir();
68
+ log(`Set HOME environment variable to ${process.env.HOME}`);
69
+ }
70
+ trackEvent.trackServerRun();
71
+ // Validate authorization before starting server
72
+ const isAuthorized = await validateAuthorization();
73
+ if (!isAuthorized) {
74
+ // Exit with code 1 (standard error code)
75
+ process.exit(1);
76
+ }
77
+ if (options.readOnly && options.tools.length === 1 && options.tools[0] === '*') {
78
+ logInfo('Starting server in read-only mode');
79
+ }
80
+ else if (options.readOnly) {
81
+ logInfo(`Starting server in read-only mode with tools matching the following pattern(s): ${options.tools.join(', ')} (--read-only has priority)`);
82
+ }
83
+ else {
84
+ logInfo(`Starting server with tools matching the following pattern(s): ${options.tools.join(', ')}`);
85
+ }
86
+ await startServer(options);
87
+ }
88
+ catch (error) {
89
+ logError('Fatal error starting server:', error);
90
+ process.exit(1);
91
+ }
92
+ };
93
+ export default run;
94
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,qBAAqB,GAAG,KAAK,IAAsB,EAAE;IACzD,wBAAwB;IACxB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACxC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,QAAQ,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,qCAAqC,CAAC,CAAC;QACpF,QAAQ,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;QAClD,QAAQ,CACN,UAAU,KAAK,CAAC,IAAI,CAAC,wCAAwC,CAAC,6CAA6C,CAC5G,CAAC;QACF,QAAQ,CACN,UAAU,KAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC,uCAAuC,CACzG,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4BAA4B;IAC5B,MAAM,OAAO,GAAG,MAAM,cAAc,EAAE,CAAC;IACvC,IAAI,OAAO,EA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EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;YAChC,GAAG,CAAC,oCAAoC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9D,CAAC;QAED,UAAU,CAAC,cAAc,EAAE,CAAC;QAE5B,gDAAgD;QAChD,MAAM,YAAY,GAAG,MAAM,qBAAqB,EAAE,CAAC;QACnD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,yCAAyC;YACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;YAC/E,OAAO,CAAC,mCAAmC,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC5B,OAAO,CACL,mFAAmF,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B,CACzI,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,CACL,iEAAiE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC5F,CAAC;QACJ,CAAC;QACD,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,QAAQ,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,GAAG,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Command options for the session command
3
+ */
4
+ export type SessionOptions = Record<string, never>;
5
+ /**
6
+ * Displays information about the current authentication session
7
+ *
8
+ * @param {SessionOptions} _options - Command options from commander (unused)
9
+ * @returns A promise that resolves when the display is complete
10
+ */
11
+ declare function session(_options?: SessionOptions): Promise<void>;
12
+ export default session;
@@ -0,0 +1,99 @@
1
+ import chalk from 'chalk';
2
+ import { keychain } from '../utils/keychain.js';
3
+ import { cliOutput } from '../utils/terminal.js';
4
+ import { log } from '../utils/logger.js';
5
+ /**
6
+ * Formats a date for display in user-friendly format
7
+ * @param timestamp - The timestamp to format
8
+ * @returns A formatted date string
9
+ */
10
+ const formatDate = (timestamp) => {
11
+ return new Date(timestamp).toLocaleString();
12
+ };
13
+ /**
14
+ * Creates a message for when no active session is found
15
+ * @returns A formatted message string
16
+ */
17
+ const createNoSessionMessage = () => {
18
+ return [
19
+ `\n${chalk.yellow('!')} No active authentication session found.\n`,
20
+ `Run ${chalk.cyan('npx @openziti/openziti-mcp-server init')} to authenticate.\n`,
21
+ ].join('');
22
+ };
23
+ /**
24
+ * Creates a header for the session information display
25
+ * @param domain - The authenticated domain
26
+ * @returns A formatted header string
27
+ */
28
+ const createSessionHeader = (zitiControllerHost, domain) => {
29
+ return [
30
+ `\n${chalk.green('✓')} Active authentication session:\n`,
31
+ `${chalk.bold('Ziti Controller Host:')} ${zitiControllerHost}\n`,
32
+ `${chalk.bold('Domain:')} ${domain}\n`,
33
+ ].join('');
34
+ };
35
+ /**
36
+ * Creates a message about token expiration status
37
+ * @param expiresAt - The timestamp when the token expires
38
+ * @returns A formatted expiration message
39
+ */
40
+ const createExpirationMessage = (expiresAt) => {
41
+ const now = Date.now();
42
+ const expiresIn = expiresAt - now;
43
+ if (expiresIn > 0) {
44
+ const hoursRemaining = Math.floor(expiresIn / (1000 * 60 * 60));
45
+ return `${chalk.bold('Token expires:')} in ${hoursRemaining} hours (${formatDate(expiresAt)})\n`;
46
+ }
47
+ else {
48
+ return `${chalk.bold('Token status:')} ${chalk.red('Expired')} on ${formatDate(expiresAt)}\n`;
49
+ }
50
+ };
51
+ /**
52
+ * Creates a footer with logout instructions
53
+ * @returns A formatted instruction string
54
+ */
55
+ const createLogoutInstructions = () => {
56
+ return `\nTo use different credentials, run ${chalk.cyan('npx @openziti/openziti-mcp-server logout')}\n`;
57
+ };
58
+ /**
59
+ * Creates an error message when session info can't be retrieved
60
+ * @returns A formatted error message
61
+ */
62
+ const createErrorMessage = () => {
63
+ return `\n${chalk.red('✗')} Failed to retrieve session information.\n`;
64
+ };
65
+ /**
66
+ * Displays information about the current authentication session
67
+ *
68
+ * @param {SessionOptions} _options - Command options from commander (unused)
69
+ * @returns A promise that resolves when the display is complete
70
+ */
71
+ async function session(_options) {
72
+ try {
73
+ log('Retrieving session information');
74
+ // Get session data from keychain
75
+ const token = await keychain.getToken();
76
+ const zitiControllerHost = await keychain.getZitiControllerHost();
77
+ const domain = await keychain.getDomain();
78
+ const expiresAt = await keychain.getTokenExpiresAt();
79
+ // Handle case where no session exists
80
+ if (!token || !zitiControllerHost || !domain) {
81
+ cliOutput(createNoSessionMessage());
82
+ return;
83
+ }
84
+ // Display session information
85
+ cliOutput(createSessionHeader(zitiControllerHost, domain));
86
+ // Add expiration information if available
87
+ if (expiresAt) {
88
+ cliOutput(createExpirationMessage(expiresAt));
89
+ }
90
+ // Add logout instructions
91
+ cliOutput(createLogoutInstructions());
92
+ }
93
+ catch (error) {
94
+ log('Error retrieving session information:', error);
95
+ cliOutput(createErrorMessage());
96
+ }
97
+ }
98
+ export default session;
99
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/commands/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,SAAiB,EAAU,EAAE;IAC/C,OAAO,IAAI,IAAI,C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EAAE,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AAED,eAAe,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import chalk from 'chalk';
4
+ import init from './commands/init.js';
5
+ import run from './commands/run.js';
6
+ import logout from './commands/logout.js';
7
+ import session from './commands/session.js';
8
+ import { logError } from './utils/logger.js';
9
+ import { TOOLS } from './tools/index.js';
10
+ import { validatePatterns } from './utils/tools.js';
11
+ import { packageName, packageVersion } from './utils/package.js';
12
+ // Set process title
13
+ process.title = packageName;
14
+ // Global error handlers
15
+ ['uncaughtException', 'unhandledRejection'].forEach((event) => {
16
+ process.on(event, (error) => {
17
+ logError(`${event}:`, error);
18
+ process.exit(1);
19
+ });
20
+ });
21
+ /**
22
+ * Parses and validates comma-separated tool patterns from command line input.
23
+ * This function processes a comma-delimited string of tool patterns,
24
+ * normalizes them by trimming whitespace, and validates each pattern
25
+ * against the available tools. If the input is empty, it returns a
26
+ * wildcard pattern ['*'] that matches all tools.
27
+ *
28
+ * @param {string} value - Raw command line input containing comma-separated patterns
29
+ * @returns {string[]} Array of validated tool pattern strings
30
+ * @throws {Error} If any pattern is invalid or doesn't match available tools
31
+ */
32
+ function parseToolPatterns(value) {
33
+ if (!value)
34
+ return ['*'];
35
+ const patterns = value
36
+ .split(',')
37
+ .map((item) => item.trim())
38
+ .filter(Boolean);
39
+ // Validate the patterns against available tools
40
+ validatePatterns(patterns, TOOLS);
41
+ return patterns;
42
+ }
43
+ // Top-level CLI
44
+ const program = new Command()
45
+ .name('ziti-mcp-server')
46
+ .description('OpenZiti MCP Server - Model Context Protocol server for OpenZiti Controller Management API')
47
+ .version(packageVersion)
48
+ .addHelpText('before', `
49
+ ${chalk.bold('OpenZiti MCP Server')}
50
+
51
+ A Model Context Protocol (MCP) server implementation that integrates the OpenZiti Controller Management API
52
+ with Claude Desktop, enabling AI-assisted management of your OpenZiti network.`)
53
+ .addHelpText('after', `
54
+ Examples:
55
+ npx ${packageName} init
56
+ npx ${packageName} init --tools 'ziti_*' --client claude
57
+ npx ${packageName} init --read-only --client claude
58
+ npx ${packageName} init --tools 'ziti_*_applications' --client windsurf
59
+ npx ${packageName} init --tools 'ziti_list_*,ziti_get_*' --client cursor
60
+ npx ${packageName} init --ziti-controller <ziti-controller> --idp-domain <idp-domain> --idp-client-id <idp-client-id> --idp-client-secret <idp-client-secret>
61
+ npx ${packageName} run
62
+ npx ${packageName} run --read-only
63
+ npx ${packageName} session
64
+ npx ${packageName} logout
65
+
66
+ For more information, visit: https://github.com/openziti/openziti-mcp-server`);
67
+ // Init command
68
+ program
69
+ .command('init')
70
+ .description('Initialize the server (authenticate and configure)')
71
+ .option('--client <client>', 'Configure specific client (claude, windsurf, cursor, or vscode)', 'claude')
72
+ .option('--ziti-controller-host <ziti controller host>', 'Ziti controller (required for Ziti network authentication)')
73
+ .option('--idp-domain <idp domain>', 'IdP domain (required for Private Cloud authentication)')
74
+ .option('--idp-client-id <idp ClientId>', 'Client ID (required for Private Cloud authentication)')
75
+ .option('--idp-client-secret <idp Client Secret>', 'Client secret (required for Private Cloud authentication)')
76
+ .option('--scopes <scopes>', 'Comma-separated list of API scopes', (text) => text
77
+ .split(',')
78
+ .map((scope) => scope.trim())
79
+ .filter(Boolean))
80
+ .option('--tools <tools>', 'Comma-separated list of tools or glob patterns to enable (defaults to "*" if not provided)', parseToolPatterns, ['*'])
81
+ .option('--read-only', 'Only expose read-only tools (list and get operations)', false)
82
+ .action(init);
83
+ // Run command
84
+ program
85
+ .command('run')
86
+ .description('Start the MCP server')
87
+ .option('--tools <tools>', 'Comma-separated list of tools or glob patterns to enable (defaults to "*" if not provided)', parseToolPatterns, ['*'])
88
+ .option('--read-only', 'Only expose read-only tools (list and get operations)', false)
89
+ .action(run);
90
+ // Logout command
91
+ program
92
+ .command('logout')
93
+ .description('Remove all stored JWT tokens from the system keychain')
94
+ .action(logout);
95
+ // Session command
96
+ program
97
+ .command('session')
98
+ .description('Display current authentication session information')
99
+ .action(session);
100
+ // Parse arguments and handle potential errors
101
+ program.parseAsync().catch((error) => {
102
+ logError('Command execution error:', error);
103
+ process.exit(1);
104
+ });
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,oBAAoB,CAAC;AACtC,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEjE,oBAAoB;AACpB,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC;AAE5B,wBAAwB;AACxB,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;IAC5D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC1B,QAAQ,CAAC,GAAG,KAAK,GAAG,EAAE,KAAK,CAAC,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,SAAS,iBAAiB,CAAC,KAAa;IACtC,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,CAA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