Skip to content

Commit cce310b

Browse files
committed
set a shell init script
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 89e4892 commit cce310b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

shell/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ func ExecuteCommand(ctx context.Context, req *mcp.CallToolRequest, input Execute
123123
}
124124

125125
func main() {
126+
// Run initialization script if SHELL_INIT_SCRIPT is set
127+
if initScript := os.Getenv("SHELL_INIT_SCRIPT"); initScript != "" {
128+
log.Printf("Running initialization script: %s", initScript)
129+
cmd := exec.CommandContext(context.Background(), "sh", "-c", initScript)
130+
cmd.Stdout = os.Stdout
131+
cmd.Stderr = os.Stderr
132+
if err := cmd.Run(); err != nil {
133+
log.Fatalf("Initialization script failed: %v", err)
134+
}
135+
log.Println("Initialization script completed successfully")
136+
}
137+
126138
// Create MCP server for shell command execution
127139
server := mcp.NewServer(&mcp.Implementation{
128140
Name: "shell",
@@ -137,7 +149,7 @@ func main() {
137149
// Add tool for executing shell scripts
138150
mcp.AddTool(server, &mcp.Tool{
139151
Name: configurableName,
140-
Description: "Execute a shell script and return the output, exit code, and any errors. The shell command can be configured via SHELL_CMD environment variable (default: 'sh -c'). The working directory can be set via SHELL_WORKING_DIR environment variable.",
152+
Description: "Execute a shell script and return the output, exit code, and any errors. The shell command can be configured via SHELL_CMD environment variable (default: 'sh -c'). The working directory can be set via SHELL_WORKING_DIR environment variable. An initialization script can be run before server startup via SHELL_INIT_SCRIPT environment variable.",
141153
}, ExecuteCommand)
142154

143155
// Run the server

0 commit comments

Comments
 (0)