Add MCP server to AST tool

Integrates the MCP server functionality into the AST tool binary. This
allows the tool to act as a server for LLM integration, enabling
communication over stdio. The server can list available bindings and
execute scripts.
This commit is contained in:
2026-03-25 14:03:22 +01:00
parent 6042415dfc
commit 641a19e736
6 changed files with 386 additions and 2 deletions
+13
View File
@@ -600,6 +600,19 @@ impl Environment {
}
/// Returns the names of all bindings registered in the fixed RTL scope.
/// Useful for introspection (e.g., MCP server listing available built-ins).
pub fn list_bindings(&self) -> Vec<String> {
let root_scopes = self.root_scopes.borrow();
let mut names: Vec<String> = root_scopes[0]
.locals
.keys()
.map(|sym| sym.name.to_string())
.collect();
names.sort();
names
}
pub fn dump_ast(&self, source: &str) -> Result<String, String> {
self.preload_dependencies(source, None)?;
let compiled = self.compile(source).into_result()?;
+1
View File
@@ -3,6 +3,7 @@ pub mod compiler;
pub mod diagnostics;
pub mod environment;
pub mod lexer;
pub mod mcp_server;
pub mod nodes;
pub mod parser;
pub mod rtl;
+12
View File
@@ -39,10 +39,22 @@ struct Cli {
/// Disable optimization
#[arg(long)]
no_opt: bool,
/// Start MCP server (stdio transport, for LLM integration)
#[arg(long)]
mcp: bool,
}
fn main() {
let cli = Cli::parse();
if cli.mcp {
if let Err(e) = myc::ast::mcp_server::run() {
eprintln!("MCP server error: {}", e);
std::process::exit(1);
}
return;
}
let mut env = Environment::new();
env.optimization = !cli.no_opt;