Skip to main content
Glama
bsmi021

Node Omnibus MCP Server

by bsmi021

add_script

Adds a new npm script to package.json for Node.js projects, enabling automation of development tasks and workflows.

Instructions

Add a new npm script to package.json

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesProject directory path
nameYesScript name
commandYesScript command

Implementation Reference

  • The handler function that executes the add_script tool: validates the project path, reads package.json, adds the new script, writes it back, and returns success message.
    private async handleAddScript(args: AddScriptArgs) {
        await this.validatePath(args.path);
    
        try {
            const packageJsonPath = path.join(args.path, 'package.json');
            const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
    
            if (!packageJson.scripts) {
                packageJson.scripts = {};
            }
    
            packageJson.scripts[args.name] = args.command;
    
            await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
    
            return {
                content: [
                    {
                        type: 'text',
                        text: `Added script '${args.name}': ${args.command}`,
                    },
                ],
            };
        } catch (error) {
            throw new McpError(
                ErrorCode.InternalError,
                `Failed to add script: ${error instanceof Error ? error.message : String(error)}`
            );
        }
    }
  • TypeScript interface defining the expected input arguments for the add_script tool: path (project directory), name (script name), command (script command).
    interface AddScriptArgs extends Record<string, unknown> {
        path: string;
        name: string;
        command: string;
    }
  • src/index.ts:324-345 (registration)
    Registration of the add_script tool in the ListToolsRequestSchema handler, providing name, description, and JSON schema for input validation.
    {
        name: 'add_script',
        description: 'Add a new npm script to package.json',
        inputSchema: {
            type: 'object',
            properties: {
                path: {
                    type: 'string',
                    description: 'Project directory path',
                },
                name: {
                    type: 'string',
                    description: 'Script name',
                },
                command: {
                    type: 'string',
                    description: 'Script command',
                },
            },
            required: ['path', 'name', 'command'],
        },
    },
  • src/index.ts:403-404 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement that calls the handleAddScript function when 'add_script' is invoked.
    case 'add_script':
        return await this.handleAddScript(args as AddScriptArgs);

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/bsmi021/mcp-node-omnibus-server'

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