@guardrail-ai/mcp 0.1.0
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/README.md +29 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @guardrail-ai/mcp
|
|
2
|
+
|
|
3
|
+
Model Context Protocol (MCP) server for Guardrail. Use Guardrail as a Claude Code plugin or with any MCP-compatible AI assistant.
|
|
4
|
+
|
|
5
|
+
## Setup with Claude Code
|
|
6
|
+
|
|
7
|
+
Add to your Claude Code settings (`.claude/settings.json`):
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"mcpServers": {
|
|
12
|
+
"guardrail": {
|
|
13
|
+
"command": "npx",
|
|
14
|
+
"args": ["@guardrail-ai/mcp"]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Available Tools
|
|
21
|
+
|
|
22
|
+
### guardrail_scan
|
|
23
|
+
Scan a directory or file for issues.
|
|
24
|
+
|
|
25
|
+
### guardrail_fix
|
|
26
|
+
Auto-fix detected issues (dry-run by default).
|
|
27
|
+
|
|
28
|
+
### guardrail_list_rules
|
|
29
|
+
List all 19 built-in detection rules.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
5
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
|
+
const zod_1 = require("zod");
|
|
7
|
+
const core_1 = require("@guardrail-ai/core");
|
|
8
|
+
const rules_1 = require("@guardrail-ai/rules");
|
|
9
|
+
const fixer_1 = require("@guardrail-ai/fixer");
|
|
10
|
+
const server = new mcp_js_1.McpServer({
|
|
11
|
+
name: 'guardrail',
|
|
12
|
+
version: '0.1.0',
|
|
13
|
+
});
|
|
14
|
+
// ── Tool: scan ──────────────────────────────────────────────────────────────
|
|
15
|
+
server.tool('guardrail_scan', 'Scan a directory or file for security issues, performance problems, bad patterns, and AI-generated code anti-patterns. Returns structured violations with file, line, severity, and rule ID.', {
|
|
16
|
+
target: zod_1.z.string().describe('Path to a file or directory to scan'),
|
|
17
|
+
severity: zod_1.z
|
|
18
|
+
.enum(['critical', 'high', 'warning', 'info'])
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('Minimum severity threshold (default: info)'),
|
|
21
|
+
}, async ({ target, severity }) => {
|
|
22
|
+
const engine = new core_1.GuardrailEngine({
|
|
23
|
+
severityThreshold: severity ?? 'info',
|
|
24
|
+
});
|
|
25
|
+
engine.registerRules(rules_1.builtinRules);
|
|
26
|
+
const summary = await engine.scan(target);
|
|
27
|
+
const lines = [];
|
|
28
|
+
lines.push(`Scanned ${summary.totalFiles} files. Found ${summary.totalViolations} issues.`);
|
|
29
|
+
lines.push(` Critical: ${summary.bySeverity.critical}, High: ${summary.bySeverity.high}, Warning: ${summary.bySeverity.warning}, Info: ${summary.bySeverity.info}`);
|
|
30
|
+
lines.push('');
|
|
31
|
+
for (const result of summary.results) {
|
|
32
|
+
if (result.violations.length === 0)
|
|
33
|
+
continue;
|
|
34
|
+
lines.push(`${result.filePath}:`);
|
|
35
|
+
for (const v of result.violations) {
|
|
36
|
+
const fix = v.fix ? ' (fixable)' : '';
|
|
37
|
+
lines.push(` ${v.severity.toUpperCase()} ${v.location.line}:${v.location.column} ${v.message} [${v.ruleId}]${fix}`);
|
|
38
|
+
}
|
|
39
|
+
lines.push('');
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
// ── Tool: fix ───────────────────────────────────────────────────────────────
|
|
46
|
+
server.tool('guardrail_fix', 'Auto-fix detected issues in a directory or file using AST transformations. Returns diffs of applied changes.', {
|
|
47
|
+
target: zod_1.z.string().describe('Path to a file or directory to fix'),
|
|
48
|
+
dryRun: zod_1.z
|
|
49
|
+
.boolean()
|
|
50
|
+
.optional()
|
|
51
|
+
.describe('If true, show diffs without applying changes (default: true)'),
|
|
52
|
+
}, async ({ target, dryRun = true }) => {
|
|
53
|
+
const engine = new core_1.GuardrailEngine();
|
|
54
|
+
engine.registerRules(rules_1.builtinRules);
|
|
55
|
+
const summary = await engine.scan(target);
|
|
56
|
+
const fixer = new fixer_1.FixerEngine();
|
|
57
|
+
const lines = [];
|
|
58
|
+
let totalFixed = 0;
|
|
59
|
+
for (const result of summary.results) {
|
|
60
|
+
const fixable = result.violations.filter((v) => v.fix);
|
|
61
|
+
if (fixable.length === 0)
|
|
62
|
+
continue;
|
|
63
|
+
const fixResult = await fixer.applyFixes(result.filePath, result.violations, !dryRun);
|
|
64
|
+
if (fixResult.applied > 0) {
|
|
65
|
+
totalFixed += fixResult.applied;
|
|
66
|
+
if (fixResult.diff) {
|
|
67
|
+
lines.push(fixResult.diff);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (totalFixed === 0) {
|
|
72
|
+
lines.push('No auto-fixable issues found.');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const action = dryRun ? 'would fix' : 'fixed';
|
|
76
|
+
lines.push(`\n${totalFixed} issues ${action}.`);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
// ── Tool: list-rules ────────────────────────────────────────────────────────
|
|
83
|
+
server.tool('guardrail_list_rules', 'List all available Guardrail detection rules with their IDs, categories, and severities.', {}, async () => {
|
|
84
|
+
const lines = rules_1.builtinRules.map((r) => `${r.id} | ${r.category} | ${r.severity} | ${r.description}`);
|
|
85
|
+
return {
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
type: 'text',
|
|
89
|
+
text: `ID | Category | Severity | Description\n${'-'.repeat(80)}\n${lines.join('\n')}`,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
// ── Start ───────────────────────────────────────────────────────────────────
|
|
95
|
+
async function main() {
|
|
96
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
97
|
+
await server.connect(transport);
|
|
98
|
+
}
|
|
99
|
+
main().catch(console.error);
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,oEAAoE;AACpE,wEAAiF;AACjF,6BAAwB;AACxB,6CAAqD;AACrD,+CAAmD;AACnD,+CAAkD;AAElD,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC;IAC3B,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,+EAA+E;AAE/E,MAAM,CAAC,IAAI,CACT,gBAAgB,EAChB,8LAA8L,EAC9L;IACE,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;IAClE,QAAQ,EAAE,OAAC;SACR,IAAI,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;SAC7C,QAAQ,EAAE;SACV,QAAQ,CAAC,4CAA4C,CAAC;CAC1D,EACD,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7B,MAAM,MAAM,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AC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@guardrail-ai/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Model Context Protocol (MCP) server for Guardrail — use as a Claude Code plugin",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"guardrail-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": ["dist", "README.md"],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/Manavarya09/Guardrail.git",
|
|
16
|
+
"directory": "packages/mcp"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/Manavarya09/Guardrail",
|
|
19
|
+
"bugs": "https://github.com/Manavarya09/Guardrail/issues",
|
|
20
|
+
"keywords": ["guardrail", "mcp", "claude", "claude-code", "model-context-protocol"],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.json",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@guardrail-ai/core": "*",
|
|
27
|
+
"@guardrail-ai/rules": "*",
|
|
28
|
+
"@guardrail-ai/fixer": "*",
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.12.1"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT"
|
|
32
|
+
}
|