Skip to main content
Glama
qianniuspace

MCP Security Audit Server

audit_nodejs_dependencies

Scan npm package dependencies for security vulnerabilities. Receive detailed reports and actionable fix recommendations integrated with the MCP Security Audit Server.

Instructions

Audit specific dependencies for vulnerabilities

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dependenciesYesDependencies object from package.json

Implementation Reference

  • Core handler function that executes the tool logic: validates input dependencies, audits each package individually via npm registry, processes vulnerabilities, and returns JSON-formatted results.
    async auditNodejsDependencies(args: { dependencies: NpmDependencies }) {
        try {
            // Validate dependencies object
            if (!args || typeof args.dependencies !== 'object') {
                throw new McpError(
                    ErrorCode.InvalidParams,
                    'Invalid dependencies object'
                );
            }
    
            // Handle potentially nested dependencies object
            const actualDeps = args.dependencies.dependencies || args.dependencies;
    
            const auditResults = [];
            for (const [name, version] of Object.entries(actualDeps)) {
                if (typeof version !== 'string') continue
                try {
                    const result = await this.auditSingleDependency(name, version);
                    auditResults.push(result);
                } catch (error) {
                    console.error(`[ERROR] Failed to audit ${name}@${version}:`, error);
                    // Continue processing other dependencies
                }
            }
    
            // Merge and process all vulnerability results
            const mergedVulnerabilities = auditResults.flatMap(result =>
                this.processVulnerabilities(result)
            );
    
            // Return consolidated results
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(mergedVulnerabilities, null, 2),
                    },
                ]
            };
        } catch (error) {
            console.error('[ERROR] Audit failed:', error);
            if (error instanceof McpError) {
                throw error;
            }
            throw new McpError(
                ErrorCode.InternalError,
                `Audit failed: ${error instanceof Error ? error.message : 'Unknown error'}`
            );
        }
    }
  • src/index.ts:61-81 (registration)
    Registers the tool in the MCP listTools handler, providing name, description, and input schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
        tools: [
            {
                name: 'audit_nodejs_dependencies',
                description: 'Audit specific dependencies for vulnerabilities',
                inputSchema: {
                    type: 'object',
                    properties: {
                        dependencies: {
                            type: 'object',
                            additionalProperties: {
                                type: 'string',
                            },
                            description: 'Dependencies object from package.json',
                        }
                    },
                    required: ['dependencies'],
                },
            },
        ],
    }))
  • src/index.ts:94-101 (registration)
    Dispatches tool calls to the appropriate handler method in the CallToolRequestSchema handler.
    switch (request.params.name) {
        case 'audit_nodejs_dependencies':
            return this.securityHandler.auditNodejsDependencies(
                request.params.arguments as { dependencies: NpmDependencies }
            );
        default:
            throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`);
    }
  • Type definition for the input dependencies object used in the tool schema and handler.
    export interface NpmDependencies {
        [key: string]: string;  // Package name -> version mapping
    }
  • Helper method that audits a single dependency by posting to npm's security audit endpoint.
    private async auditSingleDependency(name: string, version: string): Promise<any> {
        try {
            // Validate input parameters
            if (!name || !version) {
                throw new Error(`Invalid package name or version: ${name}@${version}`);
            }
    
            // Clean version string by removing prefix characters (^ or ~)
            const cleanVersion = version.trim().replace(/^[\^~]/, '');
    
            // Prepare audit data structure
            const auditData = {
                name: "single-dependency-audit",
                version: "1.0.0",
                requires: { [name]: cleanVersion },
                dependencies: {
                    [name]: { version: cleanVersion }
                }
            };
    
            // Send audit request to npm registry
            const result = await npmFetch.json('/-/npm/v1/security/audits', {
                method: 'POST',
                body: auditData,
                gzip: true
            });
    
            if (!result) {
                throw new Error(`No response received for ${name}@${cleanVersion}`);
            }
    
            return result;
        } catch (error) {
            console.error(`[ERROR] Error auditing ${name}@${version}:`, error);
            throw new McpError(
                ErrorCode.InternalError,
                `Failed to audit ${name}@${version}: ${error instanceof Error ? error.message : 'Unknown error'}`
            );
        }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'audit' and 'vulnerabilities' but lacks details on permissions, rate limits, output format, or error handling. This is a significant gap for a tool with no annotation coverage.

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 a single, efficient sentence with zero waste, clearly front-loading the purpose. It's appropriately sized for the tool's complexity, earning a score of 5.

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 annotations, no output schema, and a single parameter with high schema coverage, the description is incomplete. It lacks behavioral context, usage guidelines, and output details, making it inadequate for a tool that audits vulnerabilities.

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 description coverage is 100%, so the schema already documents the 'dependencies' parameter. The description implies it audits dependencies but doesn't add syntax or format details beyond what the schema provides, resulting in a baseline score of 3.

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 ('audit') and target ('specific dependencies for vulnerabilities'), providing a specific verb+resource combination. It doesn't need to differentiate from siblings since none exist, so it meets the criteria for a 4.

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 offers no guidance on when to use this tool, such as prerequisites, timing, or alternatives. It simply states what it does without context, which aligns with a score of 2 for no guidance.

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

Related 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/qianniuspace/mcp-security-audit'

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