Skip to main content
Glama
mozicim

Node Code Sandbox MCP

by mozicim

get_dependency_types

Fetch TypeScript definitions for npm packages to inspect APIs and types before running Node.js scripts with unfamiliar dependencies.

Instructions

Given an array of npm package names (and optional versions), fetch whether each package ships its own TypeScript definitions or has a corresponding @types/… package, and return the raw .d.ts text.

Useful whenwhen you're about to run a Node.js script against an unfamiliar dependency and want to inspect what APIs and types it exposes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dependenciesYes

Implementation Reference

  • The handler function for the get_dependency_types tool. It takes a list of dependencies, fetches their TypeScript definitions from npm registry or @types packages, and returns whether types are available along with the raw .d.ts content.
    export default async function getDependencyTypes({ dependencies, }: { dependencies: { name: string; version?: string }[]; }): Promise<McpResponse> { const results: { name: string; hasTypes: boolean; types?: string; typesPackage?: string; version?: string; }[] = []; for (const dep of dependencies) { const info: (typeof results)[number] = { name: dep.name, hasTypes: false }; try { const pkgRes = await fetch(`https://registry.npmjs.org/${dep.name}`); if (pkgRes.ok) { const pkgMeta = (await pkgRes.json()) as any; const latestTag = pkgMeta['dist-tags']?.latest as string; const versionToUse = dep.version || latestTag; const versionData = pkgMeta.versions?.[versionToUse]; // Check for in-package types if (versionData) { const typesField = versionData.types || versionData.typings; if (typesField) { const url = `https://unpkg.com/${dep.name}@${versionToUse}/${typesField}`; const contentRes = await fetch(url); if (contentRes.ok) { info.hasTypes = true; info.types = await contentRes.text(); info.version = versionToUse; results.push(info); continue; } } } // Fallback to @types package const sanitized = dep.name.replace('@', '').replace('/', '__'); const typesName = `@types/${sanitized}`; const typesRes = await fetch( `https://registry.npmjs.org/${encodeURIComponent(typesName)}` ); if (typesRes.ok) { const typesMeta = (await typesRes.json()) as any; const typesVersion = typesMeta['dist-tags']?.latest as string; const typesVersionData = typesMeta.versions?.[typesVersion]; const typesField = typesVersionData?.types || typesVersionData?.typings || 'index.d.ts'; const url = `https://unpkg.com/${typesName}@${typesVersion}/${typesField}`; const contentRes = await fetch(url); if (contentRes.ok) { info.hasTypes = true; info.typesPackage = typesName; info.version = typesVersion; info.types = await contentRes.text(); } } } } catch (e) { logger.info(`Failed to fetch type info for ${dep.name}: ${e}`); } results.push(info); } return { content: [textContent(JSON.stringify(results))] }; }
  • Zod schema defining the input for the get_dependency_types tool: an array of dependencies with name and optional version.
    export const argSchema = { dependencies: z.array( z.object({ name: z.string(), version: z.string().optional(), }) ), };
  • src/server.ts:100-112 (registration)
    Registration of the 'get_dependency_types' tool on the MCP server, specifying name, description, input schema, and handler function.
    server.tool( 'get_dependency_types', ` Given an array of npm package names (and optional versions), fetch whether each package ships its own TypeScript definitions or has a corresponding @types/… package, and return the raw .d.ts text. Useful whenwhen you're about to run a Node.js script against an unfamiliar dependency and want to inspect what APIs and types it exposes. `, getDependencyTypesSchema, getDependencyTypes );

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/mozicim/node-code-sandbox-mcp'

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