@adhisang/minecraft-modding-mcp 1.2.1 → 2.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +184 -64
  3. package/dist/cli.js +31 -4
  4. package/dist/compat-stdio-transport.d.ts +2 -7
  5. package/dist/compat-stdio-transport.js +12 -154
  6. package/dist/index.js +537 -202
  7. package/dist/json-rpc-framing.d.ts +22 -0
  8. package/dist/json-rpc-framing.js +168 -0
  9. package/dist/mapping-pipeline-service.d.ts +1 -1
  10. package/dist/mapping-pipeline-service.js +13 -5
  11. package/dist/mapping-service.d.ts +12 -4
  12. package/dist/mapping-service.js +222 -105
  13. package/dist/mcp-helpers.d.ts +10 -2
  14. package/dist/mcp-helpers.js +59 -5
  15. package/dist/minecraft-explorer-service.d.ts +1 -2
  16. package/dist/minecraft-explorer-service.js +120 -24
  17. package/dist/mixin-validator.d.ts +24 -2
  18. package/dist/mixin-validator.js +228 -103
  19. package/dist/mod-decompile-service.d.ts +5 -0
  20. package/dist/mod-decompile-service.js +40 -5
  21. package/dist/mod-remap-service.js +142 -30
  22. package/dist/mojang-tiny-mapping-service.js +26 -26
  23. package/dist/path-resolver.js +41 -4
  24. package/dist/registry-service.d.ts +10 -1
  25. package/dist/registry-service.js +154 -22
  26. package/dist/resources.js +7 -7
  27. package/dist/search-hit-accumulator.d.ts +0 -3
  28. package/dist/search-hit-accumulator.js +27 -6
  29. package/dist/source-jar-reader.js +16 -2
  30. package/dist/source-resolver.d.ts +1 -0
  31. package/dist/source-resolver.js +93 -2
  32. package/dist/source-service.d.ts +76 -47
  33. package/dist/source-service.js +1344 -763
  34. package/dist/stdio-supervisor.d.ts +46 -0
  35. package/dist/stdio-supervisor.js +349 -0
  36. package/dist/storage/files-repo.d.ts +3 -0
  37. package/dist/storage/files-repo.js +66 -1
  38. package/dist/storage/migrations.d.ts +1 -1
  39. package/dist/storage/migrations.js +6 -2
  40. package/dist/storage/schema.d.ts +1 -0
  41. package/dist/storage/schema.js +7 -0
  42. package/dist/symbols/symbol-extractor.js +6 -4
  43. package/dist/tool-execution-gate.d.ts +15 -0
  44. package/dist/tool-execution-gate.js +58 -0
  45. package/dist/tool-input.d.ts +6 -0
  46. package/dist/tool-input.js +64 -0
  47. package/dist/types.d.ts +1 -1
  48. package/dist/version-diff-service.js +10 -5
  49. package/dist/version-service.js +7 -2
  50. package/dist/workspace-mapping-service.js +12 -0
  51. package/package.json +4 -1
@@ -1,29 +1,14 @@
1
1
  import process from "node:process";
2
- import { JSONRPCMessageSchema } from "@modelcontextprotocol/sdk/types.js";
3
- function findHeaderBoundary(buffer) {
4
- const crlfBoundary = buffer.indexOf("\r\n\r\n");
5
- if (crlfBoundary !== -1) {
6
- return { index: crlfBoundary, delimiterBytes: 4 };
7
- }
8
- const lfBoundary = buffer.indexOf("\n\n");
9
- if (lfBoundary !== -1) {
10
- return { index: lfBoundary, delimiterBytes: 2 };
11
- }
12
- return undefined;
13
- }
14
- function parseJsonRpcMessage(json) {
15
- return JSONRPCMessageSchema.parse(JSON.parse(json));
16
- }
2
+ import { JsonRpcFrameReader, encodeJsonRpcMessage } from "./json-rpc-framing.js";
17
3
  function asError(value) {
18
4
  return value instanceof Error ? value : new Error(String(value));
19
5
  }
