repo
Retrieve the repository URL of an npm package by specifying its package name.
Instructions
Get the repository URL for a package
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package | Yes | Package name |
Implementation Reference
- src/index.ts:619-638 (handler)The 'repo' tool handler that executes 'npm repo <package> --no-browser' to get the repository URL for a package.
// ── npm repo ── server.tool( "repo", "Get the repository URL for a package", { package: z.string().describe("Package name"), }, async ({ package: pkg }) => { const args = ["repo", pkg, "--no-browser"]; try { const { stdout, stderr } = await run(args); return { content: [{ type: "text", text: (stdout + stderr).trim() }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:623-625 (schema)Input schema for the 'repo' tool: requires a 'package' string parameter describing the package name.
{ package: z.string().describe("Package name"), }, - src/index.ts:619-638 (registration)Registration of the 'repo' tool via server.tool(...) on the MCP server instance.
// ── npm repo ── server.tool( "repo", "Get the repository URL for a package", { package: z.string().describe("Package name"), }, async ({ package: pkg }) => { const args = ["repo", pkg, "--no-browser"]; try { const { stdout, stderr } = await run(args); return { content: [{ type: "text", text: (stdout + stderr).trim() }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:26-38 (helper)The run() helper function that executes npm commands via child_process.execFile, used by the 'repo' 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); }