Skip to content

Conversation

sebthom
Copy link
Contributor

@sebthom sebthom commented Aug 7, 2025

This PR adds support for providing a custom sgconfig.yaml file to the mcp server, either via a --config CLI argument or via a AST_GREP_CONFIG. The env var is esp. helpful when checking .mcp.json files into git without needing to hardcode a config path.

Being able to specify a custom config file is useful when e.g. needing to registering custom languages with ast-grep.

The mcp server now also supports a --help flag which results in:

> python main.py --help
usage: python main.py [-h] [--config PATH]

ast-grep MCP Server - Provides structural code search capabilities via Model Context Protocol

options:
  -h, --help     show this help message and exit
  --config PATH  Path to sgconfig.yaml file for customizing ast-grep behavior (language mappings, rule directories, etc.)

environment variables:
  AST_GREP_CONFIG    Path to sgconfig.yaml file (overridden by --config flag)

For more information, see: https://github.com/ast-grep/ast-grep-mcp

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds configuration file support to the ast-grep MCP server, allowing users to specify custom sgconfig.yaml files through a --config CLI flag or AST_GREP_CONFIG environment variable. This enhancement enables customization of ast-grep behavior such as registering custom languages and configuring rule directories.

  • Added command-line argument parsing with --config flag and --help support
  • Implemented environment variable support for AST_GREP_CONFIG with proper precedence handling
  • Updated all ast-grep command invocations to include the config path when specified

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
main.py Added argument parsing, config path resolution with validation, and updated all ast-grep subprocess calls to include config parameter
README.md Added documentation section explaining custom configuration file usage

@sebthom
Copy link
Contributor Author

sebthom commented Aug 7, 2025

@HerringtonDarkholme I addressed the CoPilot findings

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Aug 8, 2025

I don't know if adding command line argument or using an environment variable is the standard way to initialize MCP. But let's merge this first and see the feedback from the community.

@HerringtonDarkholme HerringtonDarkholme merged commit 1ddfd03 into ast-grep:main Aug 8, 2025
@sebthom sebthom deleted the config branch August 15, 2025 12:20
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