@the-hades-organization/strig-mcp 0.0.0-stage → 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 +89 -2
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +20 -0
- package/dist/src/policy.d.ts +10 -0
- package/dist/src/policy.js +36 -0
- package/dist/src/server.d.ts +4 -0
- package/dist/src/server.js +68 -0
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @the-hades-organization/strig-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io) server that lets an AI agent ask questions about an authorization policy written for [Strig](https://strig.vercel.app): may this subject do that, why, what would change the answer, and what is wrong with the policy.
|
|
4
|
+
|
|
5
|
+
It runs over stdio, reads one policy from a path you give it, and uses no network. It uses the published Node binding (`@the-hades-organization/strig`), so the answers are the ones your application gets.
|
|
6
|
+
|
|
7
|
+
## Configuration
|
|
8
|
+
|
|
9
|
+
The policy comes from the configuration, never from a tool call:
|
|
10
|
+
|
|
11
|
+
| Option | Meaning |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `--policy <path>` | A `.strig` file, a directory of `.strig` files, or the canonical JSON of a policy (`.json`) |
|
|
14
|
+
| `STRIG_POLICY` | The same, as an environment variable, used when `--policy` is absent |
|
|
15
|
+
|
|
16
|
+
The grants, tuples and subjects the policy declares are the data the questions run against. The server does not start when the policy does not load, so it never runs with an open or empty one.
|
|
17
|
+
|
|
18
|
+
### Claude Code
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
claude mcp add strig -- npx -y @the-hades-organization/strig-mcp --policy /path/to/policy.strig
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Claude Desktop
|
|
25
|
+
|
|
26
|
+
In `claude_desktop_config.json`:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"strig": {
|
|
32
|
+
"command": "npx",
|
|
33
|
+
"args": ["-y", "@the-hades-organization/strig-mcp", "--policy", "/path/to/policy.strig"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Cursor
|
|
40
|
+
|
|
41
|
+
In `.cursor/mcp.json` (or `~/.cursor/mcp.json`):
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"mcpServers": {
|
|
46
|
+
"strig": {
|
|
47
|
+
"command": "npx",
|
|
48
|
+
"args": ["-y", "@the-hades-organization/strig-mcp", "--policy", "/path/to/policy.strig"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Tools
|
|
55
|
+
|
|
56
|
+
| Tool | What it answers |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `check` | May the subject do this to the resource? `{ allowed, effect, reason }`. |
|
|
59
|
+
| `explain` | Why: the grants that applied, the overrides and the conditions. |
|
|
60
|
+
| `why_not` | What would turn a denial into an allow; `remedies: null` when it is already allowed. |
|
|
61
|
+
| `lint` | Static findings about the policy: shadowed grants, unreachable denies, unused roles. |
|
|
62
|
+
| `convert` | A policy text written in another syntax (`blocks`, `rules`, `actors`). Text to text. |
|
|
63
|
+
| `list` | The filter of the resources of a kind the subject holds a permission on. |
|
|
64
|
+
| `who_can` | Who holds a permission, anywhere or on one resource. |
|
|
65
|
+
|
|
66
|
+
A subject is one the policy declares (`user:ana`, or `ana` when the name is unique) or a subject object. A resource is a path from the most specific step to the broadest: `project:p1/org:acme`. Pass `now` (milliseconds, UTC) to questions about grants and tuples with a validity window: without an instant they do not open access.
|
|
67
|
+
|
|
68
|
+
Deny is the default answer. When the server cannot decide (an unknown subject, a malformed resource), `check` replies with an error and `allowed: false`; it never answers true on a failure.
|
|
69
|
+
|
|
70
|
+
The server does not authenticate anyone: the subject you give it is taken as established.
|
|
71
|
+
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
npm install
|
|
76
|
+
npm test
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`npm test` compiles the package and runs `test/server.test.ts`, which calls every tool through the protocol against `test/example.strig`.
|
|
80
|
+
|
|
81
|
+
## Releasing
|
|
82
|
+
|
|
83
|
+
The package is published by `.github/workflows/release-mcp.yml`, separately from the library release. Raise `version` in `package.json`, merge to `main`, wait for CI, then push a tag with the same version:
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
git tag mcp-v0.1.0
|
|
87
|
+
git push origin mcp-v0.1.0
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The workflow checks that the commit is on `main`, that CI passed on it and that the tag matches `package.json`, then runs the tests and publishes with provenance. A version with a hyphen (`0.2.0-rc.1`) goes out under the `next` tag.
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// strig-mcp --policy <path> (or STRIG_POLICY=<path>)
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { loadPolicy } from './policy.js';
|
|
5
|
+
import { createServer } from './server.js';
|
|
6
|
+
const flag = process.argv.indexOf('--policy');
|
|
7
|
+
const path = (flag >= 0 ? process.argv[flag + 1] : undefined) ?? process.env.STRIG_POLICY;
|
|
8
|
+
if (!path) {
|
|
9
|
+
console.error('strig-mcp: pass the policy with --policy <path> or STRIG_POLICY (a .strig file, a directory of them, or policy JSON).');
|
|
10
|
+
process.exit(2);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const loaded = await loadPolicy(path);
|
|
14
|
+
await createServer(loaded).connect(new StdioServerTransport());
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
// stdout belongs to the protocol: say it on stderr, and never start with a policy that did not load.
|
|
18
|
+
console.error(`strig-mcp: ${error.message}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context, Engine, NativeStrig, PolicyDocument, Subject } from '@the-hades-organization/strig';
|
|
2
|
+
export interface Loaded {
|
|
3
|
+
strig: NativeStrig;
|
|
4
|
+
policy: PolicyDocument;
|
|
5
|
+
engine: Engine;
|
|
6
|
+
context(now?: number): Context;
|
|
7
|
+
subject(reference: string | Subject): Subject;
|
|
8
|
+
}
|
|
9
|
+
/** Reads a `.strig` file, a directory of `.strig` files or the canonical JSON of a policy. Throws when it cannot. */
|
|
10
|
+
export declare function loadPolicy(path: string): Promise<Loaded>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Loads the policy named in the configuration and answers questions about it. No network, and no tool takes a path.
|
|
2
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
3
|
+
import { load } from '@the-hades-organization/strig';
|
|
4
|
+
/** Reads a `.strig` file, a directory of `.strig` files or the canonical JSON of a policy. Throws when it cannot. */
|
|
5
|
+
export async function loadPolicy(path) {
|
|
6
|
+
const strig = await load({ backend: 'native' });
|
|
7
|
+
const policy = statSync(path).isDirectory()
|
|
8
|
+
? strig.loadProjectDir(path)
|
|
9
|
+
: path.endsWith('.json')
|
|
10
|
+
? JSON.parse(readFileSync(path, 'utf8'))
|
|
11
|
+
: strig.compile(readFileSync(path, 'utf8'), { file: path });
|
|
12
|
+
// The engine part of the policy; its grants, tuples and subjects are data for the context.
|
|
13
|
+
const { catalog, roles, relations, strategy, overrides, maxRelationDepth } = policy;
|
|
14
|
+
const spec = JSON.parse(JSON.stringify({ catalog, roles, relations, strategy, overrides, maxRelationDepth }));
|
|
15
|
+
const engine = new strig.Engine(spec);
|
|
16
|
+
const subjects = (policy.subjects ?? []);
|
|
17
|
+
return {
|
|
18
|
+
strig,
|
|
19
|
+
policy,
|
|
20
|
+
engine,
|
|
21
|
+
context: (now) => new strig.Context({ grants: (policy.grants ?? []), tuples: policy.tuples ?? [], ...(now === undefined ? {} : { now }) }),
|
|
22
|
+
subject(reference) {
|
|
23
|
+
if (typeof reference !== 'string')
|
|
24
|
+
return reference;
|
|
25
|
+
// `user:ana` or just `ana`; a name that more than one subject carries is refused, never guessed.
|
|
26
|
+
const at = reference.indexOf(':');
|
|
27
|
+
const kind = at >= 0 ? reference.slice(0, at) : undefined;
|
|
28
|
+
const id = at >= 0 ? reference.slice(at + 1) : reference;
|
|
29
|
+
const found = subjects.filter((s) => s.id === id && (kind === undefined || s.kind === kind));
|
|
30
|
+
if (found.length !== 1) {
|
|
31
|
+
throw new Error(found.length === 0 ? `the policy declares no subject ${reference}` : `${reference} is ambiguous: write kind:id`);
|
|
32
|
+
}
|
|
33
|
+
return found[0];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { scopeFromString } from '@the-hades-organization/strig';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
const subjectArg = z
|
|
5
|
+
.union([z.string(), z.object({ kind: z.string(), id: z.string().optional() }).passthrough()])
|
|
6
|
+
.describe('A subject the policy declares (`user:ana` or `ana`), or a subject object: { kind, id, roles, principals, attrs }.');
|
|
7
|
+
const resourceArg = z.string().describe('A resource path from the most specific step to the broadest: `project:p1/org:acme`.');
|
|
8
|
+
const nowArg = z
|
|
9
|
+
.number()
|
|
10
|
+
.int()
|
|
11
|
+
.nonnegative()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe('The instant of the decision in milliseconds (UTC). Without it, grants and tuples with a validity window do not open access.');
|
|
14
|
+
const languageArg = z.enum(['blocks', 'rules', 'actors']);
|
|
15
|
+
const ok = (value) => ({
|
|
16
|
+
content: [{ type: 'text', text: JSON.stringify(value, (_key, v) => (typeof v === 'bigint' ? v.toString() : v), 2) }],
|
|
17
|
+
});
|
|
18
|
+
/** A failure is reported as one, never as an answer: a `check` that fails says `allowed: false`. */
|
|
19
|
+
const failed = (error, extra) => {
|
|
20
|
+
const e = error;
|
|
21
|
+
return { ...ok({ ...extra, error: e?.message ?? String(error), errorCode: e?.code, diagnostics: e?.diagnostics }), isError: true };
|
|
22
|
+
};
|
|
23
|
+
const guard = (extra, fn) => {
|
|
24
|
+
try {
|
|
25
|
+
return ok(fn());
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return failed(error, extra);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/** The server, with the policy already loaded. Connect it to a transport. */
|
|
32
|
+
export function createServer(loaded) {
|
|
33
|
+
const server = new McpServer({ name: 'strig', version: '0.1.0' });
|
|
34
|
+
const question = (args) => ({
|
|
35
|
+
subject: loaded.subject(args.subject),
|
|
36
|
+
permission: args.permission,
|
|
37
|
+
resource: scopeFromString(args.resource),
|
|
38
|
+
});
|
|
39
|
+
const asked = { subject: subjectArg, permission: z.string(), resource: resourceArg, now: nowArg };
|
|
40
|
+
server.registerTool('check', {
|
|
41
|
+
description: 'May the subject do this to the resource under the loaded policy? Deny is the default. An error comes back as an error with allowed: false, never as an allow.',
|
|
42
|
+
inputSchema: asked,
|
|
43
|
+
}, (args) => guard({ allowed: false }, () => {
|
|
44
|
+
const decision = loaded.engine.decide(loaded.context(args.now), question(args));
|
|
45
|
+
return { allowed: decision.effect === 'allow', effect: decision.effect, reason: decision.reason };
|
|
46
|
+
}));
|
|
47
|
+
server.registerTool('explain', { description: 'Why a request came out as it did: the grants that applied, the overrides and the conditions, as a trace.', inputSchema: asked }, (args) => guard({}, () => loaded.engine.explain(loaded.context(args.now), question(args))));
|
|
48
|
+
server.registerTool('why_not', { description: 'For a denied request, the changes that would allow it, smallest first. `remedies` is null when it is already allowed.', inputSchema: asked }, (args) => guard({}, () => ({ remedies: loaded.engine.whyNot(loaded.context(args.now), question(args)) })));
|
|
49
|
+
server.registerTool('lint', {
|
|
50
|
+
description: 'Static findings about the loaded policy: shadowed grants, unreachable denies, unused roles and more.',
|
|
51
|
+
inputSchema: { ignore: z.array(z.string()).optional().describe('Codes (`L004`) or names (`unused-role`) to leave out.') },
|
|
52
|
+
}, (args) => guard({}, () => ({ findings: loaded.strig.lint(loaded.policy, args.ignore ? { ignore: args.ignore } : undefined) })));
|
|
53
|
+
server.registerTool('convert', {
|
|
54
|
+
description: 'Writes a policy given as text in another syntax of the policy language (`blocks`, `rules` or `actors`). Text to text: the loaded policy is not touched.',
|
|
55
|
+
inputSchema: { text: z.string().max(1_000_000), language: languageArg },
|
|
56
|
+
}, (args) => guard({}, () => ({ text: loaded.strig.convert(args.text, args.language) })));
|
|
57
|
+
server.registerTool('list', {
|
|
58
|
+
description: 'The filter of the resources of a kind on which the subject holds the permission.',
|
|
59
|
+
inputSchema: { subject: subjectArg, permission: z.string(), kind: z.string(), now: nowArg },
|
|
60
|
+
}, (args) => guard({}, () => loaded.engine.list(loaded.context(args.now), loaded.subject(args.subject), args.permission, args.kind)));
|
|
61
|
+
server.registerTool('who_can', {
|
|
62
|
+
description: 'Who holds the permission: anywhere, or on one resource when `resource` is given.',
|
|
63
|
+
inputSchema: { permission: z.string(), resource: resourceArg.optional(), now: nowArg },
|
|
64
|
+
}, (args) => guard({}, () => args.resource === undefined
|
|
65
|
+
? { parties: loaded.engine.whoCan(loaded.context(args.now), args.permission) }
|
|
66
|
+
: loaded.engine.whoCanOn(loaded.context(args.now), args.permission, scopeFromString(args.resource))));
|
|
67
|
+
return server;
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-hades-organization/strig-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for Strig: lets an AI agent check, explain and lint an authorization policy from a local file.",
|
|
5
|
+
"keywords": ["mcp", "model-context-protocol", "authorization", "rbac", "abac", "rebac", "policy", "strig"],
|
|
6
|
+
"homepage": "https://strig.vercel.app",
|
|
7
|
+
"bugs": { "url": "https://github.com/The-Hades-Organization/Strig/issues" },
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"repository": { "type": "git", "url": "git+https://github.com/The-Hades-Organization/Strig.git", "directory": "packages/strig-mcp" },
|
|
11
|
+
"bin": { "strig-mcp": "./dist/src/cli.js" },
|
|
12
|
+
"main": "./dist/src/server.js",
|
|
13
|
+
"types": "./dist/src/server.d.ts",
|
|
14
|
+
"files": ["dist/src/", "README.md"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"test": "npm run build && node --test dist/test/server.test.js"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@modelcontextprotocol/sdk": "1.17.4",
|
|
21
|
+
"@the-hades-organization/strig": "1.0.1",
|
|
22
|
+
"zod": "3.25.76"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^22.10.0",
|
|
26
|
+
"typescript": "~5.9.3"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18.17"
|
|
30
|
+
}
|
|
31
|
+
}
|