feat(mcp): add MCP server for AI agent integration - #72
Merged
Conversation
Add `exfig mcp` subcommand that starts a JSON-RPC server over stdin/stdout using the Model Context Protocol. AI agents (Claude Code, Cursor, etc.) can validate PKL configs, inspect .tokens.json files, and list Figma resources programmatically. Tools: exfig_validate, exfig_tokens_info, exfig_inspect Resources: PKL schemas, starter config templates Prompts: setup-config, troubleshoot-export
…r lifecycle and tests - Replace [String: Any] + JSONSerialization with Codable/Sendable structs and JSONCodec.encodePrettySorted (code conventions compliance) - Replace Task.sleep(365 days) with withCheckedContinuation for proper infinite suspend - Remove duplicate stderr routing in ExFigLogHandler (TerminalOutputManager.setStderrMode already handles it) - Extract requireFileId() helper to deduplicate lightFileId checks across inspect handlers - Move resource_type validation before expensive operations (fail-fast) - Add happy-path test for exfig_validate with real PKL fixture - Fix inspectMissingResourceType test to actually test missing resource_type - Fix "Twelve modules" → "Fourteen modules" in CLAUDE.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
exfig mcpsubcommand — a Model Context Protocol server over stdin/stdout (JSON-RPC) that gives AI agents programmatic access to ExFig capabilities.What's included
3 MCP tools:
exfig_validate— validate PKL config, return platform/entry summary (no Figma token needed)exfig_tokens_info— inspect .tokens.json files, return token counts by type and groupsexfig_inspect— list Figma resources (colors, icons, images, typography) with metadata7 MCP resources:
2 MCP prompts:
setup-config— guides AI through creating exfig.pkltroubleshoot-export— diagnoses export errorsArchitecture decisions
OutputMode.mcpredirects all CLI output to stderr, keeping stdout clean for JSON-RPCMCPServerStateactor manages a lazyFigmaClientwith rate limiting, shared across all tool callsFigmaAPI.Clientfully qualified to avoid name collision withMCP.ClientChanges
Package.swift— addedswift-sdk(MCP SDK) dependencyOutputMode— new.mcpcase with stderr redirectTerminalOutputManager—setStderrMode()for MCP compatibilityExFigLogHandler— stderr output in MCP modeSources/ExFigCLI/MCP/MCPServe.swiftTests/ExFigTests/MCP/Additional notes
exfig_exportandexfig_diffare intentionally excluded — they need deeper integration with the export pipeline before being exposed via MCPfnox exec(1Password) for token injection