Skip to main content
Glama

whoami

Check which npm user is currently authenticated. If not logged in, configure the NPM_TOKEN environment variable in your MCP settings to enable authentication.

Instructions

Check which npm user is currently authenticated. If not logged in, set NPM_TOKEN env var in MCP config.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary handler for the 'whoami' tool. Registers via server.tool() with no parameters (empty schema {}). Runs `npm whoami` via run() helper, returns stdout.trim() on success, or an error message with hints about NPM_TOKEN on failure.
    // ── npm whoami ──
    server.tool(
      "whoami",
      "Check which npm user is currently authenticated. If not logged in, set NPM_TOKEN env var in MCP config.",
      {},
      async () => {
        try {
          const { stdout } = await run(["whoami"]);
          return { content: [{ type: "text", text: stdout.trim() }] };
        } catch (e: any) {
          const hint = NPM_TOKEN
            ? "Token is set but invalid."
            : "No NPM_TOKEN set. Add it to your MCP server config env, or run `npm login` first.";
          return {
            content: [{ type: "text", text: `Not logged in. ${hint}\n${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • src/index.ts:281-299 (registration)
    Registration of the 'whoami' tool via server.tool() in the main MCP server. The tool has no input parameters (empty Zod schema {}).
    server.tool(
      "whoami",
      "Check which npm user is currently authenticated. If not logged in, set NPM_TOKEN env var in MCP config.",
      {},
      async () => {
        try {
          const { stdout } = await run(["whoami"]);
          return { content: [{ type: "text", text: stdout.trim() }] };
        } catch (e: any) {
          const hint = NPM_TOKEN
            ? "Token is set but invalid."
            : "No NPM_TOKEN set. Add it to your MCP server config env, or run `npm login` first.";
          return {
            content: [{ type: "text", text: `Not logged in. ${hint}\n${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • src/index.ts:1257-1257 (registration)
    Sandbox registration of the 'whoami' tool in createSandboxServer(). Uses a noop handler that returns 'sandbox' placeholder text.
    sandbox.tool("whoami", "Check which npm user is currently authenticated", {}, noop);
  • Schema for the 'whoami' tool: empty object {} since the tool takes no parameters.
    {},
  • The `run()` helper function that executes npm commands. Used by the whoami handler to run `npm whoami`. It appends npmrcArgs (for NPM_TOKEN-based auth) and sets timeout/maxBuffer.
    async function run(
      args: string[],
      cwd?: string,
    ): Promise<{ stdout: string; stderr: string }> {
      const fullArgs = [...args, ...npmrcArgs];
      const opts: { cwd?: string; timeout: number; env: NodeJS.ProcessEnv; maxBuffer: number } = {
        timeout: 120_000,
        maxBuffer: 10 * 1024 * 1024, // 10MB buffer for large outputs
        env: { ...process.env, NO_COLOR: "1" },
      };
      if (cwd) opts.cwd = cwd;
      return exec(NPM, fullArgs, opts);
    }
Behavior4/5

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

With no annotations, the description carries the full burden. It discloses that the tool checks authentication status and suggests a remediation step. While it does not detail network calls or output format, the behavior is sufficiently transparent for a simple check.

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 two concise sentences with no filler, front-loading the purpose and then the conditional advice. Every sentence earns its place.

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

Completeness5/5

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

Given no parameters and no output schema, the description covers the tool's purpose and a critical next step (setting env var). It is complete for a simple authentication check tool.

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

Parameters4/5

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

There are no parameters, so the baseline is 4. The description does not need to add parameter meaning beyond the schema, which is fully covered.

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

Purpose5/5

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

The description clearly states the tool checks the current npm user (verb+resource). It explicitly mentions the action and a conditional remediation, distinguishing it from sibling tools like 'token' or 'login'.

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

Usage Guidelines4/5

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

The description provides clear context on when to use the tool (to check authentication) and what to do if not logged in (set NPM_TOKEN). However, it does not mention alternative tools or when not to use it.

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/mikusnuz/npm-mcp'

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