Skip to content

Commit ebe6c34

Browse files
committed
Add get_supported_languages mcp tool
1 parent e86ebdb commit ebe6c34

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

main.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import argparse
88
import os
99
import sys
10+
import yaml
1011

1112
# Determine how the script was invoked
1213
if sys.argv[0].endswith('main.py'):
@@ -76,6 +77,56 @@ def dump_syntax_tree(
7677
"""
7778
return run_ast_grep_dump(code, language, format.value)
7879

80+
@mcp.tool()
81+
def get_supported_languages() -> List[str]:
82+
"""
83+
Get list of languages supported.
84+
85+
Returns common language identifiers that can be used in the 'language' parameter of other tools.
86+
"""
87+
base_languages = [ # https://ast-grep.github.io/reference/languages.html
88+
"bash",
89+
"c",
90+
"cpp",
91+
"csharp",
92+
"css",
93+
"elixir",
94+
"go",
95+
"haskell",
96+
"html",
97+
"java",
98+
"javascript",
99+
"json",
100+
"jsx",
101+
"kotlin",
102+
"lua",
103+
"nix",
104+
"php",
105+
"python",
106+
"ruby",
107+
"rust",
108+
"scala",
109+
"solidity",
110+
"swift",
111+
"tsx",
112+
"typescript",
113+
"yaml"
114+
]
115+
116+
# Check for custom languages in config file
117+
# https://ast-grep.github.io/advanced/custom-language.html#register-language-in-sgconfig-yml
118+
if CONFIG_PATH and os.path.exists(CONFIG_PATH):
119+
try:
120+
import yaml
121+
with open(CONFIG_PATH, 'r') as f:
122+
config = yaml.safe_load(f)
123+
if config and 'customLanguages' in config:
124+
custom_langs = list(config['customLanguages'].keys())
125+
return sorted(set(base_languages + custom_langs))
126+
except Exception:
127+
pass
128+
129+
return base_languages
79130

80131
@mcp.tool()
81132
def test_match_code_rule(

0 commit comments

Comments
 (0)