-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathindex.ts
More file actions
241 lines (208 loc) · 8.3 KB
/
index.ts
File metadata and controls
241 lines (208 loc) · 8.3 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env node
import { startServer, GitHubServerOptions } from './server/index.js';
import { getI18n } from './i18n/index.js';
import { initializeI18n } from './i18n/index.js';
import { loadConfig } from './utils/config.js';
// Re-export config utilities
export * from './utils/config.js';
// Export i18n module
export * from './i18n/index.js';
// Re-export server components
export * from './server/index.js';
// Re-export repository API
export * from './api/repos/repository.js';
export * from './api/repos/types.js';
// Re-export admin API
export * from './api/admin/admin.js';
export * from './api/admin/types.js';
// Re-export issues API
export * from './api/issues/issues.js';
export * from './api/issues/types.js';
// Re-export actions API
export * from './api/actions/actions.js';
export * from './api/actions/types.js';
// Re-export users API
export * from './api/users/users.js';
export * from './api/users/types.js';
// Default CLI entry point
// ES 모듈 환경에서 실행 여부 확인 - NPX 환경 포함
const isDirectRun = process.argv[1] === import.meta.url ||
process.argv[1]?.endsWith('/index.js') ||
process.argv[1]?.endsWith('\\index.js') ||
process.argv[1]?.includes('@ddukbg/github-enterprise-mcp') ||
process.argv[0]?.includes('node') || // node 명령어로 직접 실행
process.env.npm_execpath?.includes('npx'); // npx로 실행
// 항상 실행되는 디버그 로그 (런타임 진단용)
if (process.env.DEBUG_MCP) {
console.log('Runtime debug info:');
console.log('process.argv:', process.argv);
console.log('import.meta.url:', import.meta.url);
console.log('isDirectRun:', isDirectRun);
console.log('process.env.npm_execpath:', process.env.npm_execpath);
}
if (isDirectRun) {
// Parse CLI arguments
const args = process.argv.slice(2);
// 디버깅용 로그
console.log('Command line arguments:', args);
// Parse language argument
let language: string | undefined;
for (let i = 0; i < args.length; i++) {
if (args[i] === '--language' && i + 1 < args.length) {
language = args[i + 1];
break;
} else if (args[i].startsWith('--language=')) {
language = args[i].split('=')[1];
break;
}
}
const options: GitHubServerOptions = {
config: {
// 환경 변수에서 설정 불러오기
baseUrl: process.env.GITHUB_ENTERPRISE_URL || process.env.GITHUB_API_URL,
token: process.env.GITHUB_TOKEN,
debug: process.env.DEBUG === 'true' || false,
language: (language || process.env.LANGUAGE || 'en') as 'en' | 'ko'
}
};
// 디버깅용 로그
console.log('Environment variables:');
console.log('GITHUB_ENTERPRISE_URL:', process.env.GITHUB_ENTERPRISE_URL || '(none)');
console.log('GITHUB_TOKEN:', process.env.GITHUB_TOKEN ? '(set)' : '(none)');
// Improved argument parsing
for (let i = 0; i < args.length; i++) {
const arg = args[i];
// Handle --option=value format
if (arg.includes('=')) {
console.log(`Processing argument with =: ${arg}`);
let [key, value] = arg.split('=', 2);
if (key === '--baseUrl' || key === '--github-api-url' || key === '--github-enterprise-url') {
console.log(`Setting baseUrl to: ${value}`);
options.config!.baseUrl = value;
}
else if (key === '--token') {
console.log('Setting token from --token=value format');
options.config!.token = value;
}
else if (key === '--transport') {
if (value === 'http' || value === 'stdio') {
console.log(`Setting transport to: ${value}`);
options.transport = value;
} else {
console.warn(`Unsupported transport type: ${value}. Setting to 'stdio'.`);
options.transport = 'stdio';
}
}
else if (key === '--debug') {
options.config!.debug = value !== 'false';
}
continue;
}
// Handle --option value format
if (arg === '--baseUrl' && i + 1 < args.length) {
console.log(`Setting baseUrl to: ${args[i+1]}`);
options.config!.baseUrl = args[++i];
}
else if (arg === '--github-api-url' && i + 1 < args.length) {
console.log(`Setting baseUrl to: ${args[i+1]}`);
options.config!.baseUrl = args[++i];
}
else if (arg === '--github-enterprise-url' && i + 1 < args.length) {
console.log(`Setting baseUrl to: ${args[i+1]}`);
options.config!.baseUrl = args[++i];
}
else if (arg === '--token' && i + 1 < args.length) {
console.log('Setting token from --token value format');
options.config!.token = args[++i];
}
else if (arg === '--transport' && i + 1 < args.length) {
const transportValue = args[++i];
if (transportValue === 'http' || transportValue === 'stdio') {
console.log(`Setting transport to: ${transportValue}`);
options.transport = transportValue;
} else {
console.warn(`Unsupported transport type: ${transportValue}. Setting to 'stdio'.`);
options.transport = 'stdio';
}
}
else if (arg === '--debug') {
options.config!.debug = true;
}
else if (arg === '--help') {
// Get i18n instance if available, or fall back to English
let helpText;
try {
helpText = `
MCP GitHub Enterprise Server
Usage:
npx @ddukbg/github-enterprise-mcp [options]
Options:
--baseUrl <url> GitHub Enterprise API base URL
(default: https://api.github.com)
--github-api-url <url> GitHub API URL (same as --baseUrl)
--github-enterprise-url <url> GitHub Enterprise URL (same as --baseUrl)
--token <token> GitHub personal access token
--transport <type> Transport type (stdio or http)
(default: stdio)
--debug Enable debug mode
--language <lang> Language (en or ko, default: en)
--help Show this help
Environment Variables:
GITHUB_ENTERPRISE_URL GitHub Enterprise API URL
GITHUB_API_URL GitHub API URL
GITHUB_TOKEN GitHub personal access token
DEBUG=true Enable debug mode
LANGUAGE Language (en or ko, default: en)
`;
} catch (e) {
// Fallback if i18n is not initialized
helpText = `
MCP GitHub Enterprise Server
Usage:
npx @ddukbg/github-enterprise-mcp [options]
Options:
--baseUrl <url> GitHub Enterprise API base URL
(default: https://api.github.com)
--github-api-url <url> GitHub API URL (same as --baseUrl)
--github-enterprise-url <url> GitHub Enterprise URL (same as --baseUrl)
--token <token> GitHub personal access token
--transport <type> Transport type (stdio or http)
(default: stdio)
--debug Enable debug mode
--language <lang> Language (en or ko, default: en)
--help Show this help
Environment Variables:
GITHUB_ENTERPRISE_URL GitHub Enterprise API URL
GITHUB_API_URL GitHub API URL
GITHUB_TOKEN GitHub personal access token
DEBUG=true Enable debug mode
LANGUAGE Language (en or ko, default: en)
`;
}
console.log(helpText);
process.exit(0);
}
}
// 설정 상태 확인
console.log('Final configuration:');
console.log('baseUrl:', options.config?.baseUrl || '(none)');
console.log('token:', options.config?.token ? '(set)' : '(none)');
console.log('transport:', options.transport || 'stdio');
console.log('debug:', options.config?.debug ? 'true' : 'false');
console.log('language:', options.config?.language || 'en');
console.log('Starting MCP GitHub Enterprise Server...');
if (options.config?.baseUrl) {
console.log(`Detected GitHub API URL: ${options.config.baseUrl}`);
} else {
console.log(`Detected GitHub API URL: (none)`);
}
console.log(`Token provided: ${options.config?.token ? 'yes' : 'no'}`);
// Initialize i18n with loaded config
const config = loadConfig(options.config);
initializeI18n(config);
// Start server
startServer(options).catch(error => {
console.error('Failed to start server:', error);
process.exit(1);
});
}