Skip to main content
Glama

speak

Convert text into speech via text-to-speech technology and mark delivered utterances as responded for efficient voice-based communication.

Instructions

Speak text using text-to-speech and mark delivered utterances as responded

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe text to speak

Implementation Reference

  • MCP CallToolRequestSchema request handler implementing the 'speak' tool. Proxies the call to the local /api/speak HTTP endpoint and handles success/error responses.
    mcpServer.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      try {
        if (name === 'speak') {
          const text = args?.text as string;
    
          if (!text || !text.trim()) {
            return {
              content: [
                {
                  type: 'text',
                  text: 'Error: Text is required for speak tool',
                },
              ],
              isError: true,
            };
          }
    
          const response = await fetch(`http://localhost:${HTTP_PORT}/api/speak`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ text }),
          });
    
          const data = await response.json() as any;
    
          if (response.ok) {
            return {
              content: [
                {
                  type: 'text',
                  text: '',  // Return empty string for success
                },
              ],
            };
          } else {
            return {
              content: [
                {
                  type: 'text',
                  text: `Error speaking text: ${data.error || 'Unknown error'}`,
                },
              ],
              isError: true,
            };
          }
        }
    
        throw new Error(`Unknown tool: ${name}`);
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    });
  • MCP ListToolsRequestSchema request handler that registers the 'speak' tool, including its description and input schema.
    mcpServer.setRequestHandler(ListToolsRequestSchema, async () => {
      // Only expose the speak tool - voice input is auto-delivered via hooks
      return {
        tools: [
          {
            name: 'speak',
            description: 'Speak text using text-to-speech and mark delivered utterances as responded',
            inputSchema: {
              type: 'object',
              properties: {
                text: {
                  type: 'string',
                  description: 'The text to speak',
                },
              },
              required: ['text'],
            },
          }
        ]
      };
    });
  • Input schema/JSON Schema definition for the 'speak' tool parameters.
    inputSchema: {
      type: 'object',
      properties: {
        text: {
          type: 'string',
          description: 'The text to speak',
        },
      },
      required: ['text'],
    },
  • HTTP endpoint /api/speak called by the MCP handler. Notifies connected browser clients via SSE for TTS, adds assistant message to conversation history, marks user utterances as responded, and updates last speak timestamp.
    app.post('/api/speak', async (req: Request, res: Response) => {
      const { text } = req.body;
    
      if (!text || !text.trim()) {
        res.status(400).json({ error: 'Text is required' });
        return;
      }
    
      // Check if voice responses are enabled
      if (!voicePreferences.voiceResponsesEnabled) {
        debugLog(`[Speak] Voice responses disabled, returning error`);
        res.status(400).json({
          error: 'Voice responses are disabled',
          message: 'Cannot speak when voice responses are disabled'
        });
        return;
      }
    
      try {
        // Always notify browser clients - they decide how to speak
        notifyTTSClients(text);
        debugLog(`[Speak] Sent text to browser for TTS: "${text}"`);
    
        // Note: The browser will decide whether to use system voice or browser voice
    
        // Store assistant's response in conversation history
        queue.addAssistantMessage(text);
    
        // Mark all delivered utterances as responded
        const deliveredUtterances = queue.utterances.filter(u => u.status === 'delivered');
        deliveredUtterances.forEach(u => {
          u.status = 'responded';
          debugLog(`[Queue] marked as responded: "${u.text}"	[id: ${u.id}]`);
    
          // Sync status in messages array
          const message = queue.messages.find(m => m.id === u.id && m.role === 'user');
          if (message) {
            message.status = 'responded';
          }
        });
    
        lastSpeakTimestamp = new Date();
    
        res.json({
          success: true,
          message: 'Text spoken successfully',
          respondedCount: deliveredUtterances.length
        });
      } catch (error) {
        debugLog(`[Speak] Failed to speak text: ${error}`);
        res.status(500).json({
          error: 'Failed to speak text',
          details: error instanceof Error ? error.message : String(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. It mentions the tool 'speak[s] text using text-to-speech' and 'mark[s] delivered utterances as responded,' but fails to disclose critical behavioral traits like whether this is a read-only or mutating operation, authentication needs, rate limits, or side effects. The description is insufficient for a tool with no annotation coverage.

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, efficient sentence that directly states the tool's actions without unnecessary words. It is appropriately sized and front-loaded, with no wasted information.

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 lack of annotations and output schema, the description is incomplete. It fails to address key contextual aspects like the tool's behavioral impact (e.g., whether it's a read or write operation), error handling, or what 'mark delivered utterances as responded' entails. For a tool with no structured metadata, the description should provide more comprehensive guidance.

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 schema description coverage is 100%, with the single parameter 'text' documented as 'The text to speak.' The description adds no additional meaning beyond this, such as text length limits, language support, or formatting requirements. With high 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 with a specific verb ('speak') and resource ('text'), and mentions an additional action ('mark delivered utterances as responded'). However, with no sibling tools, there's no opportunity to distinguish from alternatives, preventing a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool, such as appropriate contexts, prerequisites, or limitations. It lacks any mention of alternatives or exclusions, leaving usage entirely implicit.

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/johnmatthewtennant/mcp-voice-hooks'

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