create-guardio 0.0.4 → 0.0.6

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 (2) hide show
  1. package/index.mjs +31 -51
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createInterface } from "node:readline";
3
- import { mkdir, writeFile, chmod } from "node:fs/promises";
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { resolve, dirname } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
 
@@ -15,7 +15,7 @@ function ask(question, defaultAnswer = "") {
15
15
  resolve(
16
16
  typeof answer === "string" && answer.trim() !== ""
17
17
  ? answer.trim()
18
- : defaultAnswer
18
+ : defaultAnswer,
19
19
  );
20
20
  });
21
21
  });
@@ -27,19 +27,13 @@ async function main() {
27
27
  const guardioDir = await ask("Guardio directory", "./mcp-server-gated");
28
28
  const guardioPath = resolve(process.cwd(), guardioDir);
29
29
 
30
- const command = await ask("MCP Server command", "node");
31
- const argsStr = await ask(
32
- "MCP Server args",
33
- "path/to/your-mcp-server/index.js"
34
- );
35
- const args = argsStr
36
- .split(",")
37
- .map((s) => s.trim())
38
- .filter(Boolean);
39
- const serverConfig = { type: "command", command, args };
30
+ const url = await ask("MCP server URL", "https://example.com/mcp");
31
+ const portStr = await ask("Guardio HTTP server port", "3939");
32
+ const port = parseInt(portStr, 10) || 3939;
40
33
 
41
34
  const config = {
42
- server: serverConfig,
35
+ server: { type: "url", url },
36
+ client: { mode: "http", port, host: "127.0.0.1" },
43
37
  plugins: [
44
38
  { type: "policy", name: "default", config: { blockedTools: [] } },
45
39
  {
@@ -52,7 +46,6 @@ async function main() {
52
46
  };
53
47
 
54
48
  await mkdir(guardioPath, { recursive: true });
55
- await mkdir(resolve(guardioPath, "bin"), { recursive: true });
56
49
  await mkdir(resolve(guardioPath, "plugins", "example"), { recursive: true });
57
50
 
58
51
  const packageJson = {
@@ -62,18 +55,19 @@ async function main() {
62
55
  description: "Guardio-gated MCP server with optional local plugins",
63
56
  scripts: {
64
57
  build: "tsc",
65
- guardio: "node bin/guardio.mjs",
58
+ guardio: "node --import tsx ./node_modules/@guardiojs/guardio/dist/cli.js --config guardio.config.ts",
66
59
  },
67
60
  dependencies: { "@guardiojs/guardio": "*" },
68
61
  devDependencies: {
69
62
  typescript: "^5.6.0",
70
63
  "@types/node": "^22.0.0",
64
+ tsx: "^4.19.0",
71
65
  },
72
66
  };
73
67
  await writeFile(
74
68
  resolve(guardioPath, "package.json"),
75
69
  JSON.stringify(packageJson, null, 2),
76
- "utf-8"
70
+ "utf-8",
77
71
  );
78
72
 
79
73
  const tsconfig = {
@@ -85,37 +79,25 @@ async function main() {
85
79
  skipLibCheck: true,
86
80
  esModuleInterop: true,
87
81
  },
88
- include: ["plugins/**/*.ts"],
82
+ include: ["guardio.config.ts", "plugins/**/*.ts"],
89
83
  };
90
84
  await writeFile(
91
85
  resolve(guardioPath, "tsconfig.json"),
92
86
  JSON.stringify(tsconfig, null, 2),
93
- "utf-8"
87
+ "utf-8",
94
88
  );
95
89
 
96
- await writeFile(
97
- resolve(guardioPath, "guardio.config.json"),
98
- JSON.stringify(config, null, 2),
99
- "utf-8"
100
- );
90
+ const configTsContent = `import type { GuardioConfig } from "@guardiojs/guardio";
101
91
 
102
- const binContent = `#!/usr/bin/env node
103
- import { spawnSync } from "child_process";
104
- import path from "path";
105
- import { fileURLToPath } from "url";
106
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
107
- const configPath = path.resolve(__dirname, "..", "guardio.config.json");
108
- const result = spawnSync(
109
- "npx",
110
- ["-y", "@guardiojs/guardio", "--config", configPath],
111
- { stdio: "inherit" }
112
- );
113
- process.exit(result.status ?? 1);
114
- `;
92
+ const config: GuardioConfig = ${JSON.stringify(config, null, 2).replace(/^/gm, " ")};
115
93
 
116
- const binPath = resolve(guardioPath, "bin", "guardio.mjs");
117
- await writeFile(binPath, binContent, "utf-8");
118
- await chmod(binPath, 0o755);
94
+ export default config;
95
+ `;
96
+ await writeFile(
97
+ resolve(guardioPath, "guardio.config.ts"),
98
+ configTsContent,
99
+ "utf-8",
100
+ );
119
101
 
120
102
  const examplePluginContent = `import type {
121
103
  PolicyPluginInterface,
@@ -125,7 +107,7 @@ process.exit(result.status ?? 1);
125
107
 
126
108
  /**
127
109
  * Example policy plugin: implements PolicyPluginInterface.
128
- * Reference in guardio.config.json with: { "type": "policy", "name": "example", "path": "./plugins/example" }
110
+ * Reference in guardio.config.ts with: { type: "policy", name: "example", path: "./plugins/example" }
129
111
  * Default export must be the plugin instance.
130
112
  */
131
113
  class ExamplePolicyPlugin implements PolicyPluginInterface {
@@ -143,12 +125,12 @@ export default new ExamplePolicyPlugin();
143
125
  await writeFile(
144
126
  resolve(guardioPath, "plugins", "example", "index.ts"),
145
127
  examplePluginContent,
146
- "utf-8"
128
+ "utf-8",
147
129
  );
148
130
 
149
131
  const pluginsReadme = `# Custom plugins (path-based)
150
132
 
151
- Add a plugin by setting \`path\` in \`guardio.config.json\` to a directory that contains \`index.js\` or \`index.mjs\` (compile from \`index.ts\` with \`npm run build\`).
133
+ Add a plugin by setting \`path\` in \`guardio.config.ts\` to a directory that contains \`index.js\` or \`index.mjs\` (compile from \`index.ts\` with \`npm run build\`).
152
134
 
153
135
  - The directory must have \`index.js\` or \`index.mjs\` whose **default export is the plugin instance** (no descriptor).
154
136
  - Policy: implement \`PolicyPluginInterface\` (name, evaluate). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
@@ -160,22 +142,20 @@ Import types from "@guardiojs/guardio". See example/ for a policy plugin.
160
142
  await writeFile(
161
143
  resolve(guardioPath, "plugins", "README.md"),
162
144
  pluginsReadme,
163
- "utf-8"
145
+ "utf-8",
164
146
  );
165
147
 
166
- const relativeBin = `${guardioDir}/bin/guardio.mjs`;
167
- const absoluteBin = resolve(guardioPath, "bin", "guardio.mjs");
168
-
169
148
  console.log("\n---\n");
170
149
  console.log("Next steps");
171
150
  console.log(" cd " + guardioDir + " && npm install");
172
151
  console.log(" npm run build # compile plugins (index.ts → index.js)");
173
152
  console.log("");
174
- console.log("Add to MCP client");
175
- console.log("# Copy/paste the shown command\n");
176
- console.log(relativeBin);
177
- console.log("\n# Or use absolute path:\n");
178
- console.log(absoluteBin);
153
+ console.log("Run Guardio as HTTP server:");
154
+ console.log(" pnpm guardio");
155
+ console.log(" (uses tsx so guardio.config.ts loads without compiling)");
156
+ console.log("");
157
+ console.log("Add to MCP client (use URL):");
158
+ console.log(' "url": "http://127.0.0.1:' + port + '"');
179
159
  console.log("");
180
160
 
181
161
  rl.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guardio",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Scaffold a Guardio project",
5
5
  "type": "module",
6
6
  "bin": {