create-guardio 0.0.1 → 0.0.3
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 +98 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -42,11 +42,58 @@ async function main() {
|
|
|
42
42
|
server: serverConfig,
|
|
43
43
|
plugins: [
|
|
44
44
|
{ type: "policy", name: "default", config: { blockedTools: [] } },
|
|
45
|
+
{
|
|
46
|
+
type: "policy",
|
|
47
|
+
name: "example",
|
|
48
|
+
path: "./plugins/example",
|
|
49
|
+
config: {},
|
|
50
|
+
},
|
|
45
51
|
],
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
await mkdir(guardioPath, { recursive: true });
|
|
49
55
|
await mkdir(resolve(guardioPath, "bin"), { recursive: true });
|
|
56
|
+
await mkdir(resolve(guardioPath, "plugins", "example"), { recursive: true });
|
|
57
|
+
|
|
58
|
+
const packageJson = {
|
|
59
|
+
name: "guardio-project",
|
|
60
|
+
private: true,
|
|
61
|
+
type: "module",
|
|
62
|
+
description: "Guardio-gated MCP server with optional local plugins",
|
|
63
|
+
scripts: {
|
|
64
|
+
build: "tsc",
|
|
65
|
+
guardio: "node bin/guardio.mjs",
|
|
66
|
+
},
|
|
67
|
+
dependencies: { "@guardiojs/guardio": "*" },
|
|
68
|
+
devDependencies: {
|
|
69
|
+
typescript: "^5.6.0",
|
|
70
|
+
"@types/node": "^22.0.0",
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
await writeFile(
|
|
74
|
+
resolve(guardioPath, "package.json"),
|
|
75
|
+
JSON.stringify(packageJson, null, 2),
|
|
76
|
+
"utf-8"
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const tsconfig = {
|
|
80
|
+
compilerOptions: {
|
|
81
|
+
target: "ES2022",
|
|
82
|
+
module: "NodeNext",
|
|
83
|
+
moduleResolution: "NodeNext",
|
|
84
|
+
outDir: ".",
|
|
85
|
+
rootDir: ".",
|
|
86
|
+
strict: true,
|
|
87
|
+
skipLibCheck: true,
|
|
88
|
+
esModuleInterop: true,
|
|
89
|
+
},
|
|
90
|
+
include: ["plugins/**/*.ts"],
|
|
91
|
+
};
|
|
92
|
+
await writeFile(
|
|
93
|
+
resolve(guardioPath, "tsconfig.json"),
|
|
94
|
+
JSON.stringify(tsconfig, null, 2),
|
|
95
|
+
"utf-8"
|
|
96
|
+
);
|
|
50
97
|
|
|
51
98
|
await writeFile(
|
|
52
99
|
resolve(guardioPath, "guardio.config.json"),
|
|
@@ -72,11 +119,61 @@ process.exit(result.status ?? 1);
|
|
|
72
119
|
await writeFile(binPath, binContent, "utf-8");
|
|
73
120
|
await chmod(binPath, 0o755);
|
|
74
121
|
|
|
122
|
+
const examplePluginContent = `import type {
|
|
123
|
+
PolicyPluginInterface,
|
|
124
|
+
PolicyRequestContext,
|
|
125
|
+
PolicyResult,
|
|
126
|
+
} from "@guardiojs/guardio";
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Example policy plugin: implements PolicyPluginInterface.
|
|
130
|
+
* Reference in guardio.config.json with: { "type": "policy", "name": "example", "path": "./plugins/example" }
|
|
131
|
+
* Default export must be the plugin instance.
|
|
132
|
+
*/
|
|
133
|
+
class ExamplePolicyPlugin implements PolicyPluginInterface {
|
|
134
|
+
readonly name = "example";
|
|
135
|
+
|
|
136
|
+
evaluate(context: PolicyRequestContext): PolicyResult {
|
|
137
|
+
// Example: allow all calls. Replace with your policy logic.
|
|
138
|
+
return "allowed";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default new ExamplePolicyPlugin();
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
await writeFile(
|
|
146
|
+
resolve(guardioPath, "plugins", "example", "index.ts"),
|
|
147
|
+
examplePluginContent,
|
|
148
|
+
"utf-8"
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const pluginsReadme = `# Custom plugins (path-based)
|
|
152
|
+
|
|
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\`).
|
|
154
|
+
|
|
155
|
+
- The directory must have \`index.js\` or \`index.mjs\` whose **default export is the plugin instance** (no descriptor).
|
|
156
|
+
- Policy: implement \`PolicyPluginInterface\` (name, evaluate). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
|
|
157
|
+
- Intervention: implement \`InterventionPluginInterface\` (name, act). Config: \`{ "type": "intervention", "name": "my-intervention", "path": "./plugins/my-intervention" }\`.
|
|
158
|
+
|
|
159
|
+
Import types from "@guardiojs/guardio". See example/ for a policy plugin.
|
|
160
|
+
`;
|
|
161
|
+
|
|
162
|
+
await writeFile(
|
|
163
|
+
resolve(guardioPath, "plugins", "README.md"),
|
|
164
|
+
pluginsReadme,
|
|
165
|
+
"utf-8"
|
|
166
|
+
);
|
|
167
|
+
|
|
75
168
|
const relativeBin = `${guardioDir}/bin/guardio.mjs`;
|
|
76
169
|
const absoluteBin = resolve(guardioPath, "bin", "guardio.mjs");
|
|
77
170
|
|
|
78
171
|
console.log("\n---\n");
|
|
79
|
-
console.log("
|
|
172
|
+
console.log("Next steps");
|
|
173
|
+
console.log(" cd " + guardioDir + " && npm install");
|
|
174
|
+
console.log(" npm run build # compile plugins (index.ts → index.js)");
|
|
175
|
+
console.log("");
|
|
176
|
+
console.log("Add to MCP client");
|
|
80
177
|
console.log("# Copy/paste the shown command\n");
|
|
81
178
|
console.log(relativeBin);
|
|
82
179
|
console.log("\n# Or use absolute path:\n");
|