create-guardio 0.0.7 → 0.0.8
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/index.mjs +44 -41
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -30,43 +30,25 @@ function askYesNo(question, defaultAnswer = "n") {
|
|
|
30
30
|
async function main() {
|
|
31
31
|
console.log("\nCreate Guardio\n");
|
|
32
32
|
|
|
33
|
-
const guardioDir = await ask("Guardio directory", "
|
|
33
|
+
const guardioDir = await ask("Guardio directory", "guardio-project");
|
|
34
34
|
const guardioPath = resolve(process.cwd(), guardioDir);
|
|
35
35
|
|
|
36
|
-
// Servers: at least one, with name + URL
|
|
37
|
-
const servers = [];
|
|
38
|
-
let serverName = await ask("First MCP server name", "default");
|
|
39
|
-
let serverUrl = await ask("MCP server URL", "https://example.com/mcp");
|
|
40
|
-
servers.push({ name: serverName, type: "url", url: serverUrl });
|
|
41
|
-
|
|
42
|
-
while (await askYesNo("Add another MCP server?", "n")) {
|
|
43
|
-
serverName = await ask("MCP server name", "server-" + (servers.length + 1));
|
|
44
|
-
serverUrl = await ask("MCP server URL", "https://example.com/mcp");
|
|
45
|
-
servers.push({ name: serverName, type: "url", url: serverUrl });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
36
|
const portStr = await ask("Guardio HTTP server port", "3939");
|
|
49
37
|
const port = parseInt(portStr, 10) || 3939;
|
|
50
38
|
|
|
51
|
-
const
|
|
39
|
+
const useStorage = await askYesNo(
|
|
40
|
+
"Use storage and events (for dashboard / policy state)?",
|
|
41
|
+
"n",
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// All built-in policy plugins by default
|
|
45
|
+
const plugins = [
|
|
46
|
+
{ type: "policy", name: "deny-tool-access" },
|
|
47
|
+
{ type: "policy", name: "deny-regex-parameter" },
|
|
48
|
+
];
|
|
52
49
|
|
|
53
|
-
// Built-in plugins: by category
|
|
54
|
-
console.log("\nPolicy plugins:");
|
|
55
|
-
console.log(" 1) none");
|
|
56
|
-
console.log(" 2) deny-tool-access");
|
|
57
|
-
console.log(" 3) regex");
|
|
58
|
-
console.log(" 4) both");
|
|
59
|
-
const policyChoice = await ask("Policy plugins (1-4)", "1");
|
|
60
|
-
const policyNum = parseInt(policyChoice, 10) || 1;
|
|
61
|
-
const policyPlugins = [];
|
|
62
|
-
if (policyNum === 2 || policyNum === 4) policyPlugins.push({ type: "policy", name: "deny-tool-access" });
|
|
63
|
-
if (policyNum === 3 || policyNum === 4) policyPlugins.push({ type: "policy", name: "regex" });
|
|
64
|
-
|
|
65
|
-
const useStorage = await askYesNo("Use storage and events (for dashboard / policy state)?", installDashboard ? "y" : "n");
|
|
66
|
-
|
|
67
|
-
const plugins = [...policyPlugins];
|
|
68
50
|
if (useStorage) {
|
|
69
|
-
console.log(" 1) sqlite (
|
|
51
|
+
console.log(" 1) sqlite (in-memory or file)");
|
|
70
52
|
console.log(" 2) postgres");
|
|
71
53
|
const storageBackend = await ask("Storage backend (1-2)", "1");
|
|
72
54
|
if (storageBackend === "2") {
|
|
@@ -79,20 +61,35 @@ async function main() {
|
|
|
79
61
|
plugins.push({ type: "eventSink", name: "postgres" });
|
|
80
62
|
plugins.push({ type: "eventSinkStore", name: "postgres" });
|
|
81
63
|
} else {
|
|
82
|
-
const
|
|
64
|
+
const sqliteInMemory = await askYesNo(
|
|
65
|
+
"Use in-memory SQLite? (y = in-memory, n = file guardio.sqlite)",
|
|
66
|
+
"y",
|
|
67
|
+
);
|
|
68
|
+
const sqliteConfig = sqliteInMemory
|
|
69
|
+
? { inMemory: true }
|
|
70
|
+
: { database: "guardio.sqlite" };
|
|
83
71
|
plugins.push({ type: "storage", name: "sqlite", config: sqliteConfig });
|
|
84
72
|
plugins.push({ type: "eventSink", name: "sqlite", config: sqliteConfig });
|
|
85
|
-
plugins.push({
|
|
73
|
+
plugins.push({
|
|
74
|
+
type: "eventSinkStore",
|
|
75
|
+
name: "sqlite",
|
|
76
|
+
config: sqliteConfig,
|
|
77
|
+
});
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
80
|
|
|
89
|
-
const addExamplePlugin = await askYesNo(
|
|
81
|
+
const addExamplePlugin = await askYesNo(
|
|
82
|
+
"Add example custom policy plugin?",
|
|
83
|
+
"n",
|
|
84
|
+
);
|
|
90
85
|
if (addExamplePlugin) {
|
|
91
86
|
plugins.push({ type: "policy", name: "example", path: "./plugins/example" });
|
|
92
87
|
}
|
|
93
88
|
|
|
89
|
+
const installDashboard = await askYesNo("Install dashboard?", "n");
|
|
90
|
+
|
|
94
91
|
const config = {
|
|
95
|
-
servers,
|
|
92
|
+
servers: [],
|
|
96
93
|
client: { port, host: "127.0.0.1" },
|
|
97
94
|
plugins,
|
|
98
95
|
};
|
|
@@ -118,7 +115,7 @@ async function main() {
|
|
|
118
115
|
};
|
|
119
116
|
if (installDashboard) {
|
|
120
117
|
packageJson.dependencies["@guardiojs/dashboard"] = "*";
|
|
121
|
-
packageJson.scripts.dashboard = "
|
|
118
|
+
packageJson.scripts.dashboard = "dashboard";
|
|
122
119
|
}
|
|
123
120
|
await writeFile(
|
|
124
121
|
resolve(guardioPath, "package.json"),
|
|
@@ -145,6 +142,9 @@ async function main() {
|
|
|
145
142
|
|
|
146
143
|
const configTsContent = `import type { GuardioConfig } from "@guardiojs/guardio";
|
|
147
144
|
|
|
145
|
+
// Example server (uncomment and add to servers array to proxy an MCP server):
|
|
146
|
+
// { name: "nuvei-docs", type: "url", url: "https://mcp.nuvei.com/sse" }
|
|
147
|
+
|
|
148
148
|
const config: GuardioConfig = ${JSON.stringify(config, null, 2).replace(/^/gm, " ")};
|
|
149
149
|
|
|
150
150
|
export default config;
|
|
@@ -171,9 +171,9 @@ export default config;
|
|
|
171
171
|
class ExamplePolicyPlugin implements PolicyPluginInterface {
|
|
172
172
|
readonly name = "example";
|
|
173
173
|
|
|
174
|
-
evaluate(context: PolicyRequestContext): PolicyResult {
|
|
174
|
+
async evaluate(context: PolicyRequestContext): Promise<PolicyResult> {
|
|
175
175
|
// Example: allow all calls. Replace with your policy logic.
|
|
176
|
-
return { verdict: "allow" };
|
|
176
|
+
return Promise.resolve({ verdict: "allow" });
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -192,7 +192,7 @@ export default new ExamplePolicyPlugin();
|
|
|
192
192
|
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\`).
|
|
193
193
|
|
|
194
194
|
- The directory must have \`index.js\` or \`index.mjs\` whose **default export is the plugin instance** (no descriptor).
|
|
195
|
-
- Policy: implement \`PolicyPluginInterface\` (name, evaluate). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
|
|
195
|
+
- Policy: implement \`PolicyPluginInterface\` (name, evaluate returning Promise<PolicyResult>). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
|
|
196
196
|
|
|
197
197
|
Import types from "@guardiojs/guardio".${addExamplePlugin ? " See example/ for a policy plugin." : ""}
|
|
198
198
|
`;
|
|
@@ -204,7 +204,10 @@ Import types from "@guardiojs/guardio".${addExamplePlugin ? " See example/ for a
|
|
|
204
204
|
|
|
205
205
|
console.log("\n---\n");
|
|
206
206
|
console.log("Next steps");
|
|
207
|
-
console.log(" cd " + guardioDir
|
|
207
|
+
console.log(" cd " + guardioDir);
|
|
208
|
+
console.log(
|
|
209
|
+
" npm install # or: pnpm install, yarn, bun install, etc.",
|
|
210
|
+
);
|
|
208
211
|
if (addExamplePlugin) {
|
|
209
212
|
console.log(" npm run build # compile plugins (index.ts → index.js)");
|
|
210
213
|
}
|
|
@@ -214,8 +217,8 @@ Import types from "@guardiojs/guardio".${addExamplePlugin ? " See example/ for a
|
|
|
214
217
|
console.log("");
|
|
215
218
|
if (installDashboard) {
|
|
216
219
|
console.log("Run dashboard (point it at Guardio URL):");
|
|
217
|
-
console.log(" npm run dashboard");
|
|
218
|
-
console.log(" #
|
|
220
|
+
console.log(" pnpm run dashboard # or: npm run dashboard");
|
|
221
|
+
console.log(" # Guardio base URL: http://127.0.0.1:" + port);
|
|
219
222
|
console.log("");
|
|
220
223
|
}
|
|
221
224
|
console.log("Add to MCP client (use URL):");
|