Skip to content

feat(grok): support MCP config#2739

Merged
arnestrickmann merged 2 commits into
mainfrom
emdash/grok-support-mcp-5a68b
Jul 1, 2026
Merged

feat(grok): support MCP config#2739
arnestrickmann merged 2 commits into
mainfrom
emdash/grok-support-mcp-5a68b

Conversation

@janburzinski

Copy link
Copy Markdown
Collaborator

Description

  • add mcp support for grok
  • add grok .grok/config.toml adapter
  • support stdio and http mcp servers

Screenshot/Recording (if applicable)

https://cap.link/mhbpmbxbettbdvs

Checklist
  • I kept this PR small and focused
  • I ran a self-review before opening this PR
  • I ran the relevant local checks or explained why not
  • I updated docs when behavior or setup changed
  • I added or updated tests when behavior changed, or explained why not
  • I only added comments where the logic is not obvious
  • I used Conventional Commits for commit
    messages and, when possible, the PR title

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds MCP (Model Context Protocol) server support to the Grok AI CLI plugin by implementing a grokMcpAdapter that reads and writes Grok's .grok/config.toml TOML config format, and wires it into the plugin's capability declaration.

  • grokMcpAdapter in mcp.ts handles both stdio and HTTP transports; unlike the Codex adapter it keeps HTTP headers under their canonical key (no rename to http_headers) and injects enabled: true by default on write, matching the grok mcp add CLI behavior.
  • grok/index.ts declares the mcp capability with scope: 'global' and registers the adapter as the provider — consistent with how all other agent plugins expose MCP support.
  • Six new test cases in mcp.test.ts cover stdio write, HTTP write, enabled: false preservation, read, round-trip, and server removal.

Confidence Score: 5/5

Safe to merge — changes are additive and isolated to a new adapter function with no modifications to existing adapters or shared infrastructure.

The adapter faithfully mirrors the pattern established by codexMcpAdapter with intentional, well-documented deviations (no header renaming, default enabled flag). The test suite exercises every public code path including edge cases (explicit disabled, round-trip, multi-server removal), and the grok/index.ts changes are purely declarative additions.

No files require special attention.

Important Files Changed

Filename Overview
packages/core/src/agents/plugins/helpers/mcp.ts Adds grokMcpAdapter following the established Codex pattern, with intentional differences: headers stay under headers (not renamed to http_headers) and enabled: true is injected by default on write. Logic is correct and consistent.
packages/plugins/src/agents/impl/grok/index.ts Wires up MCP capability declaration (scope: global, stdio + http transports) and registers grokMcpAdapter() as the provider — consistent with how other agent plugins expose MCP support.
packages/core/src/agents/plugins/helpers/mcp.test.ts Adds 6 targeted test cases for grokMcpAdapter covering stdio write, HTTP write, enabled=false preservation, round-trip read, remove, and existing-config preservation. Coverage is thorough.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant UI as Emdash UI
    participant Plugin as grok/index.ts
    participant Adapter as grokMcpAdapter
    participant FS as ~/.grok/config.toml

    UI->>Plugin: writeServers(servers)
    Plugin->>Adapter: writeServers(fs, servers)
    Adapter->>FS: read existing TOML
    FS-->>Adapter: raw content (or empty)
    Note over Adapter: toNative(s):<br/>delete name/transport/type<br/>set enabled=true if not boolean<br/>keep headers as-is
    Adapter->>FS: write merged TOML

    UI->>Plugin: readServers()
    Plugin->>Adapter: readServers(fs)
    Adapter->>FS: read TOML
    FS-->>Adapter: raw content
    Note over Adapter: fromNative(name, raw):<br/>isHttp = url present && command absent<br/>if HTTP: set transport='http', type='http'
    Adapter-->>UI: McpServerRegistration[]

    UI->>Plugin: removeServer(name)
    Plugin->>Adapter: removeServer(fs, name)
    Adapter->>FS: read → filter → write TOML
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant UI as Emdash UI
    participant Plugin as grok/index.ts
    participant Adapter as grokMcpAdapter
    participant FS as ~/.grok/config.toml

    UI->>Plugin: writeServers(servers)
    Plugin->>Adapter: writeServers(fs, servers)
    Adapter->>FS: read existing TOML
    FS-->>Adapter: raw content (or empty)
    Note over Adapter: toNative(s):<br/>delete name/transport/type<br/>set enabled=true if not boolean<br/>keep headers as-is
    Adapter->>FS: write merged TOML

    UI->>Plugin: readServers()
    Plugin->>Adapter: readServers(fs)
    Adapter->>FS: read TOML
    FS-->>Adapter: raw content
    Note over Adapter: fromNative(name, raw):<br/>isHttp = url present && command absent<br/>if HTTP: set transport='http', type='http'
    Adapter-->>UI: McpServerRegistration[]

    UI->>Plugin: removeServer(name)
    Plugin->>Adapter: removeServer(fs, name)
    Adapter->>FS: read → filter → write TOML
Loading

Reviews (1): Last reviewed commit: "fix(mcp): ignore default enabled in merg..." | Re-trigger Greptile

@arnestrickmann arnestrickmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the addition!

@arnestrickmann arnestrickmann merged commit dc490b7 into main Jul 1, 2026
1 check passed
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.

2 participants