Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,6 +31,7 @@ interface CliArgs {
"figma-oauth-token"?: string;
env?: string;
port?: number;
host?: string;
json?: boolean;
"skip-image-downloads"?: boolean;
}
Expand All @@ -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",
Expand Down Expand Up @@ -91,12 +98,14 @@ export function getServerConfig(isStdioMode: boolean): ServerConfig {

const config: Omit<ServerConfig, "auth"> = {
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",
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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})`,
);
Expand Down
14 changes: 7 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export async function startServer(): Promise<void> {
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<void> {
export async function startHttpServer(host: string, port: number, mcpServer: McpServer): Promise<void> {
const app = express();

// Parse JSON requests for the Streamable HTTP endpoint only, will break SSE endpoint
Expand Down Expand Up @@ -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 () => {
Expand Down