Skip to main content
Glama

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 async handler function that processes an array of npm dependencies, fetches package metadata from npm registry and unpkg, checks for built-in types or @types packages, retrieves .d.ts contents, and returns results as JSON.
    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: an array of objects with 'name' (string, required) and 'version' (string, optional). Imported as getDependencyTypesSchema in server.ts.
    export const argSchema = { dependencies: z.array( z.object({ name: z.string(), version: z.string().optional(), }) ), };
  • src/server.ts:100-112 (registration)
    Registers the tool named 'get_dependency_types' on the MCP server, providing the tool name, description, input schema (getDependencyTypesSchema), and handler (getDependencyTypes).
    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/ssdeanx/node-code-sandbox-mcp'

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