# n8n-nodes-megasearch

[![npm version](https://img.shields.io/npm/v/n8n-nodes-megasearch.svg)](https://www.npmjs.com/package/n8n-nodes-megasearch)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

This is an n8n community node for [MegaSearch](https://megasearch.prodevs.in) - an AI-powered metasearch engine that queries multiple sources simultaneously and synthesizes comprehensive answers with citations.

[MegaSearch](https://megasearch.prodevs.in) | [n8n Community Nodes](https://docs.n8n.io/integrations/community-nodes/) | [API Documentation](https://megasearch.prodevs.in/docs)

## Features

- **Multi-Source Search**: Query 10+ search sources in parallel (web, academic, news, Reddit, YouTube, and more)
- **AI-Powered Synthesis**: Get comprehensive answers with proper citations, not just links
- **Iterative Refinement**: Up to 5 search iterations to find the perfect answer
- **n8n AI Agent Compatible**: Use as a tool in n8n AI workflows with `usableAsTool: true`
- **Simple API**: Just provide a query, get a complete answer

## Installation

### In n8n (Recommended)

1. Go to **Settings** > **Community Nodes**
2. Select **Install**
3. Enter `n8n-nodes-megasearch` and click **Install**

### Using npm

```bash
npm install n8n-nodes-megasearch
```

### Self-hosted n8n

Add the package to your n8n installation:

```bash
cd ~/.n8n
npm install n8n-nodes-megasearch
```

Then restart n8n.

## Credentials

To use this node, you need a MegaSearch API key:

1. **Create an account**: Visit [megasearch.prodevs.in](https://megasearch.prodevs.in) and sign in with Google
2. **Get your API key**: Go to **Dashboard** > **Tokens** and generate an API key
3. **Configure in n8n**:
   - Go to **Credentials** > **Add Credential** > **MegaSearch API**
   - Enter your **Base URL** (default: `https://megasearch.prodevs.in`)
   - Enter your **API Key**
   - Click **Save**

The credential will automatically validate by checking the `/health` endpoint.

## Node Operations

### Search

Execute an AI-powered search query across multiple sources.

**Parameters:**

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| Query | String | Yes | The search query (max 2000 characters) |

**Options:**

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| Include Full Content | Boolean | false | Include full extracted content from sources |
| Timeout (Seconds) | Number | 120 | Maximum time to wait (30-300 seconds) |

**Output:**

```json
{
  "query": "What are the latest advances in quantum computing?",
  "answer": "Recent advances in quantum computing include... [1] [2] [3]",
  "sources": [
    {
      "index": 1,
      "title": "IBM Unveils New Quantum Processor",
      "url": "https://example.com/article",
      "snippet": "IBM has announced..."
    }
  ],
  "sourceCount": 12,
  "usage": {
    "credits_used": 1,
    "credits_remaining": 99,
    "plan": "free"
  }
}
```

## Usage Examples

### Basic Search Workflow

1. Add a **Manual Trigger** node
2. Add a **MegaSearch** node
3. Configure the query: `What are the best practices for TypeScript in 2024?`
4. Execute the workflow

### Use with AI Agent

MegaSearch is designed to work as a tool in n8n AI workflows:

1. Add an **AI Agent** node
2. Add **MegaSearch** as a tool
3. The agent can now use MegaSearch to answer research questions

### Chain with Other Nodes

```
[HTTP Request] → [MegaSearch] → [Slack]
```

Get URLs from an API, research them with MegaSearch, and post summaries to Slack.

## Pricing

MegaSearch offers a free tier and paid plans:

| Plan | Credits/Month | Features |
|------|---------------|----------|
| Free | 25/day, 100/month | API + MCP access |
| Starter | 1,000/month | No daily cap, higher RPS |
| Pro | 5,000/month | Priority support |
| Scale | 20,000/month | Enterprise features |

Check [megasearch.prodevs.in](https://megasearch.prodevs.in/#pricing) for current pricing.

## Error Handling

The node handles common errors gracefully:

| Status Code | Error | Solution |
|-------------|-------|----------|
| 401 | Invalid API key | Check your credentials |
| 402 | Insufficient credits | Top up your account |
| 429 | Rate limit exceeded | Wait before retrying |
| 500 | Server error | Retry or contact support |

Enable **Continue On Fail** to handle errors in your workflow without stopping execution.

## Development

### Local Development

```bash
# Clone the repository
git clone https://github.com/ProDevs-Kol/n8n-nodes-megasearch.git
cd n8n-nodes-megasearch

# Install dependencies
npm install

# Start n8n with the node loaded
npm run dev
```

### Build

```bash
npm run build
```

### Lint

```bash
npm run lint
npm run lint:fix
```

## Resources

- [MegaSearch Website](https://megasearch.prodevs.in)
- [MegaSearch API Docs](https://megasearch.prodevs.in/docs)
- [n8n Community Nodes Documentation](https://docs.n8n.io/integrations/community-nodes/)
- [n8n Community Forum](https://community.n8n.io/)

## Support

- **Issues**: [GitHub Issues](https://github.com/ProDevs-Kol/n8n-nodes-megasearch/issues)
- **MegaSearch Support**: [contact@prodevs.in](mailto:contact@prodevs.in)

## License

[MIT](LICENSE.md)

---

Built with the "Fire Everything" philosophy by [ProDevs](https://prodevs.in)
