@bashcat/ai-image-chat-mcp 2.3.1 → 2.3.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/dist/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bashcat/ai-image-chat-mcp",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "MCP server for AI image generation, video generation and chat completion with support for multiple AI providers including Tongyi Wanxiang",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/dist/example.js DELETED
@@ -1,119 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 老張 MCP 工具使用範例
4
- *
5
- * 這個文件展示如何與老張 MCP 工具進行交互
6
- */
7
- import { spawn } from 'child_process';
8
- // 模擬 MCP 客戶端
9
- class MCPClient {
10
- serverProcess;
11
- async start() {
12
- console.log('🚀 啟動老張 MCP 服務器...');
13
- // 啟動 MCP 服務器
14
- this.serverProcess = spawn('node', ['dist/index.js'], {
15
- stdio: ['pipe', 'pipe', 'inherit'],
16
- cwd: process.cwd()
17
- });
18
- // 等待服務器初始化
19
- await new Promise(resolve => setTimeout(resolve, 1000));
20
- console.log('✅ 服務器已啟動\n');
21
- // 發送初始化請求
22
- await this.sendRequest({
23
- jsonrpc: "2.0",
24
- id: 1,
25
- method: "initialize",
26
- params: {
27
- protocolVersion: "2024-11-05",
28
- capabilities: {},
29
- clientInfo: {
30
- name: "example-client",
31
- version: "1.0.0"
32
- }
33
- }
34
- });
35
- // 列出可用工具
36
- await this.listTools();
37
- // 示例:生成圖片
38
- await this.generateImage();
39
- // 示例:對話完成
40
- await this.chatCompletion();
41
- this.stop();
42
- }
43
- async sendRequest(request) {
44
- return new Promise((resolve, reject) => {
45
- const requestStr = JSON.stringify(request) + '\n';
46
- this.serverProcess.stdin.write(requestStr);
47
- // 監聽響應
48
- this.serverProcess.stdout.once('data', (data) => {
49
- try {
50
- const response = JSON.parse(data.toString().trim());
51
- resolve(response);
52
- }
53
- catch (error) {
54
- reject(error);
55
- }
56
- });
57
- });
58
- }
59
- async listTools() {
60
- console.log('📋 獲取可用工具列表...');
61
- const response = await this.sendRequest({
62
- jsonrpc: "2.0",
63
- id: 2,
64
- method: "tools/list"
65
- });
66
- console.log('可用工具:');
67
- response.result.tools.forEach((tool) => {
68
- console.log(` - ${tool.name}: ${tool.description}`);
69
- });
70
- console.log('');
71
- }
72
- async generateImage() {
73
- console.log('🖼️ 生成圖片示例...');
74
- const response = await this.sendRequest({
75
- jsonrpc: "2.0",
76
- id: 3,
77
- method: "tools/call",
78
- params: {
79
- name: "generate_image",
80
- arguments: {
81
- prompt: "生成一張卡通風格的熊貓宇航員圖片,背景是星空",
82
- system_prompt: "You are a creative image generator that creates beautiful and detailed images.",
83
- model: "gpt-image-1"
84
- }
85
- }
86
- });
87
- console.log('圖片生成結果:');
88
- console.log(response.result.content[0].text);
89
- console.log('');
90
- }
91
- async chatCompletion() {
92
- console.log('💬 對話完成示例...');
93
- const response = await this.sendRequest({
94
- jsonrpc: "2.0",
95
- id: 4,
96
- method: "tools/call",
97
- params: {
98
- name: "chat_completion",
99
- arguments: {
100
- message: "請幫我寫一首關於春天的詩",
101
- system_prompt: "You are a professional poet who writes beautiful Chinese poetry.",
102
- model: "gpt-4"
103
- }
104
- }
105
- });
106
- console.log('對話回覆:');
107
- console.log(response.result.content[0].text);
108
- console.log('');
109
- }
110
- stop() {
111
- console.log('🛑 停止服務器...');
112
- if (this.serverProcess) {
113
- this.serverProcess.kill();
114
- }
115
- }
116
- }
117
- // 運行示例
118
- const client = new MCPClient();
119
- client.start().catch(console.error);