@hasna/machines 0.0.8 → 0.0.10

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.
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Hasna, Inc.
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md CHANGED
@@ -8,6 +8,21 @@ Machine fleet management for developers — provision, sync, inspect, and operat
8
8
  - `machines-mcp`: MCP server exposing fleet tools to AI agents
9
9
  - `machines-agent`: lightweight local daemon for heartbeats and runtime reporting
10
10
 
11
+ ## HTTP mode
12
+
13
+ Long-lived Streamable HTTP transport for shared agent connections (stdio remains the default):
14
+
15
+ ```bash
16
+ machines-mcp --http
17
+ # or: MCP_HTTP=1 machines-mcp
18
+ # default port: 8821 (override with --port or MCP_HTTP_PORT)
19
+ ```
20
+
21
+ Endpoints on `127.0.0.1` only:
22
+
23
+ - `GET /health` → `{"status":"ok","name":"machines"}`
24
+ - `POST /mcp` → MCP Streamable HTTP
25
+
11
26
  ## Manifest
12
27
 
13
28
  `machines.json` is the desired fleet declaration.
package/dist/index.js CHANGED
@@ -30811,6 +30811,9 @@ var MACHINE_MCP_TOOL_NAMES = [
30811
30811
  "machines_serve_info",
30812
30812
  "machines_serve_dashboard"
30813
30813
  ];
