Skip to main content
Glama
rayss868

Web-curl MCP Server

smart_command

Execute web commands by automatically fetching content from detected links or searching for detected queries to retrieve information from web pages and APIs.

Instructions

Free-form command: automatically fetch if a link is detected, automatically search if a search query is detected.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesFree-form user instruction

Implementation Reference

  • Executes the smart_command tool: parses the command string, detects URLs and fetch keywords to invoke fetchWebpage, otherwise performs Google Custom Search.
    } else if (toolName === 'smart_command') {
      // Smart command: advanced language detection, translation, and query enrichment
      const { command } = args as { command: string };
      const urlRegex = /(https?:\/\/[^\s]+)/gi;
      const fetchRegex = /\b(open|fetch|scrape|show|display|visit|go to)\b/i;
    
      const urlMatch = command.match(urlRegex);
    
      if (fetchRegex.test(command) && urlMatch) {
        // This is a fetch command
        try {
          const result = await this.fetchWebpage(urlMatch[0], {
            blockResources: false, // Force blockResources to be false
            timeout: 60000,
            maxLength: 4000,
            startIndex: 0,
            maxPages: 1,
          });
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error: any) {
          return { content: [{ type: 'text', text: 'Gagal fetch: ' + error.message }], isError: true };
        }
      } else {
        // Otherwise, this is a search command
        const apiKey = process.env.APIKEY_GOOGLE_SEARCH;
        const cx = process.env.CX_GOOGLE_SEARCH;
        if (!apiKey || !cx) {
          return { content: [{ type: 'text', text: 'Google Search API key and cx not set. Please set APIKEY_GOOGLE_SEARCH and CX_GOOGLE_SEARCH in environment variable.' }], isError: true };
        }
        const url = new URL('https://www.googleapis.com/customsearch/v1');
        url.searchParams.set('key', apiKey);
        url.searchParams.set('cx', cx);
        url.searchParams.set('q', command);
        try {
          const controller = new AbortController();
          const timeoutId = setTimeout(() => controller.abort(), 20000); // Apply timeout manually
    
          const response = await fetch(url.toString(), {
            method: 'GET',
            headers: {
              'Content-Type': 'application/json'
            },
            signal: controller.signal // Use abort signal for timeout
          });
          clearTimeout(timeoutId);
    
          if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
          }
    
          const data = await response.json(); // Parse JSON directly
    
          let formatted;
          if (data && Array.isArray(data.items)) {
            formatted = data.items.map((item: any) => ({
              title: item.title,
              link: item.link,
              snippet: item.snippet,
            }));
          } else {
            formatted = data; // Fallback to full data if items not found
          }
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(formatted, null, 2),
              },
            ],
          };
        } catch (error: any) {
          console.error('Error during Google Search:', error);
          return { content: [{ type: 'text', text: 'Error during Google Search: ' + error.message }], isError: true };
        }
      }
  • src/index.ts:236-251 (registration)
    Registers the smart_command tool in the list of available tools, including its description and input schema requiring a 'command' string.
    {
      name: 'smart_command',
      description: 'Free-form command: automatically fetch if a link is detected, automatically search if a search query is detected.',
      inputSchema: {
        type: 'object',
        properties: {
          command: {
            type: 'string',
            description: 'Free-form user instruction'
          }
        },
        required: ['command'],
        additionalProperties: false,
        description: 'Free-form command: auto fetch if link detected, auto search if query. Debug option for verbose output/logging.'
      }
    },
  • Defines the input schema for smart_command: an object with a required 'command' string property.
    inputSchema: {
      type: 'object',
      properties: {
        command: {
          type: 'string',
          description: 'Free-form user instruction'
        }
      },
      required: ['command'],
      additionalProperties: false,
      description: 'Free-form command: auto fetch if link detected, auto search if query. Debug option for verbose output/logging.'

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/rayss868/MCP-Web-Curl'

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