Skip to main content
Glama

init

Create a new package.json file in a specified directory, optionally with a scope. Sets up the foundation for npm package configuration.

Instructions

Initialize a new package.json

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the directory
scopeNoScope for the package (e.g. @myorg)

Implementation Reference

  • The actual handler function for the 'init' tool. It runs `npm init -y` in the specified directory with an optional scope argument, returning stdout or an error message.
    async ({ path, scope }) => {
      const args = ["init", "-y"];
      if (scope) args.push("--scope", scope);
      try {
        const { stdout } = await run(args, path);
        return { content: [{ type: "text", text: stdout }] };
      } catch (e: any) {
        return {
          content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
          isError: true,
        };
      }
    },
  • Input schema for the 'init' tool: 'path' (required string) and 'scope' (optional string).
    {
      path: z.string().describe("Absolute path to the directory"),
      scope: z.string().optional().describe("Scope for the package (e.g. @myorg)"),
    },
  • src/index.ts:301-322 (registration)
    Registration of the 'init' tool on the MCP server via server.tool('init', ...) with description, schema, and handler.
    // ── npm init ──
    server.tool(
      "init",
      "Initialize a new package.json",
      {
        path: z.string().describe("Absolute path to the directory"),
        scope: z.string().optional().describe("Scope for the package (e.g. @myorg)"),
      },
      async ({ path, scope }) => {
        const args = ["init", "-y"];
        if (scope) args.push("--scope", scope);
        try {
          const { stdout } = await run(args, path);
          return { content: [{ type: "text", text: stdout }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • The 'run' helper function that executes npm commands, used by the 'init' handler.
    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);
    }
  • src/index.ts:1259-1262 (registration)
    Sandbox registration of the 'init' tool (noop handler) in the createSandboxServer function.
    sandbox.tool("init", "Initialize a new package.json", {
      path: z.string().describe("Absolute path to the directory"),
      scope: z.string().optional().describe("Scope for the package"),
    }, noop);
Behavior2/5

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

The description implies creation but does not disclose behavioral traits such as whether it overwrites an existing package.json, requires directory existence, or any permissions. With no annotations, this is insufficient.

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 very concise with a single sentence. No fluff, but could be slightly expanded without losing conciseness.

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 no output schema and a simple tool, the description lacks details about side effects (e.g., overwriting) and prerequisites. Incomplete for safe invocation.

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?

Schema coverage is 100% and parameters are described in schema. The description does not add additional meaning beyond what the schema provides, so baseline score applies.

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 'Initialize a new package.json' clearly states the verb (Initialize) and resource (package.json). It is distinct from sibling tools like install or publish, which have different purposes.

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 guidance on when to use this tool versus alternatives (e.g., when to initialize vs. install). No mention of prerequisites or exclusion cases.

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