|
|
|
""" |
|
MCP Client Demo for Stack Overflow Server |
|
Demonstrates how to interact with the Stack Overflow MCP server programmatically. |
|
""" |
|
|
|
import asyncio |
|
import json |
|
from typing import Dict, Any |
|
|
|
|
|
|
|
|
|
async def demo_mcp_calls(): |
|
""" |
|
Demonstrate various MCP calls to the Stack Overflow server. |
|
This simulates what an AI assistant like Claude would do. |
|
""" |
|
|
|
print("π€ Stack Overflow MCP Server Demo") |
|
print("=" * 50) |
|
|
|
|
|
print("\n1οΈβ£ GENERAL SEARCH DEMO") |
|
print("Query: 'Django pagination best practices'") |
|
print("Tags: ['python', 'django']") |
|
print("Expected: High-quality Django pagination solutions") |
|
|
|
|
|
print("\n2οΈβ£ ERROR SEARCH DEMO") |
|
print("Error: 'TypeError: NoneType object has no attribute'") |
|
print("Language: Python") |
|
print("Expected: Common solutions for NoneType errors") |
|
|
|
|
|
print("\n3οΈβ£ QUESTION RETRIEVAL DEMO") |
|
print("Question ID: 11227809") |
|
print("Expected: Famous 'Why is processing a sorted array faster?' question") |
|
|
|
|
|
print("\n4οΈβ£ STACK TRACE ANALYSIS DEMO") |
|
print("Stack Trace: 'ReferenceError: useState is not defined'") |
|
print("Language: JavaScript") |
|
print("Expected: React hooks solutions") |
|
|
|
|
|
print("\n5οΈβ£ ADVANCED SEARCH DEMO") |
|
print("Query: 'memory optimization'") |
|
print("Tags: ['c++', 'performance']") |
|
print("Min Score: 50") |
|
print("Expected: High-quality C++ performance answers") |
|
|
|
print("\n" + "=" * 50) |
|
print("π― All demos completed!") |
|
print("π‘ These are the types of searches our MCP server can handle") |
|
print("π Try them in the web interface or via MCP client!") |
|
|
|
def demo_gradio_api_calls(): |
|
""" |
|
Demonstrate how the Gradio API exposes the MCP functionality. |
|
""" |
|
|
|
print("\nπ¨ GRADIO API INTEGRATION") |
|
print("=" * 50) |
|
|
|
|
|
api_endpoints = { |
|
"search_by_query_sync": { |
|
"description": "General Stack Overflow search", |
|
"inputs": ["query", "tags", "min_score", "has_accepted_answer", "limit", "response_format"], |
|
"example": { |
|
"query": "Django pagination best practices", |
|
"tags": "python,django", |
|
"min_score": 5, |
|
"has_accepted_answer": True, |
|
"limit": 5, |
|
"response_format": "markdown" |
|
} |
|
}, |
|
"search_by_error_sync": { |
|
"description": "Error-specific search", |
|
"inputs": ["error_message", "language", "technologies", "min_score", "has_accepted_answer", "limit", "response_format"], |
|
"example": { |
|
"error_message": "TypeError: 'NoneType' object has no attribute", |
|
"language": "python", |
|
"technologies": "flask,sqlalchemy", |
|
"min_score": 0, |
|
"has_accepted_answer": True, |
|
"limit": 5, |
|
"response_format": "markdown" |
|
} |
|
}, |
|
"get_question_sync": { |
|
"description": "Get specific question by ID", |
|
"inputs": ["question_id", "include_comments", "response_format"], |
|
"example": { |
|
"question_id": "11227809", |
|
"include_comments": True, |
|
"response_format": "markdown" |
|
} |
|
}, |
|
"analyze_stack_trace_sync": { |
|
"description": "Analyze stack traces", |
|
"inputs": ["stack_trace", "language", "min_score", "has_accepted_answer", "limit", "response_format"], |
|
"example": { |
|
"stack_trace": "ReferenceError: useState is not defined\n at Component.render", |
|
"language": "javascript", |
|
"min_score": 5, |
|
"has_accepted_answer": True, |
|
"limit": 3, |
|
"response_format": "markdown" |
|
} |
|
}, |
|
"advanced_search_sync": { |
|
"description": "Advanced search with comprehensive filters", |
|
"inputs": ["query", "tags", "excluded_tags", "min_score", "title", "body", "min_answers", "has_accepted_answer", "min_views", "sort_by", "limit", "response_format"], |
|
"example": { |
|
"query": "memory optimization", |
|
"tags": "c++,performance", |
|
"excluded_tags": "beginner", |
|
"min_score": 50, |
|
"title": "", |
|
"body": "", |
|
"min_answers": 1, |
|
"has_accepted_answer": False, |
|
"min_views": 1000, |
|
"sort_by": "votes", |
|
"limit": 5, |
|
"response_format": "markdown" |
|
} |
|
} |
|
} |
|
|
|
for endpoint, info in api_endpoints.items(): |
|
print(f"\nπ§ {endpoint}") |
|
print(f" π {info['description']}") |
|
print(f" π Example:") |
|
for key, value in info['example'].items(): |
|
print(f" {key}: {value}") |
|
|
|
def demo_mcp_integration(): |
|
""" |
|
Show how to integrate with MCP clients like Claude Desktop. |
|
""" |
|
|
|
print("\nπ MCP CLIENT INTEGRATION") |
|
print("=" * 50) |
|
{ |
|
|
|
} |
|
|
|
claude_config = { |
|
"mcpServers": { |
|
"stackoverflow": { |
|
"command": "npx", |
|
"args": [ |
|
"mcp-remote", |
|
"https://c44b366466c774a9d5.gradio.live/gradio_api/mcp/sse" |
|
] |
|
} |
|
} |
|
} |
|
|
|
print("π» Claude Desktop Configuration:") |
|
print(json.dumps(claude_config, indent=2)) |
|
|
|
print("\nπ€ Example AI Assistant Prompts:") |
|
prompts = [ |
|
"Search Stack Overflow for Django pagination best practices", |
|
"Find solutions for the error 'TypeError: NoneType object has no attribute'", |
|
"Get Stack Overflow question 11227809", |
|
"Analyze this JavaScript error: ReferenceError: useState is not defined", |
|
"Find high-scored C++ memory optimization questions" |
|
] |
|
|
|
for i, prompt in enumerate(prompts, 1): |
|
print(f" {i}. {prompt}") |
|
|
|
if __name__ == "__main__": |
|
print("π Starting Stack Overflow MCP Server Demo...") |
|
|
|
|
|
asyncio.run(demo_mcp_calls()) |
|
|
|
|
|
demo_gradio_api_calls() |
|
|
|
|
|
demo_mcp_integration() |
|
|
|
print("\nπ― Demo completed! Visit the web interface to try it live:") |
|
print("π https://c44b366466c774a9d5.gradio.live") |
|
print("π MCP Endpoint: https://c44b366466c774a9d5.gradio.live/gradio_api/mcp/sse") |
|
|