create-guardio 0.0.3 → 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 -33
  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 = {
@@ -81,24 +75,28 @@ async function main() {
81
75
  target: "ES2022",
82
76
  module: "NodeNext",
83
77
  moduleResolution: "NodeNext",
84
- outDir: ".",
85
- rootDir: ".",
86
78
  strict: true,
87
79
  skipLibCheck: true,
88
80
  esModuleInterop: true,
89
81
  },
90
- include: ["plugins/**/*.ts"],
82
+ include: ["guardio.config.ts", "plugins/**/*.ts"],
91
83
  };
92
84
  await writeFile(
93
85
  resolve(guardioPath, "tsconfig.json"),
94
86
  JSON.stringify(tsconfig, null, 2),
95
- "utf-8"
87
+ "utf-8",
96
88
  );
97
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
+ `;
98
96
  await writeFile(
99
- resolve(guardioPath, "guardio.config.json"),
100
- JSON.stringify(config, null, 2),
101
- "utf-8"
97
+ resolve(guardioPath, "guardio.config.ts"),
98
+ configTsContent,
99
+ "utf-8",
102
100
  );
103
101
 
104
102
  const binContent = `#!/usr/bin/env node
@@ -106,7 +104,7 @@ import { spawnSync } from "child_process";
106
104
  import path from "path";
107
105
  import { fileURLToPath } from "url";
108
106
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
109
- const configPath = path.resolve(__dirname, "..", "guardio.config.json");
107
+ const configPath = path.resolve(__dirname, "..", "guardio.config.ts");
110
108
  const result = spawnSync(
111
109
  "npx",
112
110
  ["-y", "@guardiojs/guardio", "--config", configPath],
@@ -127,7 +125,7 @@ process.exit(result.status ?? 1);
127
125
 
128
126
  /**
129
127
  * Example policy plugin: implements PolicyPluginInterface.
130
- * 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" }
131
129
  * Default export must be the plugin instance.
132
130
  */
133
131
  class ExamplePolicyPlugin implements PolicyPluginInterface {
@@ -145,12 +143,12 @@ export default new ExamplePolicyPlugin();
145
143
  await writeFile(
146
144
  resolve(guardioPath, "plugins", "example", "index.ts"),
147
145
  examplePluginContent,
148
- "utf-8"
146
+ "utf-8",
149
147
  );
150
148
 
151
149
  const pluginsReadme = `# Custom plugins (path-based)
152
150
 
153
- 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\`).
154
152
 
155
153
  - The directory must have \`index.js\` or \`index.mjs\` whose **default export is the plugin instance** (no descriptor).
156
154
  - Policy: implement \`PolicyPluginInterface\` (name, evaluate). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
@@ -162,22 +160,19 @@ Import types from "@guardiojs/guardio". See example/ for a policy plugin.
162
160
  await writeFile(
163
161
  resolve(guardioPath, "plugins", "README.md"),
164
162
  pluginsReadme,
165
- "utf-8"
163
+ "utf-8",
166
164
  );
167
165
 
168
- const relativeBin = `${guardioDir}/bin/guardio.mjs`;
169
- const absoluteBin = resolve(guardioPath, "bin", "guardio.mjs");
170
-
171
166
  console.log("\n---\n");
172
167
  console.log("Next steps");
173
168
  console.log(" cd " + guardioDir + " && npm install");
174
169
  console.log(" npm run build # compile plugins (index.ts → index.js)");
175
170
  console.log("");
176
- console.log("Add to MCP client");
177
- console.log("# Copy/paste the shown command\n");
178
- console.log(relativeBin);
179
- console.log("\n# Or use absolute path:\n");
180
- 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 + '"');
181
176
  console.log("");
182
177
 
183
178
  rl.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guardio",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Scaffold a Guardio project",
5
5
  "type": "module",
6
6
  "bin": {