Skip to content

Commit a2656c5

Browse files
committed
Tiny fix and version bump
1 parent e5a3eb9 commit a2656c5

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@wunderio/wdrmcp",
33
"mcpName": "io.github.wunderio/wdrmcp",
4-
"version": "0.1.16",
4+
"version": "0.1.17",
55
"description": "Wunderio local MCP developer server",
66
"type": "module",
77
"bin": {

src/executors/mcp-stdio.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
1010
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
1111
import { getLogger } from "../logger.js";
12-
import { buildSshArgs } from "./ssh.js";
12+
import { buildSshArgs, buildDdevEnvPrelude } from "./ssh.js";
1313
import type {
1414
ToolExecutionResult,
1515
ToolExecutor,
@@ -196,6 +196,13 @@ export class McpStdioExecutor implements ToolExecutor, RemoteToolProvider {
196196
remoteCmd = `cd ${this.workingDir} && ${remoteCmd}`;
197197
}
198198

199+
// SSH sessions don't inherit container env vars — prepend the DDEV
200+
// env prelude so Drush can connect to the database and bootstrap.
201+
const envPrelude = buildDdevEnvPrelude(this.workingDir);
202+
if (envPrelude) {
203+
remoteCmd = `${envPrelude}${remoteCmd}`;
204+
}
205+
199206
const sshArgs = buildSshArgs({
200207
host: this.sshTarget,
201208
user: this.sshUser,

src/executors/ssh.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ export function buildSshArgs(options: SshArgOptions): string[] {
2424
return args;
2525
}
2626

27+
function escapeShellArg(value: string): string {
28+
return `'${value.replace(/'/g, `'"'"'`)}'`;
29+
}
30+
31+
/**
32+
* Build a shell prelude that exports DDEV environment variables (DB_HOST, etc.)
33+
* from .ddev/config.yaml. SSH sessions don't inherit container env vars, so
34+
* commands that need a Drupal bootstrap (like drush) require this.
35+
*/
36+
export function buildDdevEnvPrelude(workingDir?: string): string {
37+
if (!workingDir) {
38+
return "";
39+
}
40+
41+
const baseDir = workingDir.replace(/\/$/, "");
42+
const configPath = escapeShellArg(`${baseDir}/.ddev/config.yaml`);
43+
44+
return `if [ -f ${configPath} ]; then while IFS= read -r kv; do [ -n "$kv" ] && export "$kv"; done < <(awk -F'- ' '/- (DB_(HOST|NAME|USER|PASS)|HASH_SALT|ENVIRONMENT_NAME)=/ {print $2}' ${configPath}); fi; `;
45+
}
46+
2747
/**
2848
* Executes commands on SSH hosts.
2949
* Assumes SSH keys are configured and available (e.g. via homeadditions).
@@ -64,7 +84,7 @@ export class SshExecutor implements ContainerExecutor {
6484
remoteCmd = `cd ${this.escapeShellArg(workingDir)} && ${remoteCmd}`;
6585
}
6686

67-
const envPrelude = this.buildDdevEnvPrelude(workingDir);
87+
const envPrelude = buildDdevEnvPrelude(workingDir);
6888
if (envPrelude) {
6989
remoteCmd = `${envPrelude}${remoteCmd}`;
7090
if (log.isVerbose()) {
@@ -140,18 +160,7 @@ export class SshExecutor implements ContainerExecutor {
140160
}
141161

142162
private escapeShellArg(value: string): string {
143-
return `'${value.replace(/'/g, `'"'"'`)}'`;
144-
}
145-
146-
private buildDdevEnvPrelude(workingDir?: string): string {
147-
if (!workingDir) {
148-
return "";
149-
}
150-
151-
const baseDir = workingDir.replace(/\/$/, "");
152-
const configPath = this.escapeShellArg(`${baseDir}/.ddev/config.yaml`);
153-
154-
return `if [ -f ${configPath} ]; then while IFS= read -r kv; do [ -n "$kv" ] && export "$kv"; done < <(awk -F'- ' '/- (DB_(HOST|NAME|USER|PASS)|HASH_SALT|ENVIRONMENT_NAME)=/ {print $2}' ${configPath}); fi; `;
163+
return escapeShellArg(value);
155164
}
156165
}
157166

0 commit comments

Comments
 (0)