fix(mcp): configure Figma OAuth client

This commit is contained in:
Aiden Cline
2026-06-17 13:28:55 +02:00
parent 10b6672be1
commit 871c2dd76e
3 changed files with 87 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
const CLIENT_ID = "3zVHNs9kINDDrk8loekLZV"
export async function FigmaPlugin(_input: PluginInput): Promise<Hooks> {
return {
config: async (config) => {
Object.values(config.mcp ?? {}).forEach((server) => {
if (server.type !== "remote" || server.oauth === false) return
if (!URL.canParse(server.url) || new URL(server.url).hostname !== "mcp.figma.com") return
if (server.oauth?.clientId) return
server.oauth = { ...server.oauth, clientId: CLIENT_ID }
})
},
}
}
+2
View File
@@ -20,6 +20,7 @@ import { AzureAuthPlugin } from "./azure"
import { DigitalOceanAuthPlugin } from "./digitalocean"
import { XaiAuthPlugin } from "./xai"
import { SnowflakeCortexAuthPlugin } from "./snowflake-cortex"
import { FigmaPlugin } from "./figma"
import { Effect, Layer, Context } from "effect"
import { EffectBridge } from "@/effect/bridge"
import { InstanceState } from "@/effect/instance-state"
@@ -78,6 +79,7 @@ function internalPlugins(flags: RuntimeFlags.Info): PluginInstance[] {
DigitalOceanAuthPlugin,
SnowflakeCortexAuthPlugin,
XaiAuthPlugin,
FigmaPlugin,
]
}
@@ -0,0 +1,69 @@
import { describe, expect, test } from "bun:test"
import { FigmaPlugin } from "@/plugin/figma"
describe("plugin.figma", () => {
test("adds the OpenCode client ID to configured Figma servers", async () => {
const config = {
mcp: {
figma: {
type: "remote" as const,
url: "https://mcp.figma.com/mcp",
oauth: { scope: "mcp:connect" } as { scope: string; clientId?: string },
},
},
}
const hooks = await FigmaPlugin({} as never)
await hooks.config!(config as never)
expect(config.mcp.figma.oauth).toEqual({ clientId: "3zVHNs9kINDDrk8loekLZV", scope: "mcp:connect" })
})
test("preserves an existing client ID", async () => {
const config = {
mcp: {
figma: {
type: "remote" as const,
url: "https://mcp.figma.com/mcp",
oauth: { clientId: "configured-client-id" },
},
},
}
const hooks = await FigmaPlugin({} as never)
await hooks.config!(config as never)
expect(config.mcp.figma.oauth.clientId).toBe("configured-client-id")
})
test("does not create or enable Figma servers", async () => {
const config = {
mcp: {
disabled: {
type: "remote" as const,
url: "https://mcp.figma.com/mcp",
oauth: false as const,
},
other: {
type: "remote" as const,
url: "https://mcp.example.com/mcp",
},
},
}
const hooks = await FigmaPlugin({} as never)
await hooks.config!(config as never)
expect(config.mcp).toEqual({
disabled: {
type: "remote",
url: "https://mcp.figma.com/mcp",
oauth: false,
},
other: {
type: "remote",
url: "https://mcp.example.com/mcp",
},
})
})
})