Skip to content

Commit 0009501

Browse files
kgprsclaude
andcommitted
Refactor server init to use template files with --template flag
Restructures the `docker mcp server init` command to use file-based templates instead of embedded constants, making it easier to maintain and extend. Changes: - Created two template directories: - templates/basic: Simple MCP server without UI - templates/chatgpt-app-basic: MCP server with ChatGPT App UI - Each template has separate .tmpl files for all generated files - Refactored init.go to use go:embed and text/template - Added required --template flag to init command - Template files use {{.ServerName}} for customization Templates: - basic: Simple greeter with single name parameter, no UI - chatgpt-app-basic: Greeter with dropdown (Hi/Hey/Hello), UI resource, and full ChatGPT App integration Usage: - docker mcp server init --template=basic my-server - docker mcp server init --template=chatgpt-app-basic my-app Benefits: - Easy to add new templates (just create new folder) - Templates are actual files, easier to edit and test - Clear separation between basic and ChatGPT App templates - Better error messages for invalid templates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0c26008 commit 0009501

File tree

15 files changed

+635
-478
lines changed

15 files changed

+635
-478
lines changed

cmd/docker-mcp/commands/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,19 @@ func serverCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command {
119119
})
120120

121121
var language string
122+
var templateName string
122123
initCommand := &cobra.Command{
123124
Use: "init <directory>",
124125
Short: "Initialize a new MCP server project",
125126
Long: "Initialize a new MCP server project in the specified directory with boilerplate code, Dockerfile, and compose.yaml",
126127
Args: cobra.ExactArgs(1),
127128
RunE: func(cmd *cobra.Command, args []string) error {
128129
dir := args[0]
129-
if err := server.Init(cmd.Context(), dir, language); err != nil {
130+
if err := server.Init(cmd.Context(), dir, language, templateName); err != nil {
130131
return err
131132
}
132133
serverName := filepath.Base(dir)
133-
fmt.Fprintf(cmd.OutOrStdout(), "Successfully initialized MCP server project in %s\n", dir)
134+
fmt.Fprintf(cmd.OutOrStdout(), "Successfully initialized MCP server project in %s (template: %s)\n", dir, templateName)
134135
fmt.Fprintf(cmd.OutOrStdout(), "Next steps:\n")
135136
fmt.Fprintf(cmd.OutOrStdout(), " cd %s\n", dir)
136137
fmt.Fprintf(cmd.OutOrStdout(), " docker build -t %s:latest .\n", serverName)
@@ -139,6 +140,8 @@ func serverCommand(docker docker.Client, dockerCli command.Cli) *cobra.Command {
139140
},
140141
}
141142
initCommand.Flags().StringVar(&language, "language", "go", "Programming language for the server (currently only 'go' is supported)")
143+
initCommand.Flags().StringVar(&templateName, "template", "basic", "Template to use (basic, chatgpt-app-basic)")
144+
initCommand.MarkFlagRequired("template")
142145
cmd.AddCommand(initCommand)
143146

144147
return cmd

0 commit comments

Comments
 (0)