A Node.js MCP (Model Context Protocol) server wrapper that enables AI systems to interactively query news sources through an existing Python news search tool.
This wrapper exposes the Python CLI News Search tool as an MCP server endpoint, allowing AI assistants to search across 1200+ news sources worldwide using the standard MCP protocol.
| Variable | Description | Example | Default |
|---|---|---|---|
NEWS_SEARCH_PYTHON_PATH |
Absolute path to the Python script | /home/user/travis-news-search/cli.py |
❌ Required |
PYTHON_EXECUTABLE |
Python executable command | python3 or python |
python3 |
| Variable | Description | Example | Default |
|---|---|---|---|
NEWS_SEARCH_TIMEOUT |
Search timeout in milliseconds | 30000 |
30000 |
NEWS_SEARCH_MAX_PROCESSES |
Maximum concurrent Python processes | 5 |
3 |
MCP_SERVER_PORT |
MCP server port (if using HTTP transport) | 3001 |
No default (uses stdio) |
LOG_LEVEL |
Logging verbosity | debug, info, warn, error |
info |
set NEWS_SEARCH_PYTHON_PATH="C:\path\to\travis-news-search\cli.py"
set PYTHON_EXECUTABLE="python"
set NEWS_SEARCH_TIMEOUT=30000$env:NEWS_SEARCH_PYTHON_PATH="C:\path\to\travis-news-search\cli.py"
$env:PYTHON_EXECUTABLE="python"
$env:NEWS_SEARCH_TIMEOUT=30000export NEWS_SEARCH_PYTHON_PATH="/home/user/travis-news-search/cli.py"
export PYTHON_EXECUTABLE="python3"
export NEWS_SEARCH_TIMEOUT=30000node src/index.jsAdd this to your Claude Desktop configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
Mac: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"news-search": {
"command": "node",
"args": ["C:\\MPC_Server_Share\\mcp-news-wrapper\\src\\index.js"],
"env": {
"NEWS_SEARCH_PYTHON_PATH": "C:\\path\\to\\travis-news-search\\cli.py",
"PYTHON_EXECUTABLE": "python",
"NEWS_SEARCH_TIMEOUT": "30000"
}
}
}
}Once configured, AI assistants can use the tool like this:
User: Search for news about artificial intelligence
AI: I'll search for news about artificial intelligence.
[AI internally calls: news_search(query="artificial intelligence")]
AI Assistant → MCP Protocol → Node.js Wrapper → Python CLI → News APIs
- AI Request: AI assistant calls the
news_searchtool via MCP - Node.js Wrapper: Receives MCP request, validates parameters
- Python Process: Spawns child process executing the Python script
- News Search: Python script queries news APIs/sources
- Response Processing: Parses JSON output, formats for MCP
- Return Results: Sends structured data back to AI assistant
- Input: Search query string, optional maxResults count
- Output: Structured JSON with news articles (title, content, source, URL, dates)
- Error Handling: Graceful error messages with detailed logging
Description: Searches news across 1200 sources worldwide. Use clear and unique search terms. The output is a JSON string containing titles, descriptions, content, authors, dates, and URLs.
Input Schema:
{
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query for news articles"
},
"maxResults": {
"type": "number",
"description": "Maximum number of results to return"
}
},
"required": ["query"]
}Output Schema:
{
"success": true,
"query": "artificial intelligence",
"count": 10,
"results": [
{
"title": "AI Breakthrough in Medical Diagnosis",
"content": "Recent advances in artificial intelligence...",
"source": "Tech News Daily",
"url": "https://example.com/ai-breakthrough",
"publishedAt": "2024-01-15T10:30:00Z",
"author": "John Doe"
}
]
}- Node.js: 14.0 or higher
- Python: 3.8 or higher
- Python Script: Existing CLI news search tool at the specified path
The Python script must accept command-line arguments:
- Positionitional or
--queryparameter for search terms - Optional
--max-resultsparameter for result limiting - Output structured JSON data to stdout
- Return exit code 0 for success, non-zero for errors
The Node.js wrapper requires:
@modelcontextprotocol/sdk: MCP protocol implementation- Node.js built-in modules:
child_process,path,fs
Environment Variable: NEWS_SEARCH_PYTHON_PATH
Solution: Ensure the path is absolute and the file exists
# Test the path
ls -la "$NEWS_SEARCH_PYTHON_PATH"Environment Variable: PYTHON_EXECUTABLE
Solution: Set to correct Python command (python, python3, full path)
Solutions:
- Make Python script executable:
chmod +x cli.py - Check file permissions:
ls -la cli.py - Run as user with appropriate permissions
Environment Variable: NEWS_SEARCH_TIMEOUT
Solution: Increase timeout value (default: 30 seconds)
Cause: Python script output is not valid JSON Solutions:
- Test Python script directly:
python3 cli.py --query "test" - Check for Python runtime errors in stderr
- Verify script outputs clean JSON to stdout
export LOG_LEVEL=debug
node src/index.js"$PYTHON_EXECUTABLE" "$NEWS_SEARCH_PYTHON_PATH" --query "test search" --max-results 5# Linux/Mac
env | grep NEWS_SEARCH
# Windows
echo %NEWS_SEARCH_PYTHON_PATH%
echo %PYTHON_EXECUTABLE%- Timeouts: Adjust
NEWS_SEARCH_TIMEOUTbased on typical search duration - Concurrent Processes: Use
NEWS_SEARCH_MAX_PROCESSESto limit resource usage - Python Cold Start: Consider process pooling for frequent use
- Memory: ~50MB base + Python process overhead
- CPU: Minimal during idle, spike during searches
- Network: Dependent on news API usage by Python script
- Search queries are sanitized but passed to Python script
- File paths are validated before execution
- Process timeouts prevent hanging
- Keep Python script path in secure directory
- Use absolute paths to prevent path traversal
- Set appropriate file permissions
- All network requests go through Python script
- Configure SSL certificates if needed for news APIs
- Consider rate limiting for high-usage scenarios
mcp-news-wrapper/
├── package.json # Node.js dependencies and scripts
├── README.md # This documentation
└── src/
├── config.js # Environment variable configuration
├── index.js # Main MCP server entry point
├── python-wrapper.js # Python process management
└── tools/
└── news-search.js # MCP tool definition
- MCP tools go in
src/tools/ - Configuration changes in
src/config.js - Core server logic in
src/index.js
# Manually test the python wrapper
node -e "
const wrapper = require('./src/python-wrapper.js');
const PythonWrapper = require('./src/python-wrapper.js');
const w = new PythonWrapper();
w.searchNews('test', 5).then(console.log).catch(console.error);
"This wrapper is designed to work with existing Python news search tools. Ensure you have proper licenses for any news APIs or content accessed through the underlying Python script.
For issues with:
- Python Script: Contact the original script author
- MCP Protocol: Check Model Context Protocol documentation
- Node.js Wrapper: Verify environment variables and Python script compatibility