create-guardio 0.0.6 → 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 +99 -32
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -21,32 +21,80 @@ function ask(question, defaultAnswer = "") {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function askYesNo(question, defaultAnswer = "n") {
|
|
25
|
+
return ask(question + " (y/n)", defaultAnswer).then((a) =>
|
|
26
|
+
/^y(es)?|1$/i.test(a),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
24
30
|
async function main() {
|
|
25
31
|
console.log("\nCreate Guardio\n");
|
|
26
32
|
|
|
27
|
-
const guardioDir = await ask("Guardio directory", "
|
|
33
|
+
const guardioDir = await ask("Guardio directory", "guardio-project");
|
|
28
34
|
const guardioPath = resolve(process.cwd(), guardioDir);
|
|
29
35
|
|
|
30
|
-
const url = await ask("MCP server URL", "https://example.com/mcp");
|
|
31
36
|
const portStr = await ask("Guardio HTTP server port", "3939");
|
|
32
37
|
const port = parseInt(portStr, 10) || 3939;
|
|
33
38
|
|
|
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
|
+
];
|
|
49
|
+
|
|
50
|
+
if (useStorage) {
|
|
51
|
+
console.log(" 1) sqlite (in-memory or file)");
|
|
52
|
+
console.log(" 2) postgres");
|
|
53
|
+
const storageBackend = await ask("Storage backend (1-2)", "1");
|
|
54
|
+
if (storageBackend === "2") {
|
|
55
|
+
const pgConnectionString = await ask(
|
|
56
|
+
"PostgreSQL connection string",
|
|
57
|
+
"postgresql://localhost:5432/guardio",
|
|
58
|
+
);
|
|
59
|
+
const pgConfig = { connectionString: pgConnectionString };
|
|
60
|
+
plugins.push({ type: "storage", name: "postgres", config: pgConfig });
|
|
61
|
+
plugins.push({ type: "eventSink", name: "postgres" });
|
|
62
|
+
plugins.push({ type: "eventSinkStore", name: "postgres" });
|
|
63
|
+
} else {
|
|
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" };
|
|
71
|
+
plugins.push({ type: "storage", name: "sqlite", config: sqliteConfig });
|
|
72
|
+
plugins.push({ type: "eventSink", name: "sqlite", config: sqliteConfig });
|
|
73
|
+
plugins.push({
|
|
74
|
+
type: "eventSinkStore",
|
|
75
|
+
name: "sqlite",
|
|
76
|
+
config: sqliteConfig,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const addExamplePlugin = await askYesNo(
|
|
82
|
+
"Add example custom policy plugin?",
|
|
83
|
+
"n",
|
|
84
|
+
);
|
|
85
|
+
if (addExamplePlugin) {
|
|
86
|
+
plugins.push({ type: "policy", name: "example", path: "./plugins/example" });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const installDashboard = await askYesNo("Install dashboard?", "n");
|
|
90
|
+
|
|
34
91
|
const config = {
|
|
35
|
-
|
|
36
|
-
client: {
|
|
37
|
-
plugins
|
|
38
|
-
{ type: "policy", name: "default", config: { blockedTools: [] } },
|
|
39
|
-
{
|
|
40
|
-
type: "policy",
|
|
41
|
-
name: "example",
|
|
42
|
-
path: "./plugins/example",
|
|
43
|
-
config: {},
|
|
44
|
-
},
|
|
45
|
-
],
|
|
92
|
+
servers: [],
|
|
93
|
+
client: { port, host: "127.0.0.1" },
|
|
94
|
+
plugins,
|
|
46
95
|
};
|
|
47
96
|
|
|
48
97
|
await mkdir(guardioPath, { recursive: true });
|
|
49
|
-
await mkdir(resolve(guardioPath, "plugins", "example"), { recursive: true });
|
|
50
98
|
|
|
51
99
|
const packageJson = {
|
|
52
100
|
name: "guardio-project",
|
|
@@ -55,7 +103,8 @@ async function main() {
|
|
|
55
103
|
description: "Guardio-gated MCP server with optional local plugins",
|
|
56
104
|
scripts: {
|
|
57
105
|
build: "tsc",
|
|
58
|
-
guardio:
|
|
106
|
+
guardio:
|
|
107
|
+
"node --import tsx ./node_modules/@guardiojs/guardio/dist/cli.js --config guardio.config.ts",
|
|
59
108
|
},
|
|
60
109
|
dependencies: { "@guardiojs/guardio": "*" },
|
|
61
110
|
devDependencies: {
|
|
@@ -64,6 +113,10 @@ async function main() {
|
|
|
64
113
|
tsx: "^4.19.0",
|
|
65
114
|
},
|
|
66
115
|
};
|
|
116
|
+
if (installDashboard) {
|
|
117
|
+
packageJson.dependencies["@guardiojs/dashboard"] = "*";
|
|
118
|
+
packageJson.scripts.dashboard = "dashboard";
|
|
119
|
+
}
|
|
67
120
|
await writeFile(
|
|
68
121
|
resolve(guardioPath, "package.json"),
|
|
69
122
|
JSON.stringify(packageJson, null, 2),
|
|
@@ -89,6 +142,9 @@ async function main() {
|
|
|
89
142
|
|
|
90
143
|
const configTsContent = `import type { GuardioConfig } from "@guardiojs/guardio";
|
|
91
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
|
+
|
|
92
148
|
const config: GuardioConfig = ${JSON.stringify(config, null, 2).replace(/^/gm, " ")};
|
|
93
149
|
|
|
94
150
|
export default config;
|
|
@@ -99,7 +155,9 @@ export default config;
|
|
|
99
155
|
"utf-8",
|
|
100
156
|
);
|
|
101
157
|
|
|
102
|
-
|
|
158
|
+
if (addExamplePlugin) {
|
|
159
|
+
await mkdir(resolve(guardioPath, "plugins", "example"), { recursive: true });
|
|
160
|
+
const examplePluginContent = `import type {
|
|
103
161
|
PolicyPluginInterface,
|
|
104
162
|
PolicyRequestContext,
|
|
105
163
|
PolicyResult,
|
|
@@ -113,32 +171,31 @@ export default config;
|
|
|
113
171
|
class ExamplePolicyPlugin implements PolicyPluginInterface {
|
|
114
172
|
readonly name = "example";
|
|
115
173
|
|
|
116
|
-
evaluate(context: PolicyRequestContext): PolicyResult {
|
|
174
|
+
async evaluate(context: PolicyRequestContext): Promise<PolicyResult> {
|
|
117
175
|
// Example: allow all calls. Replace with your policy logic.
|
|
118
|
-
return "
|
|
176
|
+
return Promise.resolve({ verdict: "allow" });
|
|
119
177
|
}
|
|
120
178
|
}
|
|
121
179
|
|
|
122
180
|
export default new ExamplePolicyPlugin();
|
|
123
181
|
`;
|
|
182
|
+
await writeFile(
|
|
183
|
+
resolve(guardioPath, "plugins", "example", "index.ts"),
|
|
184
|
+
examplePluginContent,
|
|
185
|
+
"utf-8",
|
|
186
|
+
);
|
|
187
|
+
}
|
|
124
188
|
|
|
125
|
-
await
|
|
126
|
-
resolve(guardioPath, "plugins", "example", "index.ts"),
|
|
127
|
-
examplePluginContent,
|
|
128
|
-
"utf-8",
|
|
129
|
-
);
|
|
130
|
-
|
|
189
|
+
await mkdir(resolve(guardioPath, "plugins"), { recursive: true });
|
|
131
190
|
const pluginsReadme = `# Custom plugins (path-based)
|
|
132
191
|
|
|
133
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\`).
|
|
134
193
|
|
|
135
194
|
- The directory must have \`index.js\` or \`index.mjs\` whose **default export is the plugin instance** (no descriptor).
|
|
136
|
-
- Policy: implement \`PolicyPluginInterface\` (name, evaluate). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
|
|
137
|
-
- Intervention: implement \`InterventionPluginInterface\` (name, act). Config: \`{ "type": "intervention", "name": "my-intervention", "path": "./plugins/my-intervention" }\`.
|
|
195
|
+
- Policy: implement \`PolicyPluginInterface\` (name, evaluate returning Promise<PolicyResult>). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
|
|
138
196
|
|
|
139
|
-
Import types from "@guardiojs/guardio"
|
|
197
|
+
Import types from "@guardiojs/guardio".${addExamplePlugin ? " See example/ for a policy plugin." : ""}
|
|
140
198
|
`;
|
|
141
|
-
|
|
142
199
|
await writeFile(
|
|
143
200
|
resolve(guardioPath, "plugins", "README.md"),
|
|
144
201
|
pluginsReadme,
|
|
@@ -147,13 +204,23 @@ Import types from "@guardiojs/guardio". See example/ for a policy plugin.
|
|
|
147
204
|
|
|
148
205
|
console.log("\n---\n");
|
|
149
206
|
console.log("Next steps");
|
|
150
|
-
console.log(" cd " + guardioDir
|
|
151
|
-
console.log(
|
|
207
|
+
console.log(" cd " + guardioDir);
|
|
208
|
+
console.log(
|
|
209
|
+
" npm install # or: pnpm install, yarn, bun install, etc.",
|
|
210
|
+
);
|
|
211
|
+
if (addExamplePlugin) {
|
|
212
|
+
console.log(" npm run build # compile plugins (index.ts → index.js)");
|
|
213
|
+
}
|
|
152
214
|
console.log("");
|
|
153
215
|
console.log("Run Guardio as HTTP server:");
|
|
154
|
-
console.log("
|
|
155
|
-
console.log(" (uses tsx so guardio.config.ts loads without compiling)");
|
|
216
|
+
console.log(" npm run guardio");
|
|
156
217
|
console.log("");
|
|
218
|
+
if (installDashboard) {
|
|
219
|
+
console.log("Run dashboard (point it at Guardio URL):");
|
|
220
|
+
console.log(" pnpm run dashboard # or: npm run dashboard");
|
|
221
|
+
console.log(" # Guardio base URL: http://127.0.0.1:" + port);
|
|
222
|
+
console.log("");
|
|
223
|
+
}
|
|
157
224
|
console.log("Add to MCP client (use URL):");
|
|
158
225
|
console.log(' "url": "http://127.0.0.1:' + port + '"');
|
|
159
226
|
console.log("");
|