cwtools-mcp 0.2.8 → 0.4.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.
@@ -33,6 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.fallbackBridgeTools = fallbackBridgeTools;
37
+ exports.fallbackBridgeResources = fallbackBridgeResources;
38
+ exports.localBridgeToolDenied = localBridgeToolDenied;
36
39
  exports.createBridgeProxyMcpServer = createBridgeProxyMcpServer;
37
40
  exports.assertBridgeWorkspaceMatches = assertBridgeWorkspaceMatches;
38
41
  const fs = __importStar(require("fs"));
@@ -40,12 +43,45 @@ const path = __importStar(require("path"));
40
43
  const url_1 = require("url");
41
44
  const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
42
45
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
46
+ const cwtools_shared_1 = require("cwtools-shared");
43
47
  const vscodeCache_1 = require("../hosts/vscodeCache");
44
48
  const resources_1 = require("./resources");
45
49
  const toolRegistrar_1 = require("./toolRegistrar");
46
50
  const toolHandlers_1 = require("./toolHandlers");
47
51
  const BRIDGE_MANIFEST_FILE = 'bridge-manifest.json';
48
52
  const BRIDGE_PROTOCOL_VERSION = 1;
53
+ function fallbackBridgeTools(project, includeWrites) {
54
+ if (project.kind === 'unsupported' || project.kind === 'ambiguous')
55
+ return [];
56
+ return (0, toolRegistrar_1.listRegisteredTools)({ includeWrites, cwtOnly: project.kind === 'cwt-only' });
57
+ }
58
+ function fallbackBridgeResources(project) {
59
+ if (project.kind === 'unsupported' || project.kind === 'ambiguous')
60
+ return [];
61
+ const resources = (0, resources_1.listResources)();
62
+ return project.kind === 'cwt-only'
63
+ ? resources.filter(resource => resource.uri === 'cwtools://knowledge/diagnostic-routing')
64
+ : resources;
65
+ }
66
+ function localBridgeToolDenied(project, name) {
67
+ if (project.kind !== 'unsupported' && project.kind !== 'ambiguous'
68
+ && (project.kind !== 'cwt-only'
69
+ || fallbackBridgeTools(project, true).some(tool => tool.name === name)))
70
+ return undefined;
71
+ return {
72
+ ok: false,
73
+ status: 'denied',
74
+ source: 'cwtools-mcp-bridge-proxy',
75
+ error: {
76
+ code: project.kind === 'ambiguous'
77
+ ? 'project_ambiguous'
78
+ : project.kind === 'unsupported' ? 'project_not_supported' : 'tool_not_available_in_cwt_only',
79
+ message: project.kind === 'cwt-only'
80
+ ? `Tool '${name}' requires a full Paradox game model and is not available in a CWT-only workspace.`
81
+ : project.reason,
82
+ },
83
+ };
84
+ }
49
85
  function createBridgeProxyMcpServer(config) {
50
86
  const server = new index_js_1.Server({
51
87
  name: 'cwtools-mcp',
@@ -64,25 +100,68 @@ function createBridgeProxyMcpServer(config) {
64
100
  });
65
101
  server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
66
102
  try {
67
- return await bridgeRpc(config, server, 'tools/list', {});
103
+ const manifest = await readBridgeManifest(config, server);
104
+ if (!manifest.project) {
105
+ const project = await detectProxyWorkspace(config, server);
106
+ return { tools: fallbackBridgeTools(project, config.enableWrites) };
107
+ }
108
+ return await bridgeRpc(config, server, 'tools/list', {
109
+ allowDomainWrites: config.enableWrites,
110
+ }, manifest);
68
111
  }
69
112
  catch {
70
- return { tools: (0, toolRegistrar_1.listRegisteredTools)() };
113
+ try {
114
+ const project = await detectProxyWorkspace(config, server);
115
+ return { tools: fallbackBridgeTools(project, config.enableWrites) };
116
+ }
117
+ catch {
118
+ return { tools: [] };
119
+ }
71
120
  }
72
121
  });
