cwtools-mcp 0.2.8 → 0.2.9

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.
@@ -64,10 +64,12 @@ function createBridgeProxyMcpServer(config) {
64
64
  });
65
65
  server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
66
66
  try {
67
- return await bridgeRpc(config, server, 'tools/list', {});
67
+ return await bridgeRpc(config, server, 'tools/list', {
68
+ allowDomainWrites: config.enableWrites,
69
+ });
68
70
  }
69
71
  catch {
70
- return { tools: (0, toolRegistrar_1.listRegisteredTools)() };
72
+ return { tools: (0, toolRegistrar_1.listRegisteredTools)({ includeWrites: config.enableWrites }) };
71
73
  }
72
74
  });
73
75
  server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => {
@@ -104,6 +106,7 @@ function createBridgeProxyMcpServer(config) {
104
106
  const result = await bridgeRpc(config, server, 'tools/call', {
105
107
  name: request.params.name,
106
108
  arguments: args,
109
+ allowDomainWrites: config.enableWrites,
107
110
  });
108
111
  return normalizeCallToolResult(result);
109
112
  }
@@ -1,6 +1,6 @@
1
1
  import { type HostServices } from 'cwtools-shared';
2
- export declare const RESOURCE_URIS: readonly ["cwtools://knowledge/game", "cwtools://knowledge/diagnostic-routing", "cwtools://knowledge/workflow-hints", "cwtools://project/profile", "cwtools://project/knowledge-manifest"];
3
- export declare function listResources(): {
2
+ export declare const RESOURCE_URIS: readonly ["cwtools://knowledge/game", "cwtools://knowledge/diagnostic-routing", "cwtools://knowledge/workflow-hints", "cwtools://project/profile", "cwtools://project/knowledge-manifest", "cwtools://skills/catalog"];
3
+ export declare function listResources(host?: HostServices): {
4
4
  uri: string;
5
5
  name: string;
6
6
  description: string;
@@ -37,6 +37,8 @@ exports.RESOURCE_URIS = void 0;
37
37
  exports.listResources = listResources;
38
38
  exports.readResource = readResource;
39
39
  const cwtools_shared_1 = require("cwtools-shared");
40
+ const fs = __importStar(require("fs"));
41
+ const os = __importStar(require("os"));
40
42
  const path = __importStar(require("path"));
41
43
  exports.RESOURCE_URIS = [
42
44
  'cwtools://knowledge/game',
@@ -44,9 +46,10 @@ exports.RESOURCE_URIS = [
44
46
  'cwtools://knowledge/workflow-hints',
45
47
  'cwtools://project/profile',
46
48
  'cwtools://project/knowledge-manifest',
49
+ 'cwtools://skills/catalog',
47
50
  ];
48
- function listResources() {
49
- return [
51
+ function listResources(host) {
52
+ const base = [
50
53
  {
51
54
  uri: 'cwtools://knowledge/game',
52
55
  name: 'CWTools game knowledge',
@@ -77,9 +80,53 @@ function listResources() {
77
80
  description: 'Freshness, domains, counts, and fingerprints for the /init-generated semantic knowledge pack.',
78
81
  mimeType: 'application/json',
79
82
  },
83
+ {
84
+ uri: 'cwtools://skills/catalog',
85
+ name: 'CWTools Paradox skills catalog',
86
+ description: 'Catalog of workspace and user Paradox modding skills exposed as cwtools://skills/<name> resources.',
87
+ mimeType: 'application/json',
88
+ },
80
89
  ];
90
+ if (host?.workspaceRoot) {
91
+ for (const skill of discoverSkills(host.workspaceRoot)) {
92
+ base.push({
93
+ uri: `cwtools://skills/${encodeURIComponent(skill.name)}`,
94
+ name: `Paradox Skill: ${skill.name}`,
95
+ description: skill.description || `Paradox modding skill ${skill.name}`,
96
+ mimeType: 'text/markdown',
97
+ });
98
+ }
99
+ }
100
+ return base;
81
101
  }
82
102
  async function readResource(host, uri) {
103
+ if (uri.startsWith('cwtools://skills/') && uri !== 'cwtools://skills/catalog') {
104
+ const skillName = decodeURIComponent(uri.slice('cwtools://skills/'.length));
105
+ const found = discoverSkills(host.workspaceRoot).find(entry => entry.name === skillName);
106
+ if (found && fs.existsSync(found.filePath)) {
107
+ return {
108
+ contents: [
109
+ {
110
+ uri,
111
+ mimeType: 'text/markdown',
112
+ text: `${fs.readFileSync(found.filePath, 'utf8').trim()}\n`,
113
+ },
114
+ ],
115
+ };
116
+ }
117
+ return {
118
+ contents: [
119
+ {
120
+ uri,
121
+ mimeType: 'application/json',
122
+ text: `${JSON.stringify({
123
+ status: 'error',
124
+ error: { code: 'skill_not_found', message: `Unknown CWTools skill: ${skillName}` },
125
+ }, null, 2)}\n`,
126
+ },
127
+ ],
128
+ };
129
+ }
83
130
  const data = await readResourceData(host, uri);
84
131
  return {
85
132
  contents: [
@@ -91,6 +138,54 @@ async function readResource(host, uri) {
91
138
  ],
92
139
  };
93
140
  }
141
+ function discoverSkills(workspaceRoot) {
142
+ const roots = [];
143
+ if (workspaceRoot) {
144
+ roots.push({ dir: path.join(workspaceRoot, '.agents', 'skills'), source: 'project' });
145
+ roots.push({ dir: path.join(workspaceRoot, '.cwtools', 'skills'), source: 'project' });
146
+ }
147
+ const home = os.homedir();
148
+ if (home) {
149
+ roots.push({ dir: path.join(home, '.cwtools', 'skills'), source: 'user' });
150
+ }
151
+ const byName = new Map();
152
+ for (const root of roots) {
153
+ if (!fs.existsSync(root.dir))
154
+ continue;
155
+ let entries = [];
156
+ try {
157
+ entries = fs.readdirSync(root.dir, { withFileTypes: true });
158
+ }
159
+ catch {
160
+ continue;
161
+ }
162
+ for (const entry of entries) {
163
+ if (!entry.isDirectory())
164
+ continue;
165
+ const skillFile = path.join(root.dir, entry.name, 'SKILL.md');
166
+ if (!fs.existsSync(skillFile))
167
+ continue;
168
+ let raw = '';
169
+ try {
170
+ raw = fs.readFileSync(skillFile, 'utf8');
171
+ }
172
+ catch {
173
+ continue;
174
+ }
175
+ const descMatch = raw.match(/^description\s*:\s*(.+)$/m);
176
+ const description = descMatch ? descMatch[1].trim().replace(/^['"]|['"]$/g, '') : `Paradox skill ${entry.name}`;
177
+ if (!byName.has(entry.name)) {
178
+ byName.set(entry.name, {
179
+ name: entry.name,
180
+ description,
181
+ source: root.source,
182
+ filePath: skillFile,
183
+ });
184
+ }
185
+ }
186
+ }
187
+ return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
188
+ }
94
189
  async function readResourceData(host, uri) {
95
190
  switch (uri) {
96
191
  case 'cwtools://knowledge/game': {
@@ -131,6 +226,19 @@ async function readResourceData(host, uri) {
131
226
  _hint: 'Run /init in the VS Code extension and wait for the deep semantic phase.',
132
227
  };
133
228
  }
229
+ case 'cwtools://skills/catalog': {
230
+ const skills = discoverSkills(host.workspaceRoot);
231
+ return {
232
+ status: 'ready',
233
+ count: skills.length,
234
+ skills: skills.map(skill => ({
235
+ name: skill.name,
236
+ description: skill.description,
237
+ source: skill.source,
238
+ uri: `cwtools://skills/${encodeURIComponent(skill.name)}`,
239
+ })),
240
+ };
241
+ }
134
242
  default:
135
243
  return {
136
244
  status: 'error',
@@ -21,16 +21,15 @@ function createToolCallHandler(host, dispatcher = cwtools_shared_1.defaultShared
21
21
  }
22
22
  };
23
23
  return async (name, args = {}) => {
24
- // Read-only surface: reject anything outside the registered (read-only) tools,
25
- // including any write tool called directly. Writes go through the host agent.
26
- if (!(0, cwtools_shared_1.isMcpToolName)(name)) {
24
+ const writesEnabled = host.writesEnabled === true && host.readonlyMode === false;
25
+ if (!(0, cwtools_shared_1.isMcpToolName)(name, { includeWrites: writesEnabled })) {
27
26
  return {
28
27
  ok: false,
29
28
  status: 'denied',
30
29
  source: 'cwtools-mcp',
31
30
  error: {
32
31
  code: 'tool_not_available',
33
- message: `Tool '${name}' is not available: this MCP server is read-only. Perform file writes through your own environment.`,
32
+ message: `Tool '${name}' is not available: this MCP server is read-only unless started with --allow-domain-writes (or --enable-writes).`,
34
33
  },
35
34
  };
36
35
  }
@@ -1,2 +1,4 @@
1
1
  import { type McpToolSchema } from 'cwtools-shared';
2
- export declare function listRegisteredTools(): McpToolSchema[];
2
+ export declare function listRegisteredTools(options?: {
3
+ includeWrites?: boolean;
4
+ }): McpToolSchema[];
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listRegisteredTools = listRegisteredTools;
4
4
  const cwtools_shared_1 = require("cwtools-shared");
5
- function listRegisteredTools() {
6
- return (0, cwtools_shared_1.listMcpToolSchemas)();
5
+ function listRegisteredTools(options) {
6
+ return (0, cwtools_shared_1.listMcpToolSchemas)(options);
7
7
  }
package/dist/server.js CHANGED
@@ -53,10 +53,10 @@ function createCwtoolsMcpServer(host, options = {}) {
53
53
  // CWTools exists (instead of falling back to hunting for a CLI). The heavy work
54
54
  // is gated at call time below, not by hiding the toolset.
55
55
  server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
56
- tools: (0, toolRegistrar_1.listRegisteredTools)(),
56
+ tools: (0, toolRegistrar_1.listRegisteredTools)({ includeWrites: host.writesEnabled === true && host.readonlyMode === false }),
57
57
  }));
58
58
  server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => ({
59
- resources: (0, resources_1.listResources)(),
59
+ resources: (0, resources_1.listResources)(host),
60
60
  }));
61
61
  server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => (0, resources_1.readResource)(host, request.params.uri));
62
62
  server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cwtools-mcp",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Read-only MCP server exposing CWTools Paradox/Stellaris semantic tools to external agents",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@modelcontextprotocol/sdk": "^1.29.0",
39
39
  "chokidar": "^4.0.3",
40
- "cwtools-shared": "0.2.8",
40
+ "cwtools-shared": "0.2.9",
41
41
  "vscode-jsonrpc": "^8.2.0"
42
42
  },
43
43
  "devDependencies": {