diff --git a/src/config.ts b/src/config.ts index 3e0c030c..a22f71f3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,12 +7,14 @@ import type { FigmaAuthOptions } from "./services/figma.js"; interface ServerConfig { auth: FigmaAuthOptions; port: number; + host: string; outputFormat: "yaml" | "json"; skipImageDownloads?: boolean; configSources: { figmaApiKey: "cli" | "env"; figmaOAuthToken: "cli" | "env" | "none"; port: "cli" | "env" | "default"; + host: "cli" | "env" | "default"; outputFormat: "cli" | "env" | "default"; envFile: "cli" | "default"; skipImageDownloads?: "cli" | "env" | "default"; @@ -29,6 +31,7 @@ interface CliArgs { "figma-oauth-token"?: string; env?: string; port?: number; + host?: string; json?: boolean; "skip-image-downloads"?: boolean; } @@ -53,6 +56,10 @@ export function getServerConfig(isStdioMode: boolean): ServerConfig { type: "number", description: "Port to run the server on", }, + host: { + type: "string", + description: "Host to run the server on", + }, json: { type: "boolean", description: "Output data from tools in JSON format instead of YAML", @@ -91,12 +98,14 @@ export function getServerConfig(isStdioMode: boolean): ServerConfig { const config: Omit = { port: 3333, + host: "127.0.0.1", outputFormat: "yaml", skipImageDownloads: false, configSources: { figmaApiKey: "env", figmaOAuthToken: "none", port: "default", + host: "default", outputFormat: "default", envFile: envFileSource, skipImageDownloads: "default", @@ -132,6 +141,15 @@ export function getServerConfig(isStdioMode: boolean): ServerConfig { config.configSources.port = "env"; } + // Handle HOST + if (argv.host) { + config.host = argv.host; + config.configSources.host = "cli"; + } else if (process.env.HOST) { + config.host = process.env.HOST; + config.configSources.host = "env"; + } + // Handle JSON output format if (argv.json) { config.outputFormat = "json"; @@ -174,6 +192,7 @@ export function getServerConfig(isStdioMode: boolean): ServerConfig { console.log("- Authentication Method: Personal Access Token (X-Figma-Token)"); } console.log(`- PORT: ${config.port} (source: ${config.configSources.port})`); + console.log(`- HOST: ${config.host} (source: ${config.configSources.host})`); console.log( `- OUTPUT_FORMAT: ${config.outputFormat} (source: ${config.configSources.outputFormat})`, ); diff --git a/src/server.ts b/src/server.ts index 5a18ef8c..23ed002b 100644 --- a/src/server.ts +++ b/src/server.ts @@ -35,12 +35,12 @@ export async function startServer(): Promise { const transport = new StdioServerTransport(); await server.connect(transport); } else { - console.log(`Initializing Figma MCP Server in HTTP mode on port ${config.port}...`); - await startHttpServer(config.port, server); + console.log(`Initializing Figma MCP Server in HTTP mode on ${config.host}:${config.port}...`); + await startHttpServer(config.host, config.port, server); } } -export async function startHttpServer(port: number, mcpServer: McpServer): Promise { +export async function startHttpServer(host: string, port: number, mcpServer: McpServer): Promise { const app = express(); // Parse JSON requests for the Streamable HTTP endpoint only, will break SSE endpoint @@ -176,11 +176,11 @@ export async function startHttpServer(port: number, mcpServer: McpServer): Promi } }); - httpServer = app.listen(port, "127.0.0.1", () => { + httpServer = app.listen(port, host, () => { Logger.log(`HTTP server listening on port ${port}`); - Logger.log(`SSE endpoint available at http://localhost:${port}/sse`); - Logger.log(`Message endpoint available at http://localhost:${port}/messages`); - Logger.log(`StreamableHTTP endpoint available at http://localhost:${port}/mcp`); + Logger.log(`SSE endpoint available at http://${host}:${port}/sse`); + Logger.log(`Message endpoint available at http://${host}:${port}/messages`); + Logger.log(`StreamableHTTP endpoint available at http://${host}:${port}/mcp`); }); process.on("SIGINT", async () => {