73
122
  server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => {
74
123
  try {
75
- return await bridgeRpc(config, server, 'resources/list', {});
124
+ const manifest = await readBridgeManifest(config, server);
125
+ if (!manifest.project) {
126
+ const project = await detectProxyWorkspace(config, server);
127
+ return { resources: fallbackBridgeResources(project) };
128
+ }
129
+ return await bridgeRpc(config, server, 'resources/list', {}, manifest);
76
130
  }
77
131
  catch {
78
- return { resources: (0, resources_1.listResources)() };
132
+ try {
133
+ const project = await detectProxyWorkspace(config, server);
134
+ return { resources: fallbackBridgeResources(project) };
135
+ }
136
+ catch {
137
+ return { resources: [] };
138
+ }
79
139
  }
80
140
  });
81
141
  server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => {
82
142
  try {
143
+ const manifest = await readBridgeManifest(config, server);
144
+ if (!manifest.project) {
145
+ const project = await detectProxyWorkspace(config, server);
146
+ if (!fallbackBridgeResources(project).some(resource => resource.uri === request.params.uri)) {
147
+ return {
148
+ contents: [{
149
+ uri: request.params.uri,
150
+ mimeType: 'application/json',
151
+ text: `${JSON.stringify({
152
+ status: 'error',
153
+ error: {
154
+ code: project.kind === 'ambiguous' ? 'project_ambiguous' : project.kind === 'unsupported' ? 'project_not_supported' : 'resource_not_available_in_cwt_only',
155
+ message: project.reason,
156
+ },
157
+ }, null, 2)}\n`,
158
+ }],
159
+ };
160
+ }
161
+ }
83
162
  return await bridgeRpc(config, server, 'resources/read', {
84
163
  uri: request.params.uri,
85
- });
164
+ }, manifest);
86
165
  }
87
166
  catch (error) {
88
167
  return {
@@ -101,20 +180,37 @@ function createBridgeProxyMcpServer(config) {
101
180
  const args = request.params.arguments && typeof request.params.arguments === 'object'
102
181
  ? request.params.arguments
103
182
  : {};
183
+ const manifest = await readBridgeManifest(config, server);
184
+ if (!manifest.project) {
185
+ const project = await detectProxyWorkspace(config, server);
186
+ const denied = localBridgeToolDenied(project, request.params.name);
187
+ if (denied)
188
+ return (0, toolHandlers_1.toMcpCallToolResult)(denied);
189
+ }
104
190
  const result = await bridgeRpc(config, server, 'tools/call', {
105
191
  name: request.params.name,
106
192
  arguments: args,
107
- });
193
+ allowDomainWrites: config.enableWrites,
194
+ }, manifest);
108
195
  return normalizeCallToolResult(result);
109
196
  }
110
197
  catch (error) {
198
+ try {
199
+ const project = await detectProxyWorkspace(config, server);
200
+ const denied = localBridgeToolDenied(project, request.params.name);
201
+ if (denied)
202
+ return (0, toolHandlers_1.toMcpCallToolResult)(denied);
203
+ }
204
+ catch {
205
+ // Preserve the original bridge error when local fallback detection fails.
206
+ }
111
207
  return (0, toolHandlers_1.toMcpCallToolResult)(unavailableResult(error));
112
208
  }
113
209
  });
114
210
  return server;
115
211
  }
