megasearch-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +139 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +279 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ProDevs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# MegaSearch MCP
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/megasearch-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A local MCP (Model Context Protocol) server that connects Claude Desktop to [MegaSearch](https://megasearch.prodevs.in) API using OAuth 2.0 client credentials.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **No timeout issues** - Direct stdio communication avoids HTTP/SSE transport timeouts
|
|
11
|
+
- **5-minute timeout** - Configurable timeout for comprehensive searches
|
|
12
|
+
- **OAuth 2.0** - Secure authentication with automatic token refresh
|
|
13
|
+
- **Simple setup** - Just set environment variables
|
|
14
|
+
|
|
15
|
+
## What is MegaSearch?
|
|
16
|
+
|
|
17
|
+
MegaSearch is an AI-powered metasearch engine that:
|
|
18
|
+
- Fires 10+ search engines in parallel
|
|
19
|
+
- Extracts and analyzes content from top results
|
|
20
|
+
- Synthesizes comprehensive answers with citations
|
|
21
|
+
- Iteratively refines queries until the answer is complete
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g megasearch-mcp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or use directly with npx (no installation needed):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx megasearch-mcp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### 1. Create OAuth Client
|
|
38
|
+
|
|
39
|
+
1. Go to [MegaSearch Dashboard](https://megasearch.prodevs.in/user/tokens)
|
|
40
|
+
2. Sign up / Log in with Google
|
|
41
|
+
3. Click **"+ Create OAuth Client"**
|
|
42
|
+
4. Copy the **Client ID** and **Client Secret** (shown only once!)
|
|
43
|
+
|
|
44
|
+
### 2. Configure Claude Desktop
|
|
45
|
+
|
|
46
|
+
Add to your Claude Desktop config:
|
|
47
|
+
|
|
48
|
+
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
49
|
+
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"megasearch": {
|
|
55
|
+
"command": "npx",
|
|
56
|
+
"args": ["megasearch-mcp"],
|
|
57
|
+
"env": {
|
|
58
|
+
"MEGASEARCH_CLIENT_ID": "mcp_your_client_id",
|
|
59
|
+
"MEGASEARCH_CLIENT_SECRET": "your_client_secret"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Restart Claude Desktop
|
|
67
|
+
|
|
68
|
+
After saving the config, restart Claude Desktop to load the MCP server.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
Once configured, ask Claude to search for anything:
|
|
73
|
+
|
|
74
|
+
> "Search for the latest developments in quantum computing"
|
|
75
|
+
|
|
76
|
+
> "What are the best practices for React performance optimization?"
|
|
77
|
+
|
|
78
|
+
> "Find recent news about AI regulations in the EU"
|
|
79
|
+
|
|
80
|
+
Claude will use MegaSearch to:
|
|
81
|
+
1. Fire multiple search engines in parallel
|
|
82
|
+
2. Extract content from top results
|
|
83
|
+
3. Analyze and synthesize a comprehensive answer
|
|
84
|
+
4. Return sources with citations
|
|
85
|
+
|
|
86
|
+
## Environment Variables
|
|
87
|
+
|
|
88
|
+
| Variable | Required | Default | Description |
|
|
89
|
+
|----------|----------|---------|-------------|
|
|
90
|
+
| `MEGASEARCH_CLIENT_ID` | Yes | - | OAuth Client ID (starts with `mcp_`) |
|
|
91
|
+
| `MEGASEARCH_CLIENT_SECRET` | Yes | - | OAuth Client Secret |
|
|
92
|
+
| `MEGASEARCH_BASE_URL` | No | `https://megasearch.prodevs.in` | MegaSearch API URL |
|
|
93
|
+
| `MEGASEARCH_TIMEOUT` | No | `300000` | Request timeout in ms (default: 5 min) |
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Clone the repository
|
|
99
|
+
git clone https://github.com/ProDevs-Kol/megasearch-mcp.git
|
|
100
|
+
cd megasearch-mcp
|
|
101
|
+
|
|
102
|
+
# Install dependencies
|
|
103
|
+
npm install
|
|
104
|
+
|
|
105
|
+
# Build
|
|
106
|
+
npm run build
|
|
107
|
+
|
|
108
|
+
# Run locally
|
|
109
|
+
MEGASEARCH_CLIENT_ID=xxx MEGASEARCH_CLIENT_SECRET=yyy npm start
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Troubleshooting
|
|
113
|
+
|
|
114
|
+
### "Missing MEGASEARCH_CLIENT_ID or MEGASEARCH_CLIENT_SECRET"
|
|
115
|
+
|
|
116
|
+
Make sure you've set both environment variables in your Claude Desktop config.
|
|
117
|
+
|
|
118
|
+
### "Failed to obtain access token"
|
|
119
|
+
|
|
120
|
+
- Check that your Client ID and Secret are correct
|
|
121
|
+
- Ensure your MegaSearch account is active
|
|
122
|
+
- Try creating a new OAuth client
|
|
123
|
+
|
|
124
|
+
### Search takes too long
|
|
125
|
+
|
|
126
|
+
MegaSearch performs comprehensive searches that may take 30-60 seconds. This is expected behavior. You can reduce the timeout with `MEGASEARCH_TIMEOUT` if needed.
|
|
127
|
+
|
|
128
|
+
## Related Projects
|
|
129
|
+
|
|
130
|
+
- [MegaSearch](https://megasearch.prodevs.in) - The AI-powered metasearch engine
|
|
131
|
+
- [n8n-nodes-megasearch](https://www.npmjs.com/package/n8n-nodes-megasearch) - n8n integration
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT - see [LICENSE](LICENSE) for details.
|
|
136
|
+
|
|
137
|
+
## Contributing
|
|
138
|
+
|
|
139
|
+
Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MegaSearch MCP Stdio Proxy
|
|
4
|
+
*
|
|
5
|
+
* A local MCP server that connects Claude Desktop to MegaSearch API
|
|
6
|
+
* using OAuth 2.0 client credentials for authentication.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* MEGASEARCH_CLIENT_ID=xxx MEGASEARCH_CLIENT_SECRET=yyy megasearch-mcp
|
|
10
|
+
*
|
|
11
|
+
* Or in Claude Desktop config:
|
|
12
|
+
* {
|
|
13
|
+
* "mcpServers": {
|
|
14
|
+
* "megasearch": {
|
|
15
|
+
* "command": "npx",
|
|
16
|
+
* "args": ["megasearch-mcp-proxy-stdio"],
|
|
17
|
+
* "env": {
|
|
18
|
+
* "MEGASEARCH_CLIENT_ID": "mcp_xxx",
|
|
19
|
+
* "MEGASEARCH_CLIENT_SECRET": "your_secret",
|
|
20
|
+
* "MEGASEARCH_BASE_URL": "https://megasearch.prodevs.in"
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* MegaSearch MCP Stdio Proxy
|
|
4
|
+
*
|
|
5
|
+
* A local MCP server that connects Claude Desktop to MegaSearch API
|
|
6
|
+
* using OAuth 2.0 client credentials for authentication.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* MEGASEARCH_CLIENT_ID=xxx MEGASEARCH_CLIENT_SECRET=yyy megasearch-mcp
|
|
10
|
+
*
|
|
11
|
+
* Or in Claude Desktop config:
|
|
12
|
+
* {
|
|
13
|
+
* "mcpServers": {
|
|
14
|
+
* "megasearch": {
|
|
15
|
+
* "command": "npx",
|
|
16
|
+
* "args": ["megasearch-mcp-proxy-stdio"],
|
|
17
|
+
* "env": {
|
|
18
|
+
* "MEGASEARCH_CLIENT_ID": "mcp_xxx",
|
|
19
|
+
* "MEGASEARCH_CLIENT_SECRET": "your_secret",
|
|
20
|
+
* "MEGASEARCH_BASE_URL": "https://megasearch.prodevs.in"
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
27
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
28
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
29
|
+
// Configuration from environment
|
|
30
|
+
const config = {
|
|
31
|
+
baseUrl: process.env.MEGASEARCH_BASE_URL || "https://megasearch.prodevs.in",
|
|
32
|
+
clientId: process.env.MEGASEARCH_CLIENT_ID || "",
|
|
33
|
+
clientSecret: process.env.MEGASEARCH_CLIENT_SECRET || "",
|
|
34
|
+
timeout: parseInt(process.env.MEGASEARCH_TIMEOUT || "300000", 10), // 5 minutes default
|
|
35
|
+
};
|
|
36
|
+
let tokenCache = null;
|
|
37
|
+
/**
|
|
38
|
+
* Get OAuth access token using client_credentials grant.
|
|
39
|
+
* Caches tokens and refreshes them when expired.
|
|
40
|
+
*/
|
|
41
|
+
async function getAccessToken() {
|
|
42
|
+
// Return cached token if still valid (with 60 second buffer)
|
|
43
|
+
if (tokenCache && Date.now() < tokenCache.expiresAt - 60000) {
|
|
44
|
+
return tokenCache.accessToken;
|
|
45
|
+
}
|
|
46
|
+
if (!config.clientId || !config.clientSecret) {
|
|
47
|
+
throw new Error("Missing MEGASEARCH_CLIENT_ID or MEGASEARCH_CLIENT_SECRET environment variables");
|
|
48
|
+
}
|
|
49
|
+
const tokenUrl = `${config.baseUrl}/api/v1/oauth/token`;
|
|
50
|
+
const response = await fetch(tokenUrl, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
54
|
+
},
|
|
55
|
+
body: new URLSearchParams({
|
|
56
|
+
grant_type: "client_credentials",
|
|
57
|
+
client_id: config.clientId,
|
|
58
|
+
client_secret: config.clientSecret,
|
|
59
|
+
}).toString(),
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const errorText = await response.text();
|
|
63
|
+
throw new Error(`Failed to obtain access token: ${response.status} ${errorText}`);
|
|
64
|
+
}
|
|
65
|
+
const data = (await response.json());
|
|
66
|
+
tokenCache = {
|
|
67
|
+
accessToken: data.access_token,
|
|
68
|
+
expiresAt: Date.now() + data.expires_in * 1000,
|
|
69
|
+
};
|
|
70
|
+
return tokenCache.accessToken;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Execute search via MegaSearch REST API
|
|
74
|
+
*/
|
|
75
|
+
async function executeSearch(query) {
|
|
76
|
+
const accessToken = await getAccessToken();
|
|
77
|
+
const controller = new AbortController();
|
|
78
|
+
const timeoutId = setTimeout(() => controller.abort(), config.timeout);
|
|
79
|
+
try {
|
|
80
|
+
const response = await fetch(`${config.baseUrl}/api/v1/search`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: {
|
|
83
|
+
"Content-Type": "application/json",
|
|
84
|
+
Authorization: `Bearer ${accessToken}`,
|
|
85
|
+
},
|
|
86
|
+
body: JSON.stringify({ query }),
|
|
87
|
+
signal: controller.signal,
|
|
88
|
+
});
|
|
89
|
+
clearTimeout(timeoutId);
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
const errorData = await response.json().catch(() => ({}));
|
|
92
|
+
const detail = errorData.detail ||
|
|
93
|
+
errorData.message ||
|
|
94
|
+
response.statusText;
|
|
95
|
+
if (response.status === 401) {
|
|
96
|
+
// Token might be invalid, clear cache and retry once
|
|
97
|
+
tokenCache = null;
|
|
98
|
+
throw new Error("Authentication failed. Please check your credentials.");
|
|
99
|
+
}
|
|
100
|
+
else if (response.status === 402) {
|
|
101
|
+
throw new Error("Insufficient credits. Please purchase more credits or upgrade your plan.");
|
|
102
|
+
}
|
|
103
|
+
else if (response.status === 429) {
|
|
104
|
+
throw new Error("Rate limit exceeded. Please wait a moment and try again.");
|
|
105
|
+
}
|
|
106
|
+
throw new Error(`Search failed: ${response.status} - ${detail}`);
|
|
107
|
+
}
|
|
108
|
+
return (await response.json());
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
clearTimeout(timeoutId);
|
|
112
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
113
|
+
throw new Error(`Search timed out after ${config.timeout / 1000} seconds`);
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Format search response for MCP
|
|
120
|
+
*/
|
|
121
|
+
function formatSearchResponse(result) {
|
|
122
|
+
const lines = [];
|
|
123
|
+
// Answer section
|
|
124
|
+
lines.push(`# Answer to: ${result.query}`);
|
|
125
|
+
lines.push("");
|
|
126
|
+
lines.push(result.answer);
|
|
127
|
+
lines.push("");
|
|
128
|
+
// Sources section
|
|
129
|
+
if (result.sources && result.sources.length > 0) {
|
|
130
|
+
lines.push("---");
|
|
131
|
+
lines.push("");
|
|
132
|
+
lines.push("## Sources");
|
|
133
|
+
lines.push("");
|
|
134
|
+
for (const source of result.sources) {
|
|
135
|
+
lines.push(`[${source.index}] **${source.title}**`);
|
|
136
|
+
lines.push(` URL: ${source.url}`);
|
|
137
|
+
if (source.provider) {
|
|
138
|
+
lines.push(` Provider: ${source.provider}`);
|
|
139
|
+
}
|
|
140
|
+
lines.push("");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Metadata section
|
|
144
|
+
if (result.metadata) {
|
|
145
|
+
lines.push("---");
|
|
146
|
+
lines.push("");
|
|
147
|
+
lines.push("## Search Metadata");
|
|
148
|
+
lines.push(`- Iterations: ${result.metadata.iterations}`);
|
|
149
|
+
lines.push(`- Providers: ${result.metadata.providers_used.join(", ")}`);
|
|
150
|
+
lines.push(`- Total time: ${result.metadata.total_time_ms}ms`);
|
|
151
|
+
lines.push(`- Used paid APIs: ${result.metadata.used_paid_apis}`);
|
|
152
|
+
if (result.metadata.gaps_identified &&
|
|
153
|
+
result.metadata.gaps_identified.length > 0) {
|
|
154
|
+
lines.push(`- Gaps identified: ${result.metadata.gaps_identified.join(", ")}`);
|
|
155
|
+
}
|
|
156
|
+
if (result.metadata.refined_queries &&
|
|
157
|
+
result.metadata.refined_queries.length > 0) {
|
|
158
|
+
lines.push(`- Query refinements: ${result.metadata.refined_queries.length}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Usage info
|
|
162
|
+
if (result.usage) {
|
|
163
|
+
lines.push("");
|
|
164
|
+
lines.push("## Usage");
|
|
165
|
+
lines.push(`- Credits charged: ${result.usage.credits_charged}`);
|
|
166
|
+
lines.push(`- Credits remaining: ${result.usage.credits_remaining}`);
|
|
167
|
+
lines.push(`- Plan: ${result.usage.plan}`);
|
|
168
|
+
}
|
|
169
|
+
return lines.join("\n");
|
|
170
|
+
}
|
|
171
|
+
// Define the search tool
|
|
172
|
+
const SEARCH_TOOL = {
|
|
173
|
+
name: "search",
|
|
174
|
+
description: "Search the web for any information using MegaSearch. " +
|
|
175
|
+
"Fires multiple search engines in parallel, extracts content, " +
|
|
176
|
+
"analyzes results, and synthesizes a comprehensive answer with citations. " +
|
|
177
|
+
"Just provide your question - the system handles everything else.",
|
|
178
|
+
inputSchema: {
|
|
179
|
+
type: "object",
|
|
180
|
+
properties: {
|
|
181
|
+
query: {
|
|
182
|
+
type: "string",
|
|
183
|
+
description: "Your search query - ask anything",
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
required: ["query"],
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
// Create MCP server
|
|
190
|
+
const server = new Server({
|
|
191
|
+
name: "megasearch",
|
|
192
|
+
version: "1.0.0",
|
|
193
|
+
}, {
|
|
194
|
+
capabilities: {
|
|
195
|
+
tools: {},
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
// Handle list tools request
|
|
199
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
200
|
+
return {
|
|
201
|
+
tools: [SEARCH_TOOL],
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
// Handle tool calls
|
|
205
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
206
|
+
const { name, arguments: args } = request.params;
|
|
207
|
+
if (name !== "search") {
|
|
208
|
+
return {
|
|
209
|
+
content: [
|
|
210
|
+
{
|
|
211
|
+
type: "text",
|
|
212
|
+
text: `Unknown tool: ${name}`,
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
isError: true,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const query = args?.query;
|
|
219
|
+
if (!query || typeof query !== "string" || query.trim().length === 0) {
|
|
220
|
+
return {
|
|
221
|
+
content: [
|
|
222
|
+
{
|
|
223
|
+
type: "text",
|
|
224
|
+
text: "Error: Query is required and must be a non-empty string",
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
isError: true,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const result = await executeSearch(query.trim());
|
|
232
|
+
const formatted = formatSearchResponse(result);
|
|
233
|
+
return {
|
|
234
|
+
content: [
|
|
235
|
+
{
|
|
236
|
+
type: "text",
|
|
237
|
+
text: formatted,
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
244
|
+
return {
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: "text",
|
|
248
|
+
text: `Search error: ${errorMessage}`,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
isError: true,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
// Start the server
|
|
256
|
+
async function main() {
|
|
257
|
+
// Validate configuration
|
|
258
|
+
if (!config.clientId || !config.clientSecret) {
|
|
259
|
+
console.error("Error: MEGASEARCH_CLIENT_ID and MEGASEARCH_CLIENT_SECRET environment variables are required");
|
|
260
|
+
console.error("");
|
|
261
|
+
console.error("Usage:");
|
|
262
|
+
console.error(" MEGASEARCH_CLIENT_ID=mcp_xxx MEGASEARCH_CLIENT_SECRET=yyy megasearch-mcp");
|
|
263
|
+
console.error("");
|
|
264
|
+
console.error("Or set in your Claude Desktop configuration.");
|
|
265
|
+
process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
const transport = new StdioServerTransport();
|
|
268
|
+
await server.connect(transport);
|
|
269
|
+
// Log to stderr (stdout is used for MCP protocol)
|
|
270
|
+
console.error(`MegaSearch MCP Proxy started`);
|
|
271
|
+
console.error(` Base URL: ${config.baseUrl}`);
|
|
272
|
+
console.error(` Client ID: ${config.clientId.substring(0, 10)}...`);
|
|
273
|
+
console.error(` Timeout: ${config.timeout / 1000}s`);
|
|
274
|
+
}
|
|
275
|
+
main().catch((error) => {
|
|
276
|
+
console.error("Fatal error:", error);
|
|
277
|
+
process.exit(1);
|
|
278
|
+
});
|
|
279
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,oCAAoC,CAAC;AAE5C,iCAAiC;AACjC,MAAM,MAAM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/C,OAAO,CAAC,KAAK,CAAC,gBAAgB,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IACrE,OAAO,CAAC,KAAK,CAAC,cAAc,MAAM,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC;AACxD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "megasearch-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MCP stdio proxy for MegaSearch - connects Claude Desktop to MegaSearch API using OAuth 2.0",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"megasearch-mcp": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"start": "node dist/index.js",
|
|
19
|
+
"dev": "ts-node src/index.ts"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"mcp",
|
|
23
|
+
"megasearch",
|
|
24
|
+
"claude",
|
|
25
|
+
"ai",
|
|
26
|
+
"search",
|
|
27
|
+
"model-context-protocol",
|
|
28
|
+
"anthropic",
|
|
29
|
+
"llm"
|
|
30
|
+
],
|
|
31
|
+
"author": {
|
|
32
|
+
"name": "ProDevs",
|
|
33
|
+
"url": "https://prodevs.in"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/ProDevs-Kol/megasearch-mcp.git"
|
|
39
|
+
},
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/ProDevs-Kol/megasearch-mcp/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/ProDevs-Kol/megasearch-mcp#readme",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^20.0.0",
|
|
49
|
+
"typescript": "^5.0.0",
|
|
50
|
+
"ts-node": "^10.9.0"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18.0.0"
|
|
54
|
+
}
|
|
55
|
+
}
|