Skip to main content
Glama

gemini_sendFunctionResult

Transmits the results of executed functions to an ongoing Gemini chat session using its sessionId, enabling the model to generate a response based on the provided function outcomes.

Instructions

Sends the result(s) of function execution(s) back to an existing Gemini chat session, identified by its sessionId. Returns the model's subsequent response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
functionResponsesYesRequired. An array containing the results of the function calls executed by the client. Each item must include the function 'name' and its 'response' object.
generationConfigNoOptional. Per-request generation configuration settings to override session defaults for this turn.
safetySettingsNoOptional. Per-request safety settings to override session defaults for this turn.
sessionIdYesRequired. The unique identifier of the chat session.

Implementation Reference

  • Handler logic within the gemini_chat tool for the 'send_function_result' operation, which sends function execution results back to a Gemini chat session by calling the service method.
    case "send_function_result": {
      // Send function results to an existing chat session
      // Note: The service expects a string, so we stringify the array of function responses
      const response: GenerateContentResponse =
        await serviceInstance.sendFunctionResultToSession({
          sessionId: typedArgs.sessionId!,
          functionResponse: JSON.stringify(typedArgs.functionResponses),
          functionCall: undefined, // Could be enhanced to pass original function call
        });
    
      // Process the response
      return processGenerateContentResponse(
        response,
        typedArgs.sessionId!,
        true
      );
    }
  • TypeScript interface defining the input structure for function responses, explicitly noted as used by the gemini_sendFunctionResult tool.
    /**
     * Represents the input structure for a function response sent from the client to the server.
     * Used by the gemini_sendFunctionResult tool.
     */
    export interface FunctionResponseInput {
      /** The name of the function that was called by the model. */
      name: string;
      /** The JSON object result returned by the function execution. */
      response: Record<string, unknown>;
    }
  • Zod schema (functionResponseInputSchema) for validating function response inputs in the send_function_result operation of gemini_chat tool, matching the FunctionResponseInput type.
    const functionResponseInputSchema = z
      .object({
        name: z
          .string()
          .min(1)
          .describe(
            "Required. The name of the function that was called by the model."
          ),
        response: z
          .record(z.unknown())
          .describe(
            "Required. The JSON object result returned by the function execution."
          ),
      })
      .describe(
        "Represents the result of a single function execution to be sent back to the model."
      );
  • Core service method that implements sending a function result to a Gemini chat session by constructing the function response content, appending to session history, and generating the model's next response via the Gemini API.
    public async sendFunctionResultToSession(
      params: SendFunctionResultParams
    ): Promise<GenerateContentResponse> {
      const { sessionId, functionResponse, functionCall } = params;
    
      // Get the chat session
      const session = this.chatSessions.get(sessionId);
      if (!session) {
        throw new GeminiApiError(`Chat session not found: ${sessionId}`);
      }
    
      // Create function response message
      const responseContent: Content = {
        role: "function",
        parts: [
          {
            functionResponse: {
              name: functionCall?.name || "function",
              response: { content: functionResponse },
            },
          },
        ],
      };
    
      // Add the function response to the session history
      session.history.push(responseContent);
    
      try {
        // Prepare the request configuration
        const requestConfig: {
          model: string;
          contents: Content[];
          generationConfig?: GenerationConfig;
          safetySettings?: SafetySetting[];
          tools?: Tool[];
          toolConfig?: ToolConfig;
          systemInstruction?: Content;
          cachedContent?: string;
          thinkingConfig?: ThinkingConfig;
        } = {
          model: session.model,
          contents: session.history,
        };
    
        // Add configuration from the session
        if (session.config.systemInstruction) {
          requestConfig.systemInstruction = session.config.systemInstruction;
        }
    
        if (session.config.generationConfig) {
          requestConfig.generationConfig = session.config.generationConfig;
    
          // Use thinking config from session if available
          if (session.config.thinkingConfig) {
            requestConfig.thinkingConfig = processThinkingConfig(
              session.config.thinkingConfig
            );
          }
        }
    
        if (session.config.safetySettings) {
          requestConfig.safetySettings = session.config.safetySettings;
        }
    
        if (session.config.tools) {
          requestConfig.tools = session.config.tools;
        }
    
        if (session.config.cachedContent) {
          requestConfig.cachedContent = session.config.cachedContent;
        }
    
        logger.debug(
          `Sending function result to session ${sessionId} using model ${session.model}`
        );
    
        // Call the generateContent API directly
        const response = await this.genAI.models.generateContent(requestConfig);
    
        // Process the response
        if (response.candidates && response.candidates.length > 0) {
          const assistantMessage = response.candidates[0].content;
          if (assistantMessage) {
            // Add the assistant response to the session history
            session.history.push(assistantMessage);
          }
        }
    
        return response;
      } catch (error: unknown) {
        logger.error(
          `Error sending function result to session ${sessionId}:`,
          error
        );
        throw new GeminiApiError(
          `Failed to send function result to session ${sessionId}: ${(error as Error).message}`,
          error
        );
      }
    }
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. While it mentions that the tool 'Returns the model's subsequent response,' it lacks critical behavioral details such as whether this is a read-only or mutating operation, what happens if the sessionId is invalid, if there are rate limits, authentication requirements, or error handling. For a tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

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 a single, well-structured sentence that efficiently conveys the core purpose and outcome. It front-loads the key action and resource, with no redundant or unnecessary information. Every word serves a clear purpose, making it highly concise and effective.

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

Completeness2/5

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

Given the complexity (4 parameters with nested objects, no output schema, and no annotations), the description is insufficient. It lacks details on behavioral traits, error conditions, and the structure of the returned 'model's subsequent response.' For a tool that interacts with chat sessions and function results, more context is needed to ensure proper usage and understanding of outcomes.

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 documents all parameters thoroughly. The description adds minimal value beyond the schema by implying that functionResponses are for 'function execution(s)' and sessionId identifies 'an existing Gemini chat session,' but it doesn't provide additional context like parameter interactions or usage examples. 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 ('Sends the result(s) of function execution(s) back') and the target resource ('an existing Gemini chat session, identified by its sessionId'). It distinguishes itself from sibling tools like gemini_sendMessage or gemini_functionCall by focusing specifically on returning function execution results rather than general messages or initiating function calls.

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 implies usage context by mentioning 'existing Gemini chat session' and 'function execution(s)', suggesting it should be used after function calls have been made. However, it doesn't explicitly state when to use this tool versus alternatives like gemini_sendMessage, nor does it mention prerequisites such as needing an active session or prior function calls. The guidance is present but incomplete.

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/bsmi021/mcp-gemini-server'

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