desearch-mcp-server 0.0.1 → 0.1.2
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/CHANGELOG.md +52 -0
- package/README.md +175 -4
- package/build/http.d.ts +32 -0
- package/build/http.d.ts.map +1 -0
- package/build/http.js +254 -0
- package/build/index.js +24 -118
- package/build/server.d.ts +103 -0
- package/build/server.d.ts.map +1 -0
- package/build/server.js +447 -0
- package/build/tool-sources.d.ts +33 -0
- package/build/tool-sources.d.ts.map +1 -0
- package/build/tool-sources.js +50 -0
- package/package.json +15 -5
package/build/index.js
CHANGED
|
@@ -1,124 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
version: "0.0.1",
|
|
9
|
-
});
|
|
10
|
-
const DESEARCH_API_KEY = process.env.DESEARCH_API_KEY;
|
|
11
|
-
if (!DESEARCH_API_KEY) {
|
|
12
|
-
throw new Error("DESEARCH_API_KEY environment variable is required");
|
|
3
|
+
import { startHttpServer } from "./http.js";
|
|
4
|
+
import { createDesearchMcpServer } from "./server.js";
|
|
5
|
+
function wantsHttp() {
|
|
6
|
+
return process.argv.includes("--http") || process.env.MCP_TRANSPORT === "http";
|
|
13
7
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"Youtube Search",
|
|
24
|
-
"Hacker News Search",
|
|
25
|
-
"Reddit Search",
|
|
26
|
-
]))
|
|
27
|
-
.optional()
|
|
28
|
-
.default(["Twitter Search", "Web Search"])
|
|
29
|
-
.describe("Tools to use for the search, example: ['Web Search', 'Twitter Search']"),
|
|
30
|
-
date_filter: z
|
|
31
|
-
.enum([
|
|
32
|
-
"PAST_24_HOURS",
|
|
33
|
-
"PAST_2_DAYS",
|
|
34
|
-
"PAST_WEEK",
|
|
35
|
-
"PAST_2_WEEKS",
|
|
36
|
-
"PAST_MONTH",
|
|
37
|
-
"PAST_2_MONTHS",
|
|
38
|
-
"PAST_YEAR",
|
|
39
|
-
"PAST_2_YEARS",
|
|
40
|
-
])
|
|
41
|
-
.optional()
|
|
42
|
-
.describe("Time range for the search, example: 'PAST_WEEK'"),
|
|
43
|
-
model: z
|
|
44
|
-
.enum(["NOVA", "ORBIT"])
|
|
45
|
-
.default("NOVA")
|
|
46
|
-
.describe("Model to use for the search, example: 'NOVA', Nova is 10s model, Orbit is 30s model"),
|
|
47
|
-
}, async ({ prompt, tools, date_filter, model }) => {
|
|
48
|
-
try {
|
|
49
|
-
const aiResult = await desearch.AISearch({
|
|
50
|
-
prompt,
|
|
51
|
-
tools,
|
|
52
|
-
date_filter,
|
|
53
|
-
model,
|
|
54
|
-
streaming: false,
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
content: [
|
|
58
|
-
{
|
|
59
|
-
type: "text",
|
|
60
|
-
text: JSON.stringify(aiResult, null, 2),
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
return {
|
|
67
|
-
content: [
|
|
68
|
-
{
|
|
69
|
-
type: "text",
|
|
70
|
-
text: `X Search error: ${error instanceof Error ? error.message : String(error)}`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
isError: true,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
server.tool("x-search", "Search the X (Twitter) using Desearch AI - performs real-time tweet search on X.", {
|
|
78
|
-
query: z
|
|
79
|
-
.string()
|
|
80
|
-
.describe("Twitter advanced search query, example: 'from:elonmusk since:2023-01-01 min_replies:10'"),
|
|
81
|
-
count: z
|
|
82
|
-
.number()
|
|
83
|
-
.optional()
|
|
84
|
-
.default(20)
|
|
85
|
-
.describe("Number of search results to return (default: 20), max is 100"),
|
|
86
|
-
}, async ({ query, count }) => {
|
|
87
|
-
try {
|
|
88
|
-
const twitterResult = await desearch.twitterSearch({
|
|
89
|
-
query,
|
|
90
|
-
sort: "Top",
|
|
91
|
-
count,
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
content: [
|
|
95
|
-
{
|
|
96
|
-
type: "text",
|
|
97
|
-
text: JSON.stringify(twitterResult, null, 2),
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
};
|
|
8
|
+
async function main() {
|
|
9
|
+
if (wantsHttp()) {
|
|
10
|
+
const port = Number(process.env.PORT ?? "3000");
|
|
11
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
12
|
+
throw new Error("PORT must be an integer between 0 and 65535");
|
|
13
|
+
}
|
|
14
|
+
const host = process.env.HOST ?? "0.0.0.0";
|
|
15
|
+
await startHttpServer({ port, host });
|
|
16
|
+
return;
|
|
101
17
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{
|
|
106
|
-
type: "text",
|
|
107
|
-
text: `X Search error: ${error instanceof Error ? error.message : String(error)}`,
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
isError: true,
|
|
111
|
-
};
|
|
18
|
+
const apiKey = process.env.DESEARCH_API_KEY;
|
|
19
|
+
if (!apiKey) {
|
|
20
|
+
throw new Error("DESEARCH_API_KEY environment variable is required");
|
|
112
21
|
}
|
|
22
|
+
const server = createDesearchMcpServer(apiKey);
|
|
23
|
+
const transport = new StdioServerTransport();
|
|
24
|
+
await server.connect(transport);
|
|
25
|
+
console.error("Desearch server is running...");
|
|
26
|
+
}
|
|
27
|
+
main().catch((error) => {
|
|
28
|
+
console.error(`Server error: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
|
+
process.exit(1);
|
|
113
30
|
});
|
|
114
|
-
(async () => {
|
|
115
|
-
try {
|
|
116
|
-
// Start receiving messages on stdin and sending messages on stdout
|
|
117
|
-
const transport = new StdioServerTransport();
|
|
118
|
-
await server.connect(transport);
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
console.log(`Server error: ${error instanceof Error ? error.message : String(error)}`);
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
})();
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
export declare const SERVER_NAME = "Desearch";
|
|
3
|
+
export declare const SERVER_VERSION = "0.1.2";
|
|
4
|
+
interface XSearchPayload {
|
|
5
|
+
query: string;
|
|
6
|
+
sort?: "Top" | "Latest";
|
|
7
|
+
count?: number;
|
|
8
|
+
user?: string;
|
|
9
|
+
start_date?: string;
|
|
10
|
+
end_date?: string;
|
|
11
|
+
lang?: string;
|
|
12
|
+
verified?: boolean;
|
|
13
|
+
blue_verified?: boolean;
|
|
14
|
+
is_quote?: boolean;
|
|
15
|
+
is_video?: boolean;
|
|
16
|
+
is_image?: boolean;
|
|
17
|
+
min_retweets?: number | string;
|
|
18
|
+
min_replies?: number | string;
|
|
19
|
+
min_likes?: number | string;
|
|
20
|
+
}
|
|
21
|
+
interface PageContentPayload {
|
|
22
|
+
url: string;
|
|
23
|
+
format?: "html" | "text";
|
|
24
|
+
js?: boolean;
|
|
25
|
+
wait?: number;
|
|
26
|
+
}
|
|
27
|
+
interface DesearchClient {
|
|
28
|
+
aiSearch(payload: Record<string, unknown>): Promise<unknown>;
|
|
29
|
+
xSearch(payload: XSearchPayload): Promise<unknown>;
|
|
30
|
+
webSearch(payload: {
|
|
31
|
+
query: string;
|
|
32
|
+
start?: number;
|
|
33
|
+
}): Promise<unknown>;
|
|
34
|
+
aiWebLinksSearch(payload: {
|
|
35
|
+
prompt: string;
|
|
36
|
+
tools: string[];
|
|
37
|
+
count?: number;
|
|
38
|
+
}): Promise<unknown>;
|
|
39
|
+
aiXLinksSearch(payload: {
|
|
40
|
+
prompt: string;
|
|
41
|
+
count?: number;
|
|
42
|
+
}): Promise<unknown>;
|
|
43
|
+
xPostsByUrls(payload: {
|
|
44
|
+
urls: string[];
|
|
45
|
+
}): Promise<unknown>;
|
|
46
|
+
xPostById(payload: {
|
|
47
|
+
id: string;
|
|
48
|
+
}): Promise<unknown>;
|
|
49
|
+
xPostsByUser(payload: {
|
|
50
|
+
user: string;
|
|
51
|
+
query?: string;
|
|
52
|
+
count?: number;
|
|
53
|
+
}): Promise<unknown>;
|
|
54
|
+
xPostRetweeters(payload: {
|
|
55
|
+
id: string;
|
|
56
|
+
cursor?: string;
|
|
57
|
+
}): Promise<unknown>;
|
|
58
|
+
xUserPosts(payload: {
|
|
59
|
+
username: string;
|
|
60
|
+
cursor?: string;
|
|
61
|
+
}): Promise<unknown>;
|
|
62
|
+
xUserReplies(payload: {
|
|
63
|
+
user: string;
|
|
64
|
+
count?: number;
|
|
65
|
+
query?: string;
|
|
66
|
+
}): Promise<unknown>;
|
|
67
|
+
xPostReplies(payload: {
|
|
68
|
+
post_id: string;
|
|
69
|
+
count?: number;
|
|
70
|
+
query?: string;
|
|
71
|
+
}): Promise<unknown>;
|
|
72
|
+
xTrends(payload: {
|
|
73
|
+
woeid: number;
|
|
74
|
+
count?: number;
|
|
75
|
+
}): Promise<unknown>;
|
|
76
|
+
extract(payload: PageContentPayload): Promise<unknown>;
|
|
77
|
+
webCrawl(payload: PageContentPayload): Promise<unknown>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Payload note when a link search body has no link list.
|
|
81
|
+
* Does not name web vs AI search, and does not say the query had "results".
|
|
82
|
+
* A missing list (the cost-only API bug) and an empty list are the same note:
|
|
83
|
+
* this response body does not contain links.
|
|
84
|
+
*/
|
|
85
|
+
export declare const NO_LINKS_MESSAGE = "no links in response";
|
|
86
|
+
/**
|
|
87
|
+
* Pass a link payload through when it contains at least one link.
|
|
88
|
+
* A cost-only body (billing fields, no link list) and an empty link list
|
|
89
|
+
* both get `message: "no links in response"` plus the original fields,
|
|
90
|
+
* including billing. The note does not claim the search returned results
|
|
91
|
+
* and does not name which search tool produced the body.
|
|
92
|
+
*/
|
|
93
|
+
export declare function presentSearchBody(value: unknown): unknown;
|
|
94
|
+
/**
|
|
95
|
+
* One MCP server bound to a single Desearch API key.
|
|
96
|
+
* Stdio uses the process env key. Remote HTTP builds a new server per request
|
|
97
|
+
* so each caller spends their own key.
|
|
98
|
+
* `client` is a test seam. Production callers omit it and the server builds
|
|
99
|
+
* a desearch-js client from `apiKey`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createDesearchMcpServer(apiKey: string, client?: DesearchClient): McpServer;
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,UAAU,cAAc;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC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