116
- async function bridgeRpc(config, server, method, params) {
117
- const manifest = await readBridgeManifest(config, server);
212
+ async function bridgeRpc(config, server, method, params, knownManifest) {
213
+ const manifest = knownManifest ?? await readBridgeManifest(config, server);
118
214
  const controller = new AbortController();
119
215
  const timer = setTimeout(() => controller.abort(), 30000);
120
216
  try {
@@ -181,6 +277,19 @@ async function resolveExpectedWorkspace(config, server) {
181
277
  }
182
278
  return { roots: [config.workspaceRoot], source: 'MCP process cwd' };
183
279
  }
280
+ async function detectProxyWorkspace(config, server) {
281
+ const expected = await resolveExpectedWorkspace(config, server);
282
+ if (expected.roots.length > 1) {
283
+ return {
284
+ kind: 'ambiguous',
285
+ strength: 'none',
286
+ evidence: [],
287
+ candidates: [...expected.roots].sort(),
288
+ reason: `Multiple MCP workspace roots are ambiguous for the CWTools bridge: ${expected.roots.join(', ')}`,
289
+ };
290
+ }
291
+ return (0, cwtools_shared_1.detectWorkspaceProject)(expected.roots[0] ?? config.workspaceRoot, () => undefined);
292
+ }
184
293
  async function readClientWorkspaceRoots(server) {
185
294
  if (!server.getClientCapabilities()?.roots)
186
295
  return [];
@@ -0,0 +1,2 @@
1
+ export { bindToolCallHandler, createToolCallHandler } from 'cwtools-shared';
2
+ export type { SharedToolHandler, ToolCallContext } from 'cwtools-shared';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createToolCallHandler = exports.bindToolCallHandler = void 0;
4
+ // Compatibility re-export: the transport-neutral call handler moved to
5
+ // `cwtools-shared` so hosts without an MCP dependency can route tools.
6
+ var cwtools_shared_1 = require("cwtools-shared");
7
+ Object.defineProperty(exports, "bindToolCallHandler", { enumerable: true, get: function () { return cwtools_shared_1.bindToolCallHandler; } });
8
+ Object.defineProperty(exports, "createToolCallHandler", { enumerable: true, get: function () { return cwtools_shared_1.createToolCallHandler; } });
@@ -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,71 @@ 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?.projectSupported === false)
91
+ return [];
92
+ if (host?.projectKind === 'cwt-only') {
93
+ return base.filter(resource => resource.uri === 'cwtools://knowledge/diagnostic-routing');
94
+ }
95
+ if (host?.workspaceRoot) {
96
+ for (const skill of discoverSkills(host.workspaceRoot)) {
97
+ base.push({
98
+ uri: `cwtools://skills/${encodeURIComponent(skill.name)}`,
99
+ name: `Paradox Skill: ${skill.name}`,
100
+ description: skill.description || `Paradox modding skill ${skill.name}`,
101
+ mimeType: 'text/markdown',
102
+ });
103
+ }
104
+ }
105
+ return base;
81
106
  }
82
107
  async function readResource(host, uri) {
108
+ if (host.projectSupported === false
109
+ || (host.projectKind === 'cwt-only' && uri !== 'cwtools://knowledge/diagnostic-routing')) {
110
+ const code = host.projectKind === 'ambiguous'
111
+ ? 'project_ambiguous'
112
+ : host.projectSupported === false ? 'project_not_supported' : 'resource_not_available_in_cwt_only';
113
+ return {
114
+ contents: [{
115
+ uri,
116
+ mimeType: 'application/json',
117
+ text: `${JSON.stringify({ status: 'error', error: { code, message: host.projectSupportReason ?? 'Resource is not available for this workspace.' } }, null, 2)}\n`,
118
+ }],
119
+ };
120
+ }
121
+ if (uri.startsWith('cwtools://skills/') && uri !== 'cwtools://skills/catalog') {
122
+ const skillName = decodeURIComponent(uri.slice('cwtools://skills/'.length));
123
+ const found = discoverSkills(host.workspaceRoot).find(entry => entry.name === skillName);
124
+ if (found && fs.existsSync(found.filePath)) {
125
+ return {
126
+ contents: [
127
+ {
128
+ uri,
129
+ mimeType: 'text/markdown',
130
+ text: `${fs.readFileSync(found.filePath, 'utf8').trim()}\n`,
131
+ },
132
+ ],
133
+ };
134
+ }
135
+ return {
136
+ contents: [
137
+ {
138
+ uri,
139
+ mimeType: 'application/json',
140
+ text: `${JSON.stringify({
141
+ status: 'error',
142
+ error: { code: 'skill_not_found', message: `Unknown CWTools skill: ${skillName}` },
143
+ }, null, 2)}\n`,
144
+ },
145
+ ],
146
+ };
147
+ }
83
148
  const data = await readResourceData(host, uri);
84
149
  return {
85
150
  contents: [
@@ -91,6 +156,54 @@ async function readResource(host, uri) {
91
156
  ],
92
157
  };
93
158
  }
159
+ function discoverSkills(workspaceRoot) {
160
+ const roots = [];
161
+ if (workspaceRoot) {
162
+ roots.push({ dir: path.join(workspaceRoot, '.agents', 'skills'), source: 'project' });
163
+ roots.push({ dir: path.join(workspaceRoot, '.cwtools', 'skills'), source: 'project' });
164
+ }
165
+ const home = os.homedir();
166
+ if (home) {
167
+ roots.push({ dir: path.join(home, '.cwtools', 'skills'), source: 'user' });
168
+ }
169
+ const byName = new Map();
170
+ for (const root of roots) {
171
+ if (!fs.existsSync(root.dir))
172
+ continue;
173
+ let entries = [];
174
+ try {
175
+ entries = fs.readdirSync(root.dir, { withFileTypes: true });
176
+ }
177
+ catch {
178
+ continue;
179
+ }
180
+ for (const entry of entries) {
181
+ if (!entry.isDirectory())
182
+ continue;
183
+ const skillFile = path.join(root.dir, entry.name, 'SKILL.md');
184
+ if (!fs.existsSync(skillFile))
185
+ continue;
186
+ let raw = '';
187
+ try {
188
+ raw = fs.readFileSync(skillFile, 'utf8');
189
+ }
190
+ catch {
191
+ continue;
192
+ }
193
+ const descMatch = raw.match(/^description\s*:\s*(.+)$/m);
194
+ const description = descMatch ? descMatch[1].trim().replace(/^['"]|['"]$/g, '') : `Paradox skill ${entry.name}`;
195
+ if (!byName.has(entry.name)) {
196
+ byName.set(entry.name, {
197
+ name: entry.name,
198
+ description,
199
+ source: root.source,
200
+ filePath: skillFile,
201
+ });
202
+ }
203
+ }
204
+ }
205
+ return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
206
+ }
94
207
  async function readResourceData(host, uri) {
95
208
  switch (uri) {
96
209
  case 'cwtools://knowledge/game': {
@@ -131,6 +244,19 @@ async function readResourceData(host, uri) {
131
244
  _hint: 'Run /init in the VS Code extension and wait for the deep semantic phase.',
132
245
  };
133
246
  }
247
+ case 'cwtools://skills/catalog': {
248
+ const skills = discoverSkills(host.workspaceRoot);
249
+ return {
250
+ status: 'ready',
251
+ count: skills.length,
252
+ skills: skills.map(skill => ({
253
+ name: skill.name,
254
+ description: skill.description,
255
+ source: skill.source,
256
+ uri: `cwtools://skills/${encodeURIComponent(skill.name)}`,
257
+ })),
258
+ };
259
+ }
134
260
  default:
135
261
  return {
136
262
  status: 'error',
@@ -1,5 +1,6 @@
1
- import { type HostServices, type SharedToolDispatcher, type SharedToolResult } from 'cwtools-shared';
2
- export declare function createToolCallHandler(host: HostServices, dispatcher?: SharedToolDispatcher): (name: string, args?: Record<string, unknown>) => Promise<SharedToolResult>;
1
+ import type { SharedToolResult } from 'cwtools-shared';
2
+ export { createToolCallHandler, bindToolCallHandler } from 'cwtools-shared';
3
+ export type { SharedToolHandler, ToolCallContext } from 'cwtools-shared';
3
4
  export declare function toMcpCallToolResult(result: SharedToolResult): {
4
5
  content: Array<{
5
6
  type: 'text';
@@ -1,50 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createToolCallHandler = createToolCallHandler;
3
+ exports.bindToolCallHandler = exports.createToolCallHandler = void 0;
4
4
  exports.toMcpCallToolResult = toMcpCallToolResult;
5
- const cwtools_shared_1 = require("cwtools-shared");
6
- function createToolCallHandler(host, dispatcher = cwtools_shared_1.defaultSharedToolDispatcher) {
7
- // The game stays loaded once ready, so probe readiness only until it flips true.
8
- let ready = false;
9
- const probeReadiness = async () => {
10
- if (ready)
11
- return { ready: true };
12
- try {
13
- const status = await host.lsp.executeCommand('cwtools.ai.getValidationStatus', [], { timeoutMs: 8000 });
14
- const verdict = (0, cwtools_shared_1.parseReadiness)(status);
15
- if (verdict.ready)
16
- ready = true;
17
- return verdict;
18
- }
19
- catch {
20
- return { ready: false, reason: 'lsp_unavailable' };
21
- }
22
- };
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)) {
27
- return {
28
- ok: false,
29
- status: 'denied',
30
- source: 'cwtools-mcp',
31
- error: {
32
- code: 'tool_not_available',
33
- message: `Tool '${name}' is not available: this MCP server is read-only. Perform file writes through your own environment.`,
34
- },
35
- };
36
- }
37
- const result = await dispatcher(host, name, args);
38
- // Tag vanilla-dependent results with cache provenance so clients never read a
39
- // mod-only answer as complete.
40
- const withVanilla = (0, cwtools_shared_1.annotateVanillaCache)(name, result, host.vanillaCache);
41
- // For load-dependent tools, mark results produced before the game is ready as
42
- // `loading` so clients retry instead of trusting an empty answer.
43
- if (!cwtools_shared_1.LOAD_DEPENDENT_TOOLS.has(name))
44
- return withVanilla;
45
- return (0, cwtools_shared_1.annotateReadiness)(name, withVanilla, await probeReadiness());
46
- };
47
- }
5
+ // MCP-specific adapter. The transport-neutral handler lives in
6
+ // `cwtools-shared` (tools/callHandler) and is re-exported here for compatibility.
7
+ var cwtools_shared_1 = require("cwtools-shared");
8
+ Object.defineProperty(exports, "createToolCallHandler", { enumerable: true, get: function () { return cwtools_shared_1.createToolCallHandler; } });
9
+ Object.defineProperty(exports, "bindToolCallHandler", { enumerable: true, get: function () { return cwtools_shared_1.bindToolCallHandler; } });
48
10
  function toMcpCallToolResult(result) {
49
11
  return {
50
12
  content: [
@@ -1,2 +1,5 @@
1
1
  import { type McpToolSchema } from 'cwtools-shared';
2
- export declare function listRegisteredTools(): McpToolSchema[];
2
+ export declare function listRegisteredTools(options?: {
3
+ includeWrites?: boolean;
4
+ cwtOnly?: boolean;
5
+ }): 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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
2
  import type { HostServices, SharedToolDispatcher } from 'cwtools-shared';
3
+ export declare function listServerTools(host: HostServices): import("cwtools-shared").McpToolSchema[];
3
4
  export declare function createCwtoolsMcpServer(host: HostServices, options?: {
4
5
  dispatcher?: SharedToolDispatcher;
5
6
  }): Server;
package/dist/server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listServerTools = listServerTools;
3
4
  exports.createCwtoolsMcpServer = createCwtoolsMcpServer;
4
5
  const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
5
6
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
@@ -8,8 +9,8 @@ const toolHandlers_1 = require("./mcp/toolHandlers");
8
9
  const resources_1 = require("./mcp/resources");
9
10
  // Server-level guidance surfaced to the model at connect time (MCP `instructions`).
10
11
  // Tells a Paradox coding agent to ground every claim in these tools.
11
- const SERVER_INSTRUCTIONS = [
12
- 'CWTools is a read-only semantic service for Paradox mods. Ground every',
12
+ const FULL_SERVER_INSTRUCTIONS = [
13
+ 'CWTools provides semantic and whitelisted domain-write tools for Paradox mods. Ground every',
13
14
  'claim about the mod in these tools instead of memory — PDX identifiers and syntax',
14
15
  'are routinely hallucinated.',
15
16
  '',
@@ -32,9 +33,29 @@ const SERVER_INSTRUCTIONS = [
32
33
  '- Results carry vanillaCache metadata: if available is false, vanilla IDs are missing',
33
34
  ' and references to them may show as false errors.',
34
35
  '',
35
- 'This server never writes files — perform edits with your own environment, then',
36
- 're-check with get_diagnostics.',
36
+ 'Use only the exposed whitelisted domain-write tools for writes, then re-check',
37
+ 'with get_diagnostics. Non-whitelisted writes remain unavailable.',
37
38
  ].join('\n');
39
+ function serverInstructions(host) {
40
+ if (host.projectSupported === false) {
41
+ return `CWTools is unavailable for this workspace: ${host.projectSupportReason ?? 'not a Paradox/CWT project.'}`;
42
+ }
43
+ if (host.projectKind === 'cwt-only') {
44
+ return 'CWTools is running in CWT-only mode. Use the exposed document, navigation, and diagnostics tools for CWT rules; no game model is loaded.';
45
+ }
46
+ if (host.projectGameId === 'paradox') {
47
+ return `${FULL_SERVER_INSTRUCTIONS}\n\nThe exact game is unknown. Generic Paradox mode is active; no game-specific rules or vanilla cache are assumed. Pass --game to enable a specific game model.`;
48
+ }
49
+ return FULL_SERVER_INSTRUCTIONS;
50
+ }
51
+ function listServerTools(host) {
52
+ if (host.projectSupported === false || host.projectKind === 'unsupported' || host.projectKind === 'ambiguous')
53
+ return [];
54
+ return (0, toolRegistrar_1.listRegisteredTools)({
55
+ includeWrites: host.writesEnabled === true && host.readonlyMode === false,
56
+ cwtOnly: host.projectKind === 'cwt-only',
57
+ });
58
+ }
38
59
  function createCwtoolsMcpServer(host, options = {}) {
39
60
  // Undefined => treat as supported (e.g. the in-extension host never sets it).
40
61
  const supported = host.projectSupported !== false;
@@ -46,17 +67,14 @@ function createCwtoolsMcpServer(host, options = {}) {
46
67
  resources: {},
47
68
  tools: {},
48
69
  },
49
- instructions: SERVER_INSTRUCTIONS,
70
+ instructions: serverInstructions(host),
50
71
  });
51
72
  const callTool = (0, toolHandlers_1.createToolCallHandler)(host, options.dispatcher);
52
- // Tools stay listed even on unsupported workspaces so the model can always see
53
- // CWTools exists (instead of falling back to hunting for a CLI). The heavy work
54
- // is gated at call time below, not by hiding the toolset.
55
- server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
56
- tools: (0, toolRegistrar_1.listRegisteredTools)(),
57
- }));
73
+ // Unsupported projects disclose no schemas. Calls are still gated below for
74
+ // clients holding a cached tool list from a previous workspace/session.
75
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: listServerTools(host) }));
58
76
  server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => ({
59
- resources: (0, resources_1.listResources)(),
77
+ resources: (0, resources_1.listResources)(host),
60
78
  }));
61
79
  server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => (0, resources_1.readResource)(host, request.params.uri));
62
80
  server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
@@ -69,8 +87,8 @@ function createCwtoolsMcpServer(host, options = {}) {
69
87
  status: 'denied',
70
88
  source: 'cwtools-mcp',
71
89
  error: {
72
- code: 'project_not_supported',
73
- message: `CWTools is disabled for this workspace (${host.workspaceRoot}): ${host.projectSupportReason ?? 'not a Paradox mod.'} ` +
90
+ code: host.projectKind === 'ambiguous' ? 'project_ambiguous' : 'project_not_supported',
91
+ message: `CWTools is disabled for this workspace (${host.workspaceRoot}): ${host.projectSupportReason ?? 'not a Paradox/CWT project.'} ` +
74
92
  'If this IS a mod, point the server at the mod root — set the working directory (or pass --workspace <mod>) — or pass --force-start to override.',
75
93
  },
76
94
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cwtools-mcp",
3
- "version": "0.2.8",
4
- "description": "Read-only MCP server exposing CWTools Paradox/Stellaris semantic tools to external agents",
3
+ "version": "0.4.0",
4
+ "description": "MCP server exposing CWTools semantic tools and default-on whitelisted domain writes",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -36,11 +36,10 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@modelcontextprotocol/sdk": "^1.29.0",
39
- "chokidar": "^4.0.3",
40
- "cwtools-shared": "0.2.8",
41
- "vscode-jsonrpc": "^8.2.0"
39
+ "cwtools-node": "0.2.0",
40
+ "cwtools-shared": "0.3.0"
42
41
  },
43
42
  "devDependencies": {
44
43
  "esbuild": "^0.28.1"
45
44
  }
46
- }
45
+ }