Skip to content

Commit c40fd3a

Browse files
committed
Make MCP server listen address configurable, using localhost by default
1 parent 14b01cd commit c40fd3a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,14 @@ options use the `PENPOT_MCP_` prefix for consistency.
197197

198198
### Server Configuration
199199

200-
| Environment Variable | Description | Default |
201-
|-----------------------------|----------------------------------------------------------------------------|---------|
202-
| `PENPOT_MCP_SERVER_PORT` | Port for the HTTP/SSE server | `4401` |
203-
| `PENPOT_MCP_WEBSOCKET_PORT` | Port for the WebSocket server (plugin connection) | `4402` |
204-
| `PENPOT_MCP_REPL_PORT` | Port for the REPL server (development/debugging) | `4403` |
205-
| `PENPOT_MCP_SERVER_ADDRESS` | Hostname or IP address where the MCP server can be reached | `localhost` |
206-
| `PENPOT_MCP_REMOTE_MODE` | Enable remote mode (disables file system access). Set to `true` to enable. | `false` |
200+
| Environment Variable | Description | Default |
201+
|------------------------------------|----------------------------------------------------------------------------|--------------|
202+
| `PENPOT_MCP_SERVER_LISTEN_ADDRESS` | Address on which the MCP server listens (binds to) | `localhost` |
203+
| `PENPOT_MCP_SERVER_PORT` | Port for the HTTP/SSE server | `4401` |
204+
| `PENPOT_MCP_WEBSOCKET_PORT` | Port for the WebSocket server (plugin connection) | `4402` |
205+
| `PENPOT_MCP_REPL_PORT` | Port for the REPL server (development/debugging) | `4403` |
206+
| `PENPOT_MCP_SERVER_ADDRESS` | Hostname or IP address via which clients can reach the MCP server | `localhost` |
207+
| `PENPOT_MCP_REMOTE_MODE` | Enable remote mode (disables file system access). Set to `true` to enable. | `false` |
207208

208209
### Logging Configuration
209210

@@ -230,6 +231,9 @@ you may set the following environment variables to configure the two servers
230231
(MCP server & plugin server) appropriately:
231232
* `PENPOT_MCP_REMOTE_MODE=true`: This ensures that the MCP server is operating
232233
in remote mode, with local file system access disabled.
234+
* `PENPOT_MCP_SERVER_LISTEN_ADDRESS=<address>`: Set this to the address on which
235+
the MCP server listens (binds to). To accept connections from any address, use
236+
`0.0.0.0` (use caution in untrusted networks).
233237
* `PENPOT_MCP_SERVER_ADDRESS=<your-address>`: This sets the hostname or IP address
234238
where the MCP server can be reached. The Penpot MCP Plugin uses this to construct
235239
the WebSocket URL as `ws://<your-address>:<port>` (default port: `4402`).

mcp-server/src/PenpotMcpServer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ export class PenpotMcpServer {
4444
private readonly port: number;
4545
private readonly webSocketPort: number;
4646
private readonly replPort: number;
47+
private readonly listenAddress: string;
48+
/**
49+
* the address (domain name or IP address) via which clients can reach the MCP server
50+
*/
4751
public readonly serverAddress: string;
4852

4953
constructor(private isMultiUser: boolean = false) {
5054
// read port configuration from environment variables
5155
this.port = parseInt(process.env.PENPOT_MCP_SERVER_PORT ?? "4401", 10);
5256
this.webSocketPort = parseInt(process.env.PENPOT_MCP_WEBSOCKET_PORT ?? "4402", 10);
5357
this.replPort = parseInt(process.env.PENPOT_MCP_REPL_PORT ?? "4403", 10);
58+
this.listenAddress = process.env.PENPOT_MCP_SERVER_LISTEN_ADDRESS ?? "localhost";
5459
this.serverAddress = process.env.PENPOT_MCP_SERVER_ADDRESS ?? "localhost";
5560

5661
this.configLoader = new ConfigurationLoader();
@@ -229,7 +234,7 @@ export class PenpotMcpServer {
229234
this.setupHttpEndpoints();
230235

231236
return new Promise((resolve) => {
232-
this.app.listen(this.port, async () => {
237+
this.app.listen(this.port, this.listenAddress, async () => {
233238
this.logger.info(`Multi-user mode: ${this.isMultiUserMode()}`);
234239
this.logger.info(`Remote mode: ${this.isRemoteMode()}`);
235240
this.logger.info(`Modern Streamable HTTP endpoint: http://${this.serverAddress}:${this.port}/mcp`);

0 commit comments

Comments
 (0)