knowfun-mcp 1.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Knowfun.io
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,307 @@
1
+ # Knowfun MCP Server
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/knowfun-mcp?style=flat-square)](https://www.npmjs.com/package/knowfun-mcp)
4
+ [![License](https://img.shields.io/npm/l/knowfun-mcp?style=flat-square)](LICENSE)
5
+ [![Node Version](https://img.shields.io/node/v/knowfun-mcp?style=flat-square)](package.json)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue?style=flat-square)](https://www.typescriptlang.org/)
7
+ [![MCP](https://img.shields.io/badge/MCP-1.0.4-green?style=flat-square)](https://modelcontextprotocol.io/)
8
+
9
+ [中文](./README.zh.md) | English
10
+
11
+ This is a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that wraps the Knowfun.io OpenAPI, allowing AI assistants (like Claude) to directly invoke Knowfun's content generation capabilities.
12
+
13
+ ## Features
14
+
15
+ Through this MCP server, AI assistants can:
16
+
17
+ - ✅ Create content generation tasks (courses, posters, games, films)
18
+ - ✅ Query task status and detailed results
19
+ - ✅ Get task lists (with pagination and filtering)
20
+ - ✅ Query credit balance and usage details
21
+ - ✅ Get API configuration schema (all available generation options)
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ # Clone or navigate to project directory
27
+ cd knowfun-mcp
28
+
29
+ # Install dependencies
30
+ npm install
31
+
32
+ # Compile TypeScript
33
+ npm run build
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ 1. Copy environment variable template:
39
+ ```bash
40
+ cp .env.example .env
41
+ ```
42
+
43
+ 2. Edit `.env` file and fill in your Knowfun API Key:
44
+ ```bash
45
+ KNOWFUN_API_KEY=kf_your_api_key_here
46
+ KNOWFUN_API_BASE_URL=https://api.knowfun.io
47
+ ```
48
+
49
+ > 💡 How to get API Key?
50
+ > 1. Login to [knowfun.io](https://knowfun.io)
51
+ > 2. Go to `/api-platform` page
52
+ > 3. Create or view your API Key
53
+
54
+ 3. Test connection (optional but recommended):
55
+ ```bash
56
+ npm test
57
+ ```
58
+
59
+ If configured correctly, it will show:
60
+ - ✅ API Key valid
61
+ - ✅ Network connection normal
62
+ - ✅ Current credit balance
63
+
64
+ ## Use in Claude Desktop
65
+
66
+ Edit Claude Desktop configuration file:
67
+
68
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
69
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
70
+
71
+ Add the following configuration:
72
+
73
+ ```json
74
+ {
75
+ "mcpServers": {
76
+ "knowfun": {
77
+ "command": "node",
78
+ "args": ["/Users/jamson/code/knowfun-mcp/dist/index.js"],
79
+ "env": {
80
+ "KNOWFUN_API_KEY": "kf_your_api_key_here",
81
+ "KNOWFUN_API_BASE_URL": "https://api.knowfun.io"
82
+ }
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ Restart Claude Desktop to use Knowfun tools.
89
+
90
+ ## Use in Claude Code (CLI)
91
+
92
+ Create or edit `~/.config/claude/settings.json`:
93
+
94
+ ```json
95
+ {
96
+ "mcpServers": {
97
+ "knowfun": {
98
+ "command": "node",
99
+ "args": ["/Users/jamson/code/knowfun-mcp/dist/index.js"],
100
+ "env": {
101
+ "KNOWFUN_API_KEY": "kf_your_api_key_here",
102
+ "KNOWFUN_API_BASE_URL": "https://api.knowfun.io"
103
+ }
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ Then use Claude Code CLI as normal.
110
+
111
+ ## Use in Cursor
112
+
113
+ Create `.cursor/mcp_config.json` in your project:
114
+
115
+ ```json
116
+ {
117
+ "mcpServers": {
118
+ "knowfun": {
119
+ "command": "node",
120
+ "args": ["/Users/jamson/code/knowfun-mcp/dist/index.js"],
121
+ "env": {
122
+ "KNOWFUN_API_KEY": "kf_your_api_key_here",
123
+ "KNOWFUN_API_BASE_URL": "https://api.knowfun.io"
124
+ }
125
+ }
126
+ }
127
+ }
128
+ ```
129
+
130
+ Or configure in Cursor settings (Settings → Features → MCP).
131
+
132
+ ## Available Tools
133
+
134
+ ### 1. create_task
135
+ Create content generation task (API: `POST /api/openapi/v1/tasks`)
136
+
137
+ **Parameters**:
138
+ - `requestId` (string, required): Custom request ID (1-64 characters)
139
+ - `taskType` (string, required): Task type - `course`, `poster`, `game`, `film`
140
+ - `material` (object, required): Input material
141
+ - `text` (string): Text content
142
+ - `url` (string): Document or webpage URL
143
+ - `type` (string): Material type (text, url, pdf, doc, etc.)
144
+ - `config` (object): Generation config (optional, call `get_schema` first to see available options)
145
+ - `callbackUrl` (string): Callback URL on completion (optional)
146
+ - `language` (string): Language setting (optional)
147
+
148
+ **Example**:
149
+ ```json
150
+ {
151
+ "requestId": "req-20260301-001",
152
+ "taskType": "course",
153
+ "material": {
154
+ "text": "Introduction to AI: AI is a branch of computer science...",
155
+ "type": "text"
156
+ },
157
+ "config": {
158
+ "course": {
159
+ "contentLanguage": "en",
160
+ "explainLanguage": "en",
161
+ "aspectRatio": "landscape"
162
+ }
163
+ }
164
+ }
165
+ ```
166
+
167
+ ### 2. get_task
168
+ Query task status by taskId (API: `GET /api/openapi/v1/tasks/:taskId`)
169
+
170
+ **Parameters**:
171
+ - `taskId` (string, required): Task ID
172
+
173
+ ### 3. get_task_by_request_id
174
+ Query task status by requestId (API: `GET /api/openapi/v1/tasks/by-request/:requestId`)
175
+
176
+ **Parameters**:
177
+ - `requestId` (string, required): Request ID
178
+
179
+ ### 4. get_task_detail
180
+ Get detailed task information (API: `GET /api/openapi/v1/tasks/:taskId/detail`)
181
+
182
+ **Parameters**:
183
+ - `taskId` (string, required): Task ID
184
+ - `verbose` (boolean): Return detailed debug info (default false)
185
+
186
+ ### 5. list_tasks
187
+ Get task list (API: `GET /api/openapi/v1/tasks`)
188
+
189
+ **Parameters**:
190
+ - `page` (number): Page number (default 1)
191
+ - `limit` (number): Items per page (default 20)
192
+ - `status` (string): Status filter (pending, processing, success, failed)
193
+ - `taskType` (string): Type filter (course, poster, game, film)
194
+
195
+ ### 6. get_credits_balance
196
+ Query current API Key credit balance (API: `GET /api/openapi/v1/credits/balance`)
197
+
198
+ **Returns**:
199
+ - `available`: Available credits
200
+ - `earned`: Total earned credits
201
+ - `used`: Used credits
202
+ - `locked`: Locked credits
203
+
204
+ ### 7. get_credits_pricing
205
+ Get credit pricing for each task type (API: `GET /api/openapi/v1/credits/pricing`)
206
+
207
+ ### 8. get_schema
208
+ Get API configuration schema (API: `GET /api/openapi/v1/schema`)
209
+
210
+ Includes all available content styles, templates, languages, etc.
211
+
212
+ ### 9. get_usage
213
+ Query credit usage details (API: `GET /api/openapi/usage`)
214
+
215
+ **Parameters**:
216
+ - `startDate` (string): Start date (YYYY-MM-DD)
217
+ - `endDate` (string): End date (YYYY-MM-DD)
218
+
219
+ ## Task Types
220
+
221
+ ### Course
222
+ Generate multimedia course content (video, PPT, etc.)
223
+
224
+ **Main config**:
225
+ - `contentStyle`: Content style (concise, detailed, etc.)
226
+ - `contentLanguage`: Content language
227
+ - `explainLanguage`: Narration language
228
+ - `voiceType`: Voice type
229
+ - `aspectRatio`: Aspect ratio (landscape, portrait)
230
+
231
+ ### Poster
232
+ Generate knowledge infographic posters
233
+
234
+ **Main config**:
235
+ - `usage`: Layout type (infographic, businessReports, etc.)
236
+ - `style`: Art style (handDrawn, photorealistic, etc.)
237
+ - `aspectRatio`: Aspect ratio (1:1, 4:3, 16:9, etc.)
238
+
239
+ ### Game
240
+ Generate interactive game content
241
+
242
+ **Main config**:
243
+ - `gameType`: Game type (story, interactive, mission, etc.)
244
+ - `aspectRatio`: Aspect ratio
245
+
246
+ ### Film
247
+ Generate short videos or micro-films
248
+
249
+ **Main config**:
250
+ - `filmStyle`: Film style (story, documentary, tutorial, etc.)
251
+ - `aspectRatio`: Aspect ratio (16:9, 9:16, 1:1)
252
+
253
+ ## Development
254
+
255
+ ```bash
256
+ # Watch file changes and auto-compile
257
+ npm run watch
258
+
259
+ # Run in development mode
260
+ npm run dev
261
+ ```
262
+
263
+ ## Tech Stack
264
+
265
+ - **MCP SDK**: @modelcontextprotocol/sdk
266
+ - **HTTP Client**: axios
267
+ - **Language**: TypeScript
268
+ - **Runtime**: Node.js
269
+
270
+ ## Documentation
271
+
272
+ ### Quick Start
273
+ - 🚀 [QUICKSTART.md](./QUICKSTART.md) - Quick Start Guide
274
+ - 🚀 [QUICKSTART.zh.md](./QUICKSTART.zh.md) - 快速入门指南
275
+
276
+ ### Complete Documentation
277
+ - 📖 [README.md](./README.md) - Complete Documentation (English)
278
+ - 📖 [README.zh.md](./README.zh.md) - 完整项目文档(中文)
279
+ - 📝 [USAGE_EXAMPLES.md](./USAGE_EXAMPLES.md) - Usage Examples
280
+ - 📝 [USAGE_EXAMPLES.zh.md](./USAGE_EXAMPLES.zh.md) - 使用示例
281
+ - ⚙️ [CONFIGURATION.md](./CONFIGURATION.md) - Configuration Guide (Bilingual)
282
+
283
+ ### Reference
284
+ - 📊 [PROJECT_STRUCTURE.md](./PROJECT_STRUCTURE.md) - Project Structure
285
+ - 📋 [CHANGELOG.md](./CHANGELOG.md) - Version History
286
+
287
+ ### Contributing
288
+ - 🤝 [CONTRIBUTING.md](./CONTRIBUTING.md) - How to Contribute
289
+ - 📜 [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) - Code of Conduct
290
+ - 🔒 [SECURITY.md](./SECURITY.md) - Security Policy
291
+
292
+ ## Related Links
293
+
294
+ - [Knowfun.io](https://knowfun.io)
295
+ - [Knowfun OpenAPI Docs](https://knowfun.io/api-platform)
296
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
297
+ - [Claude Desktop](https://claude.ai/download)
298
+ - [Claude Code CLI](https://docs.anthropic.com/claude/docs/claude-code)
299
+ - [Cursor](https://cursor.sh)
300
+
301
+ ## License
302
+
303
+ MIT
304
+
305
+ ## Support
306
+
307
+ For issues or suggestions, please contact the Knowfun team or submit an Issue.
package/README.zh.md ADDED
@@ -0,0 +1,311 @@
1
+ # Knowfun MCP Server
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/knowfun-mcp?style=flat-square)](https://www.npmjs.com/package/knowfun-mcp)
4
+ [![License](https://img.shields.io/npm/l/knowfun-mcp?style=flat-square)](LICENSE)
5
+ [![Node Version](https://img.shields.io/node/v/knowfun-mcp?style=flat-square)](package.json)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue?style=flat-square)](https://www.typescriptlang.org/)
7
+ [![MCP](https://img.shields.io/badge/MCP-1.0.4-green?style=flat-square)](https://modelcontextprotocol.io/)
8
+
9
+ 中文 | [English](./README.md)
10
+
11
+ 这是一个基于 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 的服务器,用于封装 Knowfun.io 的 OpenAPI,让 AI 助手(如 Claude)能够直接调用 Knowfun 的内容生成能力。
12
+
13
+ ## 功能特性
14
+
15
+ 通过此 MCP server,AI 助手可以:
16
+
17
+ - ✅ 创建内容生成任务(课程、海报、游戏、短剧)
18
+ - ✅ 查询任务状态和详细结果
19
+ - ✅ 获取任务列表(支持分页和筛选)
20
+ - ✅ 查询积分余额和消耗明细
21
+ - ✅ 获取 API 配置 Schema(所有可用的生成选项)
22
+
23
+ ## 安装
24
+
25
+ ```bash
26
+ # 克隆或进入项目目录
27
+ cd knowfun-mcp
28
+
29
+ # 安装依赖
30
+ npm install
31
+
32
+ # 编译 TypeScript
33
+ npm run build
34
+ ```
35
+
36
+ ## 配置
37
+
38
+ 1. 复制环境变量模板:
39
+ ```bash
40
+ cp .env.example .env
41
+ ```
42
+
43
+ 2. 编辑 `.env` 文件,填入您的 Knowfun API Key:
44
+ ```bash
45
+ KNOWFUN_API_KEY=kf_your_api_key_here
46
+ KNOWFUN_API_BASE_URL=https://api.knowfun.io
47
+ ```
48
+
49
+ > 💡 如何获取 API Key?
50
+ > 1. 登录 [knowfun.io](https://knowfun.io)
51
+ > 2. 进入 `/api-platform` 页面
52
+ > 3. 创建或查看您的 API Key
53
+
54
+ 3. 测试连接(可选但推荐):
55
+ ```bash
56
+ npm test
57
+ ```
58
+
59
+ 如果配置正确,会显示:
60
+ - ✅ API Key 有效
61
+ - ✅ 网络连接正常
62
+ - ✅ 当前积分余额
63
+
64
+ ## 使用配置
65
+
66
+ ### 在 Claude Desktop 中使用
67
+
68
+ 编辑 Claude Desktop 的配置文件:
69
+
70
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
71
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
72
+
73
+ 添加以下配置:
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "knowfun": {
79
+ "command": "node",
80
+ "args": ["/Users/jamson/code/knowfun-mcp/dist/index.js"],
81
+ "env": {
82
+ "KNOWFUN_API_KEY": "kf_your_api_key_here",
83
+ "KNOWFUN_API_BASE_URL": "https://api.knowfun.io"
84
+ }
85
+ }
86
+ }
87
+ }
88
+ ```
89
+
90
+ 重启 Claude Desktop 后,即可使用 Knowfun 工具。
91
+
92
+ ### 在 Claude Code (CLI) 中使用
93
+
94
+ 编辑或创建 `~/.config/claude/settings.json`:
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "knowfun": {
100
+ "command": "node",
101
+ "args": ["/Users/jamson/code/knowfun-mcp/dist/index.js"],
102
+ "env": {
103
+ "KNOWFUN_API_KEY": "kf_your_api_key_here",
104
+ "KNOWFUN_API_BASE_URL": "https://api.knowfun.io"
105
+ }
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ 然后正常使用 Claude Code CLI 即可。
112
+
113
+ ### 在 Cursor 中使用
114
+
115
+ 在项目根目录创建 `.cursor/mcp_config.json`:
116
+
117
+ ```json
118
+ {
119
+ "mcpServers": {
120
+ "knowfun": {
121
+ "command": "node",
122
+ "args": ["/Users/jamson/code/knowfun-mcp/dist/index.js"],
123
+ "env": {
124
+ "KNOWFUN_API_KEY": "kf_your_api_key_here",
125
+ "KNOWFUN_API_BASE_URL": "https://api.knowfun.io"
126
+ }
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ 或在 Cursor 设置中配置(Settings → Features → MCP)。
133
+
134
+ > 📖 查看 [CONFIGURATION.md](./CONFIGURATION.md) 获取详细配置指南
135
+
136
+ ## 可用工具
137
+
138
+ ### 1. create_task
139
+ 创建内容生成任务(API: `POST /api/openapi/v1/tasks`)
140
+
141
+ **参数**:
142
+ - `requestId` (string, 必需): 自定义请求ID(1-64字符)
143
+ - `taskType` (string, 必需): 任务类型 - `course`(课程), `poster`(海报), `game`(游戏), `film`(短剧)
144
+ - `material` (object, 必需): 输入素材
145
+ - `text` (string): 文本内容
146
+ - `url` (string): 文档或网页URL
147
+ - `type` (string): 素材类型(text, url, pdf, doc等)
148
+ - `config` (object): 生成配置(可选,建议先调用 `get_schema` 查看可用配置)
149
+ - `callbackUrl` (string): 完成回调URL(可选)
150
+ - `language` (string): 语言设置(可选)
151
+
152
+ **示例**:
153
+ ```json
154
+ {
155
+ "requestId": "req-20260301-001",
156
+ "taskType": "course",
157
+ "material": {
158
+ "text": "人工智能简介:AI是计算机科学的一个分支...",
159
+ "type": "text"
160
+ },
161
+ "config": {
162
+ "course": {
163
+ "contentLanguage": "zh",
164
+ "explainLanguage": "zh",
165
+ "aspectRatio": "landscape"
166
+ }
167
+ }
168
+ }
169
+ ```
170
+
171
+ ### 2. get_task
172
+ 根据 taskId 查询任务状态(API: `GET /api/openapi/v1/tasks/:taskId`)
173
+
174
+ **参数**:
175
+ - `taskId` (string, 必需): 任务ID
176
+
177
+ ### 3. get_task_by_request_id
178
+ 根据 requestId 查询任务状态(API: `GET /api/openapi/v1/tasks/by-request/:requestId`)
179
+
180
+ **参数**:
181
+ - `requestId` (string, 必需): 请求ID
182
+
183
+ ### 4. get_task_detail
184
+ 获取任务详细信息(API: `GET /api/openapi/v1/tasks/:taskId/detail`)
185
+
186
+ **参数**:
187
+ - `taskId` (string, 必需): 任务ID
188
+ - `verbose` (boolean): 是否返回详细调试信息(默认 false)
189
+
190
+ ### 5. list_tasks
191
+ 获取任务列表(API: `GET /api/openapi/v1/tasks`)
192
+
193
+ **参数**:
194
+ - `page` (number): 页码(默认 1)
195
+ - `limit` (number): 每页数量(默认 20)
196
+ - `status` (string): 状态筛选(pending, processing, success, failed)
197
+ - `taskType` (string): 类型筛选(course, poster, game, film)
198
+
199
+ ### 6. get_credits_balance
200
+ 查询当前 API Key 的积分余额(API: `GET /api/openapi/v1/credits/balance`)
201
+
202
+ **返回**:
203
+ - `available`: 可用积分
204
+ - `earned`: 总获得积分
205
+ - `used`: 已使用积分
206
+ - `locked`: 锁定积分
207
+
208
+ ### 7. get_credits_pricing
209
+ 获取各类任务的积分消耗定价(API: `GET /api/openapi/v1/credits/pricing`)
210
+
211
+ ### 8. get_schema
212
+ 获取 API 配置 Schema(API: `GET /api/openapi/v1/schema`)
213
+
214
+ 包括所有可用的内容风格、模板、语言等选项
215
+
216
+ ### 9. get_usage
217
+ 查询积分消耗明细(API: `GET /api/openapi/usage`)
218
+
219
+ **参数**:
220
+ - `startDate` (string): 开始日期(YYYY-MM-DD)
221
+ - `endDate` (string): 结束日期(YYYY-MM-DD)
222
+
223
+ ## 任务类型说明
224
+
225
+ ### Course(课程)
226
+ 生成多媒体课程内容(视频、PPT等)
227
+
228
+ **主要配置项**:
229
+ - `contentStyle`: 内容风格(concise、detailed等)
230
+ - `contentLanguage`: 内容语言
231
+ - `explainLanguage`: 解说语言
232
+ - `voiceType`: 音色类型
233
+ - `aspectRatio`: 宽高比(landscape、portrait)
234
+
235
+ ### Poster(海报)
236
+ 生成知识图解海报
237
+
238
+ **主要配置项**:
239
+ - `usage`: 布局类型(infographic、businessReports等)
240
+ - `style`: 美术风格(handDrawn、photorealistic等)
241
+ - `aspectRatio`: 宽高比(1:1、4:3、16:9等)
242
+
243
+ ### Game(游戏)
244
+ 生成互动游戏内容
245
+
246
+ **主要配置项**:
247
+ - `gameType`: 游戏类型(story、interactive、mission等)
248
+ - `aspectRatio`: 宽高比
249
+
250
+ ### Film(短剧)
251
+ 生成短视频或微电影
252
+
253
+ **主要配置项**:
254
+ - `filmStyle`: 影片风格(story、documentary、tutorial等)
255
+ - `aspectRatio`: 画面比例(16:9、9:16、1:1)
256
+
257
+ ## 开发
258
+
259
+ ```bash
260
+ # 监听文件变化并自动重新编译
261
+ npm run watch
262
+
263
+ # 运行开发模式
264
+ npm run dev
265
+ ```
266
+
267
+ ## 技术栈
268
+
269
+ - **MCP SDK**: @modelcontextprotocol/sdk
270
+ - **HTTP 客户端**: axios
271
+ - **语言**: TypeScript
272
+ - **运行时**: Node.js
273
+
274
+ ## 文档
275
+
276
+ ### 快速开始
277
+ - 🚀 [QUICKSTART.zh.md](./QUICKSTART.zh.md) - 快速入门指南
278
+ - 🚀 [QUICKSTART.md](./QUICKSTART.md) - Quick Start Guide
279
+
280
+ ### 完整文档
281
+ - 📖 [README.zh.md](./README.zh.md) - 完整项目文档(中文)
282
+ - 📖 [README.md](./README.md) - Complete Documentation (English)
283
+ - 📝 [USAGE_EXAMPLES.zh.md](./USAGE_EXAMPLES.zh.md) - 使用示例
284
+ - 📝 [USAGE_EXAMPLES.md](./USAGE_EXAMPLES.md) - Usage Examples
285
+ - ⚙️ [CONFIGURATION.md](./CONFIGURATION.md) - 详细配置指南(中英文)
286
+
287
+ ### 参考资料
288
+ - 📊 [PROJECT_STRUCTURE.zh.md](./PROJECT_STRUCTURE.zh.md) - 项目结构说明
289
+ - 📋 [CHANGELOG.md](./CHANGELOG.md) - 版本更新记录
290
+
291
+ ### 贡献指南
292
+ - 🤝 [CONTRIBUTING.md](./CONTRIBUTING.md) - 如何贡献代码
293
+ - 📜 [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) - 社区行为准则
294
+ - 🔒 [SECURITY.md](./SECURITY.md) - 安全政策
295
+
296
+ ## 相关链接
297
+
298
+ - [Knowfun.io](https://knowfun.io)
299
+ - [Knowfun OpenAPI 文档](https://knowfun.io/api-platform)
300
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
301
+ - [Claude Desktop](https://claude.ai/download)
302
+ - [Claude Code CLI](https://docs.anthropic.com/claude/docs/claude-code)
303
+ - [Cursor](https://cursor.sh)
304
+
305
+ ## 许可证
306
+
307
+ MIT
308
+
309
+ ## 支持
310
+
311
+ 如有问题或建议,请联系 Knowfun 团队或提交 Issue。
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,380 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, McpError, ErrorCode, } from "@modelcontextprotocol/sdk/types.js";
5
+ import axios from "axios";
6
+ import * as dotenv from "dotenv";
7
+ dotenv.config();
8
+ // Knowfun API Client
9
+ class KnowfunClient {
10
+ client;
11
+ apiKey;
12
+ baseURL;
13
+ constructor(apiKey, baseURL) {
14
+ this.apiKey = apiKey;
15
+ this.baseURL = baseURL;
16
+ this.client = axios.create({
17
+ baseURL: this.baseURL,
18
+ headers: {
19
+ Authorization: `Bearer ${this.apiKey}`,
20
+ "Content-Type": "application/json",
21
+ },
22
+ });
23
+ }
24
+ // 创建任务
25
+ async createTask(params) {
26
+ const response = await this.client.post("/api/openapi/v1/tasks", params);
27
+ return response.data;
28
+ }
29
+ // 查询任务状态
30
+ async getTask(taskId) {
31
+ const response = await this.client.get(`/api/openapi/v1/tasks/${taskId}`);
32
+ return response.data;
33
+ }
34
+ // 按 requestId 查询任务
35
+ async getTaskByRequestId(requestId) {
36
+ const response = await this.client.get(`/api/openapi/v1/tasks/by-request/${requestId}`);
37
+ return response.data;
38
+ }
39
+ // 查询任务详情
40
+ async getTaskDetail(taskId, verbose = false) {
41
+ const response = await this.client.get(`/api/openapi/v1/tasks/${taskId}/detail`, {
42
+ params: { verbose },
43
+ });
44
+ return response.data;
45
+ }
46
+ // 获取任务列表
47
+ async listTasks(params) {
48
+ const response = await this.client.get("/api/openapi/v1/tasks", { params });
49
+ return response.data;
50
+ }
51
+ // 查询积分余额
52
+ async getCreditsBalance() {
53
+ const response = await this.client.get("/api/openapi/v1/credits/balance");
54
+ return response.data;
55
+ }
56
+ // 获取积分定价
57
+ async getCreditsPricing() {
58
+ const response = await this.client.get("/api/openapi/v1/credits/pricing");
59
+ return response.data;
60
+ }
61
+ // 获取 API Schema
62
+ async getSchema() {
63
+ const response = await this.client.get("/api/openapi/v1/schema");
64
+ return response.data;
65
+ }
66
+ // 查询积分消耗明细
67
+ async getUsage(params) {
68
+ const response = await this.client.get("/api/openapi/usage", { params });
69
+ return response.data;
70
+ }
71
+ }
72
+ // MCP Server
73
+ const server = new Server({
74
+ name: "knowfun-mcp",
75
+ version: "1.0.0",
76
+ }, {
77
+ capabilities: {
78
+ tools: {},
79
+ },
80
+ });
81
+ // Initialize Knowfun client
82
+ const apiKey = process.env.KNOWFUN_API_KEY;
83
+ const baseURL = process.env.KNOWFUN_API_BASE_URL || "https://api.knowfun.io";
84
+ if (!apiKey) {
85
+ console.error("KNOWFUN_API_KEY environment variable is required");
86
+ process.exit(1);
87
+ }
88
+ const knowfunClient = new KnowfunClient(apiKey, baseURL);
89
+ // List available tools
90
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
91
+ return {
92
+ tools: [
93
+ {
94
+ name: "create_task",
95
+ description: "创建一个新的内容生成任务(课程、海报、游戏或短剧)",
96
+ inputSchema: {
97
+ type: "object",
98
+ properties: {
99
+ requestId: {
100
+ type: "string",
101
+ description: "用户自定义请求ID(1-64字符,用于幂等性控制)",
102
+ },
103
+ taskType: {
104
+ type: "string",
105
+ enum: ["course", "poster", "game", "film"],
106
+ description: "任务类型:course-课程,poster-海报,game-游戏,film-短剧",
107
+ },
108
+ material: {
109
+ type: "object",
110
+ properties: {
111
+ text: { type: "string", description: "文本内容" },
112
+ url: { type: "string", description: "文档或网页URL" },
113
+ type: {
114
+ type: "string",
115
+ description: "素材类型:text, url, pdf, doc, docx等",
116
+ },
117
+ },
118
+ description: "输入素材",
119
+ },
120
+ config: {
121
+ type: "object",
122
+ description: "生成配置(根据 taskType 不同,配置项也不同。可先调用 get_schema 查看可用配置)",
123
+ },
124
+ callbackUrl: {
125
+ type: "string",
126
+ description: "任务完成后的回调URL(可选)",
127
+ },
128
+ language: {
129
+ type: "string",
130
+ description: "语言设置(可选,默认为 zh)",
131
+ },
132
+ },
133
+ required: ["requestId", "taskType", "material"],
134
+ },
135
+ },
136
+ {
137
+ name: "get_task",
138
+ description: "根据 taskId 查询任务状态",
139
+ inputSchema: {
140
+ type: "object",
141
+ properties: {
142
+ taskId: {
143
+ type: "string",
144
+ description: "任务ID",
145
+ },
146
+ },
147
+ required: ["taskId"],
148
+ },
149
+ },
150
+ {
151
+ name: "get_task_by_request_id",
152
+ description: "根据 requestId 查询任务状态",
153
+ inputSchema: {
154
+ type: "object",
155
+ properties: {
156
+ requestId: {
157
+ type: "string",
158
+ description: "请求ID",
159
+ },
160
+ },
161
+ required: ["requestId"],
162
+ },
163
+ },
164
+ {
165
+ name: "get_task_detail",
166
+ description: "获取任务的详细信息(包括生成结果)",
167
+ inputSchema: {
168
+ type: "object",
169
+ properties: {
170
+ taskId: {
171
+ type: "string",
172
+ description: "任务ID",
173
+ },
174
+ verbose: {
175
+ type: "boolean",
176
+ description: "是否返回详细的调试信息(可选,默认false)",
177
+ default: false,
178
+ },
179
+ },
180
+ required: ["taskId"],
181
+ },
182
+ },
183
+ {
184
+ name: "list_tasks",
185
+ description: "获取任务列表(支持分页和筛选)",
186
+ inputSchema: {
187
+ type: "object",
188
+ properties: {
189
+ page: {
190
+ type: "number",
191
+ description: "页码(从1开始)",
192
+ default: 1,
193
+ },
194
+ limit: {
195
+ type: "number",
196
+ description: "每页数量",
197
+ default: 20,
198
+ },
199
+ status: {
200
+ type: "string",
201
+ description: "任务状态筛选:pending, processing, success, failed等",
202
+ },
203
+ taskType: {
204
+ type: "string",
205
+ description: "任务类型筛选:course, poster, game, film",
206
+ },
207
+ },
208
+ },
209
+ },
210
+ {
211
+ name: "get_credits_balance",
212
+ description: "查询当前 API Key 的积分余额",
213
+ inputSchema: {
214
+ type: "object",
215
+ properties: {},
216
+ },
217
+ },
218
+ {
219
+ name: "get_credits_pricing",
220
+ description: "获取各类任务的积分消耗定价",
221
+ inputSchema: {
222
+ type: "object",
223
+ properties: {},
224
+ },
225
+ },
226
+ {
227
+ name: "get_schema",
228
+ description: "获取 API 配置 Schema(包括所有可用的内容风格、模板、语言等选项)",
229
+ inputSchema: {
230
+ type: "object",
231
+ properties: {},
232
+ },
233
+ },
234
+ {
235
+ name: "get_usage",
236
+ description: "查询积分消耗明细",
237
+ inputSchema: {
238
+ type: "object",
239
+ properties: {
240
+ startDate: {
241
+ type: "string",
242
+ description: "开始日期(YYYY-MM-DD)",
243
+ },
244
+ endDate: {
245
+ type: "string",
246
+ description: "结束日期(YYYY-MM-DD)",
247
+ },
248
+ },
249
+ },
250
+ },
251
+ ],
252
+ };
253
+ });
254
+ // Handle tool calls
255
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
256
+ try {
257
+ const { name, arguments: args } = request.params;
258
+ switch (name) {
259
+ case "create_task": {
260
+ const result = await knowfunClient.createTask(args);
261
+ return {
262
+ content: [
263
+ {
264
+ type: "text",
265
+ text: JSON.stringify(result, null, 2),
266
+ },
267
+ ],
268
+ };
269
+ }
270
+ case "get_task": {
271
+ const result = await knowfunClient.getTask(args?.taskId);
272
+ return {
273
+ content: [
274
+ {
275
+ type: "text",
276
+ text: JSON.stringify(result, null, 2),
277
+ },
278
+ ],
279
+ };
280
+ }
281
+ case "get_task_by_request_id": {
282
+ const result = await knowfunClient.getTaskByRequestId(args?.requestId);
283
+ return {
284
+ content: [
285
+ {
286
+ type: "text",
287
+ text: JSON.stringify(result, null, 2),
288
+ },
289
+ ],
290
+ };
291
+ }
292
+ case "get_task_detail": {
293
+ const result = await knowfunClient.getTaskDetail(args?.taskId, args?.verbose);
294
+ return {
295
+ content: [
296
+ {
297
+ type: "text",
298
+ text: JSON.stringify(result, null, 2),
299
+ },
300
+ ],
301
+ };
302
+ }
303
+ case "list_tasks": {
304
+ const result = await knowfunClient.listTasks(args);
305
+ return {
306
+ content: [
307
+ {
308
+ type: "text",
309
+ text: JSON.stringify(result, null, 2),
310
+ },
311
+ ],
312
+ };
313
+ }
314
+ case "get_credits_balance": {
315
+ const result = await knowfunClient.getCreditsBalance();
316
+ return {
317
+ content: [
318
+ {
319
+ type: "text",
320
+ text: JSON.stringify(result, null, 2),
321
+ },
322
+ ],
323
+ };
324
+ }
325
+ case "get_credits_pricing": {
326
+ const result = await knowfunClient.getCreditsPricing();
327
+ return {
328
+ content: [
329
+ {
330
+ type: "text",
331
+ text: JSON.stringify(result, null, 2),
332
+ },
333
+ ],
334
+ };
335
+ }
336
+ case "get_schema": {
337
+ const result = await knowfunClient.getSchema();
338
+ return {
339
+ content: [
340
+ {
341
+ type: "text",
342
+ text: JSON.stringify(result, null, 2),
343
+ },
344
+ ],
345
+ };
346
+ }
347
+ case "get_usage": {
348
+ const result = await knowfunClient.getUsage(args);
349
+ return {
350
+ content: [
351
+ {
352
+ type: "text",
353
+ text: JSON.stringify(result, null, 2),
354
+ },
355
+ ],
356
+ };
357
+ }
358
+ default:
359
+ throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
360
+ }
361
+ }
362
+ catch (error) {
363
+ if (axios.isAxiosError(error)) {
364
+ const status = error.response?.status;
365
+ const message = error.response?.data?.error || error.message;
366
+ throw new McpError(ErrorCode.InternalError, `API Error (${status}): ${message}`);
367
+ }
368
+ throw new McpError(ErrorCode.InternalError, `Error: ${error.message}`);
369
+ }
370
+ });
371
+ // Start the server
372
+ async function main() {
373
+ const transport = new StdioServerTransport();
374
+ await server.connect(transport);
375
+ console.error("Knowfun MCP server running on stdio");
376
+ }
377
+ main().catch((error) => {
378
+ console.error("Fatal error:", error);
379
+ process.exit(1);
380
+ });
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "knowfun-mcp",
3
+ "version": "1.0.1",
4
+ "description": "MCP server for Knowfun.io OpenAPI - Generate courses, posters, games, and films using AI",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "knowfun-mcp": "dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "watch": "tsc --watch",
13
+ "start": "node dist/index.js",
14
+ "dev": "tsc && node dist/index.js",
15
+ "test": "node test-connection.js",
16
+ "prepublishOnly": "npm run build"
17
+ },
18
+ "keywords": [
19
+ "mcp",
20
+ "model-context-protocol",
21
+ "knowfun",
22
+ "openapi",
23
+ "ai",
24
+ "content-generation",
25
+ "course-generation",
26
+ "poster-generation",
27
+ "game-generation",
28
+ "claude",
29
+ "cursor",
30
+ "typescript"
31
+ ],
32
+ "author": "Knowfun.io <support@knowfun.io>",
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/knowfun/knowfun-mcp.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/knowfun/knowfun-mcp/issues"
40
+ },
41
+ "homepage": "https://github.com/knowfun/knowfun-mcp#readme",
42
+ "files": [
43
+ "dist/",
44
+ "README.md",
45
+ "LICENSE"
46
+ ],
47
+ "engines": {
48
+ "node": ">=18.0.0"
49
+ },
50
+ "dependencies": {
51
+ "@modelcontextprotocol/sdk": "^1.0.4",
52
+ "axios": "^1.7.9",
53
+ "dotenv": "^16.4.7"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^22.10.5",
57
+ "typescript": "^5.7.3"
58
+ }
59
+ }