Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Add support for Claude MCP.json configuration files in CLI run command#1922

Closed
Copilot wants to merge 4 commits into
devfrom
copilot/fix-25a7542f-90f8-488a-8a5c-4f13596e7e41
Closed

Add support for Claude MCP.json configuration files in CLI run command#1922
Copilot wants to merge 4 commits into
devfrom
copilot/fix-25a7542f-90f8-488a-8a5c-4f13596e7e41

Conversation

Copilot AI commented Sep 13, 2025

Copy link
Copy Markdown

This PR adds support for loading MCP (Model Context Protocol) servers from Claude format configuration files using the new --mcp-config option in the genaiscript run command.

Problem

Previously, MCP servers could only be configured directly in script files using the mcpServers property. Users working with Claude Desktop who already have MCP configuration files (.vscode/mcp.json or similar) had to duplicate their server configurations when using GenAIScript.

Solution

Added a new --mcp-config <file> CLI option that:

  1. Loads Claude format MCP configuration files with support for both servers and mcpServers object structures
  2. Supports enhanced environment variable interpolation using Claude's syntax:
    • ${workspaceFolder} - resolves to workspace directory or config file directory
    • ${env:VARIABLE_NAME} - resolves to environment variable values
    • ${VARIABLE_NAME} - resolves to capitalized environment variable values
  3. Merges with existing script configurations - servers from config files are combined with any mcpServers defined in the script
  4. Provides comprehensive error handling for missing files, invalid JSON, and malformed configurations
  5. Includes debug logging using genaiscriptDebug to trace MCP server resolution

Usage

# Load MCP servers from Claude configuration file
genaiscript run my-script --mcp-config .vscode/mcp.json

Example MCP configuration file:

{
    "mcpServers": {
        "filesystem": {
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-filesystem", "${workspaceFolder}"],
            "env": {
                "DEBUG": "${env:DEBUG}",
                "API_KEY": "${API_KEY}"
            }
        },
        "memory": {
            "command": "npx", 
            "args": ["-y", "@modelcontextprotocol/server-memory"]
        }
    }
}

Implementation Details

  • New module: packages/cli/src/mcp-config.ts handles configuration parsing and variable interpolation
  • CLI integration: Added option to run command and integrated loading into script execution pipeline
  • Type safety: Extended PromptScriptRunOptions interface to include mcpConfig property
  • Documentation: Updated CLI reference and added comprehensive usage examples
  • Debug logging: Added comprehensive debug tracing for MCP server resolution

Testing

The implementation includes comprehensive testing for:

  • Basic configuration loading and parsing
  • Environment variable interpolation scenarios (including new capitalized variable syntax)
  • Error handling for various failure cases
  • Integration with the script execution pipeline
  • Security validation (CodeQL analysis passed)

This change is backwards compatible and doesn't affect existing functionality when the --mcp-config option is not used.

Warning

cdn.sheetjs.com

  • Triggering command: node /usr/local/bin/yarn install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support in the cli run command to specify a MCP.json configuration file (Claude format) and add the MCP servers to the main script execution. Support Claude environment variable interpolation syntax Add support for Claude MCP.json configuration files in CLI run command Sep 13, 2025
Copilot AI requested a review from pelikhan September 13, 2025 15:05

```json title="mcp.json"
{
"servers": {

@pelikhan pelikhan Sep 13, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also support MCP servers key name @copilot

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added support for mcpServers as an alternative key name to servers in the configuration interface and updated documentation to show both options. Changes in commit 064492a.

The configuration file supports Claude environment variable interpolation syntax:

- `${workspaceFolder}` - Resolves to the workspace folder (or the directory containing the config file)
- `${env:VARIABLE_NAME}` - Resolves to the value of the environment variable `VARIABLE_NAME`

@pelikhan pelikhan Sep 13, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot also support ${VARIABLE_NAME} to resolve a env variable (must be capitalized)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added support for ${VARIABLE_NAME} syntax to resolve capitalized environment variables in addition to the existing ${env:VARIABLE_NAME} format. Updated both code and documentation. Changes in commit 064492a.

@@ -0,0 +1,113 @@
import { readJSON } from "fs-extra"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use genaiscriptDebug and add debug statements in the file to trace the mcp server resolution

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added genaiscriptDebug logging throughout the MCP configuration loading process to trace server resolution, including config file parsing, workspace folder detection, server processing, and final server count. Changes in commit 064492a.

@pelikhan pelikhan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apply latest comments @copilot

…ng in MCP config

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 13, 2025

Copy link
Copy Markdown
Author

Apply latest comments @copilot

Applied all feedback from the comments - added support for mcpServers key name, ${VARIABLE_NAME} syntax for capitalized environment variables, and comprehensive debug logging with genaiscriptDebug. Updated documentation accordingly. Changes in commit 064492a.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.sheetjs.com
    • Triggering command: node /usr/local/bin/yarn install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan September 13, 2025 16:43
@pelikhan pelikhan marked this pull request as ready for review September 13, 2025 16:46
@pelikhan pelikhan changed the base branch from main to dev September 13, 2025 16:47
@pelikhan pelikhan closed this Sep 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants