Skip to content

feat(mcp): add MCP server for AI agent integration - #72

Merged
alexey1312 merged 2 commits into
mainfrom
feature/mcp-server
Mar 20, 2026
Merged

feat(mcp): add MCP server for AI agent integration#72
alexey1312 merged 2 commits into
mainfrom
feature/mcp-server

Conversation

@alexey1312

Copy link
Copy Markdown
Collaborator

Description

Add exfig mcp subcommand — 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 groups
  • exfig_inspect — list Figma resources (colors, icons, images, typography) with metadata

7 MCP resources:

  • PKL schemas (ExFig, Common, Figma, iOS, Android, Flutter, Web)
  • Starter config templates per platform

2 MCP prompts:

  • setup-config — guides AI through creating exfig.pkl
  • troubleshoot-export — diagnoses export errors

Architecture decisions

  • Subcommand inside ExFigCLI (not a separate target) — reuses all existing loaders, evaluators, and exporters without extracting a library
  • OutputMode.mcp redirects all CLI output to stderr, keeping stdout clean for JSON-RPC
  • MCPServerState actor manages a lazy FigmaClient with rate limiting, shared across all tool calls
  • FigmaAPI.Client fully qualified to avoid name collision with MCP.Client

Changes

  • Package.swift — added swift-sdk (MCP SDK) dependency
  • OutputMode — new .mcp case with stderr redirect
  • TerminalOutputManagersetStderrMode() for MCP compatibility
  • ExFigLogHandler — stderr output in MCP mode
  • 6 new files in Sources/ExFigCLI/MCP/
  • 1 new subcommand MCPServe.swift
  • 8 unit tests in Tests/ExFigTests/MCP/
  • Documentation: README, Usage.md, CLAUDE.md, exfig.usage.kdl, CONTRIBUTING.md, llms-full.txt

Additional notes

  • exfig_export and exfig_diff are intentionally excluded — they need deeper integration with the export pipeline before being exposed via MCP
  • Tested end-to-end with Claude Code via fnox exec (1Password) for token injection

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
@alexey1312
alexey1312 merged commit 9b9fc90 into main Mar 20, 2026
3 checks passed
@alexey1312
alexey1312 deleted the feature/mcp-server branch March 20, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant