Skip to main content
Glama

getModuleName

Extract PureScript module names from files or code snippets to analyze code structure without requiring an IDE server. Supports absolute file paths or direct code input.

Instructions

Extract the module name (like 'Data.List' or 'Main') from PureScript code. Works on files or code snippets without needing the IDE server. Useful for understanding code structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNoPureScript code string.
filePathNoAbsolute path to the PureScript file. Only absolute paths are supported.

Implementation Reference

  • Handler function that implements the getModuleName tool. Parses PureScript code using Tree-sitter, queries for the qualified_module node, extracts and cleans the module name text.
    "getModuleName": async (args) => {
        if (!treeSitterInitialized) throw new Error("Tree-sitter not initialized.");
        const code = await getCodeFromInput(args, true);
        const tree = purescriptTsParser.parse(code);
        // Corrected query to capture the full text of the qualified_module node
        const query = new Query(PureScriptLanguage, `(purescript name: (qualified_module) @module.qname)`);
        const captures = query.captures(tree.rootNode);
        if (captures.length > 0 && captures[0].name === 'module.qname') {
            // The text of the qualified_module node itself is the full module name
            return { content: [{ type: "text", text: JSON.stringify(captures[0].node.text.replace(/\s+/g, ''), null, 2) }] };
        }
        return { content: [{ type: "text", text: JSON.stringify(null, null, 2) }] };
    },
  • Input schema definition for the getModuleName tool, specifying parameters filePath or code.
    {
        name: "getModuleName",
        description: "Extract the module name (like 'Data.List' or 'Main') from PureScript code. Works on files or code snippets without needing the IDE server. Useful for understanding code structure.",
        inputSchema: {
            type: "object",
            properties: {
                filePath: { type: "string", description: "Absolute path to the PureScript file. Only absolute paths are supported." },
                code: { type: "string", description: "PureScript code string." }
            },
            additionalProperties: false,
            description: "Exactly one of 'filePath' or 'code' must be provided."
        }
    },
  • index.js:1159-1164 (registration)
    Registration via tools/list endpoint that returns the TOOL_DEFINITIONS array including getModuleName.
        const toolsToExclude = ['query_purescript_ast', 'query_purs_ide']; // Keep query_purs_ide for now, for direct access if needed
        const filteredToolDefinitions = TOOL_DEFINITIONS.filter(
            tool => !toolsToExclude.includes(tool.name)
        );
        return createSuccessResponse(id, { tools: filteredToolDefinitions });
    }
  • Helper function getCodeFromInput used by getModuleName to retrieve code from either filePath or inline code argument.
    // Helper to get code from input args (filePath or code string)
    async function getCodeFromInput(args, isModuleOriented = true) {
        if (isModuleOriented) {
            const hasFilePath = args && typeof args.filePath === 'string';
            const hasCode = args && typeof args.code === 'string';
    
            if ((hasFilePath && hasCode) || (!hasFilePath && !hasCode)) {
                throw new Error("Invalid input: Exactly one of 'filePath' or 'code' must be provided for module-oriented tools.");
            }
            if (hasFilePath) {
                if (!path.isAbsolute(args.filePath)) {
                    throw new Error(`Invalid filePath: '${args.filePath}' is not an absolute path. Only absolute paths are supported.`);
                }
                try {
                    return await fs.readFile(args.filePath, 'utf-8');
                } catch (e) {
                    throw new Error(`Failed to read file at ${args.filePath}: ${e.message}`);
                }
            }
            return args.code;
        } else { // Snippet-oriented
            if (!args || typeof args.code !== 'string') {
                throw new Error("Invalid input: 'code' (string) is required for snippet-oriented tools.");
            }
            return args.code;
        }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses that it works on files or code snippets without needing the IDE server, which is useful behavioral context. However, it doesn't mention error handling, performance characteristics, or what happens with malformed input. The description doesn't contradict any annotations since none exist.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, zero waste. First sentence states purpose and scope, second sentence provides usage context. Every word earns its place with no redundancy or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a relatively simple extraction tool with 100% schema coverage but no output schema or annotations, the description provides good context about what it does and when to use it. It could be more complete by mentioning what the output looks like (since no output schema exists) or error conditions, but it covers the essential purpose well.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents both parameters. The description mentions 'files or code snippets' which aligns with the filePath/code parameters but doesn't add meaningful semantics beyond what the schema provides. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('extract'), resource ('module name from PureScript code'), and scope ('files or code snippets without needing the IDE server'). It distinguishes from siblings like getFunctionNames or getImports by focusing specifically on module names.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('useful for understanding code structure') and mentions it works without the IDE server, which differentiates it from some sibling tools. However, it doesn't explicitly state when NOT to use it or name specific alternatives for related tasks.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/avi892nash/purescript-mcp-tools'

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