@godot-mcp/bridge-client 0.0.0 → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Godot MCP contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,106 @@
1
- # @godot-mcp/bridge-client
1
+ # Godot MCP
2
2
 
3
- Namespace bootstrap only. Install the first supported release from the `latest` tag.
3
+ Godot MCP is an open-source, security-first MCP server and Godot editor addon. Phase 7 provides reversible installation, authenticated Godot 4.7 editor attachment, six default observe-only tools, explicitly gated runtime/input surfaces, permission-scoped editor authoring, native read-only GDScript debugging, and bounded structured performance evidence.
4
+
5
+ ## Requirements
6
+
7
+ - macOS (the currently certified platform)
8
+ - Node.js 22
9
+ - pnpm 11.13.0
10
+ - Godot 4.7 stable
11
+
12
+ Compatibility is evidence-gated by `release/compatibility-matrix.json`. Godot 4.4–4.6 and Linux/Windows remain experimental until their exact matrix cells carry trusted certification receipts; pending cells are not advertised as supported.
13
+
14
+ ## Source quick start
15
+
16
+ ```bash
17
+ pnpm install --frozen-lockfile
18
+ pnpm build
19
+ node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js init --project /absolute/path/to/godot-project
20
+ node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js doctor --project /absolute/path/to/godot-project
21
+ node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js editor --project /absolute/path/to/godot-project
22
+ ```
23
+
24
+ For a verified release-to-release replacement, run `godot-mcp upgrade --project /absolute/path/to/godot-project --source /absolute/path/to/new/addons/godot_mcp`. Upgrade and rollback refuse independently modified installed files and preserve the original uninstall preimage.
25
+
26
+ Use the `editor` command for the Phase 7-certified launch. It writes a short-lived owner-only startup attestation, then starts Godot with the authenticated editor debugger and native DAP assigned to one loopback port; the debugger binds first, so unauthenticated DAP never acquires a listener. The addon consumes the attestation and connects outward only when a matching MCP runtime publishes a short-lived pairing descriptor. Opening the project through another launcher keeps earlier editor features available, but runtime debugging fails closed because secure startup cannot be proven by copied user arguments alone.
27
+
28
+ Register the source checkout with Codex using absolute paths:
29
+
30
+ ```bash
31
+ codex mcp add godot -- node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js connect --project /absolute/path/to/godot-project
32
+ ```
33
+
34
+ The default registration remains observe-only. To opt into one MCP-owned instrumented runtime, explicitly grant both its tier and pack:
35
+
36
+ ```bash
37
+ codex mcp add godot-runtime -- node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js connect --project /absolute/path/to/godot-project --grant runtime_control --pack runtime
38
+ ```
39
+
40
+ To launch and automate the owned runtime, grant the input pack separately:
41
+
42
+ ```bash
43
+ codex mcp add godot-runtime-input -- node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js connect --project /absolute/path/to/godot-project --grant runtime_control --pack runtime --pack input
44
+ ```
45
+
46
+ To preview and apply bounded editor mutations, explicitly grant both the mutation tier and editor pack:
47
+
48
+ ```bash
49
+ codex mcp add godot-editor -- node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js connect --project /absolute/path/to/godot-project --grant project_mutate --pack editor
50
+ ```
51
+
52
+ Start a fresh Codex task after registration so the newly registered MCP server is exposed. To stop using the addon while retaining its files, or remove the verified installation completely:
53
+
54
+ ```bash
55
+ node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js disable --project /absolute/path/to/godot-project
56
+ node /absolute/path/to/godot-mcp/packages/cli/dist/bin.js uninstall --project /absolute/path/to/godot-project
57
+ ```
58
+
59
+ Uninstall refuses to remove the addon, project configuration, or `project.godot` if they changed independently after installation.
60
+
61
+ ## Implemented MCP tools
62
+
63
+ - `godot_session` — attachment, project identity, versions, and grants
64
+ - `godot_capabilities` — currently visible observe/core capabilities
65
+ - `godot_doctor` — installation, plugin, identity, and attachment diagnostics
66
+ - `godot_help` — built-in usage and security-boundary help
67
+ - `godot_query` — bounded editor state, open scene/tree/node metadata, indexed resources, approved project settings, and redacted diagnostics
68
+ - `godot_capture` — bounded PNG from the current 2D or selected 3D editor viewport, returned as MCP image content and persisted as session evidence
69
+
70
+ The default six tools are read-only and closed-world. A runtime-authorized session additionally exposes:
71
+
72
+ - `godot_runtime` — launch, bounded runtime queries/control, native GDScript breakpoints/stacks/variables/selector watches, monitor snapshots, and cancellable structured profiles for one authenticated child runtime
73
+ - `godot_runtime_capture` — one to eight ordered running-game PNG frames with verified evidence metadata
74
+ - `godot_input` — bounded events, frame-indexed sequences, non-passive recording, and deterministic replay for the owned runtime
75
+ - `godot_editor` — preview, apply, undo, and redo one bounded scene/node/resource/source authoring batch with durable idempotency and native editor history
76
+
77
+ For example:
78
+
79
+ ```json
80
+ { "operation": "scene_tree", "scenePath": "res://main.tscn", "maxDepth": 8, "maxNodes": 250 }
81
+ { "viewport": "2d", "maxWidth": 1280, "maxHeight": 720 }
82
+ { "operation": "launch", "scenePath": "res://main.tscn" }
83
+ { "operation": "debug_breakpoints_set", "handle": { "runId": "<run UUID>", "generation": 1 }, "breakpoints": [{ "sourcePath": "res://player.gd", "line": 42 }] }
84
+ { "operation": "profile_start", "handle": { "runId": "<run UUID>", "generation": 1 }, "durationMs": 1000, "intervalFrames": 1, "groups": ["frame", "memory"], "retainRaw": false }
85
+ { "operation": "sequence", "handle": { "runId": "<run UUID>", "generation": 1 }, "mode": "deterministic", "events": [{ "frameOffset": 0, "event": { "type": "action", "action": "jump", "pressed": true, "strengthMillionths": 1000000 } }, { "frameOffset": 1, "event": { "type": "action", "action": "jump", "pressed": false, "strengthMillionths": 0 } }] }
86
+ ```
87
+
88
+ Runtime control and input are off unless their explicit flags are present. Deterministic sequences/replay require a paused owned runtime; offsets are zero-based, so offsets 0–1 process across two rendered frames and leave it paused. Recording captures only MCP-injected events. Receipts and audit summaries omit raw action names, keycodes, coordinates, and trace payloads. There is no OS-global/editor input, arbitrary text, process, filesystem, network, method-call, or GDScript-evaluation primitive.
89
+
90
+ ## Development and certification
91
+
92
+ ```bash
93
+ GODOT_BIN=/opt/homebrew/bin/godot pnpm qa:phase-0-1
94
+ GODOT_BIN=/opt/homebrew/bin/godot pnpm qa:phase-2
95
+ GODOT_BIN=/opt/homebrew/bin/godot pnpm qa:phase-3
96
+ GODOT_BIN=/opt/homebrew/bin/godot pnpm qa:phase-4
97
+ GODOT_BIN=/opt/homebrew/bin/godot pnpm qa:phase-5
98
+ GODOT_BIN=/opt/homebrew/bin/godot pnpm qa:phase-6
99
+ GODOT_BIN=/opt/homebrew/bin/godot pnpm qa:phase-7
100
+ ```
101
+
102
+ The Phase 7 gate certifies secure shared-port editor startup, native-DAP inertness, authenticated editor-session debugging, breakpoints/stacks/variables/selector watches, bounded public monitor snapshots, completed and cancelled profiles, hostile-input rejection, published stdio behavior, and zero owned-state or fixture residue. Earlier gates remain required regressions. See [Phase 7 testing](docs/testing/phase-7.md), [Phase 6 testing](docs/testing/phase-6.md), the [threat model](docs/security/threat-model.md), the [bridge protocol](docs/protocol/bridge-v1.md), and the [master design](docs/superpowers/specs/2026-07-15-godot-mcp-master-design.md).
103
+
104
+ ## Roadmap
105
+
106
+ Later phases add declarative playtests, imports/builds/exports, evidence retrieval, compatibility lanes, and explicitly gated disposable-fixture unsafe mode. None of those capabilities are claimed by Phase 7.
@@ -0,0 +1,24 @@
1
+ import type { AddressInfo } from "node:net";
2
+ import { type AuditSink, type SessionGrants } from "@godot-mcp/control-plane";
3
+ import type { ProjectIdentity } from "@godot-mcp/protocol";
4
+ import { BridgeSession } from "./bridgeSession.js";
5
+ export interface StartBridgeServerOptions {
6
+ project: ProjectIdentity;
7
+ grants: SessionGrants;
8
+ addonManifestSha256: string;
9
+ auditSink: AuditSink;
10
+ handshakeTimeoutMs?: number;
11
+ now?: () => number;
12
+ onAttached?: (session: BridgeSession) => void;
13
+ onDisconnected?: () => void;
14
+ }
15
+ export interface BridgeServer {
16
+ readonly port: number;
17
+ readonly address: AddressInfo;
18
+ readonly descriptorPath: string;
19
+ readonly session: BridgeSession | null;
20
+ waitForAttachment(timeoutMs: number): Promise<BridgeSession>;
21
+ close(): Promise<void>;
22
+ }
23
+ export declare function startBridgeServer(options: StartBridgeServerOptions): Promise<BridgeServer>;
24
+ //# sourceMappingURL=bridgeServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridgeServer.d.ts","sourceRoot":"","sources":["../src/bridgeServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,eAAe,CAAC;IACzB,MAAM,EAAE,aAAa,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,SAAS,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC;IACvC,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuJhG"}
@@ -0,0 +1,147 @@
1
+ import { access, rm } from "node:fs/promises";
2
+ import { createPairingDescriptor, GodotMcpException, } from "@godot-mcp/control-plane";
3
+ import { WebSocketServer } from "ws";
4
+ import { BridgeSession } from "./bridgeSession.js";
5
+ import { performHandshake, rejectHandshake } from "./handshake.js";
6
+ export async function startBridgeServer(options) {
7
+ const websocket = new WebSocketServer({
8
+ host: "127.0.0.1",
9
+ port: 0,
10
+ path: "/bridge",
11
+ maxPayload: 1_048_576,
12
+ perMessageDeflate: false,
13
+ clientTracking: true,
14
+ });
15
+ await new Promise((resolvePromise, reject) => {
16
+ websocket.once("listening", resolvePromise);
17
+ websocket.once("error", reject);
18
+ });
19
+ const address = websocket.address();
20
+ let pairing;
21
+ try {
22
+ pairing = await createPairingDescriptor(options.project, address.port, options.grants);
23
+ }
24
+ catch (error) {
25
+ await new Promise((resolvePromise) => websocket.close(() => resolvePromise()));
26
+ throw error;
27
+ }
28
+ let currentSession = null;
29
+ let pendingSocket = null;
30
+ let pairingConsumed = false;
31
+ let closePromise = null;
32
+ const attachmentWaiters = new Set();
33
+ const now = options.now ?? Date.now;
34
+ const audit = async (event, outcome, argumentsValue, errorCode) => {
35
+ await options.auditSink.append({
36
+ sessionId: currentSession?.sessionId ?? null,
37
+ projectId: options.project.projectId,
38
+ event,
39
+ outcome,
40
+ permissionTier: "observe",
41
+ arguments: argumentsValue,
42
+ errorCode,
43
+ });
44
+ };
45
+ websocket.on("connection", (socket, request) => {
46
+ socket.on("error", (error) => {
47
+ if (/max payload size exceeded/i.test(error.message)) {
48
+ void audit("transport.limit", "rejected", { limit: "maxPayload" }, "PAYLOAD_TOO_LARGE");
49
+ }
50
+ });
51
+ if (request.socket.remoteAddress !== "127.0.0.1" ||
52
+ pendingSocket !== null ||
53
+ currentSession !== null ||
54
+ pairingConsumed ||
55
+ closePromise !== null) {
56
+ void audit("pair.rejected", "rejected", { reason: "connection_state" }, "AUTHENTICATION_FAILED");
57
+ socket.close(1008, "connection rejected");
58
+ return;
59
+ }
60
+ pendingSocket = socket;
61
+ void (async () => {
62
+ try {
63
+ const handshake = await performHandshake(socket, {
64
+ descriptor: pairing.descriptor,
65
+ descriptorPath: pairing.path,
66
+ addonManifestSha256: options.addonManifestSha256,
67
+ timeoutMs: options.handshakeTimeoutMs ?? 5_000,
68
+ now,
69
+ });
70
+ pairingConsumed = true;
71
+ const session = new BridgeSession(socket, handshake.key, handshake.verifier, {
72
+ sessionId: handshake.sessionId,
73
+ project: options.project,
74
+ grants: options.grants,
75
+ godotVersion: handshake.godotVersion,
76
+ addonManifestSha256: options.addonManifestSha256,
77
+ });
78
+ currentSession = session;
79
+ pendingSocket = null;
80
+ options.onAttached?.(session);
81
+ session.onClose(() => {
82
+ if (currentSession === session)
83
+ currentSession = null;
84
+ options.onDisconnected?.();
85
+ void audit("session.closed", "success", {}, null);
86
+ });
87
+ session.onRejected((code) => {
88
+ void audit("session.rejected", "rejected", {}, code);
89
+ });
90
+ await audit("pair.succeeded", "success", { godotVersion: handshake.godotVersion }, null);
91
+ for (const resolveWaiter of attachmentWaiters)
92
+ resolveWaiter(session);
93
+ attachmentWaiters.clear();
94
+ session.send("pair.complete", { attached: true }, now() + 5_000);
95
+ }
96
+ catch (error) {
97
+ pendingSocket = null;
98
+ pairingConsumed ||= await access(pairing.path).then(() => false, () => true);
99
+ const code = error instanceof GodotMcpException ? error.code : "AUTHENTICATION_FAILED";
100
+ await audit("pair.rejected", "rejected", {}, code);
101
+ rejectHandshake(socket, error);
102
+ }
103
+ })();
104
+ });
105
+ return {
106
+ port: address.port,
107
+ address,
108
+ descriptorPath: pairing.path,
109
+ get session() {
110
+ return currentSession;
111
+ },
112
+ waitForAttachment(timeoutMs) {
113
+ if (currentSession)
114
+ return Promise.resolve(currentSession);
115
+ return new Promise((resolvePromise, reject) => {
116
+ const resolveAttachment = (session) => {
117
+ clearTimeout(timeout);
118
+ attachmentWaiters.delete(resolveAttachment);
119
+ resolvePromise(session);
120
+ };
121
+ const timeout = setTimeout(() => {
122
+ attachmentWaiters.delete(resolveAttachment);
123
+ reject(new Error(`Godot addon did not attach within ${timeoutMs}ms`));
124
+ }, timeoutMs);
125
+ attachmentWaiters.add(resolveAttachment);
126
+ });
127
+ },
128
+ close() {
129
+ if (closePromise)
130
+ return closePromise;
131
+ closePromise = (async () => {
132
+ await rm(pairing.path, { force: true });
133
+ if (pendingSocket) {
134
+ pendingSocket.terminate();
135
+ pendingSocket = null;
136
+ }
137
+ if (currentSession)
138
+ await currentSession.close();
139
+ for (const client of websocket.clients)
140
+ client.terminate();
141
+ await new Promise((resolvePromise) => websocket.close(() => resolvePromise()));
142
+ })();
143
+ return closePromise;
144
+ },
145
+ };
146
+ }
147
+ //# sourceMappingURL=bridgeServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridgeServer.js","sourceRoot":"","sources":["../src/bridgeServer.ts"],"names":[],"mapp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, type SessionGrants } from "@godot-mcp/control-plane";
2
+ import { type BridgeEnvelope, type ProjectIdentity } from "@godot-mcp/protocol";
3
+ import { WebSocket } from "ws";
4
+ export interface BridgeSessionInfo {
5
+ sessionId: string;
6
+ project: ProjectIdentity;
7
+ grants: SessionGrants;
8
+ godotVersion: string;
9
+ addonManifestSha256: string;
10
+ }
11
+ export interface BridgeRequestOptions {
12
+ timeoutMs?: number;
13
+ maxResponseBytes?: number;
14
+ correlationId?: string;
15
+ }
16
+ export interface BridgeCommandResult<T> {
17
+ requestId: string;
18
+ data: T;
19
+ binary?: Uint8Array;
20
+ binarySha256?: string;
21
+ }
22
+ export declare class BridgeSession {
23
+ private readonly socket;
24
+ private readonly key;
25
+ private readonly verifier;
26
+ readonly info: BridgeSessionInfo;
27
+ private readonly events;
28
+ private readonly pending;
29
+ private sendSequence;
30
+ constructor(socket: WebSocket, key: Uint8Array, verifier: EnvelopeVerifier, info: BridgeSessionInfo);
31
+ get sessionId(): string;
32
+ onEnvelope(listener: (envelope: BridgeEnvelope) => void): () => void;
33
+ onClose(listener: () => void): () => void;
34
+ onRejected(listener: (code: "AUTHENTICATION_FAILED" | "INVALID_REQUEST") => void): () => void;
35
+ send(method: string, params: unknown, deadlineUnixMs?: number): BridgeEnvelope;
36
+ request<T>(method: "editor.query" | "editor.capture" | "editor.mutate" | "project.operation" | "runtime.prepare" | "runtime.command" | "runtime.capture" | "runtime.cleanup", params: unknown, options?: BridgeRequestOptions): Promise<BridgeCommandResult<T>>;
37
+ close(code?: number, reason?: string): Promise<void>;
38
+ private readonly handleMessage;
39
+ private handleCommandChunk;
40
+ private handleCommandResult;
41
+ private rejectPending;
42
+ private finishPending;
43
+ private rejectAllPending;
44
+ }
45
+ //# sourceMappingURL=bridgeSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridgeSession.d.ts","sourceRoot":"","sources":["../src/bridgeSession.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,gBAAgB,EACrB,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AI,GAAG,MAAM,IAAI;IAKzC,UAAU,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,uBAAuB,GAAG,iBAAiB,KAAK,IAAI,GAAG,MAAM,IAAI;IAK7F,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,SAAsB,GAAG,cAAc;IAc3F,OAAO,CAAC,CAAC,EACP,MAAM,EACF,cAAc,GACd,gBAAgB,GAChB,eAAe,GACf,mBAAmB,GACnB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,EACrB,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAyClC,KAAK,CAAC,IAAI,SAAO,EAAE,MAAM,SAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAsB5B;IAEF,OAAO,CAAC,kBAAkB;IAiC1B,OAAO,CAAC,mBAAmB;IAmE3B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,gBAAgB;CAKzB"}
@@ -0,0 +1,250 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { EventEmitter } from "node:events";
3
+ import { GodotMcpException, signEnvelope, } from "@godot-mcp/control-plane";
4
+ import { BridgeCommandChunkSchema, BridgeCommandResultSchema, } from "@godot-mcp/protocol";
5
+ import { WebSocket } from "ws";
6
+ const MAX_PENDING_REQUESTS = 16;
7
+ const MAX_CHUNK_BYTES = 512 * 1024;
8
+ const DEFAULT_MAX_RESPONSE_BYTES = 512 * 1024;
9
+ function bridgeError(code, message, retryable = false, correlationId = randomUUID(), facts = {}) {
10
+ const input = {
11
+ code,
12
+ message,
13
+ retryable,
14
+ correlationId,
15
+ partialEffects: facts.partialEffects ?? false,
16
+ rollback: facts.rollback ?? "not_needed",
17
+ };
18
+ if (facts.failedPhase !== undefined)
19
+ input.failedPhase = facts.failedPhase;
20
+ if (facts.safeRecovery !== undefined)
21
+ input.safeRecovery = facts.safeRecovery;
22
+ return new GodotMcpException(input);
23
+ }
24
+ export class BridgeSession {
25
+ socket;
26
+ key;
27
+ verifier;
28
+ info;
29
+ events = new EventEmitter();
30
+ pending = new Map();
31
+ sendSequence = 0;
32
+ constructor(socket, key, verifier, info) {
33
+ this.socket = socket;
34
+ this.key = key;
35
+ this.verifier = verifier;
36
+ this.info = info;
37
+ socket.on("message", this.handleMessage);
38
+ socket.once("close", () => {
39
+ this.rejectAllPending("NOT_ATTACHED", "Bridge session disconnected");
40
+ this.events.emit("close");
41
+ });
42
+ }
43
+ get sessionId() {
44
+ return this.info.sessionId;
45
+ }
46
+ onEnvelope(listener) {
47
+ this.events.on("envelope", listener);
48
+ return () => this.events.off("envelope", listener);
49
+ }
50
+ onClose(listener) {
51
+ this.events.on("close", listener);
52
+ return () => this.events.off("close", listener);
53
+ }
54
+ onRejected(listener) {
55
+ this.events.on("rejected", listener);
56
+ return () => this.events.off("rejected", listener);
57
+ }
58
+ send(method, params, deadlineUnixMs = Date.now() + 30_000) {
59
+ if (this.socket.readyState !== WebSocket.OPEN)
60
+ throw new Error("Bridge session is closed");
61
+ this.sendSequence += 1;
62
+ const envelope = signEnvelope(this.key, {
63
+ sessionId: this.sessionId,
64
+ sequence: this.sendSequence,
65
+ deadlineUnixMs,
66
+ method,
67
+ params,
68
+ });
69
+ this.socket.send(JSON.stringify(envelope));
70
+ return envelope;
71
+ }
72
+ request(method, params, options = {}) {
73
+ if (this.pending.size >= MAX_PENDING_REQUESTS) {
74
+ return Promise.reject(bridgeError("CONFLICT", "Bridge request queue is full"));
75
+ }
76
+ const requestId = options.correlationId ?? randomUUID();
77
+ const timeoutMs = Math.min(Math.max(options.timeoutMs ?? 30_000, 1), 60_000);
78
+ const maxResponseBytes = Math.min(Math.max(options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES, 1), 8 * 1024 * 1024);
79
+ return new Promise((resolve, reject) => {
80
+ const timeout = setTimeout(() => {
81
+ this.pending.delete(requestId);
82
+ reject(bridgeError("TIMEOUT", `Bridge request timed out after ${timeoutMs}ms`, true, requestId));
83
+ }, timeoutMs);
84
+ this.pending.set(requestId, {
85
+ resolve: resolve,
86
+ reject,
87
+ timeout,
88
+ maxResponseBytes,
89
+ chunks: [],
90
+ nextChunkIndex: 0,
91
+ receivedBytes: 0,
92
+ });
93
+ try {
94
+ this.send(method, { requestId, arguments: params }, Date.now() + timeoutMs);
95
+ }
96
+ catch (error) {
97
+ clearTimeout(timeout);
98
+ this.pending.delete(requestId);
99
+ reject(error instanceof Error ? error : new Error(String(error)));
100
+ }
101
+ });
102
+ }
103
+ close(code = 1001, reason = "server closing") {
104
+ if (this.socket.readyState === WebSocket.CLOSED)
105
+ return Promise.resolve();
106
+ return new Promise((resolvePromise) => {
107
+ const timeout = setTimeout(() => this.socket.terminate(), 1_000);
108
+ this.socket.once("close", () => {
109
+ clearTimeout(timeout);
110
+ resolvePromise();
111
+ });
112
+ this.socket.close(code, reason);
113
+ });
114
+ }
115
+ handleMessage = (data, isBinary) => {
116
+ if (isBinary) {
117
+ this.events.emit("rejected", "INVALID_REQUEST");
118
+ this.socket.close(1008, "binary frames are not allowed");
119
+ return;
120
+ }
121
+ try {
122
+ const envelope = this.verifier.verify(JSON.parse(data.toString()));
123
+ if (envelope.sessionId !== this.sessionId)
124
+ throw new Error("Session ID mismatch");
125
+ if (envelope.method === "command.chunk") {
126
+ this.handleCommandChunk(envelope.params);
127
+ return;
128
+ }
129
+ if (envelope.method === "command.result") {
130
+ this.handleCommandResult(envelope.params);
131
+ return;
132
+ }
133
+ this.events.emit("envelope", envelope);
134
+ }
135
+ catch {
136
+ this.events.emit("rejected", "AUTHENTICATION_FAILED");
137
+ this.socket.close(1008, "invalid signed envelope");
138
+ }
139
+ };
140
+ handleCommandChunk(input) {
141
+ let parsed;
142
+ try {
143
+ parsed = BridgeCommandChunkSchema.parse(input);
144
+ }
145
+ catch {
146
+ const requestId = typeof input === "object" && input !== null && "requestId" in input
147
+ ? String(input.requestId)
148
+ : undefined;
149
+ if (requestId)
150
+ this.rejectPending(requestId, "INVALID_REQUEST", "Malformed command chunk");
151
+ else
152
+ this.socket.close(1008, "malformed command chunk");
153
+ return;
154
+ }
155
+ const pending = this.pending.get(parsed.requestId);
156
+ if (!pending)
157
+ return;
158
+ const bytes = Buffer.from(parsed.data, "base64url");
159
+ if (parsed.index !== pending.nextChunkIndex ||
160
+ bytes.length > MAX_CHUNK_BYTES ||
161
+ (pending.totalChunks !== undefined && pending.totalChunks !== parsed.total) ||
162
+ (pending.binarySha256 !== undefined && pending.binarySha256 !== parsed.sha256) ||
163
+ pending.receivedBytes + bytes.length > pending.maxResponseBytes) {
164
+ this.rejectPending(parsed.requestId, "INVALID_REQUEST", "Invalid command chunk stream");
165
+ return;
166
+ }
167
+ pending.totalChunks = parsed.total;
168
+ pending.binarySha256 = parsed.sha256;
169
+ pending.chunks.push(bytes);
170
+ pending.receivedBytes += bytes.length;
171
+ pending.nextChunkIndex += 1;
172
+ }
173
+ handleCommandResult(input) {
174
+ let parsed;
175
+ try {
176
+ parsed = BridgeCommandResultSchema.parse(input);
177
+ }
178
+ catch {
179
+ const requestId = typeof input === "object" && input !== null && "requestId" in input
180
+ ? String(input.requestId)
181
+ : undefined;
182
+ if (requestId)
183
+ this.rejectPending(requestId, "INVALID_REQUEST", "Malformed command result");
184
+ else
185
+ this.socket.close(1008, "malformed command result");
186
+ return;
187
+ }
188
+ const pending = this.pending.get(parsed.requestId);
189
+ if (!pending)
190
+ return;
191
+ if (!parsed.ok) {
192
+ const error = parsed.error;
193
+ const facts = error === undefined ? {} : {
194
+ failedPhase: error.failedPhase,
195
+ partialEffects: error.partialEffects,
196
+ rollback: error.rollback,
197
+ safeRecovery: error.safeRecovery,
198
+ };
199
+ this.finishPending(parsed.requestId, undefined, bridgeError(error?.code ?? "GODOT_RUNTIME_ERROR", error?.message ?? "Godot command failed", error?.retryable ?? false, parsed.requestId, facts));
200
+ return;
201
+ }
202
+ let binary;
203
+ if (parsed.binary) {
204
+ binary = Buffer.concat(pending.chunks);
205
+ const digest = createHash("sha256").update(binary).digest("hex");
206
+ if (pending.nextChunkIndex !== parsed.binary.chunks ||
207
+ pending.totalChunks !== parsed.binary.chunks ||
208
+ pending.binarySha256 !== parsed.binary.sha256 ||
209
+ binary.length !== parsed.binary.size ||
210
+ digest !== parsed.binary.sha256) {
211
+ this.rejectPending(parsed.requestId, "INVALID_REQUEST", "Command binary verification failed");
212
+ return;
213
+ }
214
+ }
215
+ else if (pending.chunks.length > 0) {
216
+ this.rejectPending(parsed.requestId, "INVALID_REQUEST", "Command result omitted binary metadata");
217
+ return;
218
+ }
219
+ const value = {
220
+ requestId: parsed.requestId,
221
+ data: parsed.data,
222
+ };
223
+ if (binary !== undefined && parsed.binary !== undefined) {
224
+ value.binary = binary;
225
+ value.binarySha256 = parsed.binary.sha256;
226
+ }
227
+ this.finishPending(parsed.requestId, value);
228
+ }
229
+ rejectPending(requestId, code, message) {
230
+ this.finishPending(requestId, undefined, bridgeError(code, message, false, requestId));
231
+ }
232
+ finishPending(requestId, value, error) {
233
+ const pending = this.pending.get(requestId);
234
+ if (!pending)
235
+ return;
236
+ clearTimeout(pending.timeout);
237
+ this.pending.delete(requestId);
238
+ pending.chunks.length = 0;
239
+ if (error)
240
+ pending.reject(error);
241
+ else if (value)
242
+ pending.resolve(value);
243
+ }
244
+ rejectAllPending(code, message) {
245
+ for (const requestId of [...this.pending.keys()]) {
246
+ this.rejectPending(requestId, code, message);
247
+ }
248
+ }
249
+ }
250
+ //# sourceMappingURL=bridgeSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridgeSession.js","sourceRoot":"","sources":["../src/bridgeSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,C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godot-mcp/control-plane";
2
+ import { WebSocket } from "ws";
3
+ export interface PairRequest {
4
+ method: "pair";
5
+ token: string;
6
+ sessionNonce: string;
7
+ protocolVersion: string;
8
+ productVersion: string;
9
+ project: SessionDescriptor["project"];
10
+ addonManifestSha256: string;
11
+ godotVersion: string;
12
+ }
13
+ export interface HandshakeOptions {
14
+ descriptor: SessionDescriptor;
15
+ descriptorPath: string;
16
+ addonManifestSha256: string;
17
+ timeoutMs: number;
18
+ now: () => number;
19
+ }
20
+ export interface HandshakeResult {
21
+ sessionId: string;
22
+ serverNonce: string;
23
+ godotVersion: string;
24
+ verifier: EnvelopeVerifier;
25
+ key: Buffer;
26
+ }
27
+ export declare function performHandshake(socket: WebSocket, options: HandshakeOptions): Promise<HandshakeResult>;
28
+ export declare function rejectHandshake(socket: WebSocket, error: unknown): void;
29
+ //# sourceMappingURL=handshake.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handshake.d.ts","sourceRoot":"","sources":["../src/handshake.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAGhB,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,SAAS,EAAgB,MAAM,IAAI,CAAC;AAE7C,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACtC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;CACb;AAsFD,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CAgE1B;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAYvE"}
@@ -0,0 +1,145 @@
1
+ import { createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
2
+ import { rm } from "node:fs/promises";
3
+ import { EnvelopeVerifier, GodotMcpException, deriveSessionKey, } from "@godot-mcp/control-plane";
4
+ import { BRIDGE_PROTOCOL_VERSION, PRODUCT_VERSION, ProjectIdentitySchema, canonicalJson, } from "@godot-mcp/protocol";
5
+ import { WebSocket } from "ws";
6
+ function authenticationFailed(message) {
7
+ return protocolFailure("AUTHENTICATION_FAILED", message);
8
+ }
9
+ function protocolFailure(code, message) {
10
+ return new GodotMcpException({
11
+ code,
12
+ message,
13
+ retryable: false,
14
+ correlationId: randomUUID(),
15
+ partialEffects: false,
16
+ rollback: "not_needed",
17
+ });
18
+ }
19
+ function sameSecret(left, right) {
20
+ const leftBytes = Buffer.from(left, "utf8");
21
+ const rightBytes = Buffer.from(right, "utf8");
22
+ return leftBytes.length === rightBytes.length && timingSafeEqual(leftBytes, rightBytes);
23
+ }
24
+ function nextTextMessage(socket, timeoutMs) {
25
+ return new Promise((resolvePromise, reject) => {
26
+ const cleanup = () => {
27
+ clearTimeout(timeout);
28
+ socket.off("message", onMessage);
29
+ socket.off("close", onClose);
30
+ socket.off("error", onError);
31
+ };
32
+ const onMessage = (data, isBinary) => {
33
+ cleanup();
34
+ if (isBinary)
35
+ reject(authenticationFailed("Binary handshake frames are not allowed"));
36
+ else
37
+ resolvePromise(data.toString());
38
+ };
39
+ const onClose = () => {
40
+ cleanup();
41
+ reject(authenticationFailed("Pairing connection closed before authentication"));
42
+ };
43
+ const onError = () => {
44
+ cleanup();
45
+ reject(authenticationFailed("Pairing transport failed"));
46
+ };
47
+ const timeout = setTimeout(() => {
48
+ cleanup();
49
+ reject(authenticationFailed("Pairing handshake timed out"));
50
+ }, timeoutMs);
51
+ socket.on("message", onMessage);
52
+ socket.once("close", onClose);
53
+ socket.once("error", onError);
54
+ });
55
+ }
56
+ function parsePairRequest(text) {
57
+ let value;
58
+ try {
59
+ value = JSON.parse(text);
60
+ }
61
+ catch {
62
+ throw protocolFailure("INVALID_REQUEST", "Pairing request is not valid JSON");
63
+ }
64
+ if (typeof value !== "object" || value === null) {
65
+ throw protocolFailure("INVALID_REQUEST", "Pairing request must be an object");
66
+ }
67
+ const request = value;
68
+ if (request.method !== "pair" ||
69
+ typeof request.token !== "string" ||
70
+ typeof request.sessionNonce !== "string" ||
71
+ typeof request.protocolVersion !== "string" ||
72
+ typeof request.productVersion !== "string" ||
73
+ !ProjectIdentitySchema.safeParse(request.project).success ||
74
+ typeof request.addonManifestSha256 !== "string" ||
75
+ typeof request.godotVersion !== "string") {
76
+ throw protocolFailure("INVALID_REQUEST", "The only allowed unauthenticated message is a complete pair request");
77
+ }
78
+ return request;
79
+ }
80
+ export async function performHandshake(socket, options) {
81
+ const request = parsePairRequest(await nextTextMessage(socket, options.timeoutMs));
82
+ const descriptor = options.descriptor;
83
+ if (descriptor.expiresAtUnixMs < options.now())
84
+ throw authenticationFailed("Pairing descriptor expired");
85
+ if (!sameSecret(request.token, descriptor.token))
86
+ throw authenticationFailed("Pairing token is invalid");
87
+ if (!sameSecret(request.sessionNonce, descriptor.sessionNonce)) {
88
+ throw authenticationFailed("Pairing session nonce is invalid");
89
+ }
90
+ if (request.protocolVersion !== BRIDGE_PROTOCOL_VERSION ||
91
+ request.productVersion !== PRODUCT_VERSION) {
92
+ throw authenticationFailed("Pairing protocol or product version does not match");
93
+ }
94
+ if (canonicalJson(request.project) !== canonicalJson(descriptor.project)) {
95
+ if (request.project.projectId === descriptor.project.projectId &&
96
+ request.project.rootRealPath === descriptor.project.rootRealPath &&
97
+ request.project.projectConfigSha256 !== descriptor.project.projectConfigSha256) {
98
+ throw protocolFailure("PROJECT_CHANGED", "Pairing project contents changed");
99
+ }
100
+ throw authenticationFailed("Pairing project identity does not match");
101
+ }
102
+ if (request.addonManifestSha256 !== options.addonManifestSha256) {
103
+ throw authenticationFailed("Pairing addon manifest does not match");
104
+ }
105
+ if (!request.godotVersion.startsWith("4.7.stable")) {
106
+ throw authenticationFailed("Godot 4.7.stable is required");
107
+ }
108
+ await rm(options.descriptorPath, { force: true });
109
+ const sessionId = `session_${randomUUID()}`;
110
+ const serverNonce = randomBytes(32).toString("base64url");
111
+ const serverProof = createHmac("sha256", Buffer.from(descriptor.token, "base64url"))
112
+ .update(`godot-mcp:server-proof:v1\n${sessionId}\n${serverNonce}`)
113
+ .digest("hex");
114
+ const key = deriveSessionKey(descriptor.token, descriptor.sessionNonce, serverNonce);
115
+ socket.send(JSON.stringify({
116
+ method: "pair_ok",
117
+ sessionId,
118
+ serverNonce,
119
+ grants: descriptor.grants,
120
+ serverProof,
121
+ }));
122
+ const verifier = new EnvelopeVerifier(key, { now: options.now });
123
+ const acknowledgment = verifier.verify(JSON.parse(await nextTextMessage(socket, options.timeoutMs)));
124
+ const params = acknowledgment.params;
125
+ if (acknowledgment.sessionId !== sessionId ||
126
+ acknowledgment.method !== "pair.ack" ||
127
+ typeof params !== "object" ||
128
+ params === null ||
129
+ typeof params.serverProof !== "string" ||
130
+ !sameSecret(params.serverProof, serverProof)) {
131
+ throw authenticationFailed("Signed pairing acknowledgment is invalid");
132
+ }
133
+ return { sessionId, serverNonce, godotVersion: request.godotVersion, verifier, key };
134
+ }
135
+ export function rejectHandshake(socket, error) {
136
+ if (socket.readyState === WebSocket.OPEN) {
137
+ const code = error instanceof GodotMcpException ? error.code : "AUTHENTICATION_FAILED";
138
+ socket.send(JSON.stringify({
139
+ method: "pair_rejected",
140
+ code,
141
+ message: error instanceof Error ? error.message : "Pairing rejected",
142
+ }), () => socket.close(1008, "authentication failed"));
143
+ }
144
+ }
145
+ //# sourceMappingURL=handshake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handshake.js","sourceRoot":"","sources":["../src/handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,aAAa,GACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAgB,MAAM,IAAI,CAAC;AA6B7C,SAAS,oBAAoB,CAAC,OAAe;IAC3C,OAAO,eAAe,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,eAAe,CACtB,IAAqE,EACrE,OAAe;IAEf,OAAO,IAAI,iBAAiB,CAAC;QAC3B,IAAI;QACJ,OAAO;QACP,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,UAAU,EAAE;QAC3B,cAAc,EAAE,KAAK;QACrB,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,IAAY,EAAE,KAAa;IAC7C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9C,OAAO,SAAS,CAAC,MAAM,KAAK,UAAU,C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W,KAAK,QAAQ;QACtC,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,EAC5C,CAAC;QACD,MAAM,oBAAoB,CAAC,0CAA0C,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAiB,EAAE,KAAc;IAC/D,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;QACzC,MAAM,IAAI,GAAG,KAAK,YAAY,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB,CAAC;QACvF,MAAM,CAAC,IAAI,CACT,IAAI,CAAC,SAAS,CAAC;YACb,MAAM,EAAE,eAAe;YACvB,IAAI;YACJ,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB;SACrE,CAAC,EACF,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAClD,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { startBridgeServer, type BridgeServer, type StartBridgeServerOptions, } from "./bridgeServer.js";
2
+ export { BridgeSession, type BridgeCommandResult, type BridgeRequestOptions, type BridgeSessionInfo, } from "./bridgeSession.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,wBAAwB,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,GACvB,MAAM,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { startBridgeServer, } from "./bridgeServer.js";
2
+ export { BridgeSession, } from "./bridgeSession.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAGlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,GAId,MAAM,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,11 +1,31 @@
1
1
  {
2
2
  "name": "@godot-mcp/bridge-client",
3
- "version": "0.0.0",
4
- "description": "Namespace bootstrap for the Godot MCP bridge-client package.",
3
+ "version": "0.1.0",
5
4
  "type": "module",
6
- "main": "index.js",
7
- "files": ["index.js", "README.md"],
5
+ "exports": {
6
+ ".": "./dist/index.js"
7
+ },
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json",
16
+ "typecheck": "tsc -p tsconfig.json --noEmit"
17
+ },
18
+ "dependencies": {
19
+ "@godot-mcp/control-plane": "0.1.0",
20
+ "@godot-mcp/protocol": "0.1.0",
21
+ "ws": "8.21.0"
22
+ },
8
23
  "license": "MIT",
9
- "repository": "git+https://github.com/k0nkupa/godot-mcp.git",
10
- "publishConfig": { "access": "public", "tag": "bootstrap" }
24
+ "engines": {
25
+ "node": ">=22 <23"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/k0nkupa/godot-mcp.git"
30
+ }
11
31
  }
package/index.js DELETED
@@ -1 +0,0 @@
1
- export {};