create-guardio 0.0.1 → 0.0.2
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 +76 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -42,11 +42,26 @@ async function main() {
|
|
|
42
42
|
server: serverConfig,
|
|
43
43
|
plugins: [
|
|
44
44
|
{ type: "policy", name: "default", config: { blockedTools: [] } },
|
|
45
|
+
{ type: "policy", name: "example", config: {} },
|
|
45
46
|
],
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
await mkdir(guardioPath, { recursive: true });
|
|
49
50
|
await mkdir(resolve(guardioPath, "bin"), { recursive: true });
|
|
51
|
+
await mkdir(resolve(guardioPath, "plugins", "example"), { recursive: true });
|
|
52
|
+
|
|
53
|
+
const packageJson = {
|
|
54
|
+
name: "guardio-project",
|
|
55
|
+
private: true,
|
|
56
|
+
type: "module",
|
|
57
|
+
description: "Guardio-gated MCP server with optional local plugins",
|
|
58
|
+
dependencies: { "@guardiojs/guardio": "*" },
|
|
59
|
+
};
|
|
60
|
+
await writeFile(
|
|
61
|
+
resolve(guardioPath, "package.json"),
|
|
62
|
+
JSON.stringify(packageJson, null, 2),
|
|
63
|
+
"utf-8"
|
|
64
|
+
);
|
|
50
65
|
|
|
51
66
|
await writeFile(
|
|
52
67
|
resolve(guardioPath, "guardio.config.json"),
|
|
@@ -72,11 +87,71 @@ process.exit(result.status ?? 1);
|
|
|
72
87
|
await writeFile(binPath, binContent, "utf-8");
|
|
73
88
|
await chmod(binPath, 0o755);
|
|
74
89
|
|
|
90
|
+
const examplePluginContent = `import type {
|
|
91
|
+
PolicyPluginInterface,
|
|
92
|
+
PolicyRequestContext,
|
|
93
|
+
PolicyResult,
|
|
94
|
+
PolicyPluginDescriptor,
|
|
95
|
+
} from "@guardiojs/guardio";
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Example policy plugin: implements Guardio's PolicyPluginInterface.
|
|
99
|
+
* Register in guardio.config.json with: { "type": "policy", "name": "example", "config": {} }
|
|
100
|
+
*/
|
|
101
|
+
class ExamplePolicyPlugin implements PolicyPluginInterface {
|
|
102
|
+
readonly name = "example";
|
|
103
|
+
|
|
104
|
+
constructor(_config: Record<string, unknown>) {
|
|
105
|
+
// config from guardio.config.json is passed here
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
evaluate(context: PolicyRequestContext): PolicyResult {
|
|
109
|
+
// Example: allow all calls. Replace with your policy logic.
|
|
110
|
+
return "allowed";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const descriptor: PolicyPluginDescriptor = {
|
|
115
|
+
type: "policy",
|
|
116
|
+
name: "example",
|
|
117
|
+
create: (config) => new ExamplePolicyPlugin(config),
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default descriptor;
|
|
121
|
+
`;
|
|
122
|
+
|
|
123
|
+
await writeFile(
|
|
124
|
+
resolve(guardioPath, "plugins", "example", "index.ts"),
|
|
125
|
+
examplePluginContent,
|
|
126
|
+
"utf-8"
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const pluginsReadme = `# Local plugins
|
|
130
|
+
|
|
131
|
+
Each subdirectory (e.g. example/) is a plugin. Guardio loads \`index.ts\` from each subdirectory.
|
|
132
|
+
|
|
133
|
+
Your plugin must implement Guardio's interface and export a descriptor:
|
|
134
|
+
|
|
135
|
+
- Policy: \`PolicyPluginInterface\` and \`PolicyPluginDescriptor\` (type "policy", create() returns instance with evaluate()).
|
|
136
|
+
- Intervention: \`InterventionPluginInterface\` and \`InterventionPluginDescriptor\` (type "intervention", create() returns instance with act()).
|
|
137
|
+
|
|
138
|
+
Import types from "@guardiojs/guardio". Add the plugin name to \`guardio.config.json\` in the \`plugins\` array to enable it.
|
|
139
|
+
`;
|
|
140
|
+
|
|
141
|
+
await writeFile(
|
|
142
|
+
resolve(guardioPath, "plugins", "README.md"),
|
|
143
|
+
pluginsReadme,
|
|
144
|
+
"utf-8"
|
|
145
|
+
);
|
|
146
|
+
|
|
75
147
|
const relativeBin = `${guardioDir}/bin/guardio.mjs`;
|
|
76
148
|
const absoluteBin = resolve(guardioPath, "bin", "guardio.mjs");
|
|
77
149
|
|
|
78
150
|
console.log("\n---\n");
|
|
79
|
-
console.log("
|
|
151
|
+
console.log("Next steps");
|
|
152
|
+
console.log(" cd " + guardioDir + " && npm install");
|
|
153
|
+
console.log("");
|
|
154
|
+
console.log("Add to MCP client");
|
|
80
155
|
console.log("# Copy/paste the shown command\n");
|
|
81
156
|
console.log(relativeBin);
|
|
82
157
|
console.log("\n# Or use absolute path:\n");
|