Skip to main content
Glama

process-request

Process natural language requests by identifying the best tool through semantic matching and fallbacks, then confirm or execute the tool directly to streamline task handling in software development.

Instructions

Processes natural language requests, determines the best tool using semantic matching and fallbacks, and either asks for confirmation or executes the tool directly.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestYesNatural language request to process and route to the appropriate tool

Implementation Reference

  • The main executor/handler function for the 'process-request' tool. It processes the natural language request using hybrid matching, decides if confirmation is needed, and either prompts for confirmation or executes the matched tool directly via the tool registry.
    export const processUserRequest: ToolExecutor = async (
      params: Record<string, unknown>, // Use unknown instead of any for better type safety
      config: OpenRouterConfig,
      context?: ToolExecutionContext // Add context parameter
    ): Promise<CallToolResult> => {
      const request = params.request as string; // Assert type after validation
      let matchResult: EnhancedMatchResult; // Use the enhanced type
    
      try {
        logger.info(`Processing request: "${request.substring(0, 50)}..."`);
        // Step 1: Use the hybrid matcher to determine the appropriate tool
        matchResult = await hybridMatch(request, config);
    
        // Step 2: Check if confirmation is needed (unless force flag is set)
        const forceExecution = (context?.metadata as { forceExecution?: boolean })?.forceExecution === true;
        if (matchResult.requiresConfirmation && !forceExecution) {
          logger.info(`Tool execution requires confirmation: ${matchResult.toolName}`);
          const explanation = getMatchExplanation(matchResult);
          return {
            content: [{
              type: "text",
              // Provide a clear confirmation prompt to the user
              text: `I plan to use the '${matchResult.toolName}' tool for your request.\nExplanation: ${explanation}\nConfidence: ${Math.round(matchResult.confidence * 100)}%\n\nDo you want to proceed?`
            }],
            isError: false // Not an error, just needs confirmation
          };
        }
    
        // Step 3: No confirmation needed, execute the determined tool directly
        logger.info(`Executing tool '${matchResult.toolName}' directly based on processed request (Confidence: ${matchResult.confidence.toFixed(3)}).`);
        const toolResult = await executeTool(
          matchResult.toolName,
          matchResult.parameters, // Use parameters determined by hybridMatch
          config,
          context // Pass context down to executeTool
        );
    
        // Step 4: Combine explanation with the actual tool result
        const explanation = getMatchExplanation(matchResult); // Get explanation again for the final message
        return {
          content: [
            {
              type: "text",
              text: `Using ${matchResult.toolName}:\n${explanation}\n\n---\n\n`
            },
            // Spread the content from the actual tool result, handling potential null/undefined content
            ...(toolResult.content || [{ type: 'text', text: '(Tool executed successfully but returned no content)' }])
          ],
          isError: toolResult.isError ?? false // Propagate error status, default to false
        };
    
      } catch (error) {
        logger.error({ err: error, request }, "Error processing user request");
        // Return an error result
        return {
          content: [
            {
              type: "text",
              text: `Error processing request: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }; // End of processUserRequest executor
  • Zod input schema shape for the 'process-request' tool, defining the 'request' parameter.
    const processRequestInputSchemaShape = {
      request: z.string().min(3, { message: "Request must be at least 3 characters." }).describe("Natural language request to process and route to the appropriate tool")
    };
  • Tool definition object and registration call to the central tool registry using registerTool.
    const processRequestToolDefinition: ToolDefinition = {
      name: "process-request",
      description: "Processes natural language requests, determines the best tool using semantic matching and fallbacks, and either asks for confirmation or executes the tool directly.", // Updated description
      inputSchema: processRequestInputSchemaShape, // Use the raw shape
      executor: processUserRequest // Reference the adapted function
    };
    
    // Register the tool with the central registry
    registerTool(processRequestToolDefinition);
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/freshtechbro/vibe-coder-mcp'

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