Skip to main content
Glama
Cleversoft-IT

drupal-modules-mcp MCP Server

get_module_info

Retrieve detailed Drupal module information from drupal.org by inputting the module's machine name, enabling quick access to essential data for development and configuration.

Instructions

Get information about a Drupal module from drupal.org

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
module_nameYesMachine name of the Drupal module

Implementation Reference

  • MCP CallToolRequestSchema handler that dispatches to get_module_info tool logic: validates tool name and arguments, invokes fetchModuleInfo, and returns JSON-formatted result as text content.
            async (request) => {
                if (request.params.name !== "get_module_info") {
                    throw new McpError(
                        ErrorCode.MethodNotFound,
                        `Unknown tool: ${request.params.name}`
                    );
                }
    
                const args = request.params.arguments as {
                    module_name: string;
                };
                if (!args.module_name) {
                    throw new McpError(
                        ErrorCode.InvalidParams,
                        "Module name is required"
                    );
                }
    
                try {
                    const moduleInfo = await this.fetchModuleInfo(
                        args.module_name
                    );
                    return {
                        content: [
                            {
                                type: "text",
                                text: JSON.stringify(moduleInfo, null, 2),
                            },
                        ],
                    };
                } catch (error) {
                    if (axios.isAxiosError(error)) {
                        throw new McpError(
                            ErrorCode.InternalError,
                            `Failed to fetch module info: ${error.message}`
                        );
                    }
                    throw error;
                }
            }
        );
    }
  • Core helper function that performs web scraping on drupal.org to retrieve and parse detailed module information into a ModuleInfo object.
    private async fetchModuleInfo(moduleName: string): Promise<ModuleInfo> {
        const url = `https://www.drupal.org/project/${moduleName}`;
        const response = await axios.get(url);
        const $ = cheerio.load(response.data);
    
        // Get the latest recommended version
        const latestVersion = $(
            ".release.recommended-Yes .views-field-field-release-version strong"
        )
            .first()
            .text()
            .trim();
    
        // Get Drupal compatibility from the release info
        const compatibility = $(
            ".release.recommended-Yes div:contains('Works with Drupal:')"
        )
            .first()
            .text()
            .replace("Works with Drupal:", "")
            .trim()
            .split("||")
            .map((v) => v.trim());
    
        // Get description from meta tag since it's cleaner
        const description = $('meta[name="description"]').attr("content") || "";
    
        const info: ModuleInfo = {
            name: $("#page-title").text().replace("| Drupal.org", "").trim(),
            description: description,
            version: latestVersion,
            downloads:
                $(".project-info li:contains('sites report')")
                    .text()
                    .match(/\d+,\d+/)?.[0] || "0",
            status: $(".project-info li:contains('Module categories')")
                .text()
                .replace("Module categories:", "")
                .trim(),
            composerCommand: $(`.drupalorg-copy.composer-command`)
                .first()
                .text()
                .trim(),
            drupalCompatibility: compatibility,
            projectUrl: url,
            readme: (() => {
                const $body = $(".field-name-body");
                // Replace each link with text+url format
                $body.find("a").each((_, elem) => {
                    const $elem = $(elem);
                    const href = $elem.attr("href");
                    const text = $elem.text().trim();
                    $elem.replaceWith(`${text} (${href})`);
                });
                return $body.text().trim();
            })(),
        };
    
        // Add additional compatibility info from release table
        const releaseInfo = $(
            ".table-release-compatibility-current tbody tr"
        ).first();
        if (releaseInfo.length) {
            const releaseCompatibility = releaseInfo
                .find("td")
                .map((_, elem) => $(elem).text().trim())
                .get();
            info.drupalCompatibility = [
                ...new Set([
                    ...info.drupalCompatibility,
                    ...releaseCompatibility,
                ]),
            ];
        }
    
        return info;
    }
  • src/index.ts:51-71 (registration)
    Registers the 'get_module_info' tool in the ListToolsRequestSchema handler, including its name, description, and input schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
        tools: [
            {
                name: "get_module_info",
                description:
                    "Get information about a Drupal module from drupal.org",
                inputSchema: {
                    type: "object",
                    properties: {
                        module_name: {
                            type: "string",
                            description:
                                "Machine name of the Drupal module",
                        },
                    },
                    required: ["module_name"],
                },
            },
        ],
    }));
  • TypeScript interface defining the output structure of the get_module_info tool response.
    interface ModuleInfo {
        name: string;
        description: string;
        version: string;
        downloads: string;
        status: string;
        composerCommand: string;
        drupalCompatibility: string[];
        projectUrl: string;
        readme: string;
    }
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/Cleversoft-IT/drupal-modules-mcp'

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