Skip to main content
Glama
flyanima

Open Search MCP

by flyanima

search_stackoverflow

Find programming solutions by searching Stack Overflow questions and answers with filters for tags, sorting, and answered questions.

Instructions

Search Stack Overflow questions and answers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query for Stack Overflow (e.g., "javascript async await", "python pandas", "react hooks")
tagsNoProgramming language or technology tags (e.g., ["javascript", "react", "nodejs"])
sortNoSort order: relevance, votes, activity, creationrelevance
maxResultsNoMaximum number of questions to return (1-100)
answeredNoFilter for answered questions only

Implementation Reference

  • The execute function that implements the core logic of the search_stackoverflow tool. It takes query, tags, sort, maxResults, answered parameters and returns mock Stack Overflow search results including questions with titles, bodies, tags, authors, scores, etc.
    execute: async (args: any) => {
      const { query, tags = [], sort = 'relevance', maxResults = 10, answered = false } = args;
    
      try {
        // 模拟Stack Overflow搜索结果
        const mockQuestions = Array.from({ length: Math.min(maxResults, 10) }, (_, i) => ({
          questionId: 70000000 + i,
          title: `How to ${query} - Question ${i + 1}`,
          body: `I'm trying to implement ${query} in my project. Here's what I've tried so far...\n\n\`\`\`javascript\n// Sample code\nfunction example() {\n  // Implementation here\n}\n\`\`\`\n\nWhat's the best approach for this?`,
          tags: tags.length > 0 ? tags : ['javascript', 'programming', 'web-development'],
          author: {
            userId: 1000000 + i,
            displayName: `Developer${i + 1}`,
            reputation: Math.floor(Math.random() * 50000) + 100,
            profileImage: `https://www.gravatar.com/avatar/user${i}?s=64&d=identicon`
          },
          creationDate: new Date(Date.now() - Math.random() * 365 * 24 * 60 * 60 * 1000).toISOString(),
          lastActivityDate: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000).toISOString(),
          score: Math.floor(Math.random() * 100) - 10,
          viewCount: Math.floor(Math.random() * 10000) + 100,
          answerCount: answered ? Math.floor(Math.random() * 5) + 1 : Math.floor(Math.random() * 8),
          isAnswered: answered || Math.random() > 0.3,
          hasAcceptedAnswer: answered || Math.random() > 0.5,
          url: `https://stackoverflow.com/questions/${70000000 + i}`,
          excerpt: `Question about ${query}. Looking for best practices and efficient solutions...`
        }));
    
        return {
          success: true,
          data: {
            source: 'Stack Overflow',
            query,
            tags,
            sort,
            answered,
            totalResults: mockQuestions.length,
            questions: mockQuestions,
            timestamp: Date.now(),
            searchMetadata: {
              hasMore: maxResults >= 10,
              quotaRemaining: 9999,
              searchType: 'questions'
            }
          }
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Failed to search Stack Overflow'
        };
      }
    }
  • Input schema for the search_stackoverflow tool defining properties: query (required string), tags (array of strings), sort (enum: relevance,votes,activity,creation), maxResults (number 1-100), answered (boolean).
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: 'Search query for Stack Overflow (e.g., "javascript async await", "python pandas", "react hooks")'
        },
        tags: {
          type: 'array',
          items: { type: 'string' },
          description: 'Programming language or technology tags (e.g., ["javascript", "react", "nodejs"])'
        },
        sort: {
          type: 'string',
          description: 'Sort order: relevance, votes, activity, creation',
          default: 'relevance',
          enum: ['relevance', 'votes', 'activity', 'creation']
        },
        maxResults: {
          type: 'number',
          description: 'Maximum number of questions to return (1-100)',
          default: 10,
          minimum: 1,
          maximum: 100
        },
        answered: {
          type: 'boolean',
          description: 'Filter for answered questions only',
          default: false
        }
      },
      required: ['query']
    },
  • The registry.registerTool call that defines and registers the search_stackoverflow tool including its name, description, category 'tech', source 'Stack Overflow', inputSchema, and execute handler.
    registry.registerTool({
      name: 'search_stackoverflow',
      description: 'Search Stack Overflow questions and answers',
      category: 'tech',
      source: 'Stack Overflow',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search query for Stack Overflow (e.g., "javascript async await", "python pandas", "react hooks")'
          },
          tags: {
            type: 'array',
            items: { type: 'string' },
            description: 'Programming language or technology tags (e.g., ["javascript", "react", "nodejs"])'
          },
          sort: {
            type: 'string',
            description: 'Sort order: relevance, votes, activity, creation',
            default: 'relevance',
            enum: ['relevance', 'votes', 'activity', 'creation']
          },
          maxResults: {
            type: 'number',
            description: 'Maximum number of questions to return (1-100)',
            default: 10,
            minimum: 1,
            maximum: 100
          },
          answered: {
            type: 'boolean',
            description: 'Filter for answered questions only',
            default: false
          }
        },
        required: ['query']
      },
      execute: async (args: any) => {
        const { query, tags = [], sort = 'relevance', maxResults = 10, answered = false } = args;
    
        try {
          // 模拟Stack Overflow搜索结果
          const mockQuestions = Array.from({ length: Math.min(maxResults, 10) }, (_, i) => ({
            questionId: 70000000 + i,
            title: `How to ${query} - Question ${i + 1}`,
            body: `I'm trying to implement ${query} in my project. Here's what I've tried so far...\n\n\`\`\`javascript\n// Sample code\nfunction example() {\n  // Implementation here\n}\n\`\`\`\n\nWhat's the best approach for this?`,
            tags: tags.length > 0 ? tags : ['javascript', 'programming', 'web-development'],
            author: {
              userId: 1000000 + i,
              displayName: `Developer${i + 1}`,
              reputation: Math.floor(Math.random() * 50000) + 100,
              profileImage: `https://www.gravatar.com/avatar/user${i}?s=64&d=identicon`
            },
            creationDate: new Date(Date.now() - Math.random() * 365 * 24 * 60 * 60 * 1000).toISOString(),
            lastActivityDate: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000).toISOString(),
            score: Math.floor(Math.random() * 100) - 10,
            viewCount: Math.floor(Math.random() * 10000) + 100,
            answerCount: answered ? Math.floor(Math.random() * 5) + 1 : Math.floor(Math.random() * 8),
            isAnswered: answered || Math.random() > 0.3,
            hasAcceptedAnswer: answered || Math.random() > 0.5,
            url: `https://stackoverflow.com/questions/${70000000 + i}`,
            excerpt: `Question about ${query}. Looking for best practices and efficient solutions...`
          }));
    
          return {
            success: true,
            data: {
              source: 'Stack Overflow',
              query,
              tags,
              sort,
              answered,
              totalResults: mockQuestions.length,
              questions: mockQuestions,
              timestamp: Date.now(),
              searchMetadata: {
                hasMore: maxResults >= 10,
                quotaRemaining: 9999,
                searchType: 'questions'
              }
            }
          };
        } catch (error) {
          return {
            success: false,
            error: error instanceof Error ? error.message : 'Failed to search Stack Overflow'
          };
        }
      }
    });
  • src/index.ts:237-237 (registration)
    Invocation of registerStackOverflowTools(this.toolRegistry) during server startup in registerAllTools method, which registers the search_stackoverflow tool.
    registerStackOverflowTools(this.toolRegistry);      // 1 tool: search_stackoverflow
  • Additional input validation schema mapping for 'search_stackoverflow' using ToolSchemas.basicSearch in the validateToolInput method.
    'search_stackoverflow': ToolSchemas.basicSearch,
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. The description only states what the tool does ('Search Stack Overflow questions and answers') without mentioning behavioral traits such as rate limits, authentication needs, pagination, error handling, or what the output looks like (e.g., list of questions with titles, links, scores). For a search tool with no annotation coverage, this is a significant gap in transparency.

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, clear sentence ('Search Stack Overflow questions and answers') with zero waste. It's front-loaded with the core purpose, making it easy to parse. Every word earns its place, and there's no redundant or verbose language.

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 of a search tool with 5 parameters, no annotations, and no output schema, the description is incomplete. It lacks information on behavioral aspects (e.g., rate limits, output format), usage guidelines, and doesn't leverage the rich schema to add context. For a tool that interacts with an external API like Stack Overflow, more completeness is needed to help an agent use it effectively.

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%, meaning all parameters are well-documented in the input schema with descriptions, defaults, enums, and constraints. The description adds no additional parameter semantics beyond what the schema provides (e.g., it doesn't explain how 'query' and 'tags' interact or provide search syntax examples). Baseline 3 is appropriate when the schema does the heavy lifting, though the description doesn't compensate with extra insights.

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 'Search Stack Overflow questions and answers' clearly states the verb ('Search') and resource ('Stack Overflow questions and answers'), making the purpose immediately understandable. It distinguishes from siblings like 'stackoverflow_question_details' (which fetches details for a specific question) and 'stackoverflow_tags' (which lists tags), though it doesn't explicitly mention this differentiation. The description is specific but lacks explicit sibling comparison.

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 versus alternatives. It doesn't mention when to prefer this over other search tools (e.g., 'search_arxiv' for academic papers or 'search_pubmed' for medical research) or when to use sibling tools like 'stackoverflow_question_details' for detailed information on a specific question. Usage is implied by the name but not explicitly stated.

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/flyanima/open-search-mcp'

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