Skip to main content
Glama
yonaka15
by yonaka15

pyodide_install-packages

Install Python packages in Pyodide environments for LLM-driven Python execution. Specify multiple packages using space-separated names.

Instructions

Install Python packages using Pyodide. Multiple packages can be specified using space-separated format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageYesPython package(s) to install. For multiple packages, use space-separated format (e.g., 'numpy matplotlib pandas').

Implementation Reference

  • Handler logic for pyodide_install-packages: validates arguments using arktype and delegates to PyodideManager.installPackage
    case "pyodide_install-packages": {
      const installPythonPackagesArgs = isInstallPythonPackagesArgs(args);
      if (installPythonPackagesArgs instanceof type.errors) {
        throw installPythonPackagesArgs;
      }
      const { package: packageName } = installPythonPackagesArgs;
      const results = await pyodideManager.installPackage(packageName);
      return results;
    }
  • Tool schema defining name, description, and input schema for pyodide_install-packages
    export const INSTALL_PYTHON_PACKAGES_TOOL: Tool = {
      name: "pyodide_install-packages",
      description:
        "Install Python packages using Pyodide. Multiple packages can be specified using space-separated format.",
      inputSchema: {
        type: "object",
        properties: {
          package: {
            type: "string",
            description:
              "Python package(s) to install. For multiple packages, use space-separated format (e.g., 'numpy matplotlib pandas').",
          },
        },
        required: ["package"],
      },
    };
  • Registration of the pyodide_install-packages tool in the TOOLS array used for listTools
    const TOOLS: Tool[] = [
      tools.EXECUTE_PYTHON_TOOL,
      tools.INSTALL_PYTHON_PACKAGES_TOOL,
      tools.GET_MOUNT_POINTS_TOOL,
      tools.LIST_MOUNTED_DIRECTORY_TOOL,
      tools.READ_IMAGE_TOOL,
    ];
  • Core implementation of package installation: tries loadPackage first, falls back to micropip with wheel download for unsupported packages
    async installPackage(packageName: string) {
      if (!this.pyodide) {
        return formatCallToolError("Pyodide not initialized");
      }
    
      try {
        // パッケージ名をスペースで分割
        const packages = packageName
          .split(" ")
          .map((pkg) => pkg.trim())
          .filter(Boolean);
    
        if (packages.length === 0) {
          return formatCallToolError("No valid package names specified");
        }
    
        // 出力メッセージを集める
        const outputs: string[] = [];
    
        // 各パッケージを処理
        for (const pkg of packages) {
          try {
            // 1. まずpyodide.loadPackageでインストールを試みる
            outputs.push(`Attempting to install ${pkg} using loadPackage...`);
    
            try {
              await this.pyodide.loadPackage(pkg, {
                messageCallback: (msg) => {
                  outputs.push(`loadPackage: ${msg}`);
                },
                errorCallback: (err) => {
                  throw new Error(err);
                },
              });
              outputs.push(`Successfully installed ${pkg} using loadPackage.`);
              continue; // このパッケージは成功したので次のパッケージへ
            } catch (loadPackageError) {
              outputs.push(
                `loadPackage failed for ${pkg}: ${
                  loadPackageError instanceof Error
                    ? loadPackageError.message
                    : String(loadPackageError)
                }`
              );
              outputs.push(`Falling back to micropip for ${pkg}...`);
    
              // loadPackageが失敗した場合は、micropipを使用する
              // micropipがまだロードされていない場合はロードする
              try {
                // micropipをロードする
                await this.pyodide.loadPackage("micropip", {
                  messageCallback: (msg) => {
                    outputs.push(`loadPackage: ${msg}`);
                  },
                  errorCallback: (err) => {
                    throw new Error(err);
                  },
                });
              } catch (micropipLoadError) {
                throw new Error(
                  `Failed to load micropip: ${
                    micropipLoadError instanceof Error
                      ? micropipLoadError.message
                      : String(micropipLoadError)
                  }`
                );
              }
    
              // 2. micropipを使ったインストール処理
              // 一時ディレクトリを作成
              const tempDir = process.env.PYODIDE_CACHE_DIR || "./cache";
              if (!fs.existsSync(tempDir)) {
                fs.mkdirSync(tempDir, { recursive: true });
              }
    
              // Pyodide内のtempディレクトリを作成
              this.pyodide.FS.mkdirTree("/tmp/wheels");
    
              // PyPIからwheelのURLを取得
              const wheelUrl = await getWheelUrl(pkg);
              const wheelFilename = path.basename(wheelUrl);
              const localWheelPath = path.join(tempDir, wheelFilename);
    
              // wheelをダウンロード
              outputs.push(`Downloading wheel for ${pkg}...`);
              await downloadWheel(wheelUrl, localWheelPath);
    
              // wheelをPyodideのファイルシステムにコピー
              const wheelData = fs.readFileSync(localWheelPath);
              const pyodideWheelPath = `/tmp/wheels/${wheelFilename}`;
              this.pyodide.FS.writeFile(pyodideWheelPath, wheelData);
    
              // micropipでインストール
              const { output } = await withOutputCapture(
                this.pyodide,
                async () => {
                  await this.pyodide!.runPythonAsync(`
                    import micropip
                    await micropip.install("emfs:${pyodideWheelPath}")
                  `);
                },
                { suppressConsole: true }
              );
    
              outputs.push(
                `Successfully installed ${pkg} using micropip: ${output}`
              );
            }
          } catch (error) {
            // 個別のパッケージのエラーを記録して続行
            outputs.push(
              `Failed to install ${pkg}: ${
                error instanceof Error ? error.message : String(error)
              }`
            );
          }
        }
    
        return formatCallToolSuccess(outputs.join("\n\n"));
      } catch (error) {
        return formatCallToolError(error);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the installation action but fails to describe critical traits: whether this requires specific permissions, if it's idempotent (re-installing existing packages), potential side effects (e.g., overwriting dependencies), error handling, or performance implications (e.g., network delays). For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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

Conciseness5/5

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

The description is extremely concise—two sentences that directly address the core functionality and parameter format without any fluff. It's front-loaded with the primary purpose and efficiently communicates the key usage note. Every word earns its place, making it easy for an agent to parse quickly.

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?

Given the tool's complexity (a mutation operation installing packages), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what happens after installation (e.g., success/failure indicators, installed package details, or error messages), nor does it cover behavioral aspects like idempotency or dependencies. For a tool that modifies the environment, more context is needed for safe and effective use.

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?

The input schema has 100% description coverage, fully documenting the single 'package' parameter with format examples. The description adds value by reinforcing the space-separated format for multiple packages, but doesn't provide additional semantics beyond what the schema already covers (e.g., package name validation, version pinning, or dependency resolution). This meets the baseline for high schema coverage.

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 action ('Install') and resource ('Python packages using Pyodide'), making the purpose immediately understandable. It distinguishes itself from sibling tools like pyodide_execute or pyodide_read-image by focusing on package installation rather than code execution or file operations. However, it doesn't explicitly differentiate from potential non-sibling alternatives (like other package installation methods), keeping it from a perfect score.

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?

The description provides minimal guidance on when to use this tool, mentioning only that multiple packages can be installed. It lacks explicit context on when to choose this over alternatives (e.g., vs. manual installation or other package managers), prerequisites (e.g., Pyodide environment setup), or exclusions (e.g., packages not supported by Pyodide). This leaves the agent with insufficient decision-making information.

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/yonaka15/mcp-pyodide'

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