Skip to main content
Glama
XD3an
by XD3an

install_repo_mcp_server

Install MCP servers via pip or npm by specifying package names, arguments, and environment variables for configuration.

Instructions

Install an MCP server via pip or npm.

Args:
    name: The package name of the MCP server
    args: The arguments to pass along
    env: The environment variables to set, delimited by =

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
argsNo
envNo

Implementation Reference

  • The handler function for the 'install_repo_mcp_server' tool, decorated with @mcp.tool() for registration. It detects if the package is npm or pip, checks prerequisites, and installs by configuring Claude Desktop's mcpServers JSON.
    @mcp.tool()
    def install_repo_mcp_server(
        name: str, 
        args: Optional[List[str]] = None,
        env: Optional[List[str]] = None,
    ) -> str:
        """
        Install an MCP server via pip or npm.
        
        Args:
            name: The package name of the MCP server
            args: The arguments to pass along
            env: The environment variables to set, delimited by =
        """
        if args is None:
            args = []
            
        # Check if Node.js is installed (for npm packages)
        has_node = check_command_exists("node")
        has_npm = check_command_exists("npm")
        has_npx = check_command_exists("npx")
        has_pip = check_command_exists("pip")
        has_python = check_command_exists("python")
        
        if not has_node and not has_python:
            return "Neither Node.js nor Python is installed. Please install one of them."
        
        # Determine if this is likely an npm package (starts with @ or doesn't have dots)
        is_likely_npm_package = name.startswith('@') or '.' not in name
        
        # Handle npm packages
        if has_npm and has_npx and is_likely_npm_package:
            # Extract server name from package name (handle scoped packages)
            if name.startswith("@") and "/" in name:
                # For @scope/package, use just "package" as the server name
                server_name = name.split("/")[1]
            else:
                server_name = name
                
            # Install to Claude Desktop using npx directly
            install_to_claude_desktop(
                server_name,
                "npx",
                [name] + args,
                env,
            )
            
            return f"Successfully installed MCP server '{server_name}' via npx! Please tell the user to restart the application."
            
        # Handle Python packages (likely has dots in the name)
        if has_pip and has_python and '.' in name:
            # For Python packages, use the package name directly
            server_name = name
            
            # Install to Claude Desktop
            install_to_claude_desktop(
                server_name,
                "python",
                ["-m", name] + args,
                env,
            )
            
            return f"Successfully installed MCP server '{server_name}' via Python! Please tell the user to restart the application."
        
        # If we can't determine the type, try npm first if available, then Python
        if has_npm and has_npx:
            # Use the last part of the name as the server name
            if "/" in name:
                server_name = name.split("/")[-1]
            else:
                server_name = name
                
            install_to_claude_desktop(
                server_name,
                "npx",
                [name] + args,
                env,
            )
            
            return f"Successfully installed MCP server '{server_name}' via npx! Please tell the user to restart the application."
        elif has_pip and has_python:
            server_name = name.split(".")[-1] if "." in name else name
            
            install_to_claude_desktop(
                server_name,
                "python",
                ["-m", name] + args,
                env,
            )
            
            return f"Successfully installed MCP server '{server_name}' via Python! Please tell the user to restart the application."
            
        return f"Could not determine how to install '{name}'"
  • Key helper function called by install_repo_mcp_server to update the Claude Desktop configuration file with the new MCP server entry.
    def install_to_claude_desktop(
        server_name: str,
        command: str,
        args: List[str],
        env: Optional[List[str]] = None,
        cwd: Optional[str] = None,
    ) -> None:
        """
        Install an MCP server to Claude Desktop.
        
        Args:
            server_name: The name of the MCP server
            command: The command to run the MCP server
            args: The arguments to pass to the command
            env: The environment variables to set, delimited by =
            cwd: The working directory for the command
        """
        # Normalize server name to be a valid identifier
        # For npm packages, make sure we use a simple name without @ or /
        if server_name.startswith("@"):
            # For @scope/package, use just "package" as the server name
            if "/" in server_name:
                server_name = server_name.split("/")[1]
        
        # Remove any invalid characters from server name
        server_name = re.sub(r'[^a-zA-Z0-9_-]', '-', server_name)
        
        # Get the Claude Desktop config file path
        config_path = get_claude_desktop_config_path()
        
        if not config_path:
            raise ValueError("Could not find Claude Desktop config file")
            
        # Read the existing config
        try:
            with open(config_path, "r", encoding="utf-8") as f:
                config = json.load(f)
        except (FileNotFoundError, json.JSONDecodeError):
            config = {}
            
        # Initialize mcpServers if it doesn't exist
        if "mcpServers" not in config:
            config["mcpServers"] = {}
            
        # Prepare the server config
        server_config = {
            "command": command,
            "args": args,
        }
        
        # Add environment variables if provided
        if env and len(env) > 0:
            server_config["env"] = parse_env_vars(env)
                    
        # Add working directory if provided
        if cwd:
            server_config["cwd"] = cwd
            
        # Add the server to the config
        config["mcpServers"][server_name] = server_config
        
        # Write the config back to the file
        with open(config_path, "w", encoding="utf-8") as f:
            json.dump(config, f, indent=2)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but provides minimal behavioral context. It mentions installation but doesn't disclose important traits like whether this requires admin privileges, what happens if installation fails, whether it modifies system state permanently, or what the expected output is. The description doesn't contradict annotations since none exist.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with a clear purpose statement followed by parameter explanations. The structure is front-loaded with the main functionality. However, the parameter explanations could be more efficiently integrated rather than listed as separate bullet points.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool that performs system installation with 3 parameters, no annotations, and no output schema, the description is insufficient. It doesn't cover important context like prerequisites, error handling, success criteria, or what happens after installation. The agent lacks critical information to use this tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description adds value by explaining all three parameters: 'name' as package name, 'args' as arguments to pass, and 'env' as environment variables. However, it doesn't provide format details (e.g., how environment variables should be formatted with '=' delimiter), examples, or constraints beyond basic semantics.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'install' and resource 'MCP server', specifying installation via pip or npm. It distinguishes from the sibling tool 'install_local_mcp_server' by implying this is for repository-based installation rather than local, though not explicitly stated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives is provided. The existence of sibling tool 'install_local_mcp_server' suggests there are different installation methods, but the description doesn't explain when to choose repository vs local installation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/XD3an/mcp-builder'

If you have feedback or need assistance with the MCP directory API, please join our Discord server