-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug-server.js
More file actions
143 lines (121 loc) · 3.96 KB
/
Copy pathdebug-server.js
File metadata and controls
143 lines (121 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* Google Apps Script MCP Server - デバッグ版
* ステップバイステップでエラー特定
*/
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import { execSync } from 'child_process';
console.log('🔍 Google Apps Script MCP Server デバッグ開始...');
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('📂 ディレクトリ情報:');
console.log(' __filename:', __filename);
console.log(' __dirname:', __dirname);
class GoogleAppsScriptMCPServer {
constructor() {
console.log('🏗️ サーバーコンストラクター開始...');
try {
this.server = new Server(
{
name: 'google-apps-script-mcp',
version: '1.1.0',
},
{
capabilities: {
tools: {},
},
}
);
console.log('✅ サーバーインスタンス作成成功');
} catch (error) {
console.error('❌ サーバーインスタンス作成エラー:', error);
throw error;
}
this.setupHandlers();
}
setupHandlers() {
console.log('🔧 ハンドラー設定開始...');
try {
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
console.log('📋 ListTools リクエスト受信');
return {
tools: [
{
name: 'test_tool',
description: 'テスト用ツール',
inputSchema: {
type: 'object',
properties: {}
}
}
],
};
});
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
console.log('🔧 CallTool リクエスト受信:', request.params.name);
return {
content: [
{
type: 'text',
text: 'テスト成功'
}
]
};
});
console.log('✅ ハンドラー設定完了');
} catch (error) {
console.error('❌ ハンドラー設定エラー:', error);
throw error;
}
}
async run() {
console.log('🚀 サーバー起動開始...');
try {
console.log('📡 StdioServerTransport 作成中...');
const transport = new StdioServerTransport();
console.log('✅ Transport 作成成功');
console.log('🔌 サーバー接続開始...');
await this.server.connect(transport);
console.log('✅ サーバー接続成功');
console.log('✅ Google Apps Script MCP Server が正常に起動しました');
// プロセスが終了しないようにする
process.stdin.resume();
} catch (error) {
console.error('❌ サーバー起動エラー:', error);
console.error('🔍 スタックトレース:', error.stack);
throw error;
}
}
}
// メイン実行部分
console.log('🎯 メイン実行開始...');
try {
const server = new GoogleAppsScriptMCPServer();
console.log('📡 run() メソッド呼び出し...');
server.run().catch(error => {
console.error('💥 run() 内でエラー:', error);
process.exit(1);
});
} catch (error) {
console.error('💥 メイン実行でエラー:', error);
process.exit(1);
}
// プロセス終了をキャッチ
process.on('exit', (code) => {
console.log(`🏁 プロセス終了 (コード: ${code})`);
});
process.on('SIGTERM', () => {
console.log('📡 SIGTERM受信');
process.exit(0);
});
process.on('SIGINT', () => {
console.log('📡 SIGINT受信');
process.exit(0);
});