@twojestarerpg/campaignmap-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/LICENSE +21 -0
- package/README.md +34 -2
- package/THIRD-PARTY-NOTICES.txt +477 -0
- package/dist/apiClient.js +45 -0
- package/dist/config.js +13 -0
- package/dist/confirm.js +21 -0
- package/dist/index.js +49 -0
- package/dist/log.js +5 -0
- package/dist/server.js +26 -0
- package/dist/session.js +173 -0
- package/dist/tools/assets.js +30 -0
- package/dist/tools/campaigns.js +54 -0
- package/dist/tools/index.js +15 -0
- package/dist/tools/maps.js +96 -0
- package/dist/tools/pois.js +73 -0
- package/dist/tools/run.js +36 -0
- package/dist/tools/schemas.js +29 -0
- package/dist/tools/sessions.js +50 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/zones.js +63 -0
- package/dist/tty.js +98 -0
- package/package.json +58 -4
package/dist/tty.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// MCP-003 / MCP-04 / LLD-58 §4, §7: talk to a human on the controlling terminal,
|
|
2
|
+
// never on stdin/stdout (those are the JSON-RPC channel).
|
|
3
|
+
import { closeSync, openSync } from 'node:fs';
|
|
4
|
+
import { ReadStream as TtyReadStream, WriteStream as TtyWriteStream } from 'node:tty';
|
|
5
|
+
/** Prompter over an arbitrary input / output pair (character by character, so echo is ours to control). */
|
|
6
|
+
export function createPrompter(input, output, onClose = () => { }) {
|
|
7
|
+
return {
|
|
8
|
+
ask(question, opts = {}) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
let value = '';
|
|
11
|
+
output.write(question);
|
|
12
|
+
input.setRawMode?.(true);
|
|
13
|
+
input.resume();
|
|
14
|
+
const finish = (err) => {
|
|
15
|
+
input.removeListener('data', onData);
|
|
16
|
+
input.removeListener('end', onEnd);
|
|
17
|
+
input.setRawMode?.(false);
|
|
18
|
+
input.pause();
|
|
19
|
+
output.write('\n');
|
|
20
|
+
if (err)
|
|
21
|
+
reject(err);
|
|
22
|
+
else
|
|
23
|
+
resolve(value);
|
|
24
|
+
};
|
|
25
|
+
const onEnd = () => finish(new Error('Terminal closed'));
|
|
26
|
+
const onData = (chunk) => {
|
|
27
|
+
for (const ch of chunk.toString('utf8')) {
|
|
28
|
+
if (ch === '\r' || ch === '\n')
|
|
29
|
+
return finish();
|
|
30
|
+
if (ch === '\u0003' || ch === '\u0004')
|
|
31
|
+
return finish(new Error('Cancelled'));
|
|
32
|
+
if (ch === '\u007f' || ch === '\b') {
|
|
33
|
+
if (value.length > 0) {
|
|
34
|
+
value = value.slice(0, -1);
|
|
35
|
+
if (!opts.hidden)
|
|
36
|
+
output.write('\b \b');
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (ch < ' ')
|
|
41
|
+
continue;
|
|
42
|
+
value += ch;
|
|
43
|
+
if (!opts.hidden)
|
|
44
|
+
output.write(ch);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
input.on('data', onData);
|
|
48
|
+
input.on('end', onEnd);
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
close: onClose,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Open the controlling terminal: `CONIN$` / `CONOUT$` on Windows, `/dev/tty`
|
|
56
|
+
* elsewhere, or the `CAMPAIGNMAP_TTY` override. Returns `null` when there is
|
|
57
|
+
* none (an MCP client spawned us with no console) - callers treat that as
|
|
58
|
+
* "cannot prompt", never as a crash.
|
|
59
|
+
*/
|
|
60
|
+
export function openControllingTerminal(override) {
|
|
61
|
+
const inPath = override ?? (process.platform === 'win32' ? 'CONIN$' : '/dev/tty');
|
|
62
|
+
const outPath = override ?? (process.platform === 'win32' ? 'CONOUT$' : '/dev/tty');
|
|
63
|
+
let inFd;
|
|
64
|
+
let outFd;
|
|
65
|
+
try {
|
|
66
|
+
inFd = openSync(inPath, 'r+');
|
|
67
|
+
outFd = outPath === inPath ? inFd : openSync(outPath, 'r+');
|
|
68
|
+
const input = new TtyReadStream(inFd);
|
|
69
|
+
const output = new TtyWriteStream(outFd);
|
|
70
|
+
return createPrompter(input, output, () => {
|
|
71
|
+
input.destroy();
|
|
72
|
+
output.destroy();
|
|
73
|
+
for (const fd of new Set([inFd, outFd])) {
|
|
74
|
+
try {
|
|
75
|
+
if (fd !== undefined)
|
|
76
|
+
closeSync(fd);
|
|
77
|
+
}
|
|
78
|
+
catch { /* already closed by destroy() */ }
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
for (const fd of new Set([inFd, outFd])) {
|
|
84
|
+
try {
|
|
85
|
+
if (fd !== undefined)
|
|
86
|
+
closeSync(fd);
|
|
87
|
+
}
|
|
88
|
+
catch { /* ignore */ }
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Prompter for the interactive `login` subcommand, where stdin / stdout are an ordinary terminal. */
|
|
94
|
+
export function stdioPrompter() {
|
|
95
|
+
if (!process.stdin.isTTY)
|
|
96
|
+
return null;
|
|
97
|
+
return createPrompter(process.stdin, process.stderr);
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twojestarerpg/campaignmap-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server that lets an AI assistant read and edit your CampaignMap campaigns and maps",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"campaignmap-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"THIRD-PARTY-NOTICES.txt"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"dev": "tsx src/index.ts",
|
|
20
|
+
"build": "tsc --project tsconfig.build.json",
|
|
21
|
+
"start": "node dist/index.js",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"test": "npm run test:unit && npm run test:live",
|
|
24
|
+
"test:unit": "vitest run",
|
|
25
|
+
"test:live": "cd ../api && node scripts/test-db.mjs run -- node ../mcp/node_modules/vitest/vitest.mjs run --config ../mcp/vitest.live.config.ts",
|
|
26
|
+
"bundle": "node scripts/bundle.mjs",
|
|
27
|
+
"prepublishOnly": "npm run typecheck && npm run build"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
31
|
+
"zod": "^4.4.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"esbuild": "^0.28.2",
|
|
36
|
+
"tsx": "^4.19.2",
|
|
37
|
+
"typescript": "^5.7.3",
|
|
38
|
+
"vitest": "^3.2.7"
|
|
39
|
+
},
|
|
40
|
+
"overrides": {
|
|
41
|
+
"rollup": "4.67.5"
|
|
42
|
+
},
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/mdybal/CampaignMap.git",
|
|
47
|
+
"directory": "mcp"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://maps.twojestarerpg.pl/",
|
|
50
|
+
"keywords": [
|
|
51
|
+
"mcp",
|
|
52
|
+
"model-context-protocol",
|
|
53
|
+
"campaignmap",
|
|
54
|
+
"rpg",
|
|
55
|
+
"maps"
|
|
56
|
+
],
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
}
|
|
60
|
+
}
|