@orygn/opa-mcp 0.0.0 → 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/CHANGELOG.md +99 -0
- package/LICENSE +21 -0
- package/README.md +622 -2
- package/dist/config.d.ts +58 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +72 -0
- package/dist/config.js.map +1 -0
- package/dist/lib/errors.d.ts +18 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +25 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/logger.d.ts +10 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +57 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/opa-cli.d.ts +226 -0
- package/dist/lib/opa-cli.d.ts.map +1 -0
- package/dist/lib/opa-cli.js +283 -0
- package/dist/lib/opa-cli.js.map +1 -0
- package/dist/lib/opa-client.d.ts +47 -0
- package/dist/lib/opa-client.d.ts.map +1 -0
- package/dist/lib/opa-client.js +101 -0
- package/dist/lib/opa-client.js.map +1 -0
- package/dist/lib/output.d.ts +17 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/output.js +21 -0
- package/dist/lib/output.js.map +1 -0
- package/dist/lib/regal-cli.d.ts +65 -0
- package/dist/lib/regal-cli.d.ts.map +1 -0
- package/dist/lib/regal-cli.js +99 -0
- package/dist/lib/regal-cli.js.map +1 -0
- package/dist/lib/security.d.ts +16 -0
- package/dist/lib/security.d.ts.map +1 -0
- package/dist/lib/security.js +64 -0
- package/dist/lib/security.js.map +1 -0
- package/dist/lib/subprocess.d.ts +26 -0
- package/dist/lib/subprocess.d.ts.map +1 -0
- package/dist/lib/subprocess.js +72 -0
- package/dist/lib/subprocess.js.map +1 -0
- package/dist/lib/tool-helpers.d.ts +46 -0
- package/dist/lib/tool-helpers.d.ts.map +1 -0
- package/dist/lib/tool-helpers.js +73 -0
- package/dist/lib/tool-helpers.js.map +1 -0
- package/dist/prompts/index.d.ts +4 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +147 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/resources/index.d.ts +12 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +107 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/patterns.d.ts +9 -0
- package/dist/resources/patterns.d.ts.map +1 -0
- package/dist/resources/patterns.js +375 -0
- package/dist/resources/patterns.js.map +1 -0
- package/dist/resources/style-guide.d.ts +6 -0
- package/dist/resources/style-guide.d.ts.map +1 -0
- package/dist/resources/style-guide.js +187 -0
- package/dist/resources/style-guide.js.map +1 -0
- package/dist/server.d.ts +22 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +82 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/authoring/capabilities.d.ts +11 -0
- package/dist/tools/authoring/capabilities.d.ts.map +1 -0
- package/dist/tools/authoring/capabilities.js +57 -0
- package/dist/tools/authoring/capabilities.js.map +1 -0
- package/dist/tools/authoring/check.d.ts +18 -0
- package/dist/tools/authoring/check.d.ts.map +1 -0
- package/dist/tools/authoring/check.js +71 -0
- package/dist/tools/authoring/check.js.map +1 -0
- package/dist/tools/authoring/deps.d.ts +8 -0
- package/dist/tools/authoring/deps.d.ts.map +1 -0
- package/dist/tools/authoring/deps.js +51 -0
- package/dist/tools/authoring/deps.js.map +1 -0
- package/dist/tools/authoring/format.d.ts +8 -0
- package/dist/tools/authoring/format.d.ts.map +1 -0
- package/dist/tools/authoring/format.js +44 -0
- package/dist/tools/authoring/format.js.map +1 -0
- package/dist/tools/authoring/index.d.ts +11 -0
- package/dist/tools/authoring/index.d.ts.map +1 -0
- package/dist/tools/authoring/index.js +17 -0
- package/dist/tools/authoring/index.js.map +1 -0
- package/dist/tools/authoring/inspect.d.ts +10 -0
- package/dist/tools/authoring/inspect.d.ts.map +1 -0
- package/dist/tools/authoring/inspect.js +47 -0
- package/dist/tools/authoring/inspect.js.map +1 -0
- package/dist/tools/authoring/lint.d.ts +18 -0
- package/dist/tools/authoring/lint.d.ts.map +1 -0
- package/dist/tools/authoring/lint.js +84 -0
- package/dist/tools/authoring/lint.js.map +1 -0
- package/dist/tools/authoring/parse.d.ts +7 -0
- package/dist/tools/authoring/parse.d.ts.map +1 -0
- package/dist/tools/authoring/parse.js +43 -0
- package/dist/tools/authoring/parse.js.map +1 -0
- package/dist/tools/bundles/build.d.ts +8 -0
- package/dist/tools/bundles/build.d.ts.map +1 -0
- package/dist/tools/bundles/build.js +87 -0
- package/dist/tools/bundles/build.js.map +1 -0
- package/dist/tools/bundles/index.d.ts +10 -0
- package/dist/tools/bundles/index.d.ts.map +1 -0
- package/dist/tools/bundles/index.js +7 -0
- package/dist/tools/bundles/index.js.map +1 -0
- package/dist/tools/bundles/sign.d.ts +8 -0
- package/dist/tools/bundles/sign.d.ts.map +1 -0
- package/dist/tools/bundles/sign.js +47 -0
- package/dist/tools/bundles/sign.js.map +1 -0
- package/dist/tools/evaluation/_shared.d.ts +55 -0
- package/dist/tools/evaluation/_shared.d.ts.map +1 -0
- package/dist/tools/evaluation/_shared.js +102 -0
- package/dist/tools/evaluation/_shared.js.map +1 -0
- package/dist/tools/evaluation/bench.d.ts +9 -0
- package/dist/tools/evaluation/bench.d.ts.map +1 -0
- package/dist/tools/evaluation/bench.js +76 -0
- package/dist/tools/evaluation/bench.js.map +1 -0
- package/dist/tools/evaluation/compile.d.ts +11 -0
- package/dist/tools/evaluation/compile.d.ts.map +1 -0
- package/dist/tools/evaluation/compile.js +19 -0
- package/dist/tools/evaluation/compile.js.map +1 -0
- package/dist/tools/evaluation/eval.d.ts +10 -0
- package/dist/tools/evaluation/eval.d.ts.map +1 -0
- package/dist/tools/evaluation/eval.js +35 -0
- package/dist/tools/evaluation/eval.js.map +1 -0
- package/dist/tools/evaluation/index.d.ts +11 -0
- package/dist/tools/evaluation/index.d.ts.map +1 -0
- package/dist/tools/evaluation/index.js +11 -0
- package/dist/tools/evaluation/index.js.map +1 -0
- package/dist/tools/evaluation/test.d.ts +28 -0
- package/dist/tools/evaluation/test.d.ts.map +1 -0
- package/dist/tools/evaluation/test.js +74 -0
- package/dist/tools/evaluation/test.js.map +1 -0
- package/dist/tools/helpers/describe-policy.d.ts +26 -0
- package/dist/tools/helpers/describe-policy.d.ts.map +1 -0
- package/dist/tools/helpers/describe-policy.js +76 -0
- package/dist/tools/helpers/describe-policy.js.map +1 -0
- package/dist/tools/helpers/explain-decision.d.ts +41 -0
- package/dist/tools/helpers/explain-decision.d.ts.map +1 -0
- package/dist/tools/helpers/explain-decision.js +75 -0
- package/dist/tools/helpers/explain-decision.js.map +1 -0
- package/dist/tools/helpers/generate-test-skeleton.d.ts +8 -0
- package/dist/tools/helpers/generate-test-skeleton.d.ts.map +1 -0
- package/dist/tools/helpers/generate-test-skeleton.js +93 -0
- package/dist/tools/helpers/generate-test-skeleton.js.map +1 -0
- package/dist/tools/helpers/index.d.ts +12 -0
- package/dist/tools/helpers/index.d.ts.map +1 -0
- package/dist/tools/helpers/index.js +11 -0
- package/dist/tools/helpers/index.js.map +1 -0
- package/dist/tools/helpers/suggest-fix.d.ts +15 -0
- package/dist/tools/helpers/suggest-fix.d.ts.map +1 -0
- package/dist/tools/helpers/suggest-fix.js +119 -0
- package/dist/tools/helpers/suggest-fix.js.map +1 -0
- package/dist/tools/index.d.ts +31 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +13 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/server-management/_shared.d.ts +9 -0
- package/dist/tools/server-management/_shared.d.ts.map +1 -0
- package/dist/tools/server-management/_shared.js +41 -0
- package/dist/tools/server-management/_shared.js.map +1 -0
- package/dist/tools/server-management/data.d.ts +4 -0
- package/dist/tools/server-management/data.d.ts.map +1 -0
- package/dist/tools/server-management/data.js +90 -0
- package/dist/tools/server-management/data.js.map +1 -0
- package/dist/tools/server-management/decisions.d.ts +4 -0
- package/dist/tools/server-management/decisions.d.ts.map +1 -0
- package/dist/tools/server-management/decisions.js +87 -0
- package/dist/tools/server-management/decisions.js.map +1 -0
- package/dist/tools/server-management/index.d.ts +11 -0
- package/dist/tools/server-management/index.d.ts.map +1 -0
- package/dist/tools/server-management/index.js +11 -0
- package/dist/tools/server-management/index.js.map +1 -0
- package/dist/tools/server-management/policies.d.ts +4 -0
- package/dist/tools/server-management/policies.d.ts.map +1 -0
- package/dist/tools/server-management/policies.js +94 -0
- package/dist/tools/server-management/policies.js.map +1 -0
- package/dist/tools/server-management/status.d.ts +4 -0
- package/dist/tools/server-management/status.d.ts.map +1 -0
- package/dist/tools/server-management/status.js +82 -0
- package/dist/tools/server-management/status.js.map +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +82 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `rego_generate_test_skeleton` — given a policy, parse its AST and
|
|
3
|
+
* emit a `*_test.rego` skeleton with one stub test per rule.
|
|
4
|
+
*
|
|
5
|
+
* The skeleton is mechanical — the agent fills in real assertions.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { OpaCli } from '../../lib/opa-cli.js';
|
|
9
|
+
import { err, ok } from '../../lib/errors.js';
|
|
10
|
+
import { mapSubprocessFailure, tryParseJson, withToolEnvelope } from '../../lib/tool-helpers.js';
|
|
11
|
+
const RegoGenerateTestSkeletonInput = {
|
|
12
|
+
source: z.string().min(1).describe('Rego source to generate tests for.'),
|
|
13
|
+
};
|
|
14
|
+
function packageNameFromAst(ast) {
|
|
15
|
+
const parts = ast.package?.path ?? [];
|
|
16
|
+
// The first entry is always `data`. Skip it.
|
|
17
|
+
return parts
|
|
18
|
+
.slice(1)
|
|
19
|
+
.map((p) => (typeof p.value === 'string' ? p.value : ''))
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.join('.');
|
|
22
|
+
}
|
|
23
|
+
function ruleNameFromAst(rule) {
|
|
24
|
+
if (rule.head?.name)
|
|
25
|
+
return rule.head.name;
|
|
26
|
+
const ref = rule.head?.ref;
|
|
27
|
+
if (Array.isArray(ref) && ref.length > 0) {
|
|
28
|
+
return ref
|
|
29
|
+
.map((p) => (typeof p.value === 'string' ? p.value : ''))
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join('.');
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
function makeSkeleton(packageName, ruleNames) {
|
|
36
|
+
const lines = [];
|
|
37
|
+
const testPackage = packageName ? `${packageName}_test` : 'main_test';
|
|
38
|
+
lines.push(`package ${testPackage}`);
|
|
39
|
+
lines.push('');
|
|
40
|
+
lines.push('import rego.v1');
|
|
41
|
+
if (packageName) {
|
|
42
|
+
lines.push(`import data.${packageName}`);
|
|
43
|
+
}
|
|
44
|
+
lines.push('');
|
|
45
|
+
for (const name of ruleNames) {
|
|
46
|
+
const testName = `test_${name.replace(/[^a-zA-Z0-9_]/g, '_')}`;
|
|
47
|
+
const ruleRef = packageName ? `${packageName}.${name}` : name;
|
|
48
|
+
lines.push(`# TODO: replace placeholder input with a realistic case.`);
|
|
49
|
+
lines.push(`${testName} if {`);
|
|
50
|
+
lines.push(`\t# Arrange`);
|
|
51
|
+
lines.push(`\tinput := {}`);
|
|
52
|
+
lines.push('');
|
|
53
|
+
lines.push(`\t# Act / Assert`);
|
|
54
|
+
lines.push(`\tdata.${ruleRef} with input as input`);
|
|
55
|
+
lines.push(`}`);
|
|
56
|
+
lines.push('');
|
|
57
|
+
}
|
|
58
|
+
return lines.join('\n');
|
|
59
|
+
}
|
|
60
|
+
export function registerRegoGenerateTestSkeleton(server, config) {
|
|
61
|
+
const opa = new OpaCli(config);
|
|
62
|
+
server.registerTool('rego_generate_test_skeleton', {
|
|
63
|
+
title: 'Generate Rego test skeleton',
|
|
64
|
+
description: 'Generate a `*_test.rego` skeleton from a policy. Parses the AST, finds each rule, and emits one stub test per rule. The agent fills in realistic inputs and assertions.',
|
|
65
|
+
inputSchema: RegoGenerateTestSkeletonInput,
|
|
66
|
+
}, async ({ source }) => {
|
|
67
|
+
return withToolEnvelope(config, async () => {
|
|
68
|
+
const result = await opa.parse({ source });
|
|
69
|
+
const subprocessFailure = mapSubprocessFailure(result, 'opa');
|
|
70
|
+
if (subprocessFailure)
|
|
71
|
+
return subprocessFailure;
|
|
72
|
+
if (result.exitCode !== 0) {
|
|
73
|
+
return err('INVALID_REGO', 'opa parse rejected the source.', {
|
|
74
|
+
details: { stderr: result.stderr.trim() },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const ast = tryParseJson(result.stdout);
|
|
78
|
+
if (ast === undefined) {
|
|
79
|
+
return err('UNKNOWN_ERROR', 'opa parse produced no parseable JSON.');
|
|
80
|
+
}
|
|
81
|
+
const packageName = packageNameFromAst(ast);
|
|
82
|
+
const ruleNames = Array.from(new Set((ast.rules ?? [])
|
|
83
|
+
.map(ruleNameFromAst)
|
|
84
|
+
.filter((n) => typeof n === 'string' && n.length > 0)));
|
|
85
|
+
if (ruleNames.length === 0) {
|
|
86
|
+
return err('INVALID_INPUT', 'No rules found in the source — nothing to test.');
|
|
87
|
+
}
|
|
88
|
+
const testFile = makeSkeleton(packageName, ruleNames);
|
|
89
|
+
return ok({ testFile, ruleNames });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=generate-test-skeleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-test-skeleton.js","sourceRoot":"","sources":["../../../src/tools/helpers/generate-test-skeleton.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,qBAAq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AO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CACrE,CACF,CAAC;YAEF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3B,OAAO,GAAG,CAAC,eAAe,EAAE,iDAAiD,CAAC,CAAC;YACjF,CAAC;YAED,MAAM,QAAQ,GAAG,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YACtD,OAAO,EAAE,CAAiC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Category E — Higher-level helpers.
|
|
3
|
+
*
|
|
4
|
+
* These tools compose lower-level primitives or do mechanical AST
|
|
5
|
+
* analysis to provide endpoints agents can call directly without
|
|
6
|
+
* stitching together rego_eval / rego_check / rego_parse_ast
|
|
7
|
+
* themselves.
|
|
8
|
+
*/
|
|
9
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
10
|
+
import type { Config } from '../../config.js';
|
|
11
|
+
export declare function registerHelperTools(server: McpServer, config: Config): void;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/helpers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAM9C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAK3E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { registerRegoDescribePolicy } from './describe-policy.js';
|
|
2
|
+
import { registerRegoExplainDecision } from './explain-decision.js';
|
|
3
|
+
import { registerRegoGenerateTestSkeleton } from './generate-test-skeleton.js';
|
|
4
|
+
import { registerRegoSuggestFix } from './suggest-fix.js';
|
|
5
|
+
export function registerHelperTools(server, config) {
|
|
6
|
+
registerRegoExplainDecision(server, config);
|
|
7
|
+
registerRegoGenerateTestSkeleton(server, config);
|
|
8
|
+
registerRegoDescribePolicy(server, config);
|
|
9
|
+
registerRegoSuggestFix(server, config);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/helpers/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,MAAc;IACnE,2BAA2B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,gCAAgC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjD,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { Config } from '../../config.js';
|
|
3
|
+
interface FixSuggestion {
|
|
4
|
+
code: string;
|
|
5
|
+
message: string;
|
|
6
|
+
suggestion: string;
|
|
7
|
+
confidence: 'high' | 'medium' | 'low';
|
|
8
|
+
patch?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface RegoSuggestFixOutput {
|
|
11
|
+
suggestions: FixSuggestion[];
|
|
12
|
+
}
|
|
13
|
+
export declare function registerRegoSuggestFix(server: McpServer, config: Config): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=suggest-fix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suggest-fix.d.ts","sourceRoot":"","sources":["../../../src/tools/helpers/suggest-fix.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAyB9C,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAqED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,aAAa,EAAE,CAAC;CAC9B;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAkC9E"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `rego_suggest_fix` — propose mechanical fixes for common Rego
|
|
3
|
+
* compile errors and Regal lint findings.
|
|
4
|
+
*
|
|
5
|
+
* The tool is deliberately rule-based — it doesn't call out to an LLM.
|
|
6
|
+
* Common error codes have well-known mechanical fixes; we surface
|
|
7
|
+
* those, and for everything else we hand back a structured "no
|
|
8
|
+
* automated fix available, here's what we know" envelope so the agent
|
|
9
|
+
* can reason on it.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { ok } from '../../lib/errors.js';
|
|
13
|
+
import { withToolEnvelope } from '../../lib/tool-helpers.js';
|
|
14
|
+
const RegoSuggestFixInput = {
|
|
15
|
+
diagnostics: z
|
|
16
|
+
.array(z.object({
|
|
17
|
+
code: z.string().describe('Diagnostic code (e.g. "rego_unsafe_var_error").'),
|
|
18
|
+
message: z.string().describe('Diagnostic message.'),
|
|
19
|
+
location: z
|
|
20
|
+
.object({
|
|
21
|
+
file: z.string().optional(),
|
|
22
|
+
row: z.number().optional(),
|
|
23
|
+
col: z.number().optional(),
|
|
24
|
+
})
|
|
25
|
+
.optional(),
|
|
26
|
+
title: z.string().optional().describe('Title (Regal violations).'),
|
|
27
|
+
category: z.string().optional().describe('Category (Regal violations).'),
|
|
28
|
+
}))
|
|
29
|
+
.min(1)
|
|
30
|
+
.describe('Diagnostics from rego_check or rego_lint.'),
|
|
31
|
+
};
|
|
32
|
+
const KNOWN_FIXES = [
|
|
33
|
+
{
|
|
34
|
+
match: (code) => code === 'rego_unsafe_var_error',
|
|
35
|
+
suggest: (message) => {
|
|
36
|
+
const varMatch = /var (\S+) is unsafe/.exec(message);
|
|
37
|
+
const varName = varMatch?.[1];
|
|
38
|
+
return {
|
|
39
|
+
suggestion: varName
|
|
40
|
+
? `The variable \`${varName}\` is referenced but never bound. Add a clause that defines it (assignment, comprehension, or pattern match) before it is used.`
|
|
41
|
+
: 'A variable is referenced before being bound. Add a binding clause earlier in the rule body.',
|
|
42
|
+
confidence: 'high',
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
match: (code) => code === 'rego_parse_error',
|
|
48
|
+
suggest: () => ({
|
|
49
|
+
suggestion: 'The source did not parse. Run `rego_format` to confirm the syntax is well-formed, then `rego_check` for the precise location.',
|
|
50
|
+
confidence: 'medium',
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
match: (code) => code === 'rego_type_error',
|
|
55
|
+
suggest: (message) => ({
|
|
56
|
+
suggestion: `Type mismatch: ${message.replace(/^rego_type_error:\s*/, '')}. Reconcile the operand types — most often this is comparing a string with a number, or indexing a value with the wrong key shape.`,
|
|
57
|
+
confidence: 'medium',
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
match: (code) => code === 'rego_recursion_error',
|
|
62
|
+
suggest: () => ({
|
|
63
|
+
suggestion: 'A rule references itself directly or indirectly. Restructure so each rule depends only on documents lower in the DAG, or introduce an intermediate rule that breaks the cycle.',
|
|
64
|
+
confidence: 'high',
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
match: (code) => code === 'rego_compile_error',
|
|
69
|
+
suggest: () => ({
|
|
70
|
+
suggestion: 'A compile error occurred. Run `rego_check` for the structured diagnostic — the message text usually points at the precise issue (often an unresolved import or capabilities mismatch).',
|
|
71
|
+
confidence: 'low',
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
// Regal style/idiom suggestions
|
|
75
|
+
{
|
|
76
|
+
match: (code) => code === 'print-or-trace-call',
|
|
77
|
+
suggest: () => ({
|
|
78
|
+
suggestion: 'Remove the `print(...)` or `trace(...)` call before shipping — it slows evaluation and is rarely intended in production policy.',
|
|
79
|
+
confidence: 'high',
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
match: (code) => code === 'directory-package-mismatch',
|
|
84
|
+
suggest: () => ({
|
|
85
|
+
suggestion: 'The Rego file lives in a directory that does not match its `package` declaration. Move the file or rename the package so they agree (e.g., `package foo.bar` belongs in `foo/bar/`).',
|
|
86
|
+
confidence: 'high',
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
export function registerRegoSuggestFix(server, config) {
|
|
91
|
+
server.registerTool('rego_suggest_fix', {
|
|
92
|
+
title: 'Suggest fix for Rego diagnostics',
|
|
93
|
+
description: 'Map common Rego compile errors and Regal lint findings to mechanical fix suggestions. Pass diagnostics from `rego_check` or `rego_lint`. Returns one suggestion per input diagnostic; confidence is `high` for well-known patterns, `medium` for partial matches, `low` for everything else.',
|
|
94
|
+
inputSchema: RegoSuggestFixInput,
|
|
95
|
+
}, ({ diagnostics }) => {
|
|
96
|
+
return withToolEnvelope(config, () => {
|
|
97
|
+
const suggestions = diagnostics.map((diag) => {
|
|
98
|
+
const code = diag.code || diag.title || '';
|
|
99
|
+
const matched = KNOWN_FIXES.find((f) => f.match(code, diag.message));
|
|
100
|
+
if (matched) {
|
|
101
|
+
const partial = matched.suggest(diag.message);
|
|
102
|
+
return {
|
|
103
|
+
code,
|
|
104
|
+
message: diag.message,
|
|
105
|
+
...partial,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
code,
|
|
110
|
+
message: diag.message,
|
|
111
|
+
suggestion: 'No automated suggestion available for this diagnostic. Read the message text and the location for context — most Rego errors have an obvious mechanical fix once the trigger is identified.',
|
|
112
|
+
confidence: 'low',
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
return Promise.resolve(ok({ suggestions }));
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=suggest-fix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suggest-fix.js","sourceRoot":"","sources":["../../../src/tools/helpers/suggest-fix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,mBAAmB,GAAG;IAC1B,WAAW,EAAE,CAAC;SACX,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;QAC5E,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QACnD,QAAQ,EAAE,CAAC;aACR,MAAM,CAAC;YACN,IAAI,EAAE,CAAC,CAAC,MA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C,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;gBAC3C,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBACrE,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBAC9C,OAAO;wBACL,IAAI;wBACJ,OAAO,EAAE,IAAI,CAAC,OAAO;wBACrB,GAAG,OAAO;qBACX,CAAC;gBACJ,CAAC;gBACD,OAAO;oBACL,IAAI;oBACJ,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,UAAU,EACR,6LAA6L;oBAC/L,UAAU,EAAE,KAAc;iBAC3B,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAuB,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool registration entry point.
|
|
3
|
+
*
|
|
4
|
+
* Each category module exports a `register*` function. They're called
|
|
5
|
+
* here in order; ordering doesn't affect behavior but keeps the
|
|
6
|
+
* declaration site tidy.
|
|
7
|
+
*
|
|
8
|
+
* Tools planned (see SPEC.md / per-tool docs):
|
|
9
|
+
* Category A — Authoring: rego_format, rego_check, rego_lint,
|
|
10
|
+
* rego_parse_ast, rego_inspect,
|
|
11
|
+
* rego_capabilities, rego_deps
|
|
12
|
+
* Category B — Evaluation: rego_eval, rego_eval_with_explain,
|
|
13
|
+
* rego_eval_with_profile,
|
|
14
|
+
* rego_eval_with_coverage, rego_test,
|
|
15
|
+
* rego_bench, rego_compile_query
|
|
16
|
+
* Category C — Bundles: opa_bundle_build, opa_bundle_sign
|
|
17
|
+
* Category D — Server mgmt: opa_list_policies, opa_get_policy,
|
|
18
|
+
* opa_put_policy, opa_delete_policy,
|
|
19
|
+
* opa_get_data, opa_put_data,
|
|
20
|
+
* opa_patch_data, opa_query_decision,
|
|
21
|
+
* opa_compile_query, opa_health,
|
|
22
|
+
* opa_status, opa_config
|
|
23
|
+
* Category E — Helpers: rego_explain_decision,
|
|
24
|
+
* rego_generate_test_skeleton,
|
|
25
|
+
* rego_describe_policy,
|
|
26
|
+
* rego_suggest_fix
|
|
27
|
+
*/
|
|
28
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
29
|
+
import type { Config } from '../config.js';
|
|
30
|
+
export declare function registerTools(server: McpServer, config: Config): void;
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAO3C,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAMrE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { registerAuthoringTools } from './authoring/index.js';
|
|
2
|
+
import { registerBundleTools } from './bundles/index.js';
|
|
3
|
+
import { registerEvaluationTools } from './evaluation/index.js';
|
|
4
|
+
import { registerHelperTools } from './helpers/index.js';
|
|
5
|
+
import { registerServerManagementTools } from './server-management/index.js';
|
|
6
|
+
export function registerTools(server, config) {
|
|
7
|
+
registerAuthoringTools(server, config);
|
|
8
|
+
registerEvaluationTools(server, config);
|
|
9
|
+
registerBundleTools(server, config);
|
|
10
|
+
registerServerManagementTools(server, config);
|
|
11
|
+
registerHelperTools(server, config);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AA8BA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAE7E,MAAM,UAAU,aAAa,CAAC,MAAiB,EAAE,MAAc;IAC7D,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,6BAA6B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ToolEnvelope, ToolErrorCode } from '../../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Translate an exception thrown by OpaClient into a structured error
|
|
4
|
+
* envelope. `notFoundCode` lets a tool override the default 404
|
|
5
|
+
* mapping (which is generic) with something specific like
|
|
6
|
+
* `POLICY_NOT_FOUND`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function mapOpaClientError(e: unknown, notFoundCode?: ToolErrorCode): ToolEnvelope<never>;
|
|
9
|
+
//# sourceMappingURL=_shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../../src/tools/server-management/_shared.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAElE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,OAAO,EACV,YAAY,GAAE,aAA+B,GAC5C,YAAY,CAAC,KAAK,CAAC,CA0BrB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the server-management tool category. Maps the
|
|
3
|
+
* OpaClient's exception classes to the structured error codes the tool
|
|
4
|
+
* envelope contract defines.
|
|
5
|
+
*/
|
|
6
|
+
import { err } from '../../lib/errors.js';
|
|
7
|
+
import { OpaAuthError, OpaHttpError, OpaUnreachableError } from '../../lib/opa-client.js';
|
|
8
|
+
/**
|
|
9
|
+
* Translate an exception thrown by OpaClient into a structured error
|
|
10
|
+
* envelope. `notFoundCode` lets a tool override the default 404
|
|
11
|
+
* mapping (which is generic) with something specific like
|
|
12
|
+
* `POLICY_NOT_FOUND`.
|
|
13
|
+
*/
|
|
14
|
+
export function mapOpaClientError(e, notFoundCode = 'UNKNOWN_ERROR') {
|
|
15
|
+
if (e instanceof OpaUnreachableError) {
|
|
16
|
+
return err('OPA_UNREACHABLE', `OPA server unreachable at ${e.url}`, {
|
|
17
|
+
hint: 'Confirm OPA_URL points at a running OPA server (e.g. `curl $OPA_URL/health`).',
|
|
18
|
+
details: { url: e.url },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (e instanceof OpaAuthError) {
|
|
22
|
+
return err('OPA_AUTH_FAILED', 'OPA rejected the request with 401 Unauthorized.', {
|
|
23
|
+
hint: 'Set OPA_TOKEN to a valid bearer token, or remove the auth requirement on the OPA server.',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (e instanceof OpaHttpError) {
|
|
27
|
+
if (e.status === 404) {
|
|
28
|
+
return err(notFoundCode, `OPA returned 404 Not Found.`, {
|
|
29
|
+
details: { status: e.status, body: e.body },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return err('UNKNOWN_ERROR', `OPA returned HTTP ${e.status}.`, {
|
|
33
|
+
details: { status: e.status, body: e.body },
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const message = e instanceof Error ? e.message : 'Unknown error';
|
|
37
|
+
return err('UNKNOWN_ERROR', message, {
|
|
38
|
+
details: e instanceof Error ? { stack: e.stack } : { value: e },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=_shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../../src/tools/server-management/_shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG1F;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,CAAU,EACV,eAA8B,eAAe;IAE7C,IAAI,CAAC,YAAY,mBAAmB,EAAE,CAAC;QACrC,OAAO,GAAG,CAAC,iBAAiB,EAAE,6BAA6B,CAAC,CAAC,GAAG,EAAE,EAAE;YAClE,IAAI,EAAE,+EAA+E;YACrF,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE;SACxB,CAAC,CAAC;IACL,CAAC;IACD,IAAI,CAAC,YAAY,YAAY,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,iBAAiB,EAAE,iDAAiD,EAAE;YAC/E,IAAI,EAAE,0FAA0F;SACjG,CAAC,CAAC;IACL,CAAC;IACD,IAAI,CAAC,YAAY,YAAY,EAAE,CAAC;QAC9B,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACrB,OAAO,GAAG,CAAC,YAAY,EAAE,6BAA6B,EAAE;gBACtD,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;aAC5C,CAAC,CAAC;QACL,CAAC;QACD,OAAO,GAAG,CAAC,eAAe,EAAE,qBAAqB,CAAC,CAAC,MAAM,GAAG,EAAE;YAC5D,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;IACD,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;IACjE,OAAO,GAAG,CAAC,eAAe,EAAE,OAAO,EAAE;QACnC,OAAO,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;KAChE,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/tools/server-management/data.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAa9C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CA0FzE"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-document tools: opa_get_data, opa_put_data, opa_patch_data.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { OpaClient } from '../../lib/opa-client.js';
|
|
6
|
+
import { ok } from '../../lib/errors.js';
|
|
7
|
+
import { withToolEnvelope } from '../../lib/tool-helpers.js';
|
|
8
|
+
import { mapOpaClientError } from './_shared.js';
|
|
9
|
+
function dataPath(path) {
|
|
10
|
+
// Strip leading "data." or "/" — server always prepends /v1/data/.
|
|
11
|
+
const stripped = path.replace(/^data\./, '').replace(/^\/+/, '');
|
|
12
|
+
// Convert dotted form to slash form: "users.alice" -> "users/alice".
|
|
13
|
+
return `/v1/data/${stripped.replace(/\./g, '/')}`;
|
|
14
|
+
}
|
|
15
|
+
export function registerDataTools(server, config) {
|
|
16
|
+
const opa = new OpaClient(config);
|
|
17
|
+
server.registerTool('opa_get_data', {
|
|
18
|
+
title: 'Read data from OPA',
|
|
19
|
+
description: "Read a path from OPA's data hierarchy. The `path` argument may be in dotted form (`users.alice`) or slash form (`users/alice`).",
|
|
20
|
+
inputSchema: {
|
|
21
|
+
path: z.string().min(1).describe('Data path under `data.`, e.g. "users" or "users/alice".'),
|
|
22
|
+
},
|
|
23
|
+
}, async ({ path }) => {
|
|
24
|
+
return withToolEnvelope(config, async () => {
|
|
25
|
+
try {
|
|
26
|
+
const data = await opa.request({
|
|
27
|
+
method: 'GET',
|
|
28
|
+
path: dataPath(path),
|
|
29
|
+
});
|
|
30
|
+
return ok({ result: data.result });
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
return mapOpaClientError(e);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
server.registerTool('opa_put_data', {
|
|
38
|
+
title: 'Write data to OPA',
|
|
39
|
+
description: 'Write or replace a value at the given data path. Body is sent as JSON.',
|
|
40
|
+
inputSchema: {
|
|
41
|
+
path: z.string().min(1).describe('Data path to write to.'),
|
|
42
|
+
value: z.unknown().describe('JSON value to store at this path.'),
|
|
43
|
+
},
|
|
44
|
+
}, async ({ path, value }) => {
|
|
45
|
+
return withToolEnvelope(config, async () => {
|
|
46
|
+
try {
|
|
47
|
+
await opa.request({
|
|
48
|
+
method: 'PUT',
|
|
49
|
+
path: dataPath(path),
|
|
50
|
+
body: value,
|
|
51
|
+
});
|
|
52
|
+
return ok({ path, written: true });
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
return mapOpaClientError(e);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
server.registerTool('opa_patch_data', {
|
|
60
|
+
title: 'Patch data on OPA',
|
|
61
|
+
description: 'Apply a JSON Patch (RFC 6902) to the data document. Each operation is `{ op, path, value? }`.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
path: z.string().min(1).describe('Data path the patch is applied to. Use "" for the root.'),
|
|
64
|
+
operations: z
|
|
65
|
+
.array(z.object({
|
|
66
|
+
op: z.enum(['add', 'remove', 'replace']),
|
|
67
|
+
path: z.string(),
|
|
68
|
+
value: z.unknown().optional(),
|
|
69
|
+
}))
|
|
70
|
+
.min(1)
|
|
71
|
+
.describe('Array of JSON Patch operations.'),
|
|
72
|
+
},
|
|
73
|
+
}, async ({ path, operations }) => {
|
|
74
|
+
return withToolEnvelope(config, async () => {
|
|
75
|
+
try {
|
|
76
|
+
await opa.request({
|
|
77
|
+
method: 'PATCH',
|
|
78
|
+
path: dataPath(path),
|
|
79
|
+
body: operations,
|
|
80
|
+
headers: { 'Content-Type': 'application/json-patch+json' },
|
|
81
|
+
});
|
|
82
|
+
return ok({ path, patched: true });
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
return mapOpaClientError(e);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../../src/tools/server-management/data.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,iBAA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AAC,CAAC;iBACN,QAAQ,CAAC,iCAAiC,CAAC;SAC/C;KACF,EACD,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;QAC7B,OAAO,gBAAgB,CAAqC,MAAM,EAAE,KAAK,IAAI,EAAE;YAC7E,IAAI,CAAC;gBACH,MAAM,GAAG,CAAC,OAAO,CAAC;oBAChB,MAAM,EAAE,OAAO;oBACf,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;oBACpB,IAAI,EAAE,UAAU;oBAChB,OAAO,EAAE,EAAE,cAAc,EAAE,6BAA6B,EAAE;iBAC3D,CAAC,CAAC;gBACH,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decisions.d.ts","sourceRoot":"","sources":["../../../src/tools/server-management/decisions.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAW9C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAsF7E"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision-query tools that talk to a running OPA over REST:
|
|
3
|
+
* opa_query_decision, opa_compile_query.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { OpaClient } from '../../lib/opa-client.js';
|
|
7
|
+
import { ok } from '../../lib/errors.js';
|
|
8
|
+
import { withToolEnvelope } from '../../lib/tool-helpers.js';
|
|
9
|
+
import { mapOpaClientError } from './_shared.js';
|
|
10
|
+
function dataPath(path) {
|
|
11
|
+
const stripped = path.replace(/^data\./, '').replace(/^\/+/, '');
|
|
12
|
+
return `/v1/data/${stripped.replace(/\./g, '/')}`;
|
|
13
|
+
}
|
|
14
|
+
export function registerDecisionTools(server, config) {
|
|
15
|
+
const opa = new OpaClient(config);
|
|
16
|
+
server.registerTool('opa_query_decision', {
|
|
17
|
+
title: 'Query OPA decision',
|
|
18
|
+
description: 'Evaluate a decision against the running OPA server. POSTs to the data path with `{input}` and returns whatever the rule produces. Use this to ask the server "given this input, what does data.X.allow say?"',
|
|
19
|
+
inputSchema: {
|
|
20
|
+
path: z
|
|
21
|
+
.string()
|
|
22
|
+
.min(1)
|
|
23
|
+
.describe('Decision path under `data.`, e.g. "rbac/allow" or "rbac.allow".'),
|
|
24
|
+
input: z.unknown().optional().describe('Input document to evaluate against.'),
|
|
25
|
+
explain: z
|
|
26
|
+
.enum(['notes', 'fails', 'full', 'debug'])
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Include a trace at the requested level.'),
|
|
29
|
+
metrics: z.boolean().optional().describe('Include metrics in the response.'),
|
|
30
|
+
},
|
|
31
|
+
}, async ({ path, input, explain, metrics }) => {
|
|
32
|
+
return withToolEnvelope(config, async () => {
|
|
33
|
+
try {
|
|
34
|
+
const query = {};
|
|
35
|
+
if (explain)
|
|
36
|
+
query['explain'] = explain;
|
|
37
|
+
if (metrics)
|
|
38
|
+
query['metrics'] = true;
|
|
39
|
+
const data = await opa.request({
|
|
40
|
+
method: 'POST',
|
|
41
|
+
path: dataPath(path),
|
|
42
|
+
body: input !== undefined ? { input } : {},
|
|
43
|
+
query,
|
|
44
|
+
});
|
|
45
|
+
return ok({
|
|
46
|
+
result: data.result,
|
|
47
|
+
explanation: data.explanation,
|
|
48
|
+
metrics: data.metrics,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return mapOpaClientError(e);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
server.registerTool('opa_compile_query', {
|
|
57
|
+
title: 'Compile (partially evaluate) a query on OPA',
|
|
58
|
+
description: "Send a query to the OPA server's `/v1/compile` endpoint for partial evaluation. Returns the residual query — what remains after substituting in everything that's known.",
|
|
59
|
+
inputSchema: {
|
|
60
|
+
query: z.string().min(1).describe('Rego query to compile, e.g. "data.rbac.allow == true".'),
|
|
61
|
+
input: z.unknown().optional().describe('Optional partial input document.'),
|
|
62
|
+
unknowns: z
|
|
63
|
+
.array(z.string())
|
|
64
|
+
.optional()
|
|
65
|
+
.describe('Refs to treat as unknown (default: ["input"]).'),
|
|
66
|
+
},
|
|
67
|
+
}, async ({ query, input, unknowns }) => {
|
|
68
|
+
return withToolEnvelope(config, async () => {
|
|
69
|
+
try {
|
|
70
|
+
const body = { query };
|
|
71
|
+
if (input !== undefined)
|
|
72
|
+
body['input'] = input;
|
|
73
|
+
body['unknowns'] = unknowns?.length ? unknowns : ['input'];
|
|
74
|
+
const data = await opa.request({
|
|
75
|
+
method: 'POST',
|
|
76
|
+
path: '/v1/compile',
|
|
77
|
+
body,
|
|
78
|
+
});
|
|
79
|
+
return ok({ result: data.result });
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
return mapOpaClientError(e);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=decisions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decisions.js","sourceRoot":"","sources":["../../../src/tools/server-management/decisions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B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E;YAC9D,IAAI,CAAC;gBACH,MAAM,IAAI,GAA4B,EAAE,KAAK,EAAE,CAAC;gBAChD,IAAI,KAAK,KAAK,SAAS;oBAAE,IAAI,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;gBAC/C,IAAI,CAAC,UAAU,CAAC,GAAG,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBAC3D,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAsB;oBAClD,MAAM,EAAE,MAAM;oBACd,IAAI,EAAE,aAAa;oBACnB,IAAI;iBACL,CAAC,CAAC;gBACH,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Category D — OPA server management.
|
|
3
|
+
*
|
|
4
|
+
* Tools in this category talk to a running OPA server via its REST
|
|
5
|
+
* API. They require `OPA_URL` to point at a reachable server (default
|
|
6
|
+
* `http://localhost:8181`).
|
|
7
|
+
*/
|
|
8
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
9
|
+
import type { Config } from '../../config.js';
|
|
10
|
+
export declare function registerServerManagementTools(server: McpServer, config: Config): void;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/server-management/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAM9C,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAKrF"}
|