Skip to main content
Glama

install_package

Install Python packages in a REPL environment using uv for code execution and variable management.

Instructions

Install a Python package using uv

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageYesPackage name to install (e.g., 'pandas')

Implementation Reference

  • Handler for the 'install_package' tool. Validates the package name, installs the package using 'uv pip install', attempts to import it into the shared global namespace, and returns appropriate text content responses for success or errors.
    elif name == "install_package": package = arguments.get("package") if not package: raise ValueError("Missing package name") # Basic package name validation if not re.match("^[A-Za-z0-9][A-Za-z0-9._-]*$", package): return [ types.TextContent( type="text", text=f"Invalid package name: {package}" ) ] try: # Install package using uv process = subprocess.run( ["uv", "pip", "install", package], capture_output=True, text=True, check=True ) if process.returncode != 0: return [ types.TextContent( type="text", text=f"Failed to install package: {process.stderr}" ) ] # Import the package to make it available in the REPL try: exec(f"import {package.split('[')[0]}", self.global_namespace) return [ types.TextContent( type="text", text=f"Successfully installed and imported {package}" ) ] except ImportError as e: return [ types.TextContent( type="text", text=f"Package installed but import failed: {str(e)}" ) ] except subprocess.CalledProcessError as e: return [ types.TextContent( type="text", text=f"Failed to install package:\n{e.stderr}" ) ]
  • Registration of the 'install_package' tool in the list_tools handler, including its name, description, and input schema definition.
    types.Tool( name="install_package", description="Install a Python package using uv", inputSchema={ "type": "object", "properties": { "package": { "type": "string", "description": "Package name to install (e.g., 'pandas')", } }, "required": ["package"], }, )
  • Input schema definition for the 'install_package' tool, specifying the required 'package' string parameter.
    inputSchema={ "type": "object", "properties": { "package": { "type": "string", "description": "Package name to install (e.g., 'pandas')", } }, "required": ["package"], },

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/hdresearch/mcp-python'

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