30814
+ function buildServer(version2 = getPackageVersion()) {
30815
+ return createMcpServer(version2);
30816
+ }
30814
30817
  function createMcpServer(version2) {
30815
30818
  const server = new McpServer({ name: "machines", version: version2 });
30816
30819
  server.tool("machines_status", "Return local machine fleet status paths and machine identity.", {}, async () => ({
@@ -30979,6 +30982,7 @@ export {
30979
30982
  buildSyncPlan,
30980
30983
  buildSshCommand,
30981
30984
  buildSetupPlan,
30985
+ buildServer,
30982
30986
  buildClaudeInstallPlan,
30983
30987
  buildCertPlan,
30984
30988
  buildBackupPlan,
@@ -0,0 +1,12 @@
1
+ import { type Server } from "node:http";
2
+ export declare const DEFAULT_HTTP_PORT = 8821;
3
+ export declare const HTTP_NAME = "machines";
4
+ export interface StartHttpServerOptions {
5
+ port?: number;
6
+ host?: string;
7
+ name?: string;
8
+ }
9
+ export declare function isHttpMode(args?: string[]): boolean;
10
+ export declare function resolveHttpPort(args?: string[]): number;
11
+ export declare function startHttpServer(options?: StartHttpServerOptions): Server;
12
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,MAAM,EAAuB,MAAM,WAAW,CAAC;AAIjG,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,SAAS,aAAa,CAAC;AAEpC,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,UAAU,CAAC,IAAI,GAAE,MAAM,EAA0B,GAAG,OAAO,CAE1E;AAED,wBAAgB,eAAe,CAAC,IAAI,GAAE,MAAM,EAA0B,GAAG,MAAM,CAiB9E;AAmDD,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,MAAM,CA8B5E"}
package/dist/mcp/index.js CHANGED
@@ -16,11 +16,30 @@ var __export = (target, all) => {
16
16
  };
17
17
 
18
18
  // src/mcp/index.ts
19
- import { readFileSync as readFileSync7 } from "fs";
20
- import { dirname as dirname5, join as join9 } from "path";
21
- import { fileURLToPath as fileURLToPath2 } from "url";
22
19
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
23
20
 
21
+ // src/version.ts
22
+ import { existsSync, readFileSync } from "fs";
23
+ import { dirname, join } from "path";
24
+ import { fileURLToPath } from "url";
25
+ function getPackageVersion() {
26
+ try {
27
+ const here = dirname(fileURLToPath(import.meta.url));
28
+ const candidates = [join(here, "..", "package.json"), join(here, "..", "..", "package.json")];
29
+ const pkgPath = candidates.find((candidate) => existsSync(candidate));
30
+ if (!pkgPath) {
31
+ return "0.0.0";
32
+ }
33
+ return JSON.parse(readFileSync(pkgPath, "utf8")).version || "0.0.0";
34
+ } catch {
35
+ return "0.0.0";
36
+ }
37
+ }
38
+
39
+ // src/mcp/http.ts
40
+ import { createServer } from "http";
41
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
42
+
24
43
  // src/mcp/server.ts
25
44
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
26
45
 
@@ -3999,20 +4018,20 @@ var coerce = {
3999
4018
  var NEVER = INVALID;
4000
4019
  // src/commands/backup.ts
4001
4020
  import { homedir } from "os";
4002
- import { join } from "path";
4021
+ import { join as join2 } from "path";
4003
4022
  function quote(value) {
4004
4023
  return `'${value.replace(/'/g, `'\\''`)}'`;
4005
4024
  }
4006
4025
  function defaultBackupSources() {
4007
4026
  const home = homedir();
4008
4027
  return [
4009
- join(home, ".hasna"),
4010
- join(home, ".ssh"),
4011
- join(home, ".secrets")
4028
+ join2(home, ".hasna"),
4029
+ join2(home, ".ssh"),
4030
+ join2(home, ".secrets")
4012
4031
  ];
4013
4032
  }
4014
4033
  function buildBackupPlan(bucket, prefix = "machines") {
4015
- const archivePath = join(homedir(), ".hasna", "machines", "backup.tgz");
4034
+ const archivePath = join2(homedir(), ".hasna", "machines", "backup.tgz");
4016
4035
  const sources = defaultBackupSources();
4017
4036
  const steps = [
4018
4037
  {
@@ -4063,33 +4082,33 @@ function runBackup(bucket, prefix = "machines", options = {}) {
4063
4082
  }
4064
4083
 
4065
4084
  // src/manifests.ts
4066
- import { existsSync as existsSync2, readFileSync, writeFileSync } from "fs";
4085
+ import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync } from "fs";
4067
4086
  import { arch, homedir as homedir2, hostname, platform, userInfo } from "os";
4068
- import { dirname as dirname2 } from "path";
4087
+ import { dirname as dirname3 } from "path";
4069
4088
 
4070
4089
  // src/paths.ts
4071
- import { existsSync, mkdirSync } from "fs";
4072
- import { dirname, join as join2, resolve } from "path";
4090
+ import { existsSync as existsSync2, mkdirSync } from "fs";
4091
+ import { dirname as dirname2, join as join3, resolve } from "path";
4073
4092
  function homeDir() {
4074
4093
  return process.env["HOME"] || process.env["USERPROFILE"] || "~";
4075
4094
  }
4076
4095
  function getDataDir() {
4077
- return process.env["HASNA_MACHINES_DIR"] || join2(homeDir(), ".hasna", "machines");
4096
+ return process.env["HASNA_MACHINES_DIR"] || join3(homeDir(), ".hasna", "machines");
4078
4097
  }
4079
4098
  function getDbPath() {
4080
- return process.env["HASNA_MACHINES_DB_PATH"] || join2(getDataDir(), "machines.db");
4099
+ return process.env["HASNA_MACHINES_DB_PATH"] || join3(getDataDir(), "machines.db");
4081
4100
  }
4082
4101
  function getManifestPath() {
4083
- return process.env["HASNA_MACHINES_MANIFEST_PATH"] || join2(getDataDir(), "machines.json");
4102
+ return process.env["HASNA_MACHINES_MANIFEST_PATH"] || join3(getDataDir(), "machines.json");
4084
4103
  }
4085
4104
  function getNotificationsPath() {
4086
- return process.env["HASNA_MACHINES_NOTIFICATIONS_PATH"] || join2(getDataDir(), "notifications.json");
4105
+ return process.env["HASNA_MACHINES_NOTIFICATIONS_PATH"] || join3(getDataDir(), "notifications.json");
4087
4106
  }
4088
4107
  function ensureParentDir(filePath) {
4089
4108
  if (filePath === ":memory:")
4090
4109
  return;
4091
- const dir = dirname(resolve(filePath));
4092
- if (!existsSync(dir)) {
4110
+ const dir = dirname2(resolve(filePath));
4111
+ if (!existsSync2(dir)) {
4093
4112
  mkdirSync(dir, { recursive: true });
4094
4113
  }
4095
4114
  }
@@ -4154,10 +4173,10 @@ function getDefaultManifest() {
4154
4173
  };
4155
4174
  }
4156
4175
  function readManifest(path = getManifestPath()) {
4157
- if (!existsSync2(path)) {
4176
+ if (!existsSync3(path)) {
4158
4177
  return getDefaultManifest();
4159
4178
  }
4160
- const raw = JSON.parse(readFileSync(path, "utf8"));
4179
+ const raw = JSON.parse(readFileSync2(path, "utf8"));
4161
4180
  return fleetSchema.parse(raw);
4162
4181
  }
4163
4182
  function validateManifest(path = getManifestPath()) {
@@ -4181,7 +4200,7 @@ function getManifestMachine(machineId, path = getManifestPath()) {
4181
4200
  function detectCurrentMachineManifest() {
4182
4201
  const machineId = process.env["HASNA_MACHINES_MACHINE_ID"] || hostname();
4183
4202
  const user = userInfo().username;
4184
- const bunDir = dirname2(process.execPath);
4203
+ const bunDir = dirname3(process.execPath);
4185
4204
  return {
4186
4205
  id: machineId,
4187
4206
  hostname: hostname(),
@@ -4207,22 +4226,22 @@ import { hostname as hostname2 } from "os";
4207
4226
  import { createRequire } from "module";
4208
4227
  import { Database } from "bun:sqlite";
4209
4228
  import {
4210
- existsSync as existsSync3,
4229
+ existsSync as existsSync4,
4211
4230
  mkdirSync as mkdirSync2,
4212
4231
  readdirSync,
4213
4232
  copyFileSync
4214
4233
  } from "fs";
4215
4234
  import { homedir as homedir3 } from "os";
4216
- import { join as join3, relative } from "path";
4217
- import { existsSync as existsSync22, mkdirSync as mkdirSync22, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
4235
+ import { join as join4, relative } from "path";
4236
+ import { existsSync as existsSync22, mkdirSync as mkdirSync22, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
4218
4237
  import { homedir as homedir22 } from "os";
4219
4238
  import { join as join22 } from "path";
4220
4239
  import { readdirSync as readdirSync2, existsSync as existsSync32 } from "fs";
4221
4240
  import { join as join32 } from "path";
4222
4241
  import { homedir as homedir32 } from "os";
4223
4242
  import { homedir as homedir4 } from "os";
4224
- import { join as join4 } from "path";
4225
- import { join as join6, dirname as dirname3 } from "path";
4243
+ import { join as join42 } from "path";
4244
+ import { join as join6, dirname as dirname4 } from "path";
4226
4245
  import { homedir as homedir5, platform as platform2 } from "os";
4227
4246
  var __create = Object.create;
4228
4247
  var __getProtoOf = Object.getPrototypeOf;
@@ -13387,17 +13406,17 @@ var init_zod = __esm(() => {
13387
13406
  init_external();
13388
13407
  });
13389
13408
  function getDataDir2(serviceName) {
13390
- const dir = join3(HASNA_DIR, serviceName);
13409
+ const dir = join4(HASNA_DIR, serviceName);
13391
13410
  mkdirSync2(dir, { recursive: true });
13392
13411
  return dir;
13393
13412
  }
13394
13413
  function getDbPath2(serviceName) {
13395
13414
  const dir = getDataDir2(serviceName);
13396
- return join3(dir, `${serviceName}.db`);
13415
+ return join4(dir, `${serviceName}.db`);
13397
13416
  }
13398
13417
  var HASNA_DIR;
13399
13418
  var init_dotfile = __esm(() => {
13400
- HASNA_DIR = join3(homedir3(), ".hasna");
13419
+ HASNA_DIR = join4(homedir3(), ".hasna");
13401
13420
  });
13402
13421
  var exports_config = {};
13403
13422
  __export2(exports_config, {
@@ -13420,7 +13439,7 @@ function getCloudConfig() {
13420
13439
  return CloudConfigSchema.parse({});
13421
13440
  }
13422
13441
  try {
13423
- const raw = readFileSync2(CONFIG_PATH, "utf-8");
13442
+ const raw = readFileSync3(CONFIG_PATH, "utf-8");
13424
13443
  return CloudConfigSchema.parse(JSON.parse(raw));
13425
13444
  } catch {
13426
13445
  return CloudConfigSchema.parse({});
@@ -13711,7 +13730,7 @@ class SyncProgressTracker {
13711
13730
  init_adapter();
13712
13731
  init_config();
13713
13732
  init_discover();
13714
- var AUTO_SYNC_CONFIG_PATH = join4(homedir4(), ".hasna", "cloud", "config.json");
13733
+ var AUTO_SYNC_CONFIG_PATH = join42(homedir4(), ".hasna", "cloud", "config.json");
13715
13734
  init_config();
13716
13735
  init_adapter();
13717
13736
  init_dotfile();
@@ -14089,16 +14108,16 @@ function runCertPlan(domains, options = {}) {
14089
14108
  }
14090
14109
 
14091
14110
  // src/commands/dns.ts
14092
- import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
14111
+ import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
14093
14112
  import { join as join7 } from "path";
14094
14113
  function getDnsPath() {
14095
14114
  return join7(getDataDir(), "dns.json");
14096
14115
  }
14097
14116
  function readMappings() {
14098
14117
  const path = getDnsPath();
14099
- if (!existsSync4(path))
14118
+ if (!existsSync5(path))
14100
14119
  return [];
14101
- return JSON.parse(readFileSync3(path, "utf8"));
14120
+ return JSON.parse(readFileSync4(path, "utf8"));
14102
14121
  }
14103
14122
  function writeMappings(mappings) {
14104
14123
  const path = getDnsPath();
@@ -14400,7 +14419,7 @@ function runTailscaleInstall(machineId, options = {}) {
14400
14419
  }
14401
14420
 
14402
14421
  // src/commands/notifications.ts
14403
- import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "fs";
14422
+ import { existsSync as existsSync6, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "fs";
14404
14423
  var notificationChannelSchema = exports_external.object({
14405
14424
  id: exports_external.string(),
14406
14425
  type: exports_external.enum(["email", "webhook", "command"]),
@@ -14556,10 +14575,10 @@ function getDefaultNotificationConfig() {
14556
14575
  };
14557
14576
  }
14558
14577
  function readNotificationConfig(path = getNotificationsPath()) {
14559
- if (!existsSync5(path)) {
14578
+ if (!existsSync6(path)) {
14560
14579
  return getDefaultNotificationConfig();
14561
14580
  }
14562
- return notificationConfigSchema.parse(JSON.parse(readFileSync4(path, "utf8")));
14581
+ return notificationConfigSchema.parse(JSON.parse(readFileSync5(path, "utf8")));
14563
14582
  }
14564
14583
  function writeNotificationConfig(config, path = getNotificationsPath()) {
14565
14584
  ensureParentDir(path);
@@ -14731,24 +14750,6 @@ function manifestValidate() {
14731
14750
  return validateManifest(getManifestPath());
14732
14751
  }
14733
14752
 
14734
- // src/version.ts
14735
- import { existsSync as existsSync6, readFileSync as readFileSync5 } from "fs";
14736
- import { dirname as dirname4, join as join8 } from "path";
14737
- import { fileURLToPath } from "url";
14738
- function getPackageVersion() {
14739
- try {
14740
- const here = dirname4(fileURLToPath(import.meta.url));
14741
- const candidates = [join8(here, "..", "package.json"), join8(here, "..", "..", "package.json")];
14742
- const pkgPath = candidates.find((candidate) => existsSync6(candidate));
14743
- if (!pkgPath) {
14744
- return "0.0.0";
14745
- }
14746
- return JSON.parse(readFileSync5(pkgPath, "utf8")).version || "0.0.0";
14747
- } catch {
14748
- return "0.0.0";
14749
- }
14750
- }
14751
-
14752
14753
  // src/commands/status.ts
14753
14754
  function getStatus() {
14754
14755
  const manifest = readManifest();
@@ -15268,6 +15269,9 @@ function getAgentStatus(machineId = getLocalMachineId()) {
15268
15269
  }
15269
15270
 
15270
15271
  // src/mcp/server.ts
15272
+ function buildServer(version = getPackageVersion()) {
15273
+ return createMcpServer(version);
15274
+ }
15271
15275
  function createMcpServer(version) {
15272
15276
  const server = new McpServer({ name: "machines", version });
15273
15277
  server.tool("machines_status", "Return local machine fleet status paths and machine identity.", {}, async () => ({
@@ -15364,21 +15368,107 @@ function createMcpServer(version) {
15364
15368
  return server;
15365
15369
  }
15366
15370
 
15367
- // src/mcp/index.ts
15368
- function getPkgVersion() {
15371
+ // src/mcp/http.ts
15372
+ var DEFAULT_HTTP_PORT = 8821;
15373
+ var HTTP_NAME = "machines";
15374
+ function isHttpMode(args = process.argv.slice(2)) {
15375
+ return args.includes("--http") || process.env.MCP_HTTP === "1";
15376
+ }
15377
+ function resolveHttpPort(args = process.argv.slice(2)) {
15378
+ for (let i = 0;i < args.length; i++) {
15379
+ const arg = args[i];
15380
+ if (arg === "--port" && args[i + 1]) {
15381
+ return parsePort(args[i + 1]);
15382
+ }
15383
+ if (arg.startsWith("--port=")) {
15384
+ return parsePort(arg.slice("--port=".length));
15385
+ }
15386
+ }
15387
+ const envPort = process.env.MCP_HTTP_PORT;
15388
+ if (envPort) {
15389
+ return parsePort(envPort);
15390
+ }
15391
+ return DEFAULT_HTTP_PORT;
15392
+ }
15393
+ function parsePort(raw) {
15394
+ const port = Number.parseInt(raw, 10);
15395
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
15396
+ throw new Error(`Invalid port: ${raw}`);
15397
+ }
15398
+ return port;
15399
+ }
15400
+ function pathnameFromRequest(req) {
15401
+ return new URL(req.url ?? "/", "http://127.0.0.1").pathname;
15402
+ }
15403
+ async function readRequestBody(req) {
15404
+ if (req.method !== "POST" && req.method !== "DELETE") {
15405
+ return;
15406
+ }
15407
+ const chunks = [];
15408
+ for await (const chunk of req) {
15409
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
15410
+ }
15411
+ const text = Buffer.concat(chunks).toString("utf8");
15412
+ if (!text) {
15413
+ return;
15414
+ }
15415
+ return JSON.parse(text);
15416
+ }
15417
+ async function handleMcpRequest(req, res) {
15418
+ const server = buildServer();
15419
+ const transport = new StreamableHTTPServerTransport({
15420
+ sessionIdGenerator: undefined
15421
+ });
15422
+ await server.connect(transport);
15369
15423
  try {
15370
- const pkgPath = join9(dirname5(fileURLToPath2(import.meta.url)), "..", "..", "package.json");
15371
- return JSON.parse(readFileSync7(pkgPath, "utf8")).version || "0.0.0";
15372
- } catch {
15373
- return "0.0.0";
15424
+ const body = await readRequestBody(req);
15425
+ await transport.handleRequest(req, res, body);
15426
+ } finally {
15427
+ res.on("close", () => {
15428
+ transport.close().catch(() => {
15429
+ return;
15430
+ });
15431
+ server.close().catch(() => {
15432
+ return;
15433
+ });
15434
+ });
15374
15435
  }
15375
15436
  }
15437
+ function startHttpServer(options = {}) {
15438
+ const host = options.host ?? "127.0.0.1";
15439
+ const port = options.port ?? resolveHttpPort();
15440
+ const name = options.name ?? HTTP_NAME;
15441
+ const httpServer = createServer(async (req, res) => {
15442
+ const path = pathnameFromRequest(req);
15443
+ if (req.method === "GET" && path === "/health") {
15444
+ res.writeHead(200, { "content-type": "application/json" });
15445
+ res.end(JSON.stringify({ status: "ok", name }));
15446
+ return;
15447
+ }
15448
+ if (path === "/mcp") {
15449
+ await handleMcpRequest(req, res);
15450
+ return;
15451
+ }
15452
+ res.writeHead(404, { "content-type": "application/json" });
15453
+ res.end(JSON.stringify({ error: "Not found" }));
15454
+ });
15455
+ httpServer.listen(port, host, () => {
15456
+ const address = httpServer.address();
15457
+ const boundPort = typeof address === "object" && address ? address.port : port;
15458
+ console.error(`machines-mcp HTTP listening on http://${host}:${boundPort}`);
15459
+ });
15460
+ return httpServer;
15461
+ }
15462
+
15463
+ // src/mcp/index.ts
15376
15464
  function printHelp() {
15377
15465
  console.log(`Usage: machines-mcp [options]
15378
15466
 
15379
- MCP server for machine fleet management tools (stdio transport)
15467
+ MCP server for machine fleet management tools (stdio transport by default)
15380
15468
 
15381
15469
  Options:
15470
+ --http Start Streamable HTTP transport on 127.0.0.1 (or MCP_HTTP=1)
15471
+ --port <n> HTTP port (default: 8821, or MCP_HTTP_PORT env)
15382
15472
  -V, --version output the version number
15383
15473
  -h, --help display help for command`);
15384
15474
  }
@@ -15388,9 +15478,13 @@ if (args.includes("--help") || args.includes("-h")) {
15388
15478
  process.exit(0);
15389
15479
  }
15390
15480
  if (args.includes("--version") || args.includes("-V")) {
15391
- console.log(getPkgVersion());
15481
+ console.log(getPackageVersion());
15392
15482
  process.exit(0);
15393
15483
  }
15394
- var server = createMcpServer(getPkgVersion());
15395
- var transport = new StdioServerTransport;
15396
- await server.connect(transport);
15484
+ if (isHttpMode(args)) {
15485
+ startHttpServer({ port: resolveHttpPort(args) });
15486
+ } else {
15487
+ const server = buildServer();
15488
+ const transport = new StdioServerTransport;
15489
+ await server.connect(transport);
15490
+ }
@@ -1,4 +1,5 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  export declare const MACHINE_MCP_TOOL_NAMES: readonly ["machines_status", "machines_doctor", "machines_self_test", "machines_apps_list", "machines_apps_status", "machines_apps_diff", "machines_apps_plan", "machines_apps_apply", "machines_manifest", "machines_manifest_validate", "machines_manifest_bootstrap", "machines_manifest_get", "machines_manifest_remove", "machines_agent_status", "machines_setup_preview", "machines_setup_apply", "machines_sync_preview", "machines_sync_apply", "machines_diff", "machines_install_tailscale_preview", "machines_install_tailscale_apply", "machines_install_claude_status", "machines_install_claude_diff", "machines_install_claude_preview", "machines_install_claude_apply", "machines_ssh_resolve", "machines_ports", "machines_backup_preview", "machines_backup_apply", "machines_cert_preview", "machines_cert_apply", "machines_dns_add", "machines_dns_list", "machines_dns_render", "machines_notifications_add", "machines_notifications_list", "machines_notifications_test", "machines_notifications_dispatch", "machines_notifications_remove", "machines_serve_info", "machines_serve_dashboard"];
3
+ export declare function buildServer(version?: string): McpServer;
3
4
  export declare function createMcpServer(version: string): McpServer;
4
5
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA2BpE,eAAO,MAAM,sBAAsB,4jCA0CzB,CAAC;AAEX,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CA6R1D"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA4BpE,eAAO,MAAM,sBAAsB,4jCA0CzB,CAAC;AAEX,wBAAgB,WAAW,CAAC,OAAO,GAAE,MAA4B,GAAG,SAAS,CAE5E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CA6R1D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/machines",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Machine fleet management CLI + MCP for developers",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",