Skip to main content
Glama

NodeJS API Docs MCP Server

by lirantal
index.ts3.06 kB
import type { Server } from '@modelcontextprotocol/sdk/server/index.js' import { GetPromptRequestSchema, ListPromptsRequestSchema, } from '@modelcontextprotocol/sdk/types.js' import { initLogger, type Logger } from '../utils/logger.ts' const logger: Logger = initLogger() interface PromptsDictionary { [name: string]: { name: string description: string arguments: Array<{ name: string description: string required: boolean }> handler: (args: Record<string, any>) => Promise<{ messages: Array<{ role: string; content: { type: string; text: string } }> }> } } export async function initializePrompts (server: Server): Promise<void> { logger.info({ msg: 'Initializing prompts...' }) const prompts: PromptsDictionary = { 'nodejs-api-lookup': { name: 'nodejs-api-lookup', description: 'Search up-to-date knowledge for Node.js modules API Documentation', arguments: [ { name: 'module', description: 'The name of the Node.js module to search for.', required: false, }, { name: 'method', description: 'The name of the method or function to search for.', required: false, }, ], async handler ({ module: moduleName, method: methodQuery }) { const messages = [] if (moduleName) { messages.push({ role: 'user', content: { type: 'text', text: `Use the Node.js API Documentation tool to provide documentation for the module: ${moduleName}.`, }, }) return { messages } } if (methodQuery) { messages.push({ role: 'user', content: { type: 'text', text: `Use the Node.js API Documentation tool to provide documentation about the function or method: ${methodQuery}.`, }, }) return { messages } } messages.push({ role: 'user', content: { type: 'text', text: 'Use the Node.js API Documentation tool to provide documentation about core (built-in) Node.js modules and their methods', }, }) return { messages } }, }, } server.setRequestHandler(ListPromptsRequestSchema, () => { const promptsList = Object.values(prompts).map((prompt) => { return { name: prompt.name, description: prompt.description, arguments: prompt.arguments, } }) return { prompts: promptsList } }) server.setRequestHandler(GetPromptRequestSchema, async (request) => { const { name, arguments: args } = request.params if (!Object.hasOwn(prompts, name)) { throw new Error(`Prompt ${name} not found`) } // eslint-disable-next-line security/detect-object-injection const prompt = prompts[name] if (prompt) { return await prompt.handler(args || {}) } throw new Error('Prompt not found') }) }

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/lirantal/mcp-server-nodejs-api-docs'

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