Skip to main content
Glama
nahmanmate

Code Research MCP Server

by nahmanmate

search_stackoverflow

Search Stack Overflow for programming questions and answers to find code examples and solutions. Input a query to retrieve relevant results.

Instructions

Search Stack Overflow for programming questions and answers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
limitNoMaximum number of results (default: 5)

Implementation Reference

  • The core handler function that implements the search_stackoverflow tool logic: queries Stack Overflow API, extracts and formats results using Cheerio, applies caching, and handles errors.
    private async searchStackOverflow(query: string, limit: number = 5): Promise<string> {
      const cacheKey = `stackoverflow:${query}:${limit}`;
      const cached = cache.get<string>(cacheKey);
      if (cached) return cached;
    
      try {
        const response = await this.axiosInstance.get(
          `https://api.stackexchange.com/2.3/search/advanced`,
          {
            params: {
              q: query,
              site: 'stackoverflow',
              pagesize: limit,
              order: 'desc',
              sort: 'votes',
              filter: 'withbody'
            }
          }
        );
    
        const results = response.data.items.map((item: any) => {
          const $ = cheerio.load(item.body);
          return {
            title: item.title,
            link: item.link,
            score: item.score,
            answer_count: item.answer_count,
            excerpt: $.text().substring(0, 200) + '...'
          };
        });
    
        const formatted = results.map((r: any, i: number) => 
          `${i + 1}. ${r.title}\n   Score: ${r.score} | Answers: ${r.answer_count}\n   ${r.link}\n   ${r.excerpt}\n`
        ).join('\n');
    
        cache.set(cacheKey, formatted);
        return formatted;
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Stack Overflow API error: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • Input schema for the search_stackoverflow tool, defining query (required string) and optional limit (number 1-10).
    inputSchema: {
      type: 'object',
      properties: {
        query: {
          type: 'string',
          description: 'Search query'
        },
        limit: {
          type: 'number',
          description: 'Maximum number of results (default: 5)',
          minimum: 1,
          maximum: 10
        }
      },
      required: ['query']
    }
  • src/index.ts:321-339 (registration)
    Registration of the search_stackoverflow tool in the ListTools response, including name, description, and input schema.
      name: 'search_stackoverflow',
      description: 'Search Stack Overflow for programming questions and answers',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Search query'
          },
          limit: {
            type: 'number',
            description: 'Maximum number of results (default: 5)',
            minimum: 1,
            maximum: 10
          }
        },
        required: ['query']
      }
    },
  • Dispatch handler in CallToolRequestSchema that extracts arguments, calls the searchStackOverflow function, and formats the MCP response.
    case 'search_stackoverflow': {
      const { query, limit } = request.params.arguments as { query: string; limit?: number };
      const results = await this.searchStackOverflow(query, limit);
      return {
        content: [
          {
            type: 'text',
            text: results
          }
        ]
      };
    }
Behavior2/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 states the basic function but doesn't reveal important traits like whether this is a read-only operation, rate limits, authentication requirements, pagination behavior, or what format results return. For a search tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 states the core function without unnecessary words. It's appropriately sized for a simple search tool and front-loads the essential information, making it easy for an agent to parse quickly.

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 no annotations and no output schema, the description should provide more context about behavioral aspects and result format. While the purpose is clear, important details like whether this is a safe read operation, what the results look like, or any limitations are missing, making it incomplete for effective tool selection and invocation.

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%, so the schema already fully documents both parameters (query and limit). The description doesn't add any parameter-specific information beyond what's in the schema, such as query syntax examples or result format details. The baseline score of 3 reflects adequate but minimal value addition.

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 action ('Search') and target resource ('Stack Overflow for programming questions and answers'), making the purpose immediately understandable. However, it doesn't specifically differentiate from sibling tools like search_all or search_github, which likely search different platforms for similar content.

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 like search_all (which might include Stack Overflow) or other platform-specific search tools. There's no mention of use cases, prerequisites, or exclusions that would help an agent choose appropriately among the available search options.

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/nahmanmate/code-research-mcp-server'

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