read_pubnub_resources
Search and retrieve PubNub conceptual guides, integration instructions, best practices, and troubleshooting tips in markdown format for efficient development and issue resolution.
Instructions
Retrieves PubNub conceptual guides and how-to documentation from markdown files in the resources directory. Call this tool for overviews, integration instructions, best practices, and troubleshooting tips. Returns documentation in markdown format. For detailed API reference and SDK code samples, also call the read_pubnub_sdk_docs tool.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document | Yes | Resource name to fetch (file name without .md under resources directory, e.g., pubnub_concepts, how_to_send_receive_json, how_to_encrypt_messages_files) |
Implementation Reference
- index.js:478-517 (handler)Handler function that executes the tool logic: reads the specified markdown file from resources/ or resources/languages/ directories and returns it as tool content with SDK init instructions appended.toolHandlers['read_pubnub_resources'] = async ({ document }) => { try { // determine the file path for the requested resource (top-level or languages) let filePath = pathJoin(resourcesDir, `${document}.md`); if (!fs.existsSync(filePath)) { // fallback to languages directory filePath = pathJoin(languagesDir, `${document}.md`); if (!fs.existsSync(filePath)) { return { content: [ { type: 'text', text: `Documentation file not found: ${document}.md`, }, ], isError: true, }; } } const content = fs.readFileSync(filePath, 'utf8'); return { content: [ { type: 'text', text: content + getPubNubInitSDKInstructions(), }, ], }; } catch (err) { return { content: [ { type: 'text', text: `Error reading pubnub documentation for '${document}.md': ${err.message || err}`, }, ], isError: true, }; } };
- index.js:520-526 (schema)Tool schema definition with name, description, and Zod parameters schema. Uses dynamically generated enum from available resource files.toolDefinitions['read_pubnub_resources'] = { name: 'read_pubnub_resources', description: 'Retrieves PubNub conceptual guides and how-to documentation from markdown files in the resources directory. Call this tool for overviews, integration instructions, best practices, and troubleshooting tips. Returns documentation in markdown format. For detailed API reference and SDK code samples, also call the read_pubnub_sdk_docs tool.', parameters: { document: z.enum(pubnubResourceOptions).describe('Resource name to fetch (file name without .md under resources directory, e.g., pubnub_concepts, how_to_send_receive_json, how_to_encrypt_messages_files)'), } };
- index.js:454-475 (helper)Helper that dynamically scans resources/ and resources/languages/ directories to generate the enum options for the 'document' parameter, listing all available .md files without extension.const pubnubResourceOptions = (() => { try { // Top-level markdown files in resources directory const files = fs.readdirSync(resourcesDir); const topLevel = files .filter((file) => fs.statSync(pathJoin(resourcesDir, file)).isFile()) .filter((file) => extname(file).toLowerCase() === '.md') .map((file) => basename(file, extname(file))); // Markdown files in resources/languages directory let langFiles = []; if (fs.existsSync(languagesDir)) { langFiles = fs.readdirSync(languagesDir) .filter((file) => fs.statSync(pathJoin(languagesDir, file)).isFile()) .filter((file) => extname(file).toLowerCase() === '.md') .map((file) => basename(file, extname(file))); } return [...topLevel, ...langFiles]; } catch (err) { //console.error(`Error reading resources directories: ${err}`); return []; } })();
- index.js:1363-1394 (registration)Registration function that iterates over all tool definitions and registers 'read_pubnub_resources' (and others) to the MCP server instance via serverInstance.tool(). Excludes it in chat SDK mode.function registerAllTools(serverInstance, chatSdkMode = false) { // Tools to exclude when in chat SDK mode const chatSdkExcludedTools = [ 'read_pubnub_sdk_docs', 'write_pubnub_app', 'read_pubnub_resources', 'manage_pubnub_account' ]; for (const toolName in toolDefinitions) { if (toolHandlers[toolName]) { // Skip excluded tools when in chat SDK mode if (chatSdkMode && chatSdkExcludedTools.includes(toolName)) { continue; } // Special handling for chat SDK docs tool if (toolName === 'read_pubnub_chat_sdk_docs' && (chatSdkLanguages.length === 0 || chatSdkTopics.length === 0)) { continue; // Skip this tool if chat SDK data isn't loaded } const toolDef = toolDefinitions[toolName]; serverInstance.tool( toolDef.name, toolDef.description, toolDef.parameters, wrapToolHandler(toolHandlers[toolName], toolName) ); } } }