create-guardio 0.0.4 → 0.0.5

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 +28 -31
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -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
  {
@@ -73,7 +67,7 @@ async function main() {
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,18 +79,24 @@ 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
 
90
+ const configTsContent = `import type { GuardioConfig } from "@guardiojs/guardio";
91
+
92
+ const config: GuardioConfig = ${JSON.stringify(config, null, 2).replace(/^/gm, " ")};
93
+
94
+ export default config;
95
+ `;
96
96
  await writeFile(
97
- resolve(guardioPath, "guardio.config.json"),
98
- JSON.stringify(config, null, 2),
99
- "utf-8"
97
+ resolve(guardioPath, "guardio.config.ts"),
98
+ configTsContent,
99
+ "utf-8",
100
100
  );
101
101
 
102
102
  const binContent = `#!/usr/bin/env node
@@ -104,7 +104,7 @@ import { spawnSync } from "child_process";
104
104
  import path from "path";
105
105
  import { fileURLToPath } from "url";
106
106
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
107
- const configPath = path.resolve(__dirname, "..", "guardio.config.json");
107
+ const configPath = path.resolve(__dirname, "..", "guardio.config.ts");
108
108
  const result = spawnSync(
109
109
  "npx",
110
110
  ["-y", "@guardiojs/guardio", "--config", configPath],
@@ -125,7 +125,7 @@ process.exit(result.status ?? 1);
125
125
 
126
126
  /**
127
127
  * Example policy plugin: implements PolicyPluginInterface.
128
- * Reference in guardio.config.json with: { "type": "policy", "name": "example", "path": "./plugins/example" }
128
+ * Reference in guardio.config.ts with: { type: "policy", name: "example", path: "./plugins/example" }
129
129
  * Default export must be the plugin instance.
130
130
  */
131
131
  class ExamplePolicyPlugin implements PolicyPluginInterface {
@@ -143,12 +143,12 @@ export default new ExamplePolicyPlugin();
143
143
  await writeFile(
144
144
  resolve(guardioPath, "plugins", "example", "index.ts"),
145
145
  examplePluginContent,
146
- "utf-8"
146
+ "utf-8",
147
147
  );
148
148
 
149
149
  const pluginsReadme = `# Custom plugins (path-based)
150
150
 
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\`).
151
+ 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
152
 
153
153
  - The directory must have \`index.js\` or \`index.mjs\` whose **default export is the plugin instance** (no descriptor).
154
154
  - Policy: implement \`PolicyPluginInterface\` (name, evaluate). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
@@ -160,22 +160,19 @@ Import types from "@guardiojs/guardio". See example/ for a policy plugin.
160
160
  await writeFile(
161
161
  resolve(guardioPath, "plugins", "README.md"),
162
162
  pluginsReadme,
163
- "utf-8"
163
+ "utf-8",
164
164
  );
165
165
 
166
- const relativeBin = `${guardioDir}/bin/guardio.mjs`;
167
- const absoluteBin = resolve(guardioPath, "bin", "guardio.mjs");
168
-
169
166
  console.log("\n---\n");
170
167
  console.log("Next steps");
171
168
  console.log(" cd " + guardioDir + " && npm install");
172
169
  console.log(" npm run build # compile plugins (index.ts → index.js)");
173
170
  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);
171
+ console.log("Run Guardio as HTTP server:");
172
+ console.log(" guardio --config guardio.config.ts");
173
+ console.log("");
174
+ console.log("Add to MCP client (use URL):");
175
+ console.log(' "url": "http://127.0.0.1:' + port + '"');
179
176
  console.log("");
180
177
 
181
178
  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.5",
4
4
  "description": "Scaffold a Guardio project",
5
5
  "type": "module",
6
6
  "bin": {