MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / mcpAddCommand

Method mcpAddCommand

internal/cli/mcp.go:145–203  ·  view source on GitHub ↗

`cam mcp add NAME [--client TOOL] [--command bin] [--arg ARG]...` installs either a registry server (when --command absent) or a one-off custom server.

(state *globalState)

Source from the content-addressed store, hash-verified

143// `cam mcp add NAME [--client TOOL] [--command bin] [--arg ARG]...` installs
144// either a registry server (when --command absent) or a one-off custom server.
145func (a *App) mcpAddCommand(state *globalState) *cobra.Command {
146 var (
147 clientName string
148 command string
149 serverArgs []string
150 envEntries []string
151 scope string
152 urlValue string
153 )
154 cmd := &cobra.Command{
155 Use: "add NAME",
156 Short: "Add MCP server to a client",
157 Args: cobra.ExactArgs(1),
158 RunE: func(cmd *cobra.Command, args []string) error {
159 out := cmd.OutOrStdout()
160 name := args[0]
161 client, err := requireClient(clientName)
162 if err != nil {
163 return err
164 }
165 server := mcp.Server{Name: name, Command: command, Args: serverArgs, URL: urlValue, Env: parseEnv(envEntries)}
166 if command == "" && urlValue == "" {
167 registry, err := mcp.LoadBundledRegistry()
168 if err != nil {
169 return err
170 }
171 schema, ok := registry.Get(name)
172 if !ok {
173 return fmt.Errorf("server %q not found in registry (use --command for custom servers)", name)
174 }
175 server, err = mcp.ServerFromSchema(schema)
176 if err != nil {
177 return err
178 }
179 }
180 if server.Type == "" {
181 if server.URL != "" {
182 server.Type = "http"
183 } else {
184 server.Type = "stdio"
185 }
186 }
187 path, err := mcp.AddServer(client, mcp.Scope(scope), server)
188 if err != nil {
189 return err
190 }
191 fmt.Fprintf(out, "Added %s to %s\n Config: %s\n", name, client.Name, path)
192 return nil
193 },
194 }
195 cmd.Flags().StringVarP(&clientName, "client", "c", "", "Target MCP client (required)")
196 cmd.Flags().StringVar(&command, "command", "", "Server command (for custom STDIO servers)")
197 cmd.Flags().StringArrayVar(&serverArgs, "arg", nil, "Server command argument (repeatable)")
198 cmd.Flags().StringArrayVar(&envEntries, "env", nil, "Env var KEY=VALUE for the server (repeatable)")
199 cmd.Flags().StringVarP(&scope, "scope", "s", "user", "Scope (user|project)")
200 cmd.Flags().StringVar(&urlValue, "url", "", "Remote MCP server URL")
201 _ = cmd.MarkFlagRequired("client")
202 return cmd

Callers 1

mcpCommandMethod · 0.95

Calls 7

LoadBundledRegistryFunction · 0.92
ServerFromSchemaFunction · 0.92
AddServerFunction · 0.92
ScopeTypeAlias · 0.92
requireClientFunction · 0.85
parseEnvFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected