Skip to content

feat: add M formatting & validation (MCP + /format-m page)#70

Merged
kyleamueller merged 2 commits into
mainfrom
feature/format-m-code
Apr 13, 2026
Merged

feat: add M formatting & validation (MCP + /format-m page)#70
kyleamueller merged 2 commits into
mainfrom
feature/format-m-code

Conversation

@kyleamueller

Copy link
Copy Markdown
Owner

Summary

  • Wires @microsoft/powerquery-formatter and @microsoft/powerquery-parser into pqm.guide via a shared library at src/lib/formatter.ts.
  • Adds two new MCP tools — format_m_code and validate_m_code — so AI clients can clean up or parse-check M code directly.
  • Ships a user-facing /format-m page (textarea in, syntax-highlighted formatted output, Format + Validate buttons) for humans who want the same thing in a browser.
  • Supporting /api/format-m endpoint backs the page so it doesn't need to speak JSON-RPC.
  • Attribution to Microsoft added to README.md and the /format-m page (both libraries are MIT).
  • Closes the P2 backlog item "Add M formatting to the MCP Server" (Bernat).

Design decisions

  • Opinionated defaults, no knobs in v1: 4-space indent, Unix newlines, 120 maxWidth. Exposing options would partially defeat the eventual CI lint.
  • Native input handling: the formatter accepts both let … in … documents and bare expressions directly — no cascading parse fallback needed.
  • Node runtime only — the parser isn't Edge-compatible. Documented in the module header.

Follow-up items added to backlog

  • P3: Revisit format_m_code input handling — confirm native handling holds vs. exposing an explicit mode arg.
  • P3: Enforce canonical M formatting in CI across all ```powerquery blocks in src/content/.
  • P4: Build our own M formatter (replace the Microsoft dep for full style control).
  • P4: Explore a BPA-style analyze_m_code tool now that we have an AST.

Test plan

  • npm run typecheck passes
  • npm test — all 59 tests pass (8 new for the formatter lib)
  • POST /api/format-m — formats let x=1,y=2 in x+ylet x = 1, y = 2 in x + y
  • POST /api/format-m action=validate — returns structured error with line/column for let x = in
  • POST /api/mcp format_m_code — returns fenced ```powerquery block
  • POST /api/mcp validate_m_code — returns human-readable error summary
  • GET /format-m — page loads (200)
  • Manual: confirm formatter UI works end-to-end in browser (golden path + bad input)
  • Manual: confirm sidebar "Format M" link is in the right place visually

🤖 Generated with Claude Code

Wires @microsoft/powerquery-formatter and @microsoft/powerquery-parser
into pqm.guide via two surfaces sharing one library (src/lib/formatter.ts):

- MCP tools format_m_code and validate_m_code in /api/mcp for AI clients.
- User-facing /format-m page with a textarea, Format/Validate buttons, and
  syntax-highlighted output (reuses SyntaxBlock).
- Supporting /api/format-m endpoint so the page doesn't speak JSON-RPC.

Opinionated defaults (4-space indent, Unix newlines, 120 maxWidth) — no
formatter knobs in v1. Input handling is native: the formatter accepts
both let…in documents and bare expressions, so no cascading parse
fallback is needed. Node runtime only (parser isn't Edge-compatible).

Attribution to Microsoft added to README and the /format-m page. Four
follow-up items added to BACKLOG.md: revisit input handling, enforce
formatting in CI, build our own formatter, and explore a BPA-style
analyze_m_code tool now that we have an AST.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pqm-guide Ready Ready Preview, Comment Apr 13, 2026 4:49pm

Request Review

Exposes a `style: "long" | "short"` arg on formatMCode, the MCP
format_m_code tool, the /api/format-m endpoint, and the /format-m page
(segmented toggle next to the Format button).

- "long" (default, maxWidth=120): Power Query editor style — each step
  on a single line up to ~120 chars.
- "short" (maxWidth=60): spreads parameters of complex function calls
  onto their own lines for readability, without over-decomposing simple
  expressions like `each [x] > 1`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kyleamueller kyleamueller merged commit a169492 into main Apr 13, 2026
6 checks passed
@kyleamueller kyleamueller deleted the feature/format-m-code branch April 13, 2026 16:55
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