Skip to main content
Glama

MCP Wikipedia Server

by kaman05010
example_client.pyโ€ข4.01 kB
#!/usr/bin/env python3 """ MCP Wikipedia Server Example Client This script demonstrates how to interact with the Wikipedia MCP server. """ import asyncio import sys import json from pathlib import Path # Add the src directory to the path for imports sys.path.insert(0, str(Path(__file__).parent / "src")) async def demo_wikipedia_tools(): """Demonstrate the Wikipedia MCP server tools.""" print("๐Ÿ” MCP Wikipedia Server Demo") print("=" * 40) # This is a demonstration of how you would call the tools # In a real MCP client, you would use the MCP protocol print("\n1. ๐Ÿ“– Searching for 'Python programming language'...") search_example = { "tool": "fetch_wikipedia_info", "parameters": { "query": "Python programming language" } } print(f" Tool call: {json.dumps(search_example, indent=2)}") print(" Expected: Article title, summary, and URL") print("\n2. ๐Ÿ“‹ Getting sections for 'Artificial Intelligence'...") sections_example = { "tool": "list_wikipedia_sections", "parameters": { "topic": "Artificial Intelligence" } } print(f" Tool call: {json.dumps(sections_example, indent=2)}") print(" Expected: List of section titles") print("\n3. ๐Ÿ“„ Getting 'History' section content...") content_example = { "tool": "get_section_content", "parameters": { "topic": "Machine Learning", "section_title": "History" } } print(f" Tool call: {json.dumps(content_example, indent=2)}") print(" Expected: Section content text") print("\n" + "=" * 40) print("๐Ÿ“ To use these tools:") print(" 1. Start the server: python src/mcp_server/mcp_server.py") print(" 2. Connect via MCP protocol (see GUIDE.md)") print(" 3. Call tools using the JSON format shown above") print("\n๐Ÿ”— For a real MCP client implementation, see:") print(" - src/mcp_server/mcp_client.py") print(" - GUIDE.md (Integration examples)") async def test_direct_wikipedia(): """Test Wikipedia functionality directly (without MCP).""" print("\n๐Ÿงช Direct Wikipedia API Test") print("-" * 30) try: import wikipedia # Test basic search print("Searching for 'Python'...") page = wikipedia.page("Python (programming language)") print(f"โœ… Found: {page.title}") print(f" URL: {page.url}") print(f" Summary: {page.summary[:100]}...") # Test sections print(f"\n๐Ÿ“‹ Sections ({len(page.sections)} total):") for i, section in enumerate(page.sections[:5]): print(f" {i+1}. {section}") if len(page.sections) > 5: print(f" ... and {len(page.sections) - 5} more") # Test section content if page.sections: first_section = page.sections[0] content = page.section(first_section) if content: print(f"\n๐Ÿ“„ '{first_section}' section:") print(f" {content[:150]}...") print("\nโœ… Wikipedia API is working correctly!") except ImportError: print("โŒ Wikipedia package not installed") print(" Run: pip install wikipedia") except Exception as e: print(f"โŒ Error testing Wikipedia: {e}") def main(): """Main function.""" print("MCP Wikipedia Server - Example Client") print("=====================================") # Run the demo asyncio.run(demo_wikipedia_tools()) # Test Wikipedia directly asyncio.run(test_direct_wikipedia()) print("\n๐ŸŽฏ Next Steps:") print(" โ€ข Read GUIDE.md for detailed usage instructions") print(" โ€ข Check QUICK_REF.md for command reference") print(" โ€ข Start the server with: python src/mcp_server/mcp_server.py") if __name__ == "__main__": main()

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/kaman05010/MCPClientServer'

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