Skip to content

Conversation

sebthom
Copy link
Contributor

@sebthom sebthom commented Aug 9, 2025

With this PR the language parameter description is dynamically calculated on mcp server start based on the supported languages by ast-grep including custom languages configured in sgconfig.yaml

image

I had to wrap the mcp tool definitions into a function so that their language description field is not computed on import time but after the args are parsed and thus the sgconfig.yaml file can be loaded.

So to better review the PR check the changes with whitespace changes ignored: https://github.com/ast-grep/ast-grep-mcp/pull/11/files?w=1

An alternative to the current approach would be to move the mcp tool functions to a dedicated file (e.g. mcp_tools.py) and only do arg parsing, server setup in the main.py. this feels cleaner to me but is a bigger change. I would be happy to do that if you agree.

@sebthom sebthom marked this pull request as draft August 9, 2025 09:45
@sebthom sebthom changed the title Add get_supported_languages mcp tool Add supported languages to MCP tool parameter description Aug 15, 2025
@sebthom sebthom force-pushed the patch-1 branch 2 times, most recently from 6dce227 to f8db328 Compare August 15, 2025 11:46
@sebthom sebthom marked this pull request as ready for review August 15, 2025 11:52
@sebthom
Copy link
Contributor Author

sebthom commented Aug 15, 2025

@HerringtonDarkholme this PR is ready for review.

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 enhances the MCP tool parameter descriptions by dynamically generating supported language lists based on ast-grep's built-in languages and any custom languages configured in sgconfig.yaml. This provides users with accurate, up-to-date information about which languages are supported when using the tools.

Key changes:

  • Wrapped MCP tool definitions in a register_mcp_tools() function to defer execution until after configuration is loaded
  • Added dynamic language support detection that includes both built-in and custom languages
  • Updated test files to accommodate the new tool registration pattern

Reviewed Changes

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

Show a summary per file
File Description
main.py Added register_mcp_tools() function and get_supported_languages() helper, updated tool parameter descriptions to use dynamic language lists
tests/test_unit.py Updated test setup to call register_mcp_tools() and extract tool functions from mocked MCP instance
tests/test_integration.py Updated test setup to call register_mcp_tools() and extract tool functions from mocked MCP instance
pyproject.toml Added PyYAML dependency for parsing sgconfig.yaml files
README.md Added documentation links for language support and custom language configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sebthom
Copy link
Contributor Author

sebthom commented Aug 19, 2025

@HerringtonDarkholme WDYT?

@HerringtonDarkholme HerringtonDarkholme merged commit a84a1dc into ast-grep:main Aug 19, 2025
3 checks 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