create-guardio 0.0.2 → 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 +44 -22
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -42,7 +42,12 @@ async function main() {
|
|
|
42
42
|
server: serverConfig,
|
|
43
43
|
plugins: [
|
|
44
44
|
{ type: "policy", name: "default", config: { blockedTools: [] } },
|
|
45
|
-
{
|
|
45
|
+
{
|
|
46
|
+
type: "policy",
|
|
47
|
+
name: "example",
|
|
48
|
+
path: "./plugins/example",
|
|
49
|
+
config: {},
|
|
50
|
+
},
|
|
46
51
|
],
|
|
47
52
|
};
|
|
48
53
|
|
|
@@ -55,7 +60,15 @@ async function main() {
|
|
|
55
60
|
private: true,
|
|
56
61
|
type: "module",
|
|
57
62
|
description: "Guardio-gated MCP server with optional local plugins",
|
|
63
|
+
scripts: {
|
|
64
|
+
build: "tsc",
|
|
65
|
+
guardio: "node bin/guardio.mjs",
|
|
66
|
+
},
|
|
58
67
|
dependencies: { "@guardiojs/guardio": "*" },
|
|
68
|
+
devDependencies: {
|
|
69
|
+
typescript: "^5.6.0",
|
|
70
|
+
"@types/node": "^22.0.0",
|
|
71
|
+
},
|
|
59
72
|
};
|
|
60
73
|
await writeFile(
|
|
61
74
|
resolve(guardioPath, "package.json"),
|
|
@@ -63,6 +76,25 @@ async function main() {
|
|
|
63
76
|
"utf-8"
|
|
64
77
|
);
|
|
65
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
|
+
);
|
|
97
|
+
|
|
66
98
|
await writeFile(
|
|
67
99
|
resolve(guardioPath, "guardio.config.json"),
|
|
68
100
|
JSON.stringify(config, null, 2),
|
|
@@ -91,33 +123,23 @@ process.exit(result.status ?? 1);
|
|
|
91
123
|
PolicyPluginInterface,
|
|
92
124
|
PolicyRequestContext,
|
|
93
125
|
PolicyResult,
|
|
94
|
-
PolicyPluginDescriptor,
|
|
95
126
|
} from "@guardiojs/guardio";
|
|
96
127
|
|
|
97
128
|
/**
|
|
98
|
-
* Example policy plugin: implements
|
|
99
|
-
*
|
|
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.
|
|
100
132
|
*/
|
|
101
133
|
class ExamplePolicyPlugin implements PolicyPluginInterface {
|
|
102
134
|
readonly name = "example";
|
|
103
135
|
|
|
104
|
-
constructor(_config: Record<string, unknown>) {
|
|
105
|
-
// config from guardio.config.json is passed here
|
|
106
|
-
}
|
|
107
|
-
|
|
108
136
|
evaluate(context: PolicyRequestContext): PolicyResult {
|
|
109
137
|
// Example: allow all calls. Replace with your policy logic.
|
|
110
138
|
return "allowed";
|
|
111
139
|
}
|
|
112
140
|
}
|
|
113
141
|
|
|
114
|
-
|
|
115
|
-
type: "policy",
|
|
116
|
-
name: "example",
|
|
117
|
-
create: (config) => new ExamplePolicyPlugin(config),
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export default descriptor;
|
|
142
|
+
export default new ExamplePolicyPlugin();
|
|
121
143
|
`;
|
|
122
144
|
|
|
123
145
|
await writeFile(
|
|
@@ -126,16 +148,15 @@ export default descriptor;
|
|
|
126
148
|
"utf-8"
|
|
127
149
|
);
|
|
128
150
|
|
|
129
|
-
const pluginsReadme = `#
|
|
130
|
-
|
|
131
|
-
Each subdirectory (e.g. example/) is a plugin. Guardio loads \`index.ts\` from each subdirectory.
|
|
151
|
+
const pluginsReadme = `# Custom plugins (path-based)
|
|
132
152
|
|
|
133
|
-
|
|
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\`).
|
|
134
154
|
|
|
135
|
-
-
|
|
136
|
-
-
|
|
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" }\`.
|
|
137
158
|
|
|
138
|
-
Import types from "@guardiojs/guardio".
|
|
159
|
+
Import types from "@guardiojs/guardio". See example/ for a policy plugin.
|
|
139
160
|
`;
|
|
140
161
|
|
|
141
162
|
await writeFile(
|
|
@@ -150,6 +171,7 @@ Import types from "@guardiojs/guardio". Add the plugin name to \`guardio.config.
|
|
|
150
171
|
console.log("\n---\n");
|
|
151
172
|
console.log("Next steps");
|
|
152
173
|
console.log(" cd " + guardioDir + " && npm install");
|
|
174
|
+
console.log(" npm run build # compile plugins (index.ts → index.js)");
|
|
153
175
|
console.log("");
|
|
154
176
|
console.log("Add to MCP client");
|
|
155
177
|
console.log("# Copy/paste the shown command\n");
|