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,

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