20
6
  export class CompatStdioServerTransport {
21
7
  stdin;
22
8
  stdout;
9
+ frameReader = new JsonRpcFrameReader();
23
10
  started = false;
24
11
  closed = false;
25
- mode = "unknown";
26
- buffer = Buffer.alloc(0);
27
12
  onclose;
28
13
  onerror;
29
14
  onmessage;
@@ -43,10 +28,7 @@ export class CompatStdioServerTransport {
43
28
  this.stdin.resume();
44
29
  }
45
30
  async send(message) {
46
- const json = JSON.stringify(message);
47
- const frame = this.mode === "content-length"
48
- ? `Content-Length: ${Buffer.byteLength(json, "utf8")}\r\n\r\n${json}`
49
- : `${json}\n`;
31
+ const frame = encodeJsonRpcMessage(message, this.frameReader.currentMode === "content-length" ? "content-length" : "line");
50
32
  await new Promise((resolve) => {
51
33
  if (this.stdout.write(frame)) {
52
34
  resolve();
@@ -63,15 +45,18 @@ export class CompatStdioServerTransport {
63
45
  if (this.stdin.listenerCount("data") === 0) {
64
46
  this.stdin.pause();
65
47
  }
66
- this.buffer = Buffer.alloc(0);
48
+ this.frameReader.clear();
67
49
  this.emitCloseOnce();
68
50
  }
69
51
  handleData = (chunk) => {
70
- if (chunk.length === 0) {
71
- return;
72
- }
73
- this.buffer = Buffer.concat([this.buffer, chunk]);
74
- this.processReadBuffer();
52
+ this.frameReader.processChunk(chunk, {
53
+ onFrame: ({ message }) => {
54
+ this.onmessage?.(message);
55
+ },
56
+ onError: (error) => {
57
+ this.onerror?.(error);
58
+ }
59
+ });
75
60
  };
76
61
  handleStreamError = (error) => {
77
62
  this.onerror?.(error);
@@ -86,132 +71,5 @@ export class CompatStdioServerTransport {
86
71
  this.closed = true;
87
72
  this.onclose?.();
88
73
  }
89
- processReadBuffer() {
90
- while (true) {
91
- try {
92
- if (this.mode === "unknown") {
93
- const detected = this.detectMode();
94
- if (!detected) {
95
- return;
96
- }
97
- this.mode = detected;
98
- continue;
99
- }
100
- const modeBefore = this.mode;
101
- const message = this.mode === "content-length"
102
- ? this.readContentLengthMessage()
103
- : this.readLineDelimitedMessage();
104
- if (!message) {
105
- // readLineDelimitedMessage may switch mode to "content-length"
106
- // mid-stream; retry with the new parser instead of stopping.
107
- if (this.mode !== modeBefore) {
108
- continue;
109
- }
110
- return;
111
- }
112
- this.onmessage?.(message);
113
- }
114
- catch (caughtError) {
115
- this.onerror?.(asError(caughtError));
116
- this.mode = "unknown";
117
- }
118
- }
119
- }
120
- detectMode() {
121
- // Skip blank leading lines that some clients may emit.
122
- while (this.buffer.length > 0) {
123
- if (this.buffer[0] === 0x0a) {
124
- this.buffer = this.buffer.subarray(1);
125
- continue;
126
- }
127
- if (this.buffer.length >= 2 && this.buffer[0] === 0x0d && this.buffer[1] === 0x0a) {
128
- this.buffer = this.buffer.subarray(2);
129
- continue;
130
- }
131
- break;
132
- }
133
- if (this.buffer.length === 0) {
134
- return undefined;
135
- }
136
- const prefix = this.buffer
137
- .subarray(0, Math.min(this.buffer.length, 32))
138
- .toString("utf8")
139
- .toLowerCase();
140
- if (prefix.startsWith("content-length")) {
141
- return "content-length";
142
- }
143
- const firstNewline = this.buffer.indexOf(0x0a);
144
- if (firstNewline === -1) {
145
- return undefined;
146
- }
147
- const firstLine = this.buffer.subarray(0, firstNewline).toString("utf8").replace(/\r$/, "");
148
- if (/^\s*content-length\s*:/i.test(firstLine)) {
149
- return "content-length";
150
- }
151
- return "line";
152
- }
153
- readLineDelimitedMessage() {
154
- while (true) {
155
- const newlineIndex = this.buffer.indexOf(0x0a);
156
- if (newlineIndex === -1) {
157
- return undefined;
158
- }
159
- const line = this.buffer.subarray(0, newlineIndex).toString("utf8").replace(/\r$/, "");
160
- this.buffer = this.buffer.subarray(newlineIndex + 1);
161
- if (line.trim().length === 0) {
162
- continue;
163
- }
164
- if (/^\s*content-length\s*:/i.test(line)) {
165
- // Reconstruct the header with the correct line ending so that
166
- // findHeaderBoundary can locate \r\n\r\n or \n\n reliably.
167
- const sep = this.buffer.length > 0 && this.buffer[0] === 0x0d ? "\r\n" : "\n";
168
- this.buffer = Buffer.concat([Buffer.from(`${line}${sep}`, "utf8"), this.buffer]);
169
- this.mode = "content-length";
170
- return undefined;
171
- }
172
- return parseJsonRpcMessage(line);
173
- }
174
- }
175
- readContentLengthMessage() {
176
- const headerBoundary = findHeaderBoundary(this.buffer);
177
- if (!headerBoundary) {
178
- return undefined;
179
- }
180
- const headersRaw = this.buffer.subarray(0, headerBoundary.index).toString("utf8");
181
- const headerLines = headersRaw
182
- .split(/\r?\n/)
183
- .map((line) => line.trim())
184
- .filter((line) => line.length > 0);
185
- let contentLength;
186
- for (const headerLine of headerLines) {
187
- const separatorIndex = headerLine.indexOf(":");
188
- if (separatorIndex === -1) {
189
- this.buffer = this.buffer.subarray(headerBoundary.index + headerBoundary.delimiterBytes);
190
- throw new Error(`Malformed header line: ${headerLine}`);
191
- }
192
- const headerName = headerLine.slice(0, separatorIndex).trim().toLowerCase();
193
- const headerValue = headerLine.slice(separatorIndex + 1).trim();
194
- if (headerName === "content-length") {
195
- const parsed = Number.parseInt(headerValue, 10);
196
- if (!Number.isFinite(parsed) || parsed < 0) {
197
- this.buffer = this.buffer.subarray(headerBoundary.index + headerBoundary.delimiterBytes);
198
- throw new Error(`Invalid Content-Length header value: ${headerValue}`);
199
- }
200
- contentLength = parsed;
201
- }
202
- }
203
- if (contentLength === undefined) {
204
- this.buffer = this.buffer.subarray(headerBoundary.index + headerBoundary.delimiterBytes);
205
- throw new Error("Missing Content-Length header.");
206
- }
207
- const messageStart = headerBoundary.index + headerBoundary.delimiterBytes;
208
- const frameEnd = messageStart + contentLength;
209
- if (this.buffer.length < frameEnd) {
210
- return undefined;
211
- }
212
- const body = this.buffer.subarray(messageStart, frameEnd).toString("utf8");
213
- this.buffer = this.buffer.subarray(frameEnd);
214
- return parseJsonRpcMessage(body);
215
- }
216
74
  }
217
75
  //# sourceMappingURL=compat-stdio-transport.js.map