Skip to main content
Glama

getWhereBindings

Extract 'where' clauses from PureScript functions to identify local helper functions and variables, aiding in understanding function implementation details.

Instructions

Find 'where' clauses in PureScript functions. These contain local helper functions and variables. Useful for understanding function implementation details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesPureScript code snippet.

Implementation Reference

  • Handler function that uses Tree-sitter to parse PureScript code, queries for 'where' clauses in functions (where keyword followed by declarations block), extracts and combines the text of these blocks, deduplicates them, and returns as a JSON array of strings.
    "getWhereBindings": async (args) => {
        if (!treeSitterInitialized) throw new Error("Tree-sitter not initialized.");
        const code = await getCodeFromInput(args, false); // Snippet-oriented
        const tree = purescriptTsParser.parse(code);
        const whereClausesText = [];
    
        // Query for 'where' keyword followed by a 'declarations' block within a function or let binding
        const querySource = `
          (function
            (where) @where_keyword
            (declarations) @declarations_block)
        `;
        // Also consider 'let' bindings with 'where' clauses, though less common for top-level 'where'
        // (let_binding (where) @where_keyword (declarations) @declarations_block)
    
        const query = new Query(PureScriptLanguage, querySource);
        const matches = query.matches(tree.rootNode);
    
        for (const match of matches) {
            const whereKeywordNode = match.captures.find(c => c.name === 'where_keyword')?.node;
            const declarationsNode = match.captures.find(c => c.name === 'declarations_block')?.node;
            
            if (whereKeywordNode && declarationsNode) {
                // Construct the text from "where" keyword to the end of the declarations block
                // This requires careful handling of start and end positions if they are not contiguous in the source text string
                // For simplicity, if they are siblings and in order, we can take text from start of 'where' to end of 'declarations'
                // A safer way is to combine their individual texts if they represent the full conceptual block
                const fullWhereClauseText = `${whereKeywordNode.text} ${declarationsNode.text}`;
                whereClausesText.push(fullWhereClauseText.trim());
            }
        }
        // Deduplicate, as some complex structures might yield multiple partial matches
        const uniqueWhereClauses = [...new Set(whereClausesText)];
        return { content: [{ type: "text", text: JSON.stringify(uniqueWhereClauses, null, 2) }] };
    },
  • index.js:628-636 (registration)
    Tool registration in TOOL_DEFINITIONS array, including name, description, and input schema (requires 'code' string). Used by tools/list method.
        name: "getWhereBindings",
        description: "Find 'where' clauses in PureScript functions. These contain local helper functions and variables. Useful for understanding function implementation details.",
        inputSchema: {
            type: "object",
            properties: { code: { type: "string", description: "PureScript code snippet." } },
            required: ["code"],
            additionalProperties: false
        }
    },
  • Input schema definition for getWhereBindings tool: object with required 'code' property (PureScript code snippet).
        name: "getWhereBindings",
        description: "Find 'where' clauses in PureScript functions. These contain local helper functions and variables. Useful for understanding function implementation details.",
        inputSchema: {
            type: "object",
            properties: { code: { type: "string", description: "PureScript code snippet." } },
            required: ["code"],
            additionalProperties: false
        }
    },
  • Helper function getCodeFromInput used by getWhereBindings (and other tools) to retrieve code from args.code or filePath, validating inputs and preferring snippets for this tool.
    // 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;
        }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does (finds 'where' clauses) and their purpose (contain local helper functions and variables), but doesn't describe the return format, error handling, performance characteristics, or whether it requires specific code formatting. For a code analysis tool with zero annotation coverage, this leaves significant behavioral gaps.

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?

The description is extremely concise (two sentences) and front-loaded with the core purpose in the first sentence. Every word earns its place: the first sentence defines the action and target, the second explains the utility. No redundant information or unnecessary elaboration.

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

Completeness3/5

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

Given the tool's moderate complexity (code analysis with one parameter), 100% schema coverage, but no annotations or output schema, the description is minimally adequate. It explains what the tool does and why, but doesn't address return format, error cases, or detailed behavioral expectations. For a tool without output schema, more information about what gets returned would be helpful.

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?

The input schema has 100% description coverage with one parameter ('code') clearly documented as 'PureScript code snippet.' The description adds minimal value beyond this, mentioning 'PureScript functions' which aligns with the schema but doesn't provide additional context about code format expectations, size limitations, or preprocessing requirements. With complete schema coverage, the baseline score of 3 is appropriate.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Find 'where' clauses in PureScript functions' with the specific resource being PureScript code. It distinguishes from siblings by focusing on 'where' clauses rather than imports, module names, or other code analysis tasks. However, it doesn't explicitly differentiate from tools like 'getTopLevelDeclarations' which might also analyze code structure.

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

Usage Guidelines3/5

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

The description provides implied usage context: 'Useful for understanding function implementation details' suggests this tool is for code analysis rather than execution or transformation. However, it doesn't explicitly state when to use this tool versus alternatives like 'getFunctionNames' or 'getTopLevelDeclarations', nor does it mention prerequisites or exclusions.

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