cwtools-mcp 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 +279 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +76 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.js +212 -0
- package/dist/cwtools-mcp.cjs +49480 -0
- package/dist/hosts/lspProcessHost.d.ts +49 -0
- package/dist/hosts/lspProcessHost.js +412 -0
- package/dist/hosts/nodeHostServices.d.ts +3 -0
- package/dist/hosts/nodeHostServices.js +506 -0
- package/dist/hosts/projectDetect.d.ts +7 -0
- package/dist/hosts/projectDetect.js +151 -0
- package/dist/hosts/projectSettings.d.ts +11 -0
- package/dist/hosts/projectSettings.js +265 -0
- package/dist/hosts/revalidation.d.ts +12 -0
- package/dist/hosts/revalidation.js +157 -0
- package/dist/hosts/vscodeCache.d.ts +5 -0
- package/dist/hosts/vscodeCache.js +153 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +25 -0
- package/dist/mcp/bridgeProxy.d.ts +4 -0
- package/dist/mcp/bridgeProxy.js +281 -0
- package/dist/mcp/resources.d.ts +15 -0
- package/dist/mcp/resources.js +151 -0
- package/dist/mcp/toolHandlers.d.ts +9 -0
- package/dist/mcp/toolHandlers.js +58 -0
- package/dist/mcp/toolRegistrar.d.ts +2 -0
- package/dist/mcp/toolRegistrar.js +7 -0
- package/dist/mcp/transportHttp.d.ts +7 -0
- package/dist/mcp/transportHttp.js +101 -0
- package/dist/mcp/transportStdio.d.ts +2 -0
- package/dist/mcp/transportStdio.js +8 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.js +85 -0
- package/package.json +46 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCwtoolsMcpServer = createCwtoolsMcpServer;
|
|
4
|
+
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
5
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
6
|
+
const toolRegistrar_1 = require("./mcp/toolRegistrar");
|
|
7
|
+
const toolHandlers_1 = require("./mcp/toolHandlers");
|
|
8
|
+
const resources_1 = require("./mcp/resources");
|
|
9
|
+
// Server-level guidance surfaced to the model at connect time (MCP `instructions`).
|
|
10
|
+
// 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',
|
|
13
|
+
'claim about the mod in these tools instead of memory — PDX identifiers and syntax',
|
|
14
|
+
'are routinely hallucinated.',
|
|
15
|
+
'',
|
|
16
|
+
'Use it whenever working in a Paradox mod (common/, events/, localisation/, gfx/, …):',
|
|
17
|
+
'- Start structural and dependency questions with explore_pdx_project. It returns a',
|
|
18
|
+
' bounded live CWTools semantic subgraph, file facts, provenance, and freshness.',
|
|
19
|
+
'- Before using ANY game ID, verify it exists: query_types for typed entities;',
|
|
20
|
+
' query_scripted_effects / query_scripted_triggers / query_static_modifiers /',
|
|
21
|
+
' query_enums / query_variables for those kinds.',
|
|
22
|
+
'- Check trigger/effect/scope-change/modifier syntax with query_rules; check the scope',
|
|
23
|
+
' valid at a position with query_scope.',
|
|
24
|
+
'- Check common/event/interface/gfx schema shape with query_cwt_schema before writing',
|
|
25
|
+
' fields, block topology, or entity-path assumptions.',
|
|
26
|
+
'- Before declaring code correct, review get_diagnostics (whole project). Honor the',
|
|
27
|
+
' readiness/freshness fields: if readiness.ready is false the project is still loading —',
|
|
28
|
+
' retry; an empty result then is not authoritative.',
|
|
29
|
+
'- Navigate with query_definition / query_definition_by_name / query_references /',
|
|
30
|
+
' document_symbols / workspace_symbols; read structured blocks with get_pdx_block',
|
|
31
|
+
' instead of reading whole files. get_entity_info gives a file\'s referenced types/vars.',
|
|
32
|
+
'- Results carry vanillaCache metadata: if available is false, vanilla IDs are missing',
|
|
33
|
+
' and references to them may show as false errors.',
|
|
34
|
+
'',
|
|
35
|
+
'This server never writes files — perform edits with your own environment, then',
|
|
36
|
+
're-check with get_diagnostics.',
|
|
37
|
+
].join('\n');
|
|
38
|
+
function createCwtoolsMcpServer(host, options = {}) {
|
|
39
|
+
// Undefined => treat as supported (e.g. the in-extension host never sets it).
|
|
40
|
+
const supported = host.projectSupported !== false;
|
|
41
|
+
const server = new index_js_1.Server({
|
|
42
|
+
name: 'cwtools-mcp',
|
|
43
|
+
version: '0.1.0',
|
|
44
|
+
}, {
|
|
45
|
+
capabilities: {
|
|
46
|
+
resources: {},
|
|
47
|
+
tools: {},
|
|
48
|
+
},
|
|
49
|
+
instructions: SERVER_INSTRUCTIONS,
|
|
50
|
+
});
|
|
51
|
+
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
|
+
}));
|
|
58
|
+
server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => ({
|
|
59
|
+
resources: (0, resources_1.listResources)(),
|
|
60
|
+
}));
|
|
61
|
+
server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => (0, resources_1.readResource)(host, request.params.uri));
|
|
62
|
+
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
63
|
+
// On an unsupported workspace, reject before dispatch so the language server
|
|
64
|
+
// is never spawned (memory). The message is actionable: the resolved
|
|
65
|
+
// workspace is almost always the cause when this fires on a real mod.
|
|
66
|
+
if (!supported) {
|
|
67
|
+
return (0, toolHandlers_1.toMcpCallToolResult)({
|
|
68
|
+
ok: false,
|
|
69
|
+
status: 'denied',
|
|
70
|
+
source: 'cwtools-mcp',
|
|
71
|
+
error: {
|
|
72
|
+
code: 'project_not_supported',
|
|
73
|
+
message: `CWTools is disabled for this workspace (${host.workspaceRoot}): ${host.projectSupportReason ?? 'not a Paradox mod.'} ` +
|
|
74
|
+
'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
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const args = request.params.arguments && typeof request.params.arguments === 'object'
|
|
79
|
+
? request.params.arguments
|
|
80
|
+
: {};
|
|
81
|
+
const result = await callTool(request.params.name, args);
|
|
82
|
+
return (0, toolHandlers_1.toMcpCallToolResult)(result);
|
|
83
|
+
});
|
|
84
|
+
return server;
|
|
85
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cwtools-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Read-only MCP server exposing CWTools Paradox/Stellaris semantic tools to external agents",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Aa728848/cwtools-mcp.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"mcp",
|
|
12
|
+
"cwtools",
|
|
13
|
+
"stellaris",
|
|
14
|
+
"paradox",
|
|
15
|
+
"language-server"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"bin": {
|
|
23
|
+
"cwtools-mcp": "dist/cli.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md",
|
|
28
|
+
"package.json"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"prebuild": "npm run build -w cwtools-shared",
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"bundle": "esbuild dist/cli.js --bundle --platform=node --format=cjs --target=node18 --outfile=dist/cwtools-mcp.cjs",
|
|
34
|
+
"prepack": "npm run build",
|
|
35
|
+
"test:contracts": "ts-mocha -p tsconfig.test.json \"src/test/**/*.test.ts\""
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
39
|
+
"chokidar": "^4.0.3",
|
|
40
|
+
"cwtools-shared": "0.1.0",
|
|
41
|
+
"vscode-jsonrpc": "^8.2.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"esbuild": "^0.28.1"
|
|
45
|
+
}
|
|
46
|
+
}
|