Skip to main content
Glama

docs_get_example

Find working code examples for Hedera blockchain functionality across multiple programming languages to implement SDK features and learn patterns.

Instructions

Find working code examples for Hedera functionality.

SEARCHES: SDK examples, tutorials, implementation patterns RETURNS: Annotated code with explanations and source references LANGUAGES: JavaScript, TypeScript, Java, Python, Go, Rust, Solidity

USE FOR: Getting implementation code, learning patterns, finding SDK usage.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionYesWhat code you need
languageNo
complexityNo
limitNoMax examples (default: 5)

Implementation Reference

  • The primary handler function that executes the docs_get_example tool logic. It initializes RAG services, retrieves code examples via ragService.findCodeExamples based on the description, formats them with rankings, code, explanations, sources, and handles errors gracefully.
    export async function docsGetExample(args: {
      description: string;
      language?: string;
      limit?: number;
      complexity?: string;
    }) {
      try {
        const services = await initializeRAGServices();
    
        if (!services) {
          throw new Error('RAG services not initialized');
        }
    
        // Find code examples
        const examples = await services.ragService.findCodeExamples(args.description, {
          language: args.language,
          limit: args.limit || 5,
        });
    
        if (examples.length === 0) {
          return {
            content: [
              {
                type: 'text',
                text: 'No code examples found matching your description.',
              },
            ],
          };
        }
    
        // Format examples
        const formattedExamples = examples.map((example, index) => ({
          rank: index + 1,
          title: example.title,
          language: example.language,
          code: example.code,
          explanation: example.explanation,
          sourceUrl: example.sourceUrl,
          relevance: Math.round(example.score * 100) / 100,
        }));
    
        // Format sources as a readable list at the bottom
        const sourcesSection = formattedExamples.length > 0
          ? '\n\n---\n**Sources:**\n' + formattedExamples.map((ex, i) =>
              `${i + 1}. [${ex.title}](${ex.sourceUrl}) (relevance: ${Math.round(ex.relevance * 100)}%)`
            ).join('\n') + '\n\n*Answered by HashPilot RAG System*'
          : '\n\n*Answered by HashPilot RAG System*';
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                description: args.description,
                examplesFound: examples.length,
                examples: formattedExamples,
              }, null, 2) + sourcesSection,
            },
          ],
        };
      } catch (error: any) {
        logger.error('docs_get_example failed', { error: error.message });
        return {
          content: [
            {
              type: 'text',
              text: `Error: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • The tool schema definition including name, detailed description, and inputSchema specifying parameters like description (required), language, limit, and complexity for validating tool inputs.
    export const docsGetExampleTool = {
      name: 'docs_get_example',
      description: 'Find working code examples and implementation patterns for ANY Hedera functionality. Search by feature description: account creation, token operations (create, mint, burn, transfer, freeze), HCS messaging (topic create, message submit), smart contract deployment, file service operations, key management, scheduled transactions, multi-signature workflows, and more. Retrieves annotated code snippets from official Hedera SDKs (JavaScript/TypeScript, Java, Python, Go, Rust) and Solidity smart contracts. Returns code with explanations, context, and source references. Use this when you need actual implementation code, not just conceptual explanations.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          description: {
            type: 'string',
            description: 'Description of the functionality you need code for. Be specific about the operation (e.g., "create fungible token with custom fees", "submit message to HCS topic", "deploy ERC-20 contract on Hedera")',
          },
          language: {
            type: 'string',
            enum: ['javascript', 'typescript', 'java', 'python', 'go', 'rust', 'solidity'],
            description: 'Preferred programming language for the code example',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of examples to return',
            minimum: 1,
            maximum: 10,
            default: 5,
          },
          complexity: {
            type: 'string',
            enum: ['simple', 'intermediate', 'advanced'],
            description: 'Desired complexity level of the code example',
          },
        },
        required: ['description'],
      },
    };
  • src/index.ts:625-626 (registration)
    The registration of the docs_get_example handler in the main MCP server switch statement, mapping the tool name to the imported docsGetExample function call.
    case 'docs_get_example':
      result = await docsGetExample(args as any);
  • Inline tool schema definition in the optimizedToolDefinitions array used for listing available tools in the MCP server.
        name: 'docs_get_example',
        description: `Find working code examples for Hedera functionality.
    
    SEARCHES: SDK examples, tutorials, implementation patterns
    RETURNS: Annotated code with explanations and source references
    LANGUAGES: JavaScript, TypeScript, Java, Python, Go, Rust, Solidity
    
    USE FOR: Getting implementation code, learning patterns, finding SDK usage.`,
        inputSchema: {
          type: 'object' as const,
          properties: {
            description: { type: 'string', description: 'What code you need' },
            language: {
              type: 'string',
              enum: ['javascript', 'typescript', 'java', 'python', 'go', 'rust', 'solidity'],
            },
            complexity: {
              type: 'string',
              enum: ['simple', 'intermediate', 'advanced'],
            },
            limit: { type: 'number', description: 'Max examples (default: 5)' },
          },
          required: ['description'],
        },
      },
  • src/index.ts:51-51 (registration)
    Import statement bringing the docsGetExample handler function into the main index file for use in tool registration.
    import { docsSearch, docsAsk, docsGetExample, codeGenerate } from './tools/rag.js';
Behavior3/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It describes what the tool returns ('Annotated code with explanations and source references') and what it searches, but lacks details on rate limits, authentication needs, error handling, or pagination behavior. It provides basic operational context but misses important behavioral traits.

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 well-structured with clear sections (SEARCHES, RETURNS, LANGUAGES, USE FOR), front-loaded with the core purpose, and every sentence adds value without redundancy. It's appropriately sized for a tool with 4 parameters and clear differentiation needs.

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?

Given the tool's moderate complexity (4 parameters, no output schema, no annotations), the description provides good context: clear purpose, usage guidelines, return format, and language support. However, it lacks details on behavioral aspects like error cases or performance characteristics that would be helpful for an agent.

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 50% (2 of 4 parameters have descriptions). The description adds value by listing supported languages (matching the 'language' enum) and implying the 'description' parameter's purpose through context, but doesn't explain 'complexity' or 'limit' beyond what the schema provides. It partially compensates for the coverage gap but not fully.

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 tool's purpose with specific verbs ('Find working code examples') and resources ('Hedera functionality'), and distinguishes it from siblings like docs_ask or docs_search by focusing on code examples rather than general documentation. It explicitly lists what it searches for (SDK examples, tutorials, implementation patterns).

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

Usage Guidelines5/5

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

The description provides explicit usage guidance with a 'USE FOR' section that lists specific scenarios (getting implementation code, learning patterns, finding SDK usage), helping differentiate it from alternatives like code_generate or general documentation tools. It clearly indicates when this tool is appropriate.

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

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/justmert/hashpilot'

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