@n0ts123/mcplink-core 0.0.1 → 0.0.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/README.md +92 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
-
# @mcplink
|
|
1
|
+
# @n0ts123/mcplink-core
|
|
2
2
|
|
|
3
|
-
MCPLink 核心 SDK - AI Agent
|
|
3
|
+
MCPLink 核心 SDK - AI Agent 工具调用框架,让 AI 轻松调用 MCP 工具。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@n0ts123/mcplink-core)
|
|
6
|
+
[](https://github.com/N0ts/MCPLink/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## 特性
|
|
9
|
+
|
|
10
|
+
- 🚀 **简单易用** - 几行代码即可让 AI 调用 MCP 工具
|
|
11
|
+
- 🔄 **流式响应** - 支持实时流式输出,体验更流畅
|
|
12
|
+
- 🤖 **多模型支持** - OpenAI、Claude、Gemini、DeepSeek、Qwen 等
|
|
13
|
+
- 🛠️ **MCP 协议** - 完整支持 stdio 和 SSE 两种连接方式
|
|
14
|
+
- 📦 **TypeScript & JavaScript** - 同时支持 TS 和 JS 项目
|
|
4
15
|
|
|
5
16
|
## 安装
|
|
6
17
|
|
|
7
18
|
```bash
|
|
8
|
-
npm
|
|
19
|
+
# npm
|
|
20
|
+
npm install @n0ts123/mcplink-core
|
|
21
|
+
|
|
22
|
+
# pnpm
|
|
23
|
+
pnpm add @n0ts123/mcplink-core
|
|
24
|
+
|
|
25
|
+
# yarn
|
|
26
|
+
yarn add @n0ts123/mcplink-core
|
|
9
27
|
```
|
|
10
28
|
|
|
11
29
|
根据你使用的模型,还需要安装对应的 AI SDK:
|
|
@@ -26,10 +44,38 @@ npm install @ai-sdk/anthropic
|
|
|
26
44
|
|
|
27
45
|
## 快速开始
|
|
28
46
|
|
|
29
|
-
###
|
|
47
|
+
### TypeScript 示例
|
|
30
48
|
|
|
31
49
|
```typescript
|
|
32
|
-
import { MCPLink } from '@mcplink
|
|
50
|
+
import { MCPLink } from '@n0ts123/mcplink-core'
|
|
51
|
+
import { createOpenAI } from '@ai-sdk/openai'
|
|
52
|
+
|
|
53
|
+
// 创建模型
|
|
54
|
+
const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY })
|
|
55
|
+
|
|
56
|
+
// 创建 Agent
|
|
57
|
+
const agent = new MCPLink({
|
|
58
|
+
model: openai('gpt-4o'),
|
|
59
|
+
mcpServers: {
|
|
60
|
+
myTools: {
|
|
61
|
+
type: 'stdio',
|
|
62
|
+
command: 'node',
|
|
63
|
+
args: ['./my-mcp-server.js'],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// 初始化并对话
|
|
69
|
+
await agent.initialize()
|
|
70
|
+
const result = await agent.chat('你好')
|
|
71
|
+
console.log(result.content)
|
|
72
|
+
await agent.close()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### JavaScript 示例 (ESM)
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
import { MCPLink } from '@n0ts123/mcplink-core'
|
|
33
79
|
import { createOpenAI } from '@ai-sdk/openai'
|
|
34
80
|
|
|
35
81
|
// 创建模型
|
|
@@ -54,10 +100,41 @@ console.log(result.content)
|
|
|
54
100
|
await agent.close()
|
|
55
101
|
```
|
|
56
102
|
|
|
103
|
+
### JavaScript 示例 (CommonJS)
|
|
104
|
+
|
|
105
|
+
> ⚠️ 注意:本包是 ES Module,在 CommonJS 环境中需要使用动态 import
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
async function main() {
|
|
109
|
+
const { MCPLink } = await import('@n0ts123/mcplink-core')
|
|
110
|
+
const { createOpenAI } = await import('@ai-sdk/openai')
|
|
111
|
+
|
|
112
|
+
const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY })
|
|
113
|
+
|
|
114
|
+
const agent = new MCPLink({
|
|
115
|
+
model: openai('gpt-4o'),
|
|
116
|
+
mcpServers: {
|
|
117
|
+
myTools: {
|
|
118
|
+
type: 'stdio',
|
|
119
|
+
command: 'node',
|
|
120
|
+
args: ['./my-mcp-server.js'],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
await agent.initialize()
|
|
126
|
+
const result = await agent.chat('你好')
|
|
127
|
+
console.log(result.content)
|
|
128
|
+
await agent.close()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
main()
|
|
132
|
+
```
|
|
133
|
+
|
|
57
134
|
### 流式响应
|
|
58
135
|
|
|
59
136
|
```typescript
|
|
60
|
-
import { MCPLink, MCPLinkEventType } from '@mcplink
|
|
137
|
+
import { MCPLink, MCPLinkEventType } from '@n0ts123/mcplink-core'
|
|
61
138
|
|
|
62
139
|
const agent = new MCPLink({
|
|
63
140
|
model: openai('gpt-4o'),
|
|
@@ -333,7 +410,7 @@ await agent.stopMCPServer('myServer')
|
|
|
333
410
|
如果你只需要使用特定的 Agent 实现:
|
|
334
411
|
|
|
335
412
|
```typescript
|
|
336
|
-
import { Agent, PromptBasedAgent, MCPManager } from '@mcplink
|
|
413
|
+
import { Agent, PromptBasedAgent, MCPManager } from '@n0ts123/mcplink-core'
|
|
337
414
|
import { createOpenAI } from '@ai-sdk/openai'
|
|
338
415
|
|
|
339
416
|
const openai = createOpenAI({ apiKey: '...' })
|
|
@@ -373,7 +450,7 @@ await mcpManager.stopAll()
|
|
|
373
450
|
### 自定义 MCP 管理器
|
|
374
451
|
|
|
375
452
|
```typescript
|
|
376
|
-
import { MCPManager } from '@mcplink
|
|
453
|
+
import { MCPManager } from '@n0ts123/mcplink-core'
|
|
377
454
|
|
|
378
455
|
const mcpManager = new MCPManager()
|
|
379
456
|
|
|
@@ -413,11 +490,16 @@ import type {
|
|
|
413
490
|
MCPTool,
|
|
414
491
|
MCPServerStatus,
|
|
415
492
|
ChatResult,
|
|
416
|
-
} from '@mcplink
|
|
493
|
+
} from '@n0ts123/mcplink-core'
|
|
417
494
|
|
|
418
|
-
import { MCPLinkEventType } from '@mcplink
|
|
495
|
+
import { MCPLinkEventType } from '@n0ts123/mcplink-core'
|
|
419
496
|
```
|
|
420
497
|
|
|
498
|
+
## 环境要求
|
|
499
|
+
|
|
500
|
+
- **Node.js**: >= 18.0.0
|
|
501
|
+
- **模块系统**: ES Module(推荐)或 CommonJS(需使用动态 import)
|
|
502
|
+
|
|
421
503
|
## 许可证
|
|
422
504
|
|
|
423
505
|
MIT
|