@evantahler/mcpx 0.17.0 → 0.17.1
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/.claude/skills/mcpx.md +29 -0
- package/.cursor/rules/mcpx.mdc +26 -3
- package/README.md +84 -0
- package/package.json +1 -1
- package/src/cli.ts +4 -0
- package/src/commands/allow.ts +163 -0
- package/src/commands/deny.ts +134 -0
- package/src/lib/client-settings.ts +210 -0
package/.claude/skills/mcpx.md
CHANGED
|
@@ -8,6 +8,26 @@ trigger: when the user wants to interact with external services, APIs, or MCP to
|
|
|
8
8
|
|
|
9
9
|
You have access to external tools via `mcpx`. Use this workflow:
|
|
10
10
|
|
|
11
|
+
## 0. Self-authorize (if needed)
|
|
12
|
+
|
|
13
|
+
By default, Claude Code prompts the user for every `mcpx exec` call. If the user has approved `Bash(mcpx allow:*)` (you cannot do this yourself — the user must approve it when prompted), you can grant yourself granular permissions before executing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
mcpx allow <server> <tool>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This writes a specific pattern to `.claude/settings.local.json`. After that, `mcpx exec <server> <tool>` runs without prompting.
|
|
20
|
+
|
|
21
|
+
For broader access:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
mcpx allow <server> # all tools on a server
|
|
25
|
+
mcpx allow --all-read # search, info, list, servers, ping, etc.
|
|
26
|
+
mcpx allow --all # all mcpx exec calls
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Important:** If the user has not approved `Bash(mcpx allow:*)`, skip this step — Claude Code will prompt the user directly for each `mcpx exec` call instead.
|
|
30
|
+
|
|
11
31
|
## 1. Search for tools
|
|
12
32
|
|
|
13
33
|
```bash
|
|
@@ -152,6 +172,15 @@ mcpx deauth <server> # remove stored auth
|
|
|
152
172
|
| `mcpx task get <server> <taskId>` | Get task status |
|
|
153
173
|
| `mcpx task result <server> <taskId>` | Retrieve completed task result |
|
|
154
174
|
| `mcpx task cancel <server> <taskId>` | Cancel a running task |
|
|
175
|
+
| `mcpx allow <server>` | Allow agent to exec all tools on a server |
|
|
176
|
+
| `mcpx allow <server> <tools...>` | Allow specific tools only |
|
|
177
|
+
| `mcpx allow --all` | Allow all mcpx exec calls |
|
|
178
|
+
| `mcpx allow --all-read` | Allow read-only commands |
|
|
179
|
+
| `mcpx allow --list` | Show current mcpx permissions |
|
|
180
|
+
| `mcpx allow --cursor <server>` | Target Cursor instead of Claude |
|
|
181
|
+
| `mcpx deny <server>` | Remove server permissions |
|
|
182
|
+
| `mcpx deny --all` | Remove all mcpx permissions |
|
|
183
|
+
| `mcpx deny --cursor <server>` | Target Cursor instead of Claude |
|
|
155
184
|
| `mcpx check-update` | Check for a newer version of mcpx |
|
|
156
185
|
| `mcpx upgrade` | Upgrade mcpx to the latest version|
|
|
157
186
|
|
package/.cursor/rules/mcpx.mdc
CHANGED
|
@@ -101,6 +101,22 @@ mcpx task list my-server
|
|
|
101
101
|
|
|
102
102
|
Some servers request user input mid-operation. mcpx handles this automatically in interactive mode. Use `-N` / `--no-interactive` to decline all elicitation (for scripts/CI), or `--json` to handle elicitation programmatically via stdin/stdout.
|
|
103
103
|
|
|
104
|
+
## 6. Self-authorize (if needed)
|
|
105
|
+
|
|
106
|
+
Cursor prompts you for every `mcpx exec` call. You can grant yourself granular permissions:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
mcpx allow <server> --cursor # all tools on a server
|
|
110
|
+
mcpx allow <server> <tool> --cursor # specific tool
|
|
111
|
+
mcpx allow --all-read --cursor # search, info, list, etc.
|
|
112
|
+
mcpx allow --all --cursor # all mcpx exec calls
|
|
113
|
+
mcpx allow --list --cursor # show current permissions
|
|
114
|
+
mcpx deny <server> --cursor # revoke server permissions
|
|
115
|
+
mcpx deny --all --cursor # revoke all permissions
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This writes `Shell(mcpx exec:server:*)` patterns to `.cursor/cli.json`.
|
|
119
|
+
|
|
104
120
|
## Authentication
|
|
105
121
|
|
|
106
122
|
```bash
|
|
@@ -132,7 +148,7 @@ mcpx deauth <server> # remove stored auth
|
|
|
132
148
|
| `mcpx index -i` | Show index status |
|
|
133
149
|
| `mcpx auth <server>` | Authenticate with OAuth |
|
|
134
150
|
| `mcpx auth <server> -s` | Check token status and TTL |
|
|
135
|
-
| `mcpx auth <server> -r`
|
|
151
|
+
| `mcpx auth <server> -r` | Force token refresh |
|
|
136
152
|
| `mcpx auth <server> --no-index` | Authenticate without rebuilding index |
|
|
137
153
|
| `mcpx deauth <server>` | Remove stored authentication |
|
|
138
154
|
| `mcpx ping` | Check connectivity to all servers |
|
|
@@ -152,8 +168,15 @@ mcpx deauth <server> # remove stored auth
|
|
|
152
168
|
| `mcpx task get <server> <taskId>` | Get task status |
|
|
153
169
|
| `mcpx task result <server> <taskId>` | Retrieve completed task result |
|
|
154
170
|
| `mcpx task cancel <server> <taskId>` | Cancel a running task |
|
|
155
|
-
| `mcpx
|
|
156
|
-
| `mcpx
|
|
171
|
+
| `mcpx allow <server> --cursor` | Allow exec all tools on a server |
|
|
172
|
+
| `mcpx allow <server> <tools...> --cursor` | Allow specific tools only |
|
|
173
|
+
| `mcpx allow --all --cursor` | Allow all mcpx exec calls |
|
|
174
|
+
| `mcpx allow --all-read --cursor` | Allow read-only commands |
|
|
175
|
+
| `mcpx allow --list --cursor` | Show current permissions |
|
|
176
|
+
| `mcpx deny <server> --cursor` | Remove server permissions |
|
|
177
|
+
| `mcpx deny --all --cursor` | Remove all mcpx permissions |
|
|
178
|
+
| `mcpx check-update` | Check for a newer version of mcpx |
|
|
179
|
+
| `mcpx upgrade` | Upgrade mcpx to the latest version|
|
|
157
180
|
|
|
158
181
|
## Global flags
|
|
159
182
|
|
package/README.md
CHANGED
|
@@ -104,6 +104,14 @@ mcpx search -n 5 "manage pull requests"
|
|
|
104
104
|
| `mcpx task get <server> <taskId>` | Get task status |
|
|
105
105
|
| `mcpx task result <server> <taskId>` | Retrieve completed task result |
|
|
106
106
|
| `mcpx task cancel <server> <taskId>` | Cancel a running task |
|
|
107
|
+
| `mcpx allow <server>` | Allow an agent to exec all tools on a server |
|
|
108
|
+
| `mcpx allow <server> <tools...>` | Allow specific tools only |
|
|
109
|
+
| `mcpx allow --all` | Allow all mcpx exec calls |
|
|
110
|
+
| `mcpx allow --all-read` | Allow read-only commands (search, info, list, etc.) |
|
|
111
|
+
| `mcpx allow --list` | Show current mcpx-related permissions |
|
|
112
|
+
| `mcpx allow --cursor <server>` | Allow for Cursor instead of Claude Code |
|
|
113
|
+
| `mcpx deny <server>` | Remove permissions for a server |
|
|
114
|
+
| `mcpx deny --all` | Remove all mcpx-related permissions |
|
|
107
115
|
| `mcpx check-update` | Check for a newer version of mcpx |
|
|
108
116
|
| `mcpx upgrade` | Upgrade mcpx to the latest version |
|
|
109
117
|
|
|
@@ -627,6 +635,82 @@ To execute tools:
|
|
|
627
635
|
Always search before executing — don't assume tool names.
|
|
628
636
|
```
|
|
629
637
|
|
|
638
|
+
## Permissions (Claude Code & Cursor)
|
|
639
|
+
|
|
640
|
+
AI agents like Claude Code and Cursor prompt users to approve each `mcpx exec` call. `mcpx allow` and `mcpx deny` manage fine-grained permission rules so agents can self-authorize specific tools without broad access.
|
|
641
|
+
|
|
642
|
+
**Key insight:** If the user allows the initial permission pattern once (safe — it only writes to local settings files), the agent can then grant itself access to specific tools as needed. This is an opt-in workflow — by default, agents cannot self-authorize and will prompt the user for each `mcpx exec` call.
|
|
643
|
+
|
|
644
|
+
```bash
|
|
645
|
+
# Allow all tools on a server (Claude Code, default)
|
|
646
|
+
mcpx allow github
|
|
647
|
+
|
|
648
|
+
# Allow for Cursor instead
|
|
649
|
+
mcpx allow github --cursor
|
|
650
|
+
|
|
651
|
+
# Allow specific tools only
|
|
652
|
+
mcpx allow github search_repositories get_file
|
|
653
|
+
|
|
654
|
+
# Allow read-only commands (search, info, list, servers, ping, etc.)
|
|
655
|
+
mcpx allow --all-read
|
|
656
|
+
|
|
657
|
+
# Allow all mcpx exec calls
|
|
658
|
+
mcpx allow --all
|
|
659
|
+
|
|
660
|
+
# Show current permissions across all scopes
|
|
661
|
+
mcpx allow --list
|
|
662
|
+
mcpx allow --list --cursor
|
|
663
|
+
|
|
664
|
+
# Preview what would be written
|
|
665
|
+
mcpx allow github --dry-run
|
|
666
|
+
|
|
667
|
+
# Revoke a server's permissions
|
|
668
|
+
mcpx deny github
|
|
669
|
+
|
|
670
|
+
# Revoke all mcpx permissions
|
|
671
|
+
mcpx deny --all
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
**Target flag** — by default, permissions target Claude Code. Use `--cursor` to target Cursor instead:
|
|
675
|
+
|
|
676
|
+
| Flag | Pattern prefix | Settings files |
|
|
677
|
+
| ----------- | -------------- | ----------------------------------------------- |
|
|
678
|
+
| _(default)_ | `Bash(…)` | `.claude/settings.local.json`, etc. |
|
|
679
|
+
| `--cursor` | `Shell(…)` | `.cursor/cli.json`, `~/.cursor/cli-config.json` |
|
|
680
|
+
|
|
681
|
+
**Scope flags** control where the permission is written:
|
|
682
|
+
|
|
683
|
+
| Flag | Claude Code file | Cursor file | Default |
|
|
684
|
+
| ----------- | ----------------------------- | --------------------------- | ------- |
|
|
685
|
+
| `--local` | `.claude/settings.local.json` | `.cursor/cli.json` | ✓ |
|
|
686
|
+
| `--project` | `.claude/settings.json` | `.cursor/cli.json` | |
|
|
687
|
+
| `--global` | `~/.claude/settings.json` | `~/.cursor/cli-config.json` | |
|
|
688
|
+
|
|
689
|
+
**`allow` options:**
|
|
690
|
+
|
|
691
|
+
| Flag | Purpose |
|
|
692
|
+
| ------------ | --------------------------------------------------- |
|
|
693
|
+
| `--all` | Allow all mcpx exec calls |
|
|
694
|
+
| `--all-read` | Allow read-only commands (search, info, list, etc.) |
|
|
695
|
+
| `--list` | Show current mcpx-related permissions |
|
|
696
|
+
| `--cursor` | Target Cursor settings instead of Claude Code |
|
|
697
|
+
| `--local` | Write to local settings (default) |
|
|
698
|
+
| `--project` | Write to project settings (shared) |
|
|
699
|
+
| `--global` | Write to global settings |
|
|
700
|
+
| `--dry-run` | Show patterns without writing |
|
|
701
|
+
|
|
702
|
+
**`deny` options:**
|
|
703
|
+
|
|
704
|
+
| Flag | Purpose |
|
|
705
|
+
| ------------ | --------------------------------------------- |
|
|
706
|
+
| `--all` | Remove all mcpx-related permissions |
|
|
707
|
+
| `--all-read` | Remove read-only command permissions |
|
|
708
|
+
| `--cursor` | Target Cursor settings instead of Claude Code |
|
|
709
|
+
| `--local` | Write to local settings (default) |
|
|
710
|
+
| `--project` | Write to project settings (shared) |
|
|
711
|
+
| `--global` | Write to global settings |
|
|
712
|
+
| `--dry-run` | Show what would be removed |
|
|
713
|
+
|
|
630
714
|
## Development
|
|
631
715
|
|
|
632
716
|
```bash
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -15,6 +15,8 @@ import { registerResourceCommand } from "./commands/resource.ts";
|
|
|
15
15
|
import { registerPromptCommand } from "./commands/prompt.ts";
|
|
16
16
|
import { registerServersCommand } from "./commands/servers.ts";
|
|
17
17
|
import { registerTaskCommand } from "./commands/task.ts";
|
|
18
|
+
import { registerAllowCommand } from "./commands/allow.ts";
|
|
19
|
+
import { registerDenyCommand } from "./commands/deny.ts";
|
|
18
20
|
import { registerCheckUpdateCommand } from "./commands/check-update.ts";
|
|
19
21
|
import { registerUpgradeCommand } from "./commands/upgrade.ts";
|
|
20
22
|
import { maybeCheckForUpdate } from "./update/background.ts";
|
|
@@ -53,6 +55,8 @@ registerResourceCommand(program);
|
|
|
53
55
|
registerPromptCommand(program);
|
|
54
56
|
registerServersCommand(program);
|
|
55
57
|
registerTaskCommand(program);
|
|
58
|
+
registerAllowCommand(program);
|
|
59
|
+
registerDenyCommand(program);
|
|
56
60
|
registerCheckUpdateCommand(program);
|
|
57
61
|
registerUpgradeCommand(program);
|
|
58
62
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { bold, cyan, dim, green, yellow } from "ansis";
|
|
3
|
+
import {
|
|
4
|
+
type Client,
|
|
5
|
+
type Scope,
|
|
6
|
+
resolveSettingsPath,
|
|
7
|
+
readClientSettings,
|
|
8
|
+
writeClientSettings,
|
|
9
|
+
execPattern,
|
|
10
|
+
readOnlyPatterns,
|
|
11
|
+
allExecPattern,
|
|
12
|
+
allowCommandPattern,
|
|
13
|
+
denyCommandPattern,
|
|
14
|
+
addPatterns,
|
|
15
|
+
getMcpxPatterns,
|
|
16
|
+
} from "../lib/client-settings.ts";
|
|
17
|
+
import { formatOutput } from "../output/format-output.ts";
|
|
18
|
+
import type { FormatOptions } from "../output/formatter.ts";
|
|
19
|
+
|
|
20
|
+
export function registerAllowCommand(program: Command) {
|
|
21
|
+
program
|
|
22
|
+
.command("allow")
|
|
23
|
+
.description("add permission rules for mcpx commands (Claude Code or Cursor)")
|
|
24
|
+
.argument("[server]", "server name to allow")
|
|
25
|
+
.argument("[tools...]", "specific tool names to allow")
|
|
26
|
+
.option("--all", "allow all mcpx exec calls")
|
|
27
|
+
.option("--all-read", "allow read-only commands (search, info, list, servers, ping, etc.)")
|
|
28
|
+
.option("--list", "show current mcpx-related permissions")
|
|
29
|
+
.option("--cursor", "target Cursor settings instead of Claude Code")
|
|
30
|
+
.option("--local", "write to local settings (default)")
|
|
31
|
+
.option("--project", "write to project settings (shared)")
|
|
32
|
+
.option("--global", "write to global settings")
|
|
33
|
+
.option("--dry-run", "show patterns without writing")
|
|
34
|
+
.action(
|
|
35
|
+
async (
|
|
36
|
+
server: string | undefined,
|
|
37
|
+
tools: string[],
|
|
38
|
+
options: {
|
|
39
|
+
all?: boolean;
|
|
40
|
+
allRead?: boolean;
|
|
41
|
+
list?: boolean;
|
|
42
|
+
cursor?: boolean;
|
|
43
|
+
local?: boolean;
|
|
44
|
+
project?: boolean;
|
|
45
|
+
global?: boolean;
|
|
46
|
+
dryRun?: boolean;
|
|
47
|
+
},
|
|
48
|
+
) => {
|
|
49
|
+
const formatOptions: FormatOptions = { json: program.opts().json };
|
|
50
|
+
const client: Client = options.cursor ? "cursor" : "claude";
|
|
51
|
+
|
|
52
|
+
// --list mode: show current permissions across all scopes
|
|
53
|
+
if (options.list) {
|
|
54
|
+
// Cursor maps local and project to the same file, so only show unique scopes
|
|
55
|
+
const scopes: Scope[] =
|
|
56
|
+
client === "cursor" ? ["local", "global"] : ["local", "project", "global"];
|
|
57
|
+
const results: { scope: Scope; path: string; patterns: string[] }[] = [];
|
|
58
|
+
|
|
59
|
+
for (const scope of scopes) {
|
|
60
|
+
const path = resolveSettingsPath(scope, client);
|
|
61
|
+
const settings = await readClientSettings(path);
|
|
62
|
+
const patterns = getMcpxPatterns(settings, client);
|
|
63
|
+
results.push({ scope, path, patterns });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log(
|
|
67
|
+
formatOutput(
|
|
68
|
+
results.map((r) => ({ scope: r.scope, path: r.path, patterns: r.patterns })),
|
|
69
|
+
() => {
|
|
70
|
+
const lines: string[] = [];
|
|
71
|
+
for (const r of results) {
|
|
72
|
+
lines.push(bold(`${r.scope}`) + dim(` (${r.path})`));
|
|
73
|
+
if (r.patterns.length === 0) {
|
|
74
|
+
lines.push(` ${dim("(none)")}`);
|
|
75
|
+
} else {
|
|
76
|
+
for (const p of r.patterns) {
|
|
77
|
+
lines.push(` ${green("✓")} ${p}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
lines.push("");
|
|
81
|
+
}
|
|
82
|
+
return lines.join("\n").trimEnd();
|
|
83
|
+
},
|
|
84
|
+
formatOptions,
|
|
85
|
+
),
|
|
86
|
+
);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Build the list of patterns to add
|
|
91
|
+
const patterns: string[] = [];
|
|
92
|
+
|
|
93
|
+
if (options.all) {
|
|
94
|
+
patterns.push(allExecPattern(client));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (options.allRead) {
|
|
98
|
+
patterns.push(...readOnlyPatterns(client));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (server && tools.length > 0) {
|
|
102
|
+
for (const tool of tools) {
|
|
103
|
+
patterns.push(execPattern(server, tool, client));
|
|
104
|
+
}
|
|
105
|
+
} else if (server) {
|
|
106
|
+
patterns.push(execPattern(server, undefined, client));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (patterns.length === 0) {
|
|
110
|
+
console.error("error: specify a server, --all, or --all-read. See 'mcpx allow --help'.");
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Always include allow/deny command patterns so the agent can self-manage
|
|
115
|
+
patterns.push(allowCommandPattern(client));
|
|
116
|
+
patterns.push(denyCommandPattern(client));
|
|
117
|
+
|
|
118
|
+
const scope: Scope = options.global ? "global" : options.project ? "project" : "local";
|
|
119
|
+
const path = resolveSettingsPath(scope, client);
|
|
120
|
+
|
|
121
|
+
if (options.dryRun) {
|
|
122
|
+
console.log(
|
|
123
|
+
formatOutput(
|
|
124
|
+
{ scope, path, patterns },
|
|
125
|
+
() => {
|
|
126
|
+
const lines: string[] = [];
|
|
127
|
+
lines.push(bold("Dry run") + dim(` — would write to ${path}:`));
|
|
128
|
+
for (const p of patterns) {
|
|
129
|
+
lines.push(` ${yellow("+")} ${p}`);
|
|
130
|
+
}
|
|
131
|
+
return lines.join("\n");
|
|
132
|
+
},
|
|
133
|
+
formatOptions,
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const settings = await readClientSettings(path);
|
|
140
|
+
const { settings: updated, added } = addPatterns(settings, patterns);
|
|
141
|
+
await writeClientSettings(path, updated);
|
|
142
|
+
|
|
143
|
+
console.log(
|
|
144
|
+
formatOutput(
|
|
145
|
+
{ scope, path, added, total: (updated.permissions?.allow ?? []).length },
|
|
146
|
+
() => {
|
|
147
|
+
const lines: string[] = [];
|
|
148
|
+
if (added.length === 0) {
|
|
149
|
+
lines.push(dim("All patterns already present — no changes."));
|
|
150
|
+
} else {
|
|
151
|
+
lines.push(bold(`Added ${added.length} permission(s)`) + dim(` → ${path}`));
|
|
152
|
+
for (const p of added) {
|
|
153
|
+
lines.push(` ${green("+")} ${p}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return lines.join("\n");
|
|
157
|
+
},
|
|
158
|
+
formatOptions,
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { bold, dim, green, red, yellow } from "ansis";
|
|
3
|
+
import {
|
|
4
|
+
type Client,
|
|
5
|
+
type Scope,
|
|
6
|
+
resolveSettingsPath,
|
|
7
|
+
readClientSettings,
|
|
8
|
+
writeClientSettings,
|
|
9
|
+
execPattern,
|
|
10
|
+
readOnlyPatterns,
|
|
11
|
+
allExecPattern,
|
|
12
|
+
removePatterns,
|
|
13
|
+
removeAllMcpxPatterns,
|
|
14
|
+
getServerPatterns,
|
|
15
|
+
} from "../lib/client-settings.ts";
|
|
16
|
+
import { formatOutput } from "../output/format-output.ts";
|
|
17
|
+
import type { FormatOptions } from "../output/formatter.ts";
|
|
18
|
+
|
|
19
|
+
export function registerDenyCommand(program: Command) {
|
|
20
|
+
program
|
|
21
|
+
.command("deny")
|
|
22
|
+
.description("remove permission rules for mcpx commands (Claude Code or Cursor)")
|
|
23
|
+
.argument("[server]", "server name to deny")
|
|
24
|
+
.argument("[tools...]", "specific tool names to deny")
|
|
25
|
+
.option("--all", "remove all mcpx-related permissions")
|
|
26
|
+
.option("--all-read", "remove read-only command permissions")
|
|
27
|
+
.option("--cursor", "target Cursor settings instead of Claude Code")
|
|
28
|
+
.option("--local", "write to local settings (default)")
|
|
29
|
+
.option("--project", "write to project settings (shared)")
|
|
30
|
+
.option("--global", "write to global settings")
|
|
31
|
+
.option("--dry-run", "show what would be removed")
|
|
32
|
+
.action(
|
|
33
|
+
async (
|
|
34
|
+
server: string | undefined,
|
|
35
|
+
tools: string[],
|
|
36
|
+
options: {
|
|
37
|
+
all?: boolean;
|
|
38
|
+
allRead?: boolean;
|
|
39
|
+
cursor?: boolean;
|
|
40
|
+
local?: boolean;
|
|
41
|
+
project?: boolean;
|
|
42
|
+
global?: boolean;
|
|
43
|
+
dryRun?: boolean;
|
|
44
|
+
},
|
|
45
|
+
) => {
|
|
46
|
+
const formatOptions: FormatOptions = { json: program.opts().json };
|
|
47
|
+
const client: Client = options.cursor ? "cursor" : "claude";
|
|
48
|
+
const scope: Scope = options.global ? "global" : options.project ? "project" : "local";
|
|
49
|
+
const path = resolveSettingsPath(scope, client);
|
|
50
|
+
const settings = await readClientSettings(path);
|
|
51
|
+
|
|
52
|
+
let result: { settings: typeof settings; removed: string[] };
|
|
53
|
+
|
|
54
|
+
if (options.all) {
|
|
55
|
+
// Remove all mcpx-related patterns
|
|
56
|
+
result = removeAllMcpxPatterns(settings, client);
|
|
57
|
+
} else {
|
|
58
|
+
// Build the list of patterns to remove
|
|
59
|
+
const patterns: string[] = [];
|
|
60
|
+
|
|
61
|
+
if (options.allRead) {
|
|
62
|
+
patterns.push(...readOnlyPatterns(client));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (server && tools.length > 0) {
|
|
66
|
+
for (const tool of tools) {
|
|
67
|
+
patterns.push(execPattern(server, tool, client));
|
|
68
|
+
}
|
|
69
|
+
} else if (server) {
|
|
70
|
+
// Remove the server-level pattern AND all tool-specific patterns for this server
|
|
71
|
+
patterns.push(execPattern(server, undefined, client));
|
|
72
|
+
patterns.push(...getServerPatterns(settings, server, client));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (patterns.length === 0) {
|
|
76
|
+
console.error("error: specify a server, --all, or --all-read. See 'mcpx deny --help'.");
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
result = removePatterns(settings, patterns);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (options.dryRun) {
|
|
84
|
+
console.log(
|
|
85
|
+
formatOutput(
|
|
86
|
+
{ scope, path, wouldRemove: result.removed },
|
|
87
|
+
() => {
|
|
88
|
+
const lines: string[] = [];
|
|
89
|
+
lines.push(bold("Dry run") + dim(` — would remove from ${path}:`));
|
|
90
|
+
if (result.removed.length === 0) {
|
|
91
|
+
lines.push(` ${dim("(no matching patterns found)")}`);
|
|
92
|
+
} else {
|
|
93
|
+
for (const p of result.removed) {
|
|
94
|
+
lines.push(` ${yellow("-")} ${p}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return lines.join("\n");
|
|
98
|
+
},
|
|
99
|
+
formatOptions,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
await writeClientSettings(path, result.settings);
|
|
106
|
+
|
|
107
|
+
console.log(
|
|
108
|
+
formatOutput(
|
|
109
|
+
{
|
|
110
|
+
scope,
|
|
111
|
+
path,
|
|
112
|
+
removed: result.removed,
|
|
113
|
+
total: (result.settings.permissions?.allow ?? []).length,
|
|
114
|
+
},
|
|
115
|
+
() => {
|
|
116
|
+
const lines: string[] = [];
|
|
117
|
+
if (result.removed.length === 0) {
|
|
118
|
+
lines.push(dim("No matching patterns found — no changes."));
|
|
119
|
+
} else {
|
|
120
|
+
lines.push(
|
|
121
|
+
bold(`Removed ${result.removed.length} permission(s)`) + dim(` → ${path}`),
|
|
122
|
+
);
|
|
123
|
+
for (const p of result.removed) {
|
|
124
|
+
lines.push(` ${red("-")} ${p}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return lines.join("\n");
|
|
128
|
+
},
|
|
129
|
+
formatOptions,
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { homedir } from "os";
|
|
3
|
+
import { readFile, mkdir, writeFile } from "fs/promises";
|
|
4
|
+
|
|
5
|
+
export type Client = "claude" | "cursor";
|
|
6
|
+
export type Scope = "local" | "project" | "global";
|
|
7
|
+
|
|
8
|
+
export interface ClientSettings {
|
|
9
|
+
permissions?: {
|
|
10
|
+
allow?: string[];
|
|
11
|
+
deny?: string[];
|
|
12
|
+
};
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function prefix(client: Client): string {
|
|
17
|
+
return client === "claude" ? "Bash" : "Shell";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Resolve the settings file path for a given scope and client */
|
|
21
|
+
export function resolveSettingsPath(scope: Scope, client: Client = "claude"): string {
|
|
22
|
+
if (client === "cursor") {
|
|
23
|
+
switch (scope) {
|
|
24
|
+
case "local":
|
|
25
|
+
case "project":
|
|
26
|
+
return join(process.cwd(), ".cursor", "cli.json");
|
|
27
|
+
case "global":
|
|
28
|
+
return join(homedir(), ".cursor", "cli-config.json");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
switch (scope) {
|
|
33
|
+
case "local":
|
|
34
|
+
return join(process.cwd(), ".claude", "settings.local.json");
|
|
35
|
+
case "project":
|
|
36
|
+
return join(process.cwd(), ".claude", "settings.json");
|
|
37
|
+
case "global":
|
|
38
|
+
return join(homedir(), ".claude", "settings.json");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Read client settings from a file, returning empty settings if the file doesn't exist */
|
|
43
|
+
export async function readClientSettings(path: string): Promise<ClientSettings> {
|
|
44
|
+
try {
|
|
45
|
+
const content = await readFile(path, "utf-8");
|
|
46
|
+
return JSON.parse(content) as ClientSettings;
|
|
47
|
+
} catch {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Write client settings to a file, creating parent directories as needed */
|
|
53
|
+
export async function writeClientSettings(path: string, settings: ClientSettings): Promise<void> {
|
|
54
|
+
const dir = join(path, "..");
|
|
55
|
+
await mkdir(dir, { recursive: true });
|
|
56
|
+
await writeFile(path, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Generate a permission pattern for mcpx exec with a specific server and optional tool */
|
|
60
|
+
export function execPattern(server: string, tool?: string, client: Client = "claude"): string {
|
|
61
|
+
const p = prefix(client);
|
|
62
|
+
if (tool) {
|
|
63
|
+
return `${p}(mcpx exec:${server}:${tool}:*)`;
|
|
64
|
+
}
|
|
65
|
+
return `${p}(mcpx exec:${server}:*)`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Read-only mcpx commands that are safe to allow broadly */
|
|
69
|
+
const READ_ONLY_COMMANDS = [
|
|
70
|
+
"search",
|
|
71
|
+
"info",
|
|
72
|
+
"servers",
|
|
73
|
+
"ping",
|
|
74
|
+
"resource",
|
|
75
|
+
"prompt",
|
|
76
|
+
"task",
|
|
77
|
+
"index",
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
/** Generate patterns for all read-only mcpx commands */
|
|
81
|
+
export function readOnlyPatterns(client: Client = "claude"): string[] {
|
|
82
|
+
const p = prefix(client);
|
|
83
|
+
return READ_ONLY_COMMANDS.map((cmd) => `${p}(mcpx ${cmd}:*)`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Generate the broad allow-all pattern for mcpx exec */
|
|
87
|
+
export function allExecPattern(client: Client = "claude"): string {
|
|
88
|
+
return `${prefix(client)}(mcpx exec:*)`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Generate the allow pattern for mcpx allow itself */
|
|
92
|
+
export function allowCommandPattern(client: Client = "claude"): string {
|
|
93
|
+
return `${prefix(client)}(mcpx allow:*)`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Generate the allow pattern for mcpx deny itself */
|
|
97
|
+
export function denyCommandPattern(client: Client = "claude"): string {
|
|
98
|
+
return `${prefix(client)}(mcpx deny:*)`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Check if a permission pattern is mcpx-related */
|
|
102
|
+
export function isMcpxPattern(pattern: string, client: Client = "claude"): boolean {
|
|
103
|
+
return pattern.startsWith(`${prefix(client)}(mcpx `);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Add patterns to settings, deduplicating. Returns the updated settings and list of newly added patterns. */
|
|
107
|
+
export function addPatterns(
|
|
108
|
+
settings: ClientSettings,
|
|
109
|
+
patterns: string[],
|
|
110
|
+
): { settings: ClientSettings; added: string[] } {
|
|
111
|
+
const existing = new Set(settings.permissions?.allow ?? []);
|
|
112
|
+
const added: string[] = [];
|
|
113
|
+
|
|
114
|
+
for (const p of patterns) {
|
|
115
|
+
if (!existing.has(p)) {
|
|
116
|
+
existing.add(p);
|
|
117
|
+
added.push(p);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
settings: {
|
|
123
|
+
...settings,
|
|
124
|
+
permissions: {
|
|
125
|
+
...settings.permissions,
|
|
126
|
+
allow: [...existing],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
added,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Remove specific patterns from settings. Returns the updated settings and list of removed patterns. */
|
|
134
|
+
export function removePatterns(
|
|
135
|
+
settings: ClientSettings,
|
|
136
|
+
patterns: string[],
|
|
137
|
+
): { settings: ClientSettings; removed: string[] } {
|
|
138
|
+
const existing = settings.permissions?.allow ?? [];
|
|
139
|
+
const toRemove = new Set(patterns);
|
|
140
|
+
const removed: string[] = [];
|
|
141
|
+
const remaining: string[] = [];
|
|
142
|
+
|
|
143
|
+
for (const p of existing) {
|
|
144
|
+
if (toRemove.has(p)) {
|
|
145
|
+
removed.push(p);
|
|
146
|
+
} else {
|
|
147
|
+
remaining.push(p);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
settings: {
|
|
153
|
+
...settings,
|
|
154
|
+
permissions: {
|
|
155
|
+
...settings.permissions,
|
|
156
|
+
allow: remaining,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
removed,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Remove all mcpx-related patterns from settings. Returns the updated settings and list of removed patterns. */
|
|
164
|
+
export function removeAllMcpxPatterns(
|
|
165
|
+
settings: ClientSettings,
|
|
166
|
+
client: Client = "claude",
|
|
167
|
+
): {
|
|
168
|
+
settings: ClientSettings;
|
|
169
|
+
removed: string[];
|
|
170
|
+
} {
|
|
171
|
+
const existing = settings.permissions?.allow ?? [];
|
|
172
|
+
const removed: string[] = [];
|
|
173
|
+
const remaining: string[] = [];
|
|
174
|
+
|
|
175
|
+
for (const p of existing) {
|
|
176
|
+
if (isMcpxPattern(p, client)) {
|
|
177
|
+
removed.push(p);
|
|
178
|
+
} else {
|
|
179
|
+
remaining.push(p);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
settings: {
|
|
185
|
+
...settings,
|
|
186
|
+
permissions: {
|
|
187
|
+
...settings.permissions,
|
|
188
|
+
allow: remaining,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
removed,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Extract all mcpx-related patterns from settings */
|
|
196
|
+
export function getMcpxPatterns(settings: ClientSettings, client: Client = "claude"): string[] {
|
|
197
|
+
return (settings.permissions?.allow ?? []).filter((p) => isMcpxPattern(p, client));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Get all mcpx-related patterns for a specific server */
|
|
201
|
+
export function getServerPatterns(
|
|
202
|
+
settings: ClientSettings,
|
|
203
|
+
server: string,
|
|
204
|
+
client: Client = "claude",
|
|
205
|
+
): string[] {
|
|
206
|
+
const p = prefix(client);
|
|
207
|
+
return getMcpxPatterns(settings, client).filter(
|
|
208
|
+
(pat) => pat.startsWith(`${p}(mcpx exec:${server}:`) || pat === `${p}(mcpx exec:${server}:*)`,
|
|
209
|
+
);
|
|
210
|
+
}
|