Skip to main content
Glama
chainfetch

ChainFETCH MCP Server

Official
by chainfetch

search_smart_contracts_semantic

Find smart contracts by semantic meaning using AI-powered vector similarity matching on Ethereum blockchain data.

Instructions

Semantic search for smart contracts using AI-powered vector similarity matching

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe query to search for
limitNoThe number of results to return (default: 10)

Implementation Reference

  • Schema definition for the 'search_smart_contracts_semantic' tool, including input schema with query (required) and optional limit.
    {
      name: 'search_smart_contracts_semantic',
      description: 'Semantic search for smart contracts using AI-powered vector similarity matching',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'The query to search for',
          },
          limit: {
            type: 'integer',
            description: 'The number of results to return (default: 10)',
            default: 10,
          },
        },
        required: ['query'],
      },
    },
  • Handler for 'search_smart_contracts_semantic' tool: proxies the request to the ChainFetch API endpoint '/api/v1/ethereum/smart-contracts/semantic_search' using GET with provided arguments.
    case 'search_smart_contracts_semantic':
      return await this.makeRequest('/api/v1/ethereum/smart-contracts/semantic_search', 'GET', args, null, token);
  • Shared helper method 'makeRequest' used by all tools, including this one, to make authenticated API calls to ChainFetch service.
    async makeRequest(endpoint, method = 'GET', params = {}, body = null, token = null) {
      const chainfetchToken = token || process.env.CHAINFETCH_API_TOKEN;
      
      if (!chainfetchToken) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          'CHAINFETCH_API_TOKEN is required'
        );
      }
    
      const url = new URL(`${API_BASE_URL}${endpoint}`);
      
      // Add query parameters for GET requests
      if (method === 'GET' && Object.keys(params).length > 0) {
        Object.entries(params).forEach(([key, value]) => {
          if (value !== undefined && value !== null) {
            if (Array.isArray(value)) {
              value.forEach(v => url.searchParams.append(`${key}[]`, v));
            } else {
              url.searchParams.append(key, value.toString());
            }
          }
        });
      }
    
      const fetchOptions = {
        method,
        headers: {
          'Authorization': `Bearer ${chainfetchToken}`,
          'Content-Type': 'application/json',
        },
      };
    
      if (body && method !== 'GET') {
        fetchOptions.body = JSON.stringify(body);
      }
    
      const response = await fetch(url.toString(), fetchOptions);
      
      if (!response.ok) {
        const errorText = await response.text();
        throw new McpError(
          ErrorCode.InternalError,
          `API request failed: ${response.status} ${response.statusText} - ${errorText}`
        );
      }
    
      return await response.json();
    }
  • index.js:612-632 (registration)
    Registration of CallToolRequestSchema handler, which dispatches to handleToolCall based on tool name, enabling execution of 'search_smart_contracts_semantic'.
      this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
        const { name, arguments: args } = request.params;
    
        try {
          const result = await this.handleToolCall(name, args, this.currentToken);
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error) {
          throw new McpError(
            ErrorCode.InternalError,
            `Tool execution failed: ${error.message}`
          );
        }
      });
    }

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

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