@he110/deepseek-mcp 0.0.0-stage → 0.1.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/README.md CHANGED
@@ -1,3 +1,121 @@
1
- # Temporary Holding Version
1
+ # DeepSeek Tools MCP
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 基于 DeepSeek 官方 Search / Fetch API 的本地 MCP 服务。API 与 MCP 工具一一对应,不经过第三方搜索服务,也不需要额外调用模型。
4
+
5
+ ## 为什么选 MCP,而不是只做 Skill
6
+
7
+ - **MCP 负责能力**:封装鉴权、参数校验、超时重试和结构化响应,让支持 MCP 的客户端直接调用。
8
+ - **Skill 负责策略**:如果后续需要固定的调研流程、来源筛选规则或报告格式,再加一个 Skill 指导模型使用这些工具即可。
9
+ - 两者不是互斥关系;对于纯 API 封装,先实现 MCP 更直接,也更容易测试和复用。
10
+
11
+ ## 已提供工具
12
+
13
+ | MCP 工具 | 官方接口 | 用途 |
14
+ | --- | --- | --- |
15
+ | `deepseek_search` | `POST https://api.deepseek.com/v1/tools/search` | 网页搜索,返回排序结果、摘要、来源与权威性信息 |
16
+ | `deepseek_fetch` | `POST https://api.deepseek.com/v1/tools/fetch` | 抓取单个网页,返回标题和 Markdown 正文 |
17
+
18
+ Search 的 `query` 支持官方操作符:`site:`、`-site:`、`lang:`、`after:`、`before:`、精确短语和排除词。默认不返回正文;确有需要时再设置 `need_content: true`,避免产生过大的上下文。
19
+
20
+ ## 环境与安装
21
+
22
+ 要求 Node.js 20 或更高版本,并准备 DeepSeek 开放平台 API Key。公开发布的 npm 包名为 `@he110/deepseek-mcp`,CLI 名称为 `deepseek-mcp`。
23
+
24
+ ### 使用 npm 包
25
+
26
+ ```bash
27
+ export DEEPSEEK_API_KEY="你的 API Key"
28
+ npx -y @he110/deepseek-mcp
29
+ ```
30
+
31
+ ### 从源码开发
32
+
33
+ ```bash
34
+ npm install
35
+ npm run build
36
+ export DEEPSEEK_API_KEY="你的 API Key"
37
+ npm start
38
+ ```
39
+
40
+ 服务使用 stdio 传输,正常情况下应交由 MCP 客户端启动,而不是长期手动运行。日志只写 stderr,不会污染 MCP 的 stdout 协议流。
41
+
42
+ ## MCP 客户端配置
43
+
44
+ 使用已发布的 npm 包时,可采用以下配置。不要提交真实 Key。
45
+
46
+ ```json
47
+ {
48
+ "mcpServers": {
49
+ "deepseek-tools": {
50
+ "command": "npx",
51
+ "args": ["-y", "@he110/deepseek-mcp"],
52
+ "env": {
53
+ "DEEPSEEK_API_KEY": "your-deepseek-api-key"
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ 从源码运行时,先执行 `npm install && npm run build`,再把 `command` 改为 `node`,并把 `args` 改为项目内 `dist/index.js` 的绝对路径。
61
+
62
+ 保存后重启或刷新 MCP 客户端,应能看到 `deepseek_search` 与 `deepseek_fetch` 两个工具。
63
+
64
+ ## 调用示例
65
+
66
+ 搜索:
67
+
68
+ ```json
69
+ {
70
+ "query": "DeepSeek Search API site:api-docs.deepseek.com lang:zh",
71
+ "count": 5,
72
+ "need_content": false
73
+ }
74
+ ```
75
+
76
+ 读取页面:
77
+
78
+ ```json
79
+ {
80
+ "url": "https://api-docs.deepseek.com/zh-cn/guides/search/"
81
+ }
82
+ ```
83
+
84
+ ## 行为与边界
85
+
86
+ - Key 仅从 `DEEPSEEK_API_KEY` 读取,不写入源码、日志或工具响应。
87
+ - 默认每次请求超时 60 秒;网络错误、HTTP 408、429 和 5xx 最多重试 2 次,并优先遵守 `Retry-After`。
88
+ - 其他 4xx 错误不重试;官方错误信息会以 MCP `isError` 结果返回。
89
+ - Fetch 仅接受 HTTP/HTTPS URL,拒绝内嵌用户名或密码。
90
+ - Search 与 Fetch 都是计费接口,只有符合官方规则的成功请求才收费;空结果和失败请求是否计费以官方文档为准。
91
+ - 当前只封装原始 Search / Fetch API,不包含模型对话、联网工具、图片搜索或 OCR 等能力。
92
+
93
+ ## 验证
94
+
95
+ ```bash
96
+ npm run check
97
+ ```
98
+
99
+ 测试使用模拟 HTTP 响应与内存 MCP 传输,不会访问真实 API,也不会产生费用。若需验证真实账号、额度和线上响应,请在配置 API Key 后通过 MCP 客户端执行一次低结果数搜索。
100
+
101
+ ## CI
102
+
103
+ GitHub Actions 会在 `main` 推送、Pull Request 和手动触发时,分别使用 Node.js 20、22、24 执行 `npm ci` 与 `npm run check`。
104
+
105
+ ## 发布 npm 包
106
+
107
+ 该包使用公开访问权限。维护者发布前需要登录有 `@he110` scope 权限的 npm 账号:
108
+
109
+ ```bash
110
+ npm login
111
+ npm pack --dry-run
112
+ npm publish
113
+ ```
114
+
115
+ `prepack` 会自动执行类型检查、测试和构建;`files` 白名单确保只发布运行所需文件与 README。
116
+
117
+ ## 官方文档
118
+
119
+ - [网页搜索与抓取指南](https://api-docs.deepseek.com/zh-cn/guides/search/)
120
+ - [Search API Reference](https://api-docs.deepseek.com/zh-cn/api/search/)
121
+ - [Fetch API Reference](https://api-docs.deepseek.com/zh-cn/api/fetch/)
@@ -0,0 +1,58 @@
1
+ export type SearchParams = {
2
+ query: string;
3
+ count?: number;
4
+ ori_question?: string | null;
5
+ localization?: string;
6
+ need_content?: boolean;
7
+ };
8
+ export type SearchResult = {
9
+ rerank_score: number;
10
+ title: string;
11
+ url: string;
12
+ snippet: string;
13
+ summary: string;
14
+ content: string;
15
+ site_name: string | null;
16
+ site_icon: string | null;
17
+ date: string | null;
18
+ authority: number;
19
+ };
20
+ export type SearchResponse = {
21
+ results: SearchResult[];
22
+ };
23
+ export type FetchParams = {
24
+ url: string;
25
+ };
26
+ export type FetchResponse = {
27
+ title: string;
28
+ content: string;
29
+ };
30
+ type DeepSeekClientOptions = {
31
+ apiKey: string;
32
+ baseUrl?: string;
33
+ fetchImpl?: typeof fetch;
34
+ timeoutMs?: number;
35
+ maxRetries?: number;
36
+ retryBaseDelayMs?: number;
37
+ };
38
+ export declare class DeepSeekApiError extends Error {
39
+ readonly status?: number | undefined;
40
+ readonly code?: string | undefined;
41
+ readonly retryable: boolean;
42
+ readonly retryAfterMs?: number | undefined;
43
+ constructor(message: string, status?: number | undefined, code?: string | undefined, retryable?: boolean, retryAfterMs?: number | undefined);
44
+ }
45
+ export declare class DeepSeekClient {
46
+ private readonly options;
47
+ private readonly baseUrl;
48
+ private readonly fetchImpl;
49
+ private readonly timeoutMs;
50
+ private readonly maxRetries;
51
+ private readonly retryBaseDelayMs;
52
+ constructor(options: DeepSeekClientOptions);
53
+ search(params: SearchParams): Promise<SearchResponse>;
54
+ fetchPage(params: FetchParams): Promise<FetchResponse>;
55
+ private request;
56
+ private requestOnce;
57
+ }
58
+ export {};
package/dist/client.js ADDED
@@ -0,0 +1,115 @@
1
+ export class DeepSeekApiError extends Error {
2
+ status;
3
+ code;
4
+ retryable;
5
+ retryAfterMs;
6
+ constructor(message, status, code, retryable = false, retryAfterMs) {
7
+ super(message);
8
+ this.status = status;
9
+ this.code = code;
10
+ this.retryable = retryable;
11
+ this.retryAfterMs = retryAfterMs;
12
+ this.name = "DeepSeekApiError";
13
+ }
14
+ }
15
+ const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
16
+ function parseRetryAfter(value) {
17
+ if (!value)
18
+ return undefined;
19
+ const seconds = Number(value);
20
+ if (Number.isFinite(seconds) && seconds >= 0) {
21
+ return Math.min(seconds * 1000, 60_000);
22
+ }
23
+ const date = Date.parse(value);
24
+ if (Number.isNaN(date))
25
+ return undefined;
26
+ return Math.min(Math.max(date - Date.now(), 0), 60_000);
27
+ }
28
+ export class DeepSeekClient {
29
+ options;
30
+ baseUrl;
31
+ fetchImpl;
32
+ timeoutMs;
33
+ maxRetries;
34
+ retryBaseDelayMs;
35
+ constructor(options) {
36
+ this.options = options;
37
+ if (!options.apiKey.trim()) {
38
+ throw new Error("DEEPSEEK_API_KEY is required");
39
+ }
40
+ this.baseUrl = (options.baseUrl ?? "https://api.deepseek.com").replace(/\/$/, "");
41
+ this.fetchImpl = options.fetchImpl ?? fetch;
42
+ this.timeoutMs = options.timeoutMs ?? 60_000;
43
+ this.maxRetries = options.maxRetries ?? 2;
44
+ this.retryBaseDelayMs = options.retryBaseDelayMs ?? 500;
45
+ }
46
+ search(params) {
47
+ return this.request("/v1/tools/search", params);
48
+ }
49
+ fetchPage(params) {
50
+ return this.request("/v1/tools/fetch", params);
51
+ }
52
+ async request(path, body) {
53
+ for (let attempt = 0;; attempt += 1) {
54
+ try {
55
+ return await this.requestOnce(path, body);
56
+ }
57
+ catch (error) {
58
+ if (!(error instanceof DeepSeekApiError) ||
59
+ !error.retryable ||
60
+ attempt >= this.maxRetries) {
61
+ throw error;
62
+ }
63
+ const backoff = Math.min(this.retryBaseDelayMs * 2 ** attempt, 10_000);
64
+ await sleep(error.retryAfterMs ?? backoff);
65
+ }
66
+ }
67
+ }
68
+ async requestOnce(path, body) {
69
+ const controller = new AbortController();
70
+ const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
71
+ try {
72
+ const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
73
+ method: "POST",
74
+ headers: {
75
+ Authorization: `Bearer ${this.options.apiKey}`,
76
+ "Content-Type": "application/json",
77
+ Accept: "application/json",
78
+ },
79
+ body: JSON.stringify(body),
80
+ signal: controller.signal,
81
+ });
82
+ if (response.ok) {
83
+ return (await response.json());
84
+ }
85
+ const rawBody = await response.text();
86
+ let message = `DeepSeek API returned HTTP ${response.status}`;
87
+ let code;
88
+ try {
89
+ const parsed = JSON.parse(rawBody);
90
+ if (parsed.error?.message)
91
+ message = parsed.error.message;
92
+ code = parsed.error?.code;
93
+ }
94
+ catch {
95
+ if (rawBody.trim())
96
+ message = `${message}: ${rawBody.slice(0, 300)}`;
97
+ }
98
+ const retryable = response.status === 408 || response.status === 429 || response.status >= 500;
99
+ throw new DeepSeekApiError(`DeepSeek API error (HTTP ${response.status}): ${message}`, response.status, code, retryable, parseRetryAfter(response.headers.get("retry-after")));
100
+ }
101
+ catch (error) {
102
+ if (error instanceof DeepSeekApiError)
103
+ throw error;
104
+ if (controller.signal.aborted) {
105
+ throw new DeepSeekApiError(`DeepSeek API request timed out after ${this.timeoutMs} ms`, undefined, "timeout", true);
106
+ }
107
+ const detail = error instanceof Error ? error.message : String(error);
108
+ throw new DeepSeekApiError(`Unable to reach DeepSeek API: ${detail}`, undefined, "network_error", true);
109
+ }
110
+ finally {
111
+ clearTimeout(timeout);
112
+ }
113
+ }
114
+ }
115
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA2CA,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAG9B;IACA;IACA;IACA;IALX,YACE,OAAe,EACN,MAAe,EACf,IAAa,EACb,YAAY,KAAK,EACjB,YAAqB;QAE9B,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,WAAM,GAAN,MAAM,CAAS;QACf,SAAI,GAAJ,IAAI,CAAS;QACb,cAAS,GAAT,SAAS,CAAQ;QACjB,iBAAY,GAAZ,YAAY,CAAS;QAG9B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,MAAM,KAAK,GAAG,CAAC,YAAoB,EAAE,EAAE,CACrC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;AAEpE,SAAS,eAAe,CAAC,KAAoB;IAC3C,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAE7B,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,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AAS,EACT,SAAS,EACT,IAAI,CACL,CAAC;YACJ,CAAC;YAED,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtE,MAAM,IAAI,gBAAgB,CACxB,iCAAiC,MAAM,EAAE,EACzC,SAAS,EACT,eAAe,EACf,IAAI,CACL,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { DeepSeekClient } from "./client.js";
4
+ import { createDeepSeekServer } from "./server.js";
5
+ async function main() {
6
+ const apiKey = process.env.DEEPSEEK_API_KEY?.trim();
7
+ if (!apiKey) {
8
+ console.error("DEEPSEEK_API_KEY is required. Set it in the MCP server environment.");
9
+ process.exitCode = 1;
10
+ return;
11
+ }
12
+ const client = new DeepSeekClient({ apiKey });
13
+ const server = createDeepSeekServer(client);
14
+ await server.connect(new StdioServerTransport());
15
+ }
16
+ main().catch((error) => {
17
+ const message = error instanceof Error ? error.message : String(error);
18
+ console.error(`Failed to start deepseek-tools MCP server: ${message}`);
19
+ process.exitCode = 1;
20
+ });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC;IACpD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,qEAAqE,CAAC,CAAC;QACrF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;AACnD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CAAC,KAAK,CAAC,8CAA8C,OAAO,EAAE,CAAC,CAAC;IACvE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { DeepSeekClient } from "./client.js";
3
+ export declare function createDeepSeekServer(client: DeepSeekClient): McpServer;
package/dist/server.js ADDED
@@ -0,0 +1,116 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ const searchResultSchema = z.object({
4
+ rerank_score: z.number(),
5
+ title: z.string(),
6
+ url: z.string(),
7
+ snippet: z.string(),
8
+ summary: z.string(),
9
+ content: z.string(),
10
+ site_name: z.string().nullable(),
11
+ site_icon: z.string().nullable(),
12
+ date: z.string().nullable(),
13
+ authority: z.number().int(),
14
+ });
15
+ const httpUrlSchema = z
16
+ .string()
17
+ .trim()
18
+ .min(1)
19
+ .max(8192)
20
+ .superRefine((value, context) => {
21
+ try {
22
+ const url = new URL(value);
23
+ if (!["http:", "https:"].includes(url.protocol) ||
24
+ !url.hostname ||
25
+ url.username ||
26
+ url.password) {
27
+ context.addIssue({
28
+ code: "custom",
29
+ message: "URL must be HTTP/HTTPS, include a host, and contain no username or password",
30
+ });
31
+ }
32
+ }
33
+ catch {
34
+ context.addIssue({ code: "custom", message: "Invalid URL" });
35
+ }
36
+ });
37
+ function errorResult(error) {
38
+ const message = error instanceof Error ? error.message : String(error);
39
+ return {
40
+ content: [{ type: "text", text: message }],
41
+ isError: true,
42
+ };
43
+ }
44
+ export function createDeepSeekServer(client) {
45
+ const server = new McpServer({ name: "deepseek-tools", version: "0.1.0" }, {
46
+ instructions: "Use deepseek_search for current web information and deepseek_fetch to read a specific HTTP/HTTPS page. Preserve source URLs when using results.",
47
+ });
48
+ server.registerTool("deepseek_search", {
49
+ title: "DeepSeek Web Search",
50
+ description: "Search the live web using DeepSeek's official Search API. The query supports site:, -site:, lang:, after:, before:, exact phrases, and exclusion operators. Keep need_content false unless full page content is required.",
51
+ inputSchema: {
52
+ query: z
53
+ .string()
54
+ .trim()
55
+ .min(1)
56
+ .max(128)
57
+ .describe("Search query, including optional DeepSeek search operators"),
58
+ count: z.number().int().min(1).max(50).default(10),
59
+ ori_question: z
60
+ .string()
61
+ .trim()
62
+ .min(1)
63
+ .max(128)
64
+ .nullish()
65
+ .describe("Original user question that triggered the search"),
66
+ localization: z
67
+ .string()
68
+ .optional()
69
+ .describe("Optional IP address used to localize search results"),
70
+ need_content: z.boolean().default(false),
71
+ },
72
+ outputSchema: { results: z.array(searchResultSchema) },
73
+ annotations: {
74
+ readOnlyHint: true,
75
+ idempotentHint: true,
76
+ openWorldHint: true,
77
+ },
78
+ }, async (params) => {
79
+ try {
80
+ const result = await client.search(params);
81
+ return {
82
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
83
+ structuredContent: result,
84
+ };
85
+ }
86
+ catch (error) {
87
+ return errorResult(error);
88
+ }
89
+ });
90
+ server.registerTool("deepseek_fetch", {
91
+ title: "DeepSeek Web Fetch",
92
+ description: "Fetch one web page using DeepSeek's official Fetch API and return its title and Markdown content. Use a URL returned by deepseek_search or supplied by the user.",
93
+ inputSchema: {
94
+ url: httpUrlSchema.describe("HTTP/HTTPS page URL without embedded credentials"),
95
+ },
96
+ outputSchema: { title: z.string(), content: z.string() },
97
+ annotations: {
98
+ readOnlyHint: true,
99
+ idempotentHint: true,
100
+ openWorldHint: true,
101
+ },
102
+ }, async ({ url }) => {
103
+ try {
104
+ const result = await client.fetchPage({ url });
105
+ return {
106
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
107
+ structuredContent: result,
108
+ };
109
+ }
110
+ catch (error) {
111
+ return errorResult(error);
112
+ }
113
+ });
114
+ return server;
115
+ }
116
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE;IACxB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,SAAS,EAAE,CAAC,CAAC,MA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AAC;gBAClE,iBAAiB,EAAE,MAAM;aAC1B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,CACF,CAAC;IAEF,MAAM,CAAC,YAAY,CACjB,gBAAgB,EAChB;QACE,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EACT,kKAAkK;QACpK,WAAW,EAAE;YACX,GAAG,EAAE,aAAa,CAAC,QAAQ,CAAC,kDAAkD,CAAC;SAChF;QACD,YAAY,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;QACxD,WAAW,EAAE;YACX,YAAY,EAAE,IAAI;YAClB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,IAAI;SACpB;KACF,EACD,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QAChB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YAC/C,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBAClE,iBAAiB,EAAE,MAAM;aAC1B,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@he110/deepseek-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP server for DeepSeek's official Search and Fetch APIs",
5
+ "type": "module",
6
+ "bin": {
7
+ "deepseek-mcp": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist/",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=20"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "dev": "tsx src/index.ts",
19
+ "start": "node dist/index.js",
20
+ "test": "tsx --test test/*.test.ts",
21
+ "typecheck": "tsc -p tsconfig.test.json --noEmit",
22
+ "check": "npm run typecheck && npm test && npm run build",
23
+ "prepack": "npm run check"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/He110te4m/DeepSeek-MCP.git"
28
+ },
29
+ "homepage": "https://github.com/He110te4m/DeepSeek-MCP#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/He110te4m/DeepSeek-MCP/issues"
32
+ },
33
+ "keywords": [
34
+ "deepseek",
35
+ "mcp",
36
+ "model-context-protocol",
37
+ "search",
38
+ "fetch"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "dependencies": {
44
+ "@modelcontextprotocol/sdk": "^1.32.2",
45
+ "zod": "^4.6.7"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^24.0.0",
49
+ "tsx": "^4.23.15",
50
+ "typescript": "^5.9.3"
51
+ }
52
+ }