bluelamp 2.0.9 → 3.0.0
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 +12 -25
- package/bin/bluelamp +368 -0
- package/bin/bluelamp-base +368 -0
- package/bin/bluelamp10 +368 -0
- package/bin/bluelamp100 +368 -0
- package/bin/bluelamp11 +368 -0
- package/bin/bluelamp12 +368 -0
- package/bin/bluelamp13 +368 -0
- package/bin/bluelamp14 +368 -0
- package/bin/bluelamp15 +368 -0
- package/bin/bluelamp16 +368 -0
- package/bin/bluelamp17 +368 -0
- package/bin/bluelamp18 +368 -0
- package/bin/bluelamp19 +368 -0
- package/bin/bluelamp2 +368 -0
- package/bin/bluelamp20 +368 -0
- package/bin/bluelamp21 +368 -0
- package/bin/bluelamp22 +368 -0
- package/bin/bluelamp23 +368 -0
- package/bin/bluelamp24 +368 -0
- package/bin/bluelamp25 +368 -0
- package/bin/bluelamp26 +368 -0
- package/bin/bluelamp27 +368 -0
- package/bin/bluelamp28 +368 -0
- package/bin/bluelamp29 +368 -0
- package/bin/bluelamp3 +368 -0
- package/bin/bluelamp30 +368 -0
- package/bin/bluelamp31 +368 -0
- package/bin/bluelamp32 +368 -0
- package/bin/bluelamp33 +368 -0
- package/bin/bluelamp34 +368 -0
- package/bin/bluelamp35 +368 -0
- package/bin/bluelamp36 +368 -0
- package/bin/bluelamp37 +368 -0
- package/bin/bluelamp38 +368 -0
- package/bin/bluelamp39 +368 -0
- package/bin/bluelamp4 +368 -0
- package/bin/bluelamp40 +368 -0
- package/bin/bluelamp41 +368 -0
- package/bin/bluelamp42 +368 -0
- package/bin/bluelamp43 +368 -0
- package/bin/bluelamp44 +368 -0
- package/bin/bluelamp45 +368 -0
- package/bin/bluelamp46 +368 -0
- package/bin/bluelamp47 +368 -0
- package/bin/bluelamp48 +368 -0
- package/bin/bluelamp49 +368 -0
- package/bin/bluelamp5 +368 -0
- package/bin/bluelamp50 +368 -0
- package/bin/bluelamp51 +368 -0
- package/bin/bluelamp52 +368 -0
- package/bin/bluelamp53 +368 -0
- package/bin/bluelamp54 +368 -0
- package/bin/bluelamp55 +368 -0
- package/bin/bluelamp56 +368 -0
- package/bin/bluelamp57 +368 -0
- package/bin/bluelamp58 +368 -0
- package/bin/bluelamp59 +368 -0
- package/bin/bluelamp6 +368 -0
- package/bin/bluelamp60 +368 -0
- package/bin/bluelamp61 +368 -0
- package/bin/bluelamp62 +368 -0
- package/bin/bluelamp63 +368 -0
- package/bin/bluelamp64 +368 -0
- package/bin/bluelamp65 +368 -0
- package/bin/bluelamp66 +368 -0
- package/bin/bluelamp67 +368 -0
- package/bin/bluelamp68 +368 -0
- package/bin/bluelamp69 +368 -0
- package/bin/bluelamp7 +368 -0
- package/bin/bluelamp70 +368 -0
- package/bin/bluelamp71 +368 -0
- package/bin/bluelamp72 +368 -0
- package/bin/bluelamp73 +368 -0
- package/bin/bluelamp74 +368 -0
- package/bin/bluelamp75 +368 -0
- package/bin/bluelamp76 +368 -0
- package/bin/bluelamp77 +368 -0
- package/bin/bluelamp78 +368 -0
- package/bin/bluelamp79 +368 -0
- package/bin/bluelamp8 +368 -0
- package/bin/bluelamp80 +368 -0
- package/bin/bluelamp81 +368 -0
- package/bin/bluelamp82 +368 -0
- package/bin/bluelamp83 +368 -0
- package/bin/bluelamp84 +368 -0
- package/bin/bluelamp85 +368 -0
- package/bin/bluelamp86 +368 -0
- package/bin/bluelamp87 +368 -0
- package/bin/bluelamp88 +368 -0
- package/bin/bluelamp89 +368 -0
- package/bin/bluelamp9 +368 -0
- package/bin/bluelamp90 +368 -0
- package/bin/bluelamp91 +368 -0
- package/bin/bluelamp92 +368 -0
- package/bin/bluelamp93 +368 -0
- package/bin/bluelamp94 +368 -0
- package/bin/bluelamp95 +368 -0
- package/bin/bluelamp96 +368 -0
- package/bin/bluelamp97 +368 -0
- package/bin/bluelamp98 +368 -0
- package/bin/bluelamp99 +368 -0
- package/lib/mcp-server/dist/bluelamp-system.js +32 -0
- package/lib/mcp-server/dist/crypto-utils.js +27 -0
- package/lib/mcp-server/dist/database-version.js +33 -0
- package/lib/mcp-server/dist/index.js +62 -0
- package/lib/mcp-server/dist/plugins/base-plugin.js +24 -0
- package/lib/mcp-server/dist/plugins/plugin-manager.js +31 -0
- package/lib/mcp-server/dist/plugins/services/leonardo-plugin.js +95 -0
- package/lib/mcp-server/dist/plugins/services/leonardo-prompt-parser.js +36 -0
- package/lib/mcp-server/dist/plugins/services/portal-api-client.js +22 -0
- package/lib/mcp-server/dist/plugins/services/portal-plugin.js +52 -0
- package/lib/mcp-server/dist/secure-mcp-server.js +76 -0
- package/lib/mcp-server/dist/security/ApiKeyManager.js +24 -0
- package/lib/mcp-server/dist/security/InteractiveLogin.js +32 -0
- package/lib/mcp-server/dist/security/PortalAuthClient.js +1 -0
- package/lib/mcp-server/dist/security/SimpleAuthManager.js +1 -0
- package/lib/mcp-server/dist/security/TokenManager.js +25 -0
- package/lib/mcp-server/package.json +21 -0
- package/package.json +119 -35
- package/INSTALLATION_GUIDE.md +0 -109
- package/bin/blcf +0 -2
- package/bin/blcf2 +0 -28
- package/bin/blcf3 +0 -2
- package/bin/blcf4 +0 -2
- package/knowledge-injection/hooks/inject-encrypted.sh +0 -321
- package/lib/agents//343/203/225/343/202/231/343/203/253/343/203/274/343/203/251/343/203/263/343/203/225/343/202/232.md +0 -106
- package/lib/mcp-server/dist_optimized/bluelamp-system.d.ts +0 -29
- package/lib/mcp-server/dist_optimized/bluelamp-system.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/bluelamp-system.js +0 -1
- package/lib/mcp-server/dist_optimized/bluelamp-system.js.bak +0 -340
- package/lib/mcp-server/dist_optimized/bluelamp-system.js.map +0 -1
- package/lib/mcp-server/dist_optimized/crypto-utils.d.ts +0 -33
- package/lib/mcp-server/dist_optimized/crypto-utils.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/crypto-utils.js +0 -1
- package/lib/mcp-server/dist_optimized/crypto-utils.js.map +0 -1
- package/lib/mcp-server/dist_optimized/database-version.d.ts +0 -72
- package/lib/mcp-server/dist_optimized/database-version.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/database-version.js +0 -2
- package/lib/mcp-server/dist_optimized/database-version.js.bak +0 -374
- package/lib/mcp-server/dist_optimized/database-version.js.map +0 -1
- package/lib/mcp-server/dist_optimized/index.d.ts +0 -3
- package/lib/mcp-server/dist_optimized/index.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/index.js +0 -2
- package/lib/mcp-server/dist_optimized/index.js.map +0 -1
- package/lib/mcp-server/dist_optimized/secure-mcp-server.d.ts +0 -64
- package/lib/mcp-server/dist_optimized/secure-mcp-server.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/secure-mcp-server.js +0 -1
- package/lib/mcp-server/dist_optimized/secure-mcp-server.js.bak +0 -1
- package/lib/mcp-server/dist_optimized/secure-mcp-server.js.bak2 +0 -1
- package/lib/mcp-server/dist_optimized/secure-mcp-server.js.map +0 -1
- package/lib/mcp-server/dist_optimized/security/InteractiveLogin.d.ts +0 -47
- package/lib/mcp-server/dist_optimized/security/InteractiveLogin.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/security/InteractiveLogin.js +0 -1
- package/lib/mcp-server/dist_optimized/security/InteractiveLogin.js.map +0 -1
- package/lib/mcp-server/dist_optimized/security/PortalAuthClient.d.ts +0 -65
- package/lib/mcp-server/dist_optimized/security/PortalAuthClient.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/security/PortalAuthClient.js +0 -1
- package/lib/mcp-server/dist_optimized/security/PortalAuthClient.js.map +0 -1
- package/lib/mcp-server/dist_optimized/security/SimpleAuthManager.backup +0 -294
- package/lib/mcp-server/dist_optimized/security/SimpleAuthManager.d.ts +0 -71
- package/lib/mcp-server/dist_optimized/security/SimpleAuthManager.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/security/SimpleAuthManager.js +0 -1
- package/lib/mcp-server/dist_optimized/security/SimpleAuthManager.js.backup +0 -25
- package/lib/mcp-server/dist_optimized/security/SimpleAuthManager.js.map +0 -1
- package/lib/mcp-server/dist_optimized/security/TokenManager.d.ts +0 -61
- package/lib/mcp-server/dist_optimized/security/TokenManager.d.ts.map +0 -1
- package/lib/mcp-server/dist_optimized/security/TokenManager.js +0 -1
- package/lib/mcp-server/dist_optimized/security/TokenManager.js.map +0 -1
- package/scripts/setup-agents.js +0 -9
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* データベース管理版MCPサーバー
|
|
5
|
-
* プロンプトをSQLiteデータベースで管理する実装例
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.PromptDatabase = exports.DatabaseMCPServer = void 0;
|
|
9
|
-
const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
10
|
-
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
11
|
-
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
12
|
-
// デバッグログ用ヘルパー
|
|
13
|
-
function debugLog(message, data) {
|
|
14
|
-
// 完全静寂モード - 全ログ無効化
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* データベース管理クラス
|
|
18
|
-
*/
|
|
19
|
-
class PromptDatabase {
|
|
20
|
-
// private db: sqlite3.Database;
|
|
21
|
-
constructor() {
|
|
22
|
-
// 実際の実装では以下のようにSQLiteを初期化
|
|
23
|
-
// this.db = new sqlite3.Database('./prompts.db');
|
|
24
|
-
// this.initializeDatabase();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* データベース初期化
|
|
28
|
-
*/
|
|
29
|
-
initializeDatabase() {
|
|
30
|
-
const schema = `
|
|
31
|
-
CREATE TABLE IF NOT EXISTS prompts (
|
|
32
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
33
|
-
uri TEXT UNIQUE NOT NULL,
|
|
34
|
-
title TEXT NOT NULL,
|
|
35
|
-
content TEXT NOT NULL,
|
|
36
|
-
category TEXT DEFAULT 'general',
|
|
37
|
-
tags TEXT DEFAULT '',
|
|
38
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
39
|
-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
CREATE INDEX IF NOT EXISTS idx_prompts_category ON prompts(category);
|
|
43
|
-
CREATE INDEX IF NOT EXISTS idx_prompts_uri ON prompts(uri);
|
|
44
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS prompts_fts USING fts5(
|
|
45
|
-
title, content, tags, content='prompts', content_rowid='id'
|
|
46
|
-
);
|
|
47
|
-
`;
|
|
48
|
-
debugLog('データベーススキーマ初期化', { schema });
|
|
49
|
-
// this.db.exec(schema);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* プロンプト検索
|
|
53
|
-
*/
|
|
54
|
-
async searchPrompts(query, category, limit = 10) {
|
|
55
|
-
debugLog('プロンプト検索', { query, category, limit });
|
|
56
|
-
// 実際の実装例(現在はモックデータ)
|
|
57
|
-
const mockData = [
|
|
58
|
-
{
|
|
59
|
-
id: 1,
|
|
60
|
-
uri: 'prompt://sample/greeting',
|
|
61
|
-
title: '挨拶プロンプト',
|
|
62
|
-
content: 'こんにちは!私はAIアシスタントです。',
|
|
63
|
-
category: 'general',
|
|
64
|
-
tags: '挨拶,基本',
|
|
65
|
-
created_at: new Date().toISOString(),
|
|
66
|
-
updated_at: new Date().toISOString()
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
id: 2,
|
|
70
|
-
uri: 'prompt://sample/analysis',
|
|
71
|
-
title: '分析プロンプト',
|
|
72
|
-
content: 'データを詳細に分析し、洞察を提供します。',
|
|
73
|
-
category: 'analysis',
|
|
74
|
-
tags: '分析,データ',
|
|
75
|
-
created_at: new Date().toISOString(),
|
|
76
|
-
updated_at: new Date().toISOString()
|
|
77
|
-
}
|
|
78
|
-
];
|
|
79
|
-
// フィルタリング
|
|
80
|
-
let results = mockData;
|
|
81
|
-
if (category) {
|
|
82
|
-
results = results.filter(p => p.category === category);
|
|
83
|
-
}
|
|
84
|
-
if (query) {
|
|
85
|
-
const lowerQuery = query.toLowerCase();
|
|
86
|
-
results = results.filter(p => p.title.toLowerCase().includes(lowerQuery) ||
|
|
87
|
-
p.content.toLowerCase().includes(lowerQuery) ||
|
|
88
|
-
p.tags.toLowerCase().includes(lowerQuery));
|
|
89
|
-
}
|
|
90
|
-
return results.slice(0, limit);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* URIでプロンプト取得
|
|
94
|
-
*/
|
|
95
|
-
async getPromptByUri(uri) {
|
|
96
|
-
debugLog('URI検索', { uri });
|
|
97
|
-
// モックデータから検索
|
|
98
|
-
const mockData = await this.searchPrompts();
|
|
99
|
-
return mockData.find(p => p.uri === uri) || null;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* プロンプト追加
|
|
103
|
-
*/
|
|
104
|
-
async addPrompt(data) {
|
|
105
|
-
debugLog('プロンプト追加', data);
|
|
106
|
-
// 実際の実装では以下のようにINSERT
|
|
107
|
-
const newPrompt = {
|
|
108
|
-
id: Date.now(), // 実際はAUTO_INCREMENT
|
|
109
|
-
uri: data.uri,
|
|
110
|
-
title: data.title,
|
|
111
|
-
content: data.content,
|
|
112
|
-
category: data.category || 'general',
|
|
113
|
-
tags: data.tags || '',
|
|
114
|
-
created_at: new Date().toISOString(),
|
|
115
|
-
updated_at: new Date().toISOString()
|
|
116
|
-
};
|
|
117
|
-
return newPrompt;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* カテゴリ一覧取得
|
|
121
|
-
*/
|
|
122
|
-
async getCategories() {
|
|
123
|
-
debugLog('カテゴリ一覧取得');
|
|
124
|
-
// 実際の実装では以下のようにSELECT DISTINCT
|
|
125
|
-
return ['general', 'analysis', 'creative', 'technical'];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.PromptDatabase = PromptDatabase;
|
|
129
|
-
/**
|
|
130
|
-
* データベース版MCPサーバー
|
|
131
|
-
*/
|
|
132
|
-
class DatabaseMCPServer {
|
|
133
|
-
constructor() {
|
|
134
|
-
this.server = new index_js_1.Server({
|
|
135
|
-
name: 'database-mcp-server',
|
|
136
|
-
version: '1.0.0',
|
|
137
|
-
}, {
|
|
138
|
-
capabilities: {
|
|
139
|
-
resources: {},
|
|
140
|
-
tools: {},
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
this.database = new PromptDatabase();
|
|
144
|
-
this.setupHandlers();
|
|
145
|
-
}
|
|
146
|
-
setupHandlers() {
|
|
147
|
-
// リソース一覧ハンドラー
|
|
148
|
-
this.server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => {
|
|
149
|
-
debugLog('リソース一覧要求');
|
|
150
|
-
try {
|
|
151
|
-
const prompts = await this.database.searchPrompts();
|
|
152
|
-
const resources = prompts.map(prompt => ({
|
|
153
|
-
uri: prompt.uri,
|
|
154
|
-
name: prompt.title,
|
|
155
|
-
description: `${prompt.category} - ${prompt.content.substring(0, 100)}...`,
|
|
156
|
-
mimeType: 'text/plain'
|
|
157
|
-
}));
|
|
158
|
-
debugLog('リソース一覧応答', { count: resources.length });
|
|
159
|
-
return { resources };
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
debugLog('リソース一覧エラー', { error: error.message });
|
|
163
|
-
return { resources: [] };
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
// リソース読み取りハンドラー
|
|
167
|
-
this.server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => {
|
|
168
|
-
const { uri } = request.params;
|
|
169
|
-
debugLog('リソース読み取り要求', { uri });
|
|
170
|
-
try {
|
|
171
|
-
const prompt = await this.database.getPromptByUri(uri);
|
|
172
|
-
if (!prompt) {
|
|
173
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidRequest, `プロンプトが見つかりません: ${uri}`);
|
|
174
|
-
}
|
|
175
|
-
debugLog('リソース読み取り成功', { uri, title: prompt.title });
|
|
176
|
-
return {
|
|
177
|
-
contents: [{
|
|
178
|
-
uri: prompt.uri,
|
|
179
|
-
mimeType: 'text/plain',
|
|
180
|
-
text: prompt.content
|
|
181
|
-
}]
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
debugLog('リソース読み取りエラー', { uri, error: error.message });
|
|
186
|
-
if (error instanceof types_js_1.McpError) {
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `リソース読み取りエラー: ${error.message}`);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
// ツール一覧ハンドラー
|
|
193
|
-
this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
194
|
-
debugLog('ツール一覧要求');
|
|
195
|
-
const tools = [
|
|
196
|
-
{
|
|
197
|
-
name: 'search_prompts',
|
|
198
|
-
description: 'データベースからプロンプトを検索します',
|
|
199
|
-
inputSchema: {
|
|
200
|
-
type: 'object',
|
|
201
|
-
properties: {
|
|
202
|
-
query: {
|
|
203
|
-
type: 'string',
|
|
204
|
-
description: '検索クエリ(タイトル、内容、タグを対象)'
|
|
205
|
-
},
|
|
206
|
-
category: {
|
|
207
|
-
type: 'string',
|
|
208
|
-
description: 'カテゴリでフィルタ'
|
|
209
|
-
},
|
|
210
|
-
limit: {
|
|
211
|
-
type: 'number',
|
|
212
|
-
description: '取得件数の上限',
|
|
213
|
-
default: 10
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
required: []
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: 'add_prompt',
|
|
221
|
-
description: 'データベースに新しいプロンプトを追加します',
|
|
222
|
-
inputSchema: {
|
|
223
|
-
type: 'object',
|
|
224
|
-
properties: {
|
|
225
|
-
uri: {
|
|
226
|
-
type: 'string',
|
|
227
|
-
description: 'プロンプトのURI'
|
|
228
|
-
},
|
|
229
|
-
title: {
|
|
230
|
-
type: 'string',
|
|
231
|
-
description: 'プロンプトのタイトル'
|
|
232
|
-
},
|
|
233
|
-
content: {
|
|
234
|
-
type: 'string',
|
|
235
|
-
description: 'プロンプトの内容'
|
|
236
|
-
},
|
|
237
|
-
category: {
|
|
238
|
-
type: 'string',
|
|
239
|
-
description: 'カテゴリ',
|
|
240
|
-
default: 'general'
|
|
241
|
-
},
|
|
242
|
-
tags: {
|
|
243
|
-
type: 'string',
|
|
244
|
-
description: 'タグ(カンマ区切り)'
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
required: ['uri', 'title', 'content']
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
name: 'get_categories',
|
|
252
|
-
description: '利用可能なカテゴリ一覧を取得します',
|
|
253
|
-
inputSchema: {
|
|
254
|
-
type: 'object',
|
|
255
|
-
properties: {},
|
|
256
|
-
required: []
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
];
|
|
260
|
-
return { tools };
|
|
261
|
-
});
|
|
262
|
-
// ツール実行ハンドラー
|
|
263
|
-
this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
264
|
-
const { name, arguments: args } = request.params;
|
|
265
|
-
debugLog(`ツール実行要求: ${name}`, args);
|
|
266
|
-
try {
|
|
267
|
-
switch (name) {
|
|
268
|
-
case 'search_prompts':
|
|
269
|
-
return await this.handleSearchPrompts(args || {});
|
|
270
|
-
case 'add_prompt':
|
|
271
|
-
return await this.handleAddPrompt(args);
|
|
272
|
-
case 'get_categories':
|
|
273
|
-
return await this.handleGetCategories();
|
|
274
|
-
default:
|
|
275
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `不明なツール: ${name}`);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
debugLog('ツール実行エラー', { name, error: error.message });
|
|
280
|
-
if (error instanceof types_js_1.McpError) {
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
283
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `ツール実行エラー: ${error.message}`);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* プロンプト検索ツールの実装
|
|
289
|
-
*/
|
|
290
|
-
async handleSearchPrompts(args) {
|
|
291
|
-
const { query, category, limit = 10 } = args;
|
|
292
|
-
debugLog('プロンプト検索実行', { query, category, limit });
|
|
293
|
-
try {
|
|
294
|
-
const results = await this.database.searchPrompts(query, category, limit);
|
|
295
|
-
const content = {
|
|
296
|
-
type: 'text',
|
|
297
|
-
text: `検索結果: ${results.length}件\n\n` +
|
|
298
|
-
results.map(p => `【${p.title}】\n` +
|
|
299
|
-
`URI: ${p.uri}\n` +
|
|
300
|
-
`カテゴリ: ${p.category}\n` +
|
|
301
|
-
`内容: ${p.content.substring(0, 100)}...\n` +
|
|
302
|
-
`タグ: ${p.tags}\n`).join('\n')
|
|
303
|
-
};
|
|
304
|
-
debugLog('プロンプト検索完了', { count: results.length });
|
|
305
|
-
return { content: [content] };
|
|
306
|
-
}
|
|
307
|
-
catch (error) {
|
|
308
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `検索エラー: ${error.message}`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* プロンプト追加ツールの実装
|
|
313
|
-
*/
|
|
314
|
-
async handleAddPrompt(args) {
|
|
315
|
-
const { uri, title, content, category, tags } = args;
|
|
316
|
-
if (!uri || !title || !content) {
|
|
317
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, 'uri, title, contentは必須です');
|
|
318
|
-
}
|
|
319
|
-
debugLog('プロンプト追加実行', { uri, title, category });
|
|
320
|
-
try {
|
|
321
|
-
const newPrompt = await this.database.addPrompt({
|
|
322
|
-
uri, title, content, category, tags
|
|
323
|
-
});
|
|
324
|
-
const responseContent = {
|
|
325
|
-
type: 'text',
|
|
326
|
-
text: `プロンプトを追加しました:\n\n` +
|
|
327
|
-
`【${newPrompt.title}】\n` +
|
|
328
|
-
`URI: ${newPrompt.uri}\n` +
|
|
329
|
-
`カテゴリ: ${newPrompt.category}\n` +
|
|
330
|
-
`ID: ${newPrompt.id}\n` +
|
|
331
|
-
`作成日時: ${newPrompt.created_at}`
|
|
332
|
-
};
|
|
333
|
-
debugLog('プロンプト追加完了', { id: newPrompt.id, uri: newPrompt.uri });
|
|
334
|
-
return { content: [responseContent] };
|
|
335
|
-
}
|
|
336
|
-
catch (error) {
|
|
337
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `追加エラー: ${error.message}`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* カテゴリ一覧ツールの実装
|
|
342
|
-
*/
|
|
343
|
-
async handleGetCategories() {
|
|
344
|
-
debugLog('カテゴリ一覧取得実行');
|
|
345
|
-
try {
|
|
346
|
-
const categories = await this.database.getCategories();
|
|
347
|
-
const content = {
|
|
348
|
-
type: 'text',
|
|
349
|
-
text: `利用可能なカテゴリ:\n\n` +
|
|
350
|
-
categories.map(cat => `- ${cat}`).join('\n')
|
|
351
|
-
};
|
|
352
|
-
debugLog('カテゴリ一覧取得完了', { count: categories.length });
|
|
353
|
-
return { content: [content] };
|
|
354
|
-
}
|
|
355
|
-
catch (error) {
|
|
356
|
-
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `カテゴリ取得エラー: ${error.message}`);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
async run() {
|
|
360
|
-
debugLog('データベース版MCPサーバー開始');
|
|
361
|
-
const transport = new stdio_js_1.StdioServerTransport();
|
|
362
|
-
await this.server.connect(transport);
|
|
363
|
-
debugLog('データベース版MCPサーバー接続完了');
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
exports.DatabaseMCPServer = DatabaseMCPServer;
|
|
367
|
-
// サーバー起動
|
|
368
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
369
|
-
const server = new DatabaseMCPServer();
|
|
370
|
-
server.run().catch((error) => {
|
|
371
|
-
process.exit(1);
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
//# sourceMappingURL=database-version.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database-version.js","sourceRoot":"","sources":["../src/database-version.ts"],"names":[],"mappings":";;AAEA;;;GAGG;;;AAEH,wEAAmE;AACnE,wEAAiF;AACjF,iEAO4C;AAE5C,cAAc;AACd,SAAS,QAAQ,CAAC,OAAe,EAAE,IAAU;IAC3C,mBAAmB;AACrB,CAAC;AA2BD;;GAEG;AACH,MAAM,cAAc;IAClB,gCAAgC;IAEhC;QACE,0BAA0B;QAC1B,kDAAkD;QAClD,6BAA6B;IAC/B,CAAC;IAED;;OAEG;IACK,kBAAkB;QACxB,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;KAiBd,CAAC;QAEF,QAAQ,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACtC,wBAAwB;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,KAAc,EAAE,QAAiB,EAAE,QAAgB,EAAE;QACvE,QAAQ,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QAEhD,oBAAoB;QACpB,MAAM,QAAQ,GAAmB;YAC/B;gBACE,EAAE,EAAE,CAAC;gBACL,GAAG,EAAE,0BAA0B;gBAC/B,KAAK,EAAE,SAAS;gBAChB,OAAO,EAAE,qBAAqB;gBAC9B,QAAQ,EAAE,SAAS;gBACnB,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;gBACpC,U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AAC,CAAC;QAC7B,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IACjC,CAAC;CACF;AAUQ,8CAAiB;AAR1B,SAAS;AACT,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACpD,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACvC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e,t=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)},function(n){if(n&&n.__esModule)return n;var o={};if(null!=n)for(var s=e(n),i=0;i<s.length;i++)"default"!==s[i]&&t(o,n,s[i]);return r(o,n),o});Object.defineProperty(exports,"__esModule",{value:!0});const o=require("@modelcontextprotocol/sdk/server/index.js"),s=require("@modelcontextprotocol/sdk/server/stdio.js"),i=require("@modelcontextprotocol/sdk/types.js");(new class{constructor(){this.server=new o.Server({name:"sample-mcp-server",version:"1.0.0"},{capabilities:{tools:{},resources:{}}}),this.setupHandlers()}setupHandlers(){this.server.setRequestHandler(i.ListResourcesRequestSchema,async()=>({resources:[]})),this.server.setRequestHandler(i.ReadResourceRequestSchema,async e=>{const{uri:t}=e.params;throw new i.McpError(i.ErrorCode.InvalidRequest,`リソースが見つかりません: ${t}`)}),this.server.setRequestHandler(i.ListToolsRequestSchema,async()=>({tools:[{name:"get_current_time",description:"現在の日時を取得します",inputSchema:{type:"object",properties:{timezone:{type:"string",description:"タイムゾーン (例: Asia/Tokyo)",default:"Asia/Tokyo"}},required:[]}},{name:"calculate",description:"数学的な計算を実行します",inputSchema:{type:"object",properties:{expression:{type:"string",description:"計算式 (例: 2 + 3 * 4)"}},required:["expression"]}},{name:"echo",description:"メッセージをそのまま返します",inputSchema:{type:"object",properties:{message:{type:"string",description:"返すメッセージ"}},required:["message"]}},{name:"inject_knowledge",description:"Portal APIから専門知識を注入します",inputSchema:{type:"object",properties:{keyword:{type:"string",description:"注入する知識のキーワード",enum:["オーケストレーター","要件定義質問テンプレート","要件定義","デザイナー","デザイン設計","UIUX","本番環境準備ガイドテンプレート","データ設計","デプロイ","GitHub","実装計画","プロトタイプ","検証","バックエンド","総合テスト","テスター","フロントエンド","認証追加テンプレート","ブルーランプ","ディレクトリ構造"]},token:{type:"string",description:"Portal APIトークン(省略時は自動取得)",default:"auto"},context:{type:"string",description:"Additional context"}},required:["keyword"]}}]})),this.server.setRequestHandler(i.CallToolRequestSchema,async e=>{const{name:t,arguments:r}=e.params;try{switch(t){case"get_current_time":return await this.handleGetCurrentTime(r||{});case"calculate":return await this.handleCalculate(r||{});case"echo":return await this.handleEcho(r||{});case"inject_knowledge":return await this.handleInjectKnowledge(r||{});default:throw new i.McpError(i.ErrorCode.MethodNotFound,`不明なツール: ${t}`)}}catch(e){if(e.message,e instanceof i.McpError)throw e;throw new i.McpError(i.ErrorCode.InternalError,`ツール実行中にエラーが発生しました: ${e.message}`)}})}async handleGetCurrentTime(e){const{timezone:t="Asia/Tokyo"}=e;try{const e=(new Date).toLocaleString("ja-JP",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"});return{content:[{type:"text",text:`現在の日時: ${e} (${t})`}]}}catch(e){throw new i.McpError(i.ErrorCode.InternalError,`時刻取得エラー: ${e.message}`)}}async handleCalculate(e){const{expression:t}=e;if(!t)throw new i.McpError(i.ErrorCode.InvalidParams,"計算式が指定されていません");try{const e=t.replace(/[^0-9+\-*/().\s]/g,"");if(e!==t)throw new Error("無効な文字が含まれています");const r=Function(`"use strict"; return (${e})`)();return{content:[{type:"text",text:`計算結果: ${t} = ${r}`}]}}catch(e){throw new i.McpError(i.ErrorCode.InvalidParams,`計算エラー: ${e.message}`)}}async handleEcho(e){const{message:t}=e;if(!t)throw new i.McpError(i.ErrorCode.InvalidParams,"メッセージが指定されていません");return{content:[{type:"text",text:`エコー: ${t}`}]}}async handleInjectKnowledge(e){const{keyword:t,token:r="auto",context:o}=e;if(!t)throw new i.McpError(i.ErrorCode.InvalidParams,"キーワードが指定されていません");const s=Date.now();let a=!1;try{const{spawn:e}=await Promise.resolve().then(()=>n(require("child_process"))),o="/Users/tatsuya/Desktop/bluelamp-test/knowledge-injection/hooks/inject-encrypted.sh",s={...process.env};"auto"!==r&&(s.PORTAL_TOKEN=r),s.KNOWLEDGE_KEYWORD=t;const i=e("bash",[o],{env:s,stdio:["pipe","pipe","pipe"]});let c="",d="";i.stdout.on("data",e=>{c+=e.toString()}),i.stderr.on("data",e=>{d+=e.toString()});const u=await new Promise(e=>{i.on("close",e)});c.substring(0,200),d.substring(0,200);Date.now();if(0===u){try{0}catch(e){}return{content:[{type:"text",text:`Knowledge Injection成功: "${t}" の知識が注入されました。\n\n実行結果:\n${c}\n\n統計記録: ${a?"✅ 完了":"⚠️ スキップ"}`}]}}throw new Error(`スクリプト実行失敗 (exit code: ${u})\nstderr: ${d}`)}catch(e){throw e.message,new i.McpError(i.ErrorCode.InternalError,`Knowledge Injection実行エラー: ${e.message}`)}}async run(){const e=new s.StdioServerTransport;await this.server.connect(e)}}).run().catch(e=>{process.exit(1)});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wEAAmE;AACnE,wEAAiF;AACjF,iEAO4C;AAE5C;;;;GAIG;AAEH,eAAe;AACf,SAAS,QAAQ,CAAC,OAAe,EAAE,IAAU;IAC3C,mBAAmB;AACrB,CAAC;AAqBD,aAAa;AACb,MAAM,eAAe;IAGnB;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAM,CAAC;YACvB,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE,OAAO;SACjB,EAAE;YACD,YAAY,EAAE;gBACZ,KAAK,EAAE,EAAE;gBACT,SAAS,EAAE,EAAE;aACd;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,oBAAoB;QACpB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,qCAA0B,EAAE,KAAK,IAAI,EAAE;YACnE,QAAQ,CAAC,UAAU,CAAC,CAAC;YACrB,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,SAAS;QACrC,CAAC,CAAC,CAAC;QAEH,sBAAsB;QACtB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,oCAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACzE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;YAC/B,QAAQ,CAAC,YAAY,EAAE,EAAE,GAAG,EAAE,CAAC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CAAC,oBAAS,CAAC,aAAa,EAAE,6BAA6B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG;QACP,QAAQ,CAAC,WAAW,CAAC,CAAC;QACtB,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;QAC7C,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACrC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC1B,CAAC;CACF;AAED,SAAS;AACT,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;AACrC,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* セキュアMCPサーバー
|
|
3
|
-
* 暗号化されたプロンプトの管理と配信
|
|
4
|
-
*/
|
|
5
|
-
export declare class SecureMCPServer {
|
|
6
|
-
private server;
|
|
7
|
-
private validTokens;
|
|
8
|
-
private encryptionKey;
|
|
9
|
-
private promptCache;
|
|
10
|
-
private cacheTimeout;
|
|
11
|
-
private logFilePath;
|
|
12
|
-
private keywordMapping;
|
|
13
|
-
constructor();
|
|
14
|
-
/**
|
|
15
|
-
* デバッグログをファイルに出力
|
|
16
|
-
*/
|
|
17
|
-
private debugLog;
|
|
18
|
-
private initializeTokensSync;
|
|
19
|
-
/**
|
|
20
|
-
* SimpleAuthManagerからCLIトークンを同期的に読み込み
|
|
21
|
-
*/
|
|
22
|
-
private loadCLITokenFromFile;
|
|
23
|
-
private loadCLITokenAsync;
|
|
24
|
-
/**
|
|
25
|
-
* システム側でトークンを自動取得(AIは関与しない)
|
|
26
|
-
*/
|
|
27
|
-
private getSystemToken;
|
|
28
|
-
private setupHandlers;
|
|
29
|
-
private validateToken;
|
|
30
|
-
/**
|
|
31
|
-
* Portal APIから専門知識を取得(直接API通信)
|
|
32
|
-
* @param keyword 検索キーワード
|
|
33
|
-
* @param token 認証トークン
|
|
34
|
-
* @returns 専門知識
|
|
35
|
-
*/
|
|
36
|
-
private fetchFromPortalAPI;
|
|
37
|
-
/**
|
|
38
|
-
* 知識注入ハンドラー
|
|
39
|
-
*/
|
|
40
|
-
private handleInjectKnowledge;
|
|
41
|
-
/**
|
|
42
|
-
* レスポンス形式の構築(AI知識注入版)
|
|
43
|
-
*/
|
|
44
|
-
private buildResponse;
|
|
45
|
-
/**
|
|
46
|
-
* 知識保存ハンドラー
|
|
47
|
-
*/
|
|
48
|
-
private handleSaveKnowledge;
|
|
49
|
-
/**
|
|
50
|
-
* プロンプト一覧ハンドラー
|
|
51
|
-
*/
|
|
52
|
-
private handleListPrompts;
|
|
53
|
-
/**
|
|
54
|
-
* サブエージェント委譲ハンドラー
|
|
55
|
-
*/
|
|
56
|
-
private handleDelegateToAgent;
|
|
57
|
-
/**
|
|
58
|
-
* 定期的なキャッシュクリーンアップ(無効化済み)
|
|
59
|
-
* 理由: SimpleAuthManagerでセキュリティ確保済み、Knowledge Injection継続性のため
|
|
60
|
-
*/
|
|
61
|
-
private startCacheCleanup;
|
|
62
|
-
run(): Promise<void>;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=secure-mcp-server.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"secure-mcp-server.d.ts","sourceRoot":"","sources":["../src/secure-mcp-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2BH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAsB;;IA8C5C;;OAEG;IACH,OAAO,CAAC,QAAQ;IAehB,OAAO,CAAC,oBAAoB;IAqB5B;;OAEG;IACH,OAAO,CAAC,oBAAoB;YAKd,iBAAiB;IAmB/B;;OAEG;YACW,cAAc;IAwC5B,OAAO,CAAC,aAAa;IA4JrB,OAAO,CAAC,aAAa;IAIrB;;;;;OAKG;YACW,kBAAkB;IAiEhC;;OAEG;YACW,qBAAqB;IA8InC;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;OAEG;YACW,mBAAmB;IAuDjC;;OAEG;YACW,iBAAiB;IAmE/B;;OAEG;YACW,qBAAqB;IAsEnC;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAMnB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAM3B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e,t=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},e(t)},function(r){if(r&&r.__esModule)return r;var o={};if(null!=r)for(var i=e(r),s=0;s<i.length;s++)"default"!==i[s]&&t(o,r,i[s]);return n(o,r),o});Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecureMCPServer=void 0;const o=require("@modelcontextprotocol/sdk/server/index.js"),i=require("@modelcontextprotocol/sdk/server/stdio.js"),s=require("@modelcontextprotocol/sdk/types.js"),a=require("./crypto-utils.js"),c=r(require("fs")),l=r(require("path")),d=r(require("os"));class u{constructor(){this.cacheTimeout=3e5,this.server=new o.Server({name:"secure-bluelamp-mcp",version:"3.0.0"},{capabilities:{tools:{}}}),this.validTokens=new Set,this.promptCache=new Map,this.encryptionKey=process.env.BLUELAMP_ENCRYPTION_KEY||"demo-encryption-password-2024",this.keywordMapping=new Map([["orchestrator","オーケストレーター"],["requirements-engineer","要件定義エンジニア"],["ui-ux-designer","UI/UXデザイナー"],["data-modeling-engineer","データモデリングエンジニア"],["system-architect","システムアーキテクト"],["implementation-consultant","実装コンサルタント"],["environment-setup","環境構築"],["prototype-implementation","プロトタイプ実装"],["implementation-agent","実装エージェント"],["debug-agent","デバッグエージェント"],["deploy-specialist","デプロイスペシャリスト"],["page-creator","ページクリエイター"],["refactoring-engineer","リファクタリングエンジニア"],["ai-friendliness-diagnostic","AI親和性診断"]]),this.logFilePath=l.join(d.tmpdir(),`bluelamp-debug-${Date.now()}.log`),this.debugLog(`BlueLamp MCP Server starting - Log file: ${this.logFilePath}`),this.initializeTokensSync(),this.setupHandlers()}debugLog(e,t){const n=(new Date).toISOString(),r=t?`[${n}] ${e}\n${JSON.stringify(t,null,2)}\n`:`[${n}] ${e}\n`;try{c.appendFileSync(this.logFilePath,r),console.error(`[DEBUG] ${e}`,t||"")}catch(e){}}initializeTokensSync(){try{const e=process.env.BLUELAMP_TOKEN;e&&this.validTokens.add(e),this.loadCLITokenFromFile(),this.debugLog(`Total valid tokens: ${this.validTokens.size}`)}catch(e){this.debugLog("Token initialization error:",e)}}loadCLITokenFromFile(){this.loadCLITokenAsync()}async loadCLITokenAsync(){try{const e=require("path"),t=e.dirname(__filename),n=e.dirname(e.dirname(e.dirname(t))),r=e.join(n,"lib/mcp-server/dist_optimized/security"),o=require(`${r}/SimpleAuthManager.js`),i=await o.SimpleAuthManager.getToken();i&&i.startsWith("cli_")&&(this.validTokens.add(i),this.debugLog(`Loaded CLI token from SimpleAuthManager: ${i.substring(0,20)}...`))}catch(e){this.debugLog("CLI token loading error:",e)}}async getSystemToken(){try{const e=process.env.BLUELAMP_TOKEN;if(e&&this.validTokens.has(e))return e;const t=require("path"),n=t.dirname(__filename),r=t.dirname(t.dirname(t.dirname(n))),o=t.join(r,"lib/mcp-server/dist_optimized/security");try{const e=require(`${o}/SimpleAuthManager.js`),t=await e.SimpleAuthManager.getToken();if(t&&t.startsWith("cli_"))return t}catch(e){this.debugLog("Failed to load token from SimpleAuthManager:",e)}for(const e of this.validTokens)if(e.startsWith("cli_"))return e;return null}catch(e){return this.debugLog("System token retrieval error:",e),null}}setupHandlers(){this.server.setRequestHandler(s.ListToolsRequestSchema,async()=>({tools:[{name:"inject_knowledge",description:"Inject specialized knowledge from Portal API",inputSchema:{type:"object",properties:{keyword:{type:"string",description:"Keyword to search for specialized knowledge"},level:{type:"string",description:"Knowledge detail level"},context:{type:"string",description:"Additional context"}},required:["keyword"]}},{name:"save_knowledge",description:"Save knowledge to encrypted storage",inputSchema:{type:"object",properties:{knowledge:{type:"string",description:"Knowledge content to save (encrypted)"},identifier:{type:"string",description:"Unique identifier for the knowledge"},token:{type:"string",description:"Authentication token for access"}},required:["knowledge","identifier","token"]}},{name:"list_prompts",description:"List available encrypted prompt templates",inputSchema:{type:"object",properties:{token:{type:"string",description:"Authentication token for access"},category:{type:"string",description:"Filter by category (optional)"}},required:["token"]}},{name:"delegate_to_agent",description:"Delegate task to specialized sub-agent with knowledge injection",inputSchema:{type:"object",properties:{agentName:{type:"string",description:"Name of the target agent"},token:{type:"string",description:"Authentication token for access"}},required:["agentName","token"]}},{name:"get_debug_log_path",description:"Get the path to the debug log file",inputSchema:{type:"object",properties:{},required:[]}}]})),this.server.setRequestHandler(s.CallToolRequestSchema,async e=>{const{name:t,arguments:n}=e.params;this.debugLog(`Tool called: ${t}`),this.debugLog("Tool args:",n);try{switch(t){case"inject_knowledge":return this.debugLog("Calling handleInjectKnowledge"),await this.handleInjectKnowledge(n);case"save_knowledge":return await this.handleSaveKnowledge(n);case"list_prompts":return await this.handleListPrompts(n);case"delegate_to_agent":return await this.handleDelegateToAgent(n);case"get_debug_log_path":return{content:[{type:"text",text:JSON.stringify({success:!0,logPath:this.logFilePath,message:`Debug log is being written to: ${this.logFilePath}`})}]};default:throw new s.McpError(s.ErrorCode.MethodNotFound,`Unknown tool: ${t}`)}}catch(e){if(e instanceof s.McpError)throw e;throw new s.McpError(s.ErrorCode.InternalError,`Tool execution failed: ${t}: ${e}`)}})}validateToken(e){return this.validTokens.has(e)}async fetchFromPortalAPI(e,t){try{const n=`${process.env.BLUELAMP_PORTAL_API_URL||"https://bluelamp-235426778039.asia-northeast1.run.app/api/cli/prompts/knowledge-injection"}/${encodeURIComponent(e)}`;this.debugLog("Portal API request:",{url:n,token:t.substring(0,20)+"...",keyword:e});const r=new AbortController,o=setTimeout(()=>r.abort(),3e4),i=await fetch(n,{method:"GET",headers:{"X-CLI-Token":t,"Content-Type":"application/json","User-Agent":"BlueLamp-MCP-Server/1.0"},signal:r.signal});if(clearTimeout(o),this.debugLog(`Portal API response status: ${i.status}`),!i.ok){if(this.debugLog(`Portal API error: ${i.status} ${i.statusText}`),401===i.status)return this.debugLog("Authentication failed - token may be invalid"),null;if(404===i.status)return this.debugLog(`Knowledge not found for keyword: ${e}`),null;throw new Error(`Portal API error: ${i.status} ${i.statusText}`)}const s=await i.text();return this.debugLog("Portal API raw response:",s.substring(0,200)+"..."),s&&s.trim()?s.trim():(this.debugLog("Empty response from Portal API"),null)}catch(e){return null}}async handleInjectKnowledge(e){this.debugLog("Received args:",e),this.debugLog(`Valid tokens: ${Array.from(this.validTokens).map(e=>e.substring(0,30)+"...").join(", ")}`);let t=await this.getSystemToken();if(this.debugLog(`Using system token: ${t?.substring(0,30)}...`),!t||!this.validateToken(t))return this.debugLog("System authentication failed"),{content:[{type:"text",text:JSON.stringify({success:!1,error:"System authentication failed",code:"SYSTEM_AUTH_ERROR"})}]};try{const n=`${e.keyword}:${e.level}`,r=this.promptCache.get(n);let o,i="unknown";if(r&&Date.now()-r.timestamp<this.cacheTimeout)o=r.content,i=r.source||"cache";else{const r=l.join(process.cwd(),"lib/knowledge","encrypted",`${e.keyword}.enc`);if(c.existsSync(r))try{o=a.CryptoUtils.decryptFile(r,this.encryptionKey),i="local"}catch(n){const r=await this.fetchFromPortalAPI(e.keyword,t);if(!r)return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Portal APIから知識を取得できませんでした: ${e.keyword}`,code:"KNOWLEDGE_NOT_FOUND"})}]};o=r,i="api"}else{this.debugLog(`Fetching from Portal API for keyword: ${e.keyword}`);const n=await this.fetchFromPortalAPI(e.keyword,t);if(this.debugLog("Portal API result:",{keyword:e.keyword,resultExists:!!n,resultType:typeof n,resultLength:n?n.length:0}),!n)return this.debugLog(`Portal API returned null for keyword: ${e.keyword}`),{content:[{type:"text",text:JSON.stringify({success:!1,error:`専門知識が見つかりませんでした: ${e.keyword}`,code:"KNOWLEDGE_NOT_FOUND"})}]};o=n,i="api"}this.promptCache.set(n,{content:o,timestamp:Date.now(),source:i})}const s=this.buildResponse(o,t,e.context);return{content:[{type:"text",text:JSON.stringify({success:!0,result:s,keyword:e.keyword,token:t.substring(0,20)+"...",cached:"cache"===i,source:i,timestamp:(new Date).toISOString()})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`知識注入処理中にエラーが発生しました: ${e}`,code:"INJECTION_ERROR"})}]}}}buildResponse(e,t,n){return this.debugLog(`buildResponse called with content length: ${e?e.length:0}`),{content:[{type:"text",text:e}]}}async handleSaveKnowledge(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","encrypted");c.existsSync(t)||c.mkdirSync(t,{recursive:!0});const n=l.join(t,`${e.identifier}.enc`);return a.CryptoUtils.encryptFile(e.knowledge,n,this.encryptionKey),{content:[{type:"text",text:JSON.stringify({success:!0,message:"Knowledge saved successfully",outputPath:n,size:c.statSync(n).size})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Knowledge save failed: ${e}`,code:"SAVE_ERROR"})}]}}}async handleListPrompts(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","encrypted"),n=l.join(t,"prompt-registry.json");if(!c.existsSync(n))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Prompt registry not found",code:"REGISTRY_NOT_FOUND"})}]};const r=JSON.parse(c.readFileSync(n,"utf8"));let o=r.prompts;return e.category&&(o=o.filter(t=>t.category===e.category)),{content:[{type:"text",text:JSON.stringify({success:!0,totalCount:o.length,prompts:o,categories:r.categories,lastUpdated:r.lastUpdated})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Failed to list prompts: ${e}`,code:"LIST_ERROR"})}]}}}async handleDelegateToAgent(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","agents",`${e.agentName}.agent`);if(!c.existsSync(t))return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Agent script not found: ${e.agentName}`,code:"AGENT_NOT_FOUND"})}]};const n=JSON.parse(c.readFileSync(t,"utf8")),r=l.join(process.cwd(),"lib/knowledge","encrypted"),o=l.join(r,`${e.agentName}.enc`),i=c.existsSync(o);return{content:[{type:"text",text:JSON.stringify({success:!0,agentName:e.agentName,agentData:n,hasKnowledge:i,knowledgeSize:i?c.statSync(o).size:0})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Agent delegation failed: ${e}`,code:"DELEGATION_ERROR"})}]}}}startCacheCleanup(){}async run(){const e=new i.StdioServerTransport;await this.server.connect(e),this.startCacheCleanup()}}if(exports.SecureMCPServer=u,require.main===module){(new u).run().catch(()=>{})}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e,t=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)},function(n){if(n&&n.__esModule)return n;var o={};if(null!=n)for(var i=e(n),s=0;s<i.length;s++)"default"!==i[s]&&t(o,n,i[s]);return r(o,n),o});Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecureMCPServer=void 0;const o=require("@modelcontextprotocol/sdk/server/index.js"),i=require("@modelcontextprotocol/sdk/server/stdio.js"),s=require("@modelcontextprotocol/sdk/types.js"),a=require("./crypto-utils.js"),c=n(require("fs")),l=n(require("path")),d=n(require("os"));class u{constructor(){this.cacheTimeout=3e5,this.server=new o.Server({name:"secure-bluelamp-mcp",version:"3.0.0"},{capabilities:{tools:{}}}),this.validTokens=new Set,this.promptCache=new Map,this.encryptionKey=process.env.BLUELAMP_ENCRYPTION_KEY||"demo-encryption-password-2024",this.keywordMapping=new Map([["orchestrator","オーケストレーター"],["requirements-engineer","要件定義エンジニア"],["ui-ux-designer","UI/UXデザイナー"],["data-modeling-engineer","データモデリングエンジニア"],["system-architect","システムアーキテクト"],["implementation-consultant","実装コンサルタント"],["environment-setup","環境構築"],["prototype-implementation","プロトタイプ実装"],["implementation-agent","実装エージェント"],["debug-agent","デバッグエージェント"],["deploy-specialist","デプロイスペシャリスト"],["page-creator","ページクリエイター"],["refactoring-engineer","リファクタリングエンジニア"],["ai-friendliness-diagnostic","AI親和性診断"]]),this.logFilePath=l.join(d.tmpdir(),`bluelamp-debug-${Date.now()}.log`),this.debugLog(`BlueLamp MCP Server starting - Log file: ${this.logFilePath}`),this.initializeTokensSync(),this.setupHandlers()}debugLog(e,t){const r=(new Date).toISOString(),n=t?`[${r}] ${e}\n${JSON.stringify(t,null,2)}\n`:`[${r}] ${e}\n`;try{c.appendFileSync(this.logFilePath,n),console.error(`[DEBUG] ${e}`,t||"")}catch(e){}}initializeTokensSync(){try{const e=process.env.BLUELAMP_TOKEN;e&&this.validTokens.add(e),this.loadCLITokenFromFile(),this.debugLog(`Total valid tokens: ${this.validTokens.size}`)}catch(e){this.debugLog("Token initialization error:",e)}}loadCLITokenFromFile(){this.loadCLITokenAsync()}async loadCLITokenAsync(){try{const e=await Promise.resolve().then(()=>n(require("path"))),t=(await Promise.resolve().then(()=>n(require("url")))).fileURLToPath(import.meta.url),r=e.dirname(t),o=e.dirname(e.dirname(e.dirname(r))),i=e.join(o,"lib/mcp-server/dist/security"),s=await Promise.resolve(`file://${i}/SimpleAuthManager.js`).then(e=>n(require(e))),a=await s.SimpleAuthManager.getToken();a&&a.startsWith("cli_")&&(this.validTokens.add(a),this.debugLog(`Loaded CLI token from SimpleAuthManager: ${a.substring(0,20)}...`))}catch(e){this.debugLog("CLI token loading error:",e)}}async getSystemToken(){try{const e=process.env.BLUELAMP_TOKEN;if(e&&this.validTokens.has(e))return e;const t=await Promise.resolve().then(()=>n(require("path"))),r=(await Promise.resolve().then(()=>n(require("url")))).fileURLToPath(import.meta.url),o=t.dirname(r),i=t.dirname(t.dirname(t.dirname(o))),s=t.join(i,"lib/mcp-server/dist/security");try{const e=await Promise.resolve(`file://${s}/SimpleAuthManager.js`).then(e=>n(require(e))),t=await e.SimpleAuthManager.getToken();if(t&&t.startsWith("cli_"))return t}catch(e){this.debugLog("Failed to load token from SimpleAuthManager:",e)}for(const e of this.validTokens)if(e.startsWith("cli_"))return e;return null}catch(e){return this.debugLog("System token retrieval error:",e),null}}setupHandlers(){this.server.setRequestHandler(s.ListToolsRequestSchema,async()=>({tools:[{name:"inject_knowledge",description:"Inject specialized knowledge from Portal API",inputSchema:{type:"object",properties:{keyword:{type:"string",description:"Keyword to search for specialized knowledge"},level:{type:"string",description:"Knowledge detail level"},context:{type:"string",description:"Additional context"}},required:["keyword"]}},{name:"save_knowledge",description:"Save knowledge to encrypted storage",inputSchema:{type:"object",properties:{knowledge:{type:"string",description:"Knowledge content to save (encrypted)"},identifier:{type:"string",description:"Unique identifier for the knowledge"},token:{type:"string",description:"Authentication token for access"}},required:["knowledge","identifier","token"]}},{name:"list_prompts",description:"List available encrypted prompt templates",inputSchema:{type:"object",properties:{token:{type:"string",description:"Authentication token for access"},category:{type:"string",description:"Filter by category (optional)"}},required:["token"]}},{name:"delegate_to_agent",description:"Delegate task to specialized sub-agent with knowledge injection",inputSchema:{type:"object",properties:{agentName:{type:"string",description:"Name of the target agent"},token:{type:"string",description:"Authentication token for access"}},required:["agentName","token"]}},{name:"get_debug_log_path",description:"Get the path to the debug log file",inputSchema:{type:"object",properties:{},required:[]}}]})),this.server.setRequestHandler(s.CallToolRequestSchema,async e=>{const{name:t,arguments:r}=e.params;this.debugLog(`Tool called: ${t}`),this.debugLog("Tool args:",r);try{switch(t){case"inject_knowledge":return this.debugLog("Calling handleInjectKnowledge"),await this.handleInjectKnowledge(r);case"save_knowledge":return await this.handleSaveKnowledge(r);case"list_prompts":return await this.handleListPrompts(r);case"delegate_to_agent":return await this.handleDelegateToAgent(r);case"get_debug_log_path":return{content:[{type:"text",text:JSON.stringify({success:!0,logPath:this.logFilePath,message:`Debug log is being written to: ${this.logFilePath}`})}]};default:throw new s.McpError(s.ErrorCode.MethodNotFound,`Unknown tool: ${t}`)}}catch(e){if(e instanceof s.McpError)throw e;throw new s.McpError(s.ErrorCode.InternalError,`Tool execution failed: ${t}: ${e}`)}})}validateToken(e){return this.validTokens.has(e)}async fetchFromPortalAPI(e,t){try{const r=`${process.env.BLUELAMP_PORTAL_API_URL||"https://bluelamp-235426778039.asia-northeast1.run.app/api/cli/prompts/knowledge-injection"}/${encodeURIComponent(e)}`;this.debugLog("Portal API request:",{url:r,token:t.substring(0,20)+"...",keyword:e});const n=new AbortController,o=setTimeout(()=>n.abort(),3e4),i=await fetch(r,{method:"GET",headers:{"X-CLI-Token":t,"Content-Type":"application/json","User-Agent":"BlueLamp-MCP-Server/1.0"},signal:n.signal});if(clearTimeout(o),this.debugLog(`Portal API response status: ${i.status}`),!i.ok){if(this.debugLog(`Portal API error: ${i.status} ${i.statusText}`),401===i.status)return this.debugLog("Authentication failed - token may be invalid"),null;if(404===i.status)return this.debugLog(`Knowledge not found for keyword: ${e}`),null;throw new Error(`Portal API error: ${i.status} ${i.statusText}`)}const s=await i.text();return this.debugLog("Portal API raw response:",s.substring(0,200)+"..."),s&&s.trim()?s.trim():(this.debugLog("Empty response from Portal API"),null)}catch(e){return null}}async handleInjectKnowledge(e){this.debugLog("Received args:",e),this.debugLog(`Valid tokens: ${Array.from(this.validTokens).map(e=>e.substring(0,30)+"...").join(", ")}`);let t=await this.getSystemToken();if(this.debugLog(`Using system token: ${t?.substring(0,30)}...`),!t||!this.validateToken(t))return this.debugLog("System authentication failed"),{content:[{type:"text",text:JSON.stringify({success:!1,error:"System authentication failed",code:"SYSTEM_AUTH_ERROR"})}]};try{const r=`${e.keyword}:${e.level}`,n=this.promptCache.get(r);let o,i="unknown";if(n&&Date.now()-n.timestamp<this.cacheTimeout)o=n.content,i=n.source||"cache";else{const n=l.join(process.cwd(),"lib/knowledge","encrypted",`${e.keyword}.enc`);if(c.existsSync(n))try{o=a.CryptoUtils.decryptFile(n,this.encryptionKey),i="local"}catch(r){const n=await this.fetchFromPortalAPI(e.keyword,t);if(!n)return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Portal APIから知識を取得できませんでした: ${e.keyword}`,code:"KNOWLEDGE_NOT_FOUND"})}]};o=n,i="api"}else{this.debugLog(`Fetching from Portal API for keyword: ${e.keyword}`);const r=await this.fetchFromPortalAPI(e.keyword,t);if(this.debugLog("Portal API result:",{keyword:e.keyword,resultExists:!!r,resultType:typeof r,resultLength:r?r.length:0}),!r)return this.debugLog(`Portal API returned null for keyword: ${e.keyword}`),{content:[{type:"text",text:JSON.stringify({success:!1,error:`専門知識が見つかりませんでした: ${e.keyword}`,code:"KNOWLEDGE_NOT_FOUND"})}]};o=r,i="api"}this.promptCache.set(r,{content:o,timestamp:Date.now(),source:i})}const s=this.buildResponse(o,t,e.context);return{content:[{type:"text",text:JSON.stringify({success:!0,result:s,keyword:e.keyword,token:t.substring(0,20)+"...",cached:"cache"===i,source:i,timestamp:(new Date).toISOString()})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`知識注入処理中にエラーが発生しました: ${e}`,code:"INJECTION_ERROR"})}]}}}buildResponse(e,t,r){return this.debugLog(`buildResponse called with content length: ${e?e.length:0}`),{content:[{type:"text",text:e}]}}async handleSaveKnowledge(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","encrypted");c.existsSync(t)||c.mkdirSync(t,{recursive:!0});const r=l.join(t,`${e.identifier}.enc`);return a.CryptoUtils.encryptFile(e.knowledge,r,this.encryptionKey),{content:[{type:"text",text:JSON.stringify({success:!0,message:"Knowledge saved successfully",outputPath:r,size:c.statSync(r).size})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Knowledge save failed: ${e}`,code:"SAVE_ERROR"})}]}}}async handleListPrompts(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","encrypted"),r=l.join(t,"prompt-registry.json");if(!c.existsSync(r))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Prompt registry not found",code:"REGISTRY_NOT_FOUND"})}]};const n=JSON.parse(c.readFileSync(r,"utf8"));let o=n.prompts;return e.category&&(o=o.filter(t=>t.category===e.category)),{content:[{type:"text",text:JSON.stringify({success:!0,totalCount:o.length,prompts:o,categories:n.categories,lastUpdated:n.lastUpdated})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Failed to list prompts: ${e}`,code:"LIST_ERROR"})}]}}}async handleDelegateToAgent(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","agents",`${e.agentName}.agent`);if(!c.existsSync(t))return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Agent script not found: ${e.agentName}`,code:"AGENT_NOT_FOUND"})}]};const r=JSON.parse(c.readFileSync(t,"utf8")),n=l.join(process.cwd(),"lib/knowledge","encrypted"),o=l.join(n,`${e.agentName}.enc`),i=c.existsSync(o);return{content:[{type:"text",text:JSON.stringify({success:!0,agentName:e.agentName,agentData:r,hasKnowledge:i,knowledgeSize:i?c.statSync(o).size:0})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Agent delegation failed: ${e}`,code:"DELEGATION_ERROR"})}]}}}startCacheCleanup(){}async run(){const e=new i.StdioServerTransport;await this.server.connect(e),this.startCacheCleanup()}}exports.SecureMCPServer=u,import.meta.url===`file://${process.argv[1]}`&&(new u).run().catch(()=>{});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e,t=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),n=this&&this.__importStar||(e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},e(t)},function(n){if(n&&n.__esModule)return n;var o={};if(null!=n)for(var i=e(n),s=0;s<i.length;s++)"default"!==i[s]&&t(o,n,i[s]);return r(o,n),o});Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecureMCPServer=void 0;const o=require("@modelcontextprotocol/sdk/server/index.js"),i=require("@modelcontextprotocol/sdk/server/stdio.js"),s=require("@modelcontextprotocol/sdk/types.js"),a=require("./crypto-utils.js"),c=n(require("fs")),l=n(require("path")),d=n(require("os"));class u{constructor(){this.cacheTimeout=3e5,this.server=new o.Server({name:"secure-bluelamp-mcp",version:"3.0.0"},{capabilities:{tools:{}}}),this.validTokens=new Set,this.promptCache=new Map,this.encryptionKey=process.env.BLUELAMP_ENCRYPTION_KEY||"demo-encryption-password-2024",this.keywordMapping=new Map([["orchestrator","オーケストレーター"],["requirements-engineer","要件定義エンジニア"],["ui-ux-designer","UI/UXデザイナー"],["data-modeling-engineer","データモデリングエンジニア"],["system-architect","システムアーキテクト"],["implementation-consultant","実装コンサルタント"],["environment-setup","環境構築"],["prototype-implementation","プロトタイプ実装"],["implementation-agent","実装エージェント"],["debug-agent","デバッグエージェント"],["deploy-specialist","デプロイスペシャリスト"],["page-creator","ページクリエイター"],["refactoring-engineer","リファクタリングエンジニア"],["ai-friendliness-diagnostic","AI親和性診断"]]),this.logFilePath=l.join(d.tmpdir(),`bluelamp-debug-${Date.now()}.log`),this.debugLog(`BlueLamp MCP Server starting - Log file: ${this.logFilePath}`),this.initializeTokensSync(),this.setupHandlers()}debugLog(e,t){const r=(new Date).toISOString(),n=t?`[${r}] ${e}\n${JSON.stringify(t,null,2)}\n`:`[${r}] ${e}\n`;try{c.appendFileSync(this.logFilePath,n),console.error(`[DEBUG] ${e}`,t||"")}catch(e){}}initializeTokensSync(){try{const e=process.env.BLUELAMP_TOKEN;e&&this.validTokens.add(e),this.loadCLITokenFromFile(),this.debugLog(`Total valid tokens: ${this.validTokens.size}`)}catch(e){this.debugLog("Token initialization error:",e)}}loadCLITokenFromFile(){this.loadCLITokenAsync()}async loadCLITokenAsync(){try{const e=await Promise.resolve().then(()=>n(require("path"))),t=(await Promise.resolve().then(()=>n(require("url")))).fileURLToPath(import.meta.url),r=e.dirname(t),o=e.dirname(e.dirname(e.dirname(r))),i=e.join(o,"lib/mcp-server/dist/security"),s=await Promise.resolve(`file://${i}/SimpleAuthManager.js`).then(e=>n(require(e))),a=await s.SimpleAuthManager.getToken();a&&a.startsWith("cli_")&&(this.validTokens.add(a),this.debugLog(`Loaded CLI token from SimpleAuthManager: ${a.substring(0,20)}...`))}catch(e){this.debugLog("CLI token loading error:",e)}}async getSystemToken(){try{const e=process.env.BLUELAMP_TOKEN;if(e&&this.validTokens.has(e))return e;const t=await Promise.resolve().then(()=>n(require("path"))),r=(await Promise.resolve().then(()=>n(require("url")))).fileURLToPath(import.meta.url),o=t.dirname(r),i=t.dirname(t.dirname(t.dirname(o))),s=t.join(i,"lib/mcp-server/dist/security");try{const e=await Promise.resolve(`file://${s}/SimpleAuthManager.js`).then(e=>n(require(e))),t=await e.SimpleAuthManager.getToken();if(t&&t.startsWith("cli_"))return t}catch(e){this.debugLog("Failed to load token from SimpleAuthManager:",e)}for(const e of this.validTokens)if(e.startsWith("cli_"))return e;return null}catch(e){return this.debugLog("System token retrieval error:",e),null}}setupHandlers(){this.server.setRequestHandler(s.ListToolsRequestSchema,async()=>({tools:[{name:"inject_knowledge",description:"Inject specialized knowledge from Portal API",inputSchema:{type:"object",properties:{keyword:{type:"string",description:"Keyword to search for specialized knowledge"},level:{type:"string",description:"Knowledge detail level"},context:{type:"string",description:"Additional context"}},required:["keyword"]}},{name:"save_knowledge",description:"Save knowledge to encrypted storage",inputSchema:{type:"object",properties:{knowledge:{type:"string",description:"Knowledge content to save (encrypted)"},identifier:{type:"string",description:"Unique identifier for the knowledge"},token:{type:"string",description:"Authentication token for access"}},required:["knowledge","identifier","token"]}},{name:"list_prompts",description:"List available encrypted prompt templates",inputSchema:{type:"object",properties:{token:{type:"string",description:"Authentication token for access"},category:{type:"string",description:"Filter by category (optional)"}},required:["token"]}},{name:"delegate_to_agent",description:"Delegate task to specialized sub-agent with knowledge injection",inputSchema:{type:"object",properties:{agentName:{type:"string",description:"Name of the target agent"},token:{type:"string",description:"Authentication token for access"}},required:["agentName","token"]}},{name:"get_debug_log_path",description:"Get the path to the debug log file",inputSchema:{type:"object",properties:{},required:[]}}]})),this.server.setRequestHandler(s.CallToolRequestSchema,async e=>{const{name:t,arguments:r}=e.params;this.debugLog(`Tool called: ${t}`),this.debugLog("Tool args:",r);try{switch(t){case"inject_knowledge":return this.debugLog("Calling handleInjectKnowledge"),await this.handleInjectKnowledge(r);case"save_knowledge":return await this.handleSaveKnowledge(r);case"list_prompts":return await this.handleListPrompts(r);case"delegate_to_agent":return await this.handleDelegateToAgent(r);case"get_debug_log_path":return{content:[{type:"text",text:JSON.stringify({success:!0,logPath:this.logFilePath,message:`Debug log is being written to: ${this.logFilePath}`})}]};default:throw new s.McpError(s.ErrorCode.MethodNotFound,`Unknown tool: ${t}`)}}catch(e){if(e instanceof s.McpError)throw e;throw new s.McpError(s.ErrorCode.InternalError,`Tool execution failed: ${t}: ${e}`)}})}validateToken(e){return this.validTokens.has(e)}async fetchFromPortalAPI(e,t){try{const r=`${process.env.BLUELAMP_PORTAL_API_URL||"https://bluelamp-235426778039.asia-northeast1.run.app/api/cli/prompts/knowledge-injection"}/${encodeURIComponent(e)}`;this.debugLog("Portal API request:",{url:r,token:t.substring(0,20)+"...",keyword:e});const n=new AbortController,o=setTimeout(()=>n.abort(),3e4),i=await fetch(r,{method:"GET",headers:{"X-CLI-Token":t,"Content-Type":"application/json","User-Agent":"BlueLamp-MCP-Server/1.0"},signal:n.signal});if(clearTimeout(o),this.debugLog(`Portal API response status: ${i.status}`),!i.ok){if(this.debugLog(`Portal API error: ${i.status} ${i.statusText}`),401===i.status)return this.debugLog("Authentication failed - token may be invalid"),null;if(404===i.status)return this.debugLog(`Knowledge not found for keyword: ${e}`),null;throw new Error(`Portal API error: ${i.status} ${i.statusText}`)}const s=await i.text();return this.debugLog("Portal API raw response:",s.substring(0,200)+"..."),s&&s.trim()?s.trim():(this.debugLog("Empty response from Portal API"),null)}catch(e){return null}}async handleInjectKnowledge(e){this.debugLog("Received args:",e),this.debugLog(`Valid tokens: ${Array.from(this.validTokens).map(e=>e.substring(0,30)+"...").join(", ")}`);let t=await this.getSystemToken();if(this.debugLog(`Using system token: ${t?.substring(0,30)}...`),!t||!this.validateToken(t))return this.debugLog("System authentication failed"),{content:[{type:"text",text:JSON.stringify({success:!1,error:"System authentication failed",code:"SYSTEM_AUTH_ERROR"})}]};try{const r=`${e.keyword}:${e.level}`,n=this.promptCache.get(r);let o,i="unknown";if(n&&Date.now()-n.timestamp<this.cacheTimeout)o=n.content,i=n.source||"cache";else{const n=l.join(process.cwd(),"lib/knowledge","encrypted",`${e.keyword}.enc`);if(c.existsSync(n))try{o=a.CryptoUtils.decryptFile(n,this.encryptionKey),i="local"}catch(r){const n=await this.fetchFromPortalAPI(e.keyword,t);if(!n)return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Portal APIから知識を取得できませんでした: ${e.keyword}`,code:"KNOWLEDGE_NOT_FOUND"})}]};o=n,i="api"}else{this.debugLog(`Fetching from Portal API for keyword: ${e.keyword}`);const r=await this.fetchFromPortalAPI(e.keyword,t);if(this.debugLog("Portal API result:",{keyword:e.keyword,resultExists:!!r,resultType:typeof r,resultLength:r?r.length:0}),!r)return this.debugLog(`Portal API returned null for keyword: ${e.keyword}`),{content:[{type:"text",text:JSON.stringify({success:!1,error:`専門知識が見つかりませんでした: ${e.keyword}`,code:"KNOWLEDGE_NOT_FOUND"})}]};o=r,i="api"}this.promptCache.set(r,{content:o,timestamp:Date.now(),source:i})}const s=this.buildResponse(o,t,e.context);return{content:[{type:"text",text:JSON.stringify({success:!0,result:s,keyword:e.keyword,token:t.substring(0,20)+"...",cached:"cache"===i,source:i,timestamp:(new Date).toISOString()})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`知識注入処理中にエラーが発生しました: ${e}`,code:"INJECTION_ERROR"})}]}}}buildResponse(e,t,r){return this.debugLog(`buildResponse called with content length: ${e?e.length:0}`),{content:[{type:"text",text:e}]}}async handleSaveKnowledge(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","encrypted");c.existsSync(t)||c.mkdirSync(t,{recursive:!0});const r=l.join(t,`${e.identifier}.enc`);return a.CryptoUtils.encryptFile(e.knowledge,r,this.encryptionKey),{content:[{type:"text",text:JSON.stringify({success:!0,message:"Knowledge saved successfully",outputPath:r,size:c.statSync(r).size})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Knowledge save failed: ${e}`,code:"SAVE_ERROR"})}]}}}async handleListPrompts(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","encrypted"),r=l.join(t,"prompt-registry.json");if(!c.existsSync(r))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Prompt registry not found",code:"REGISTRY_NOT_FOUND"})}]};const n=JSON.parse(c.readFileSync(r,"utf8"));let o=n.prompts;return e.category&&(o=o.filter(t=>t.category===e.category)),{content:[{type:"text",text:JSON.stringify({success:!0,totalCount:o.length,prompts:o,categories:n.categories,lastUpdated:n.lastUpdated})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Failed to list prompts: ${e}`,code:"LIST_ERROR"})}]}}}async handleDelegateToAgent(e){if(!this.validateToken(e.token))return{content:[{type:"text",text:JSON.stringify({success:!1,error:"Invalid authentication token",code:"AUTH_ERROR"})}]};try{const t=l.join(process.cwd(),"lib/knowledge","agents",`${e.agentName}.agent`);if(!c.existsSync(t))return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Agent script not found: ${e.agentName}`,code:"AGENT_NOT_FOUND"})}]};const r=JSON.parse(c.readFileSync(t,"utf8")),n=l.join(process.cwd(),"lib/knowledge","encrypted"),o=l.join(n,`${e.agentName}.enc`),i=c.existsSync(o);return{content:[{type:"text",text:JSON.stringify({success:!0,agentName:e.agentName,agentData:r,hasKnowledge:i,knowledgeSize:i?c.statSync(o).size:0})}]}}catch(e){return{content:[{type:"text",text:JSON.stringify({success:!1,error:`Agent delegation failed: ${e}`,code:"DELEGATION_ERROR"})}]}}}startCacheCleanup(){}async run(){const e=new i.StdioServerTransport;await this.server.connect(e),this.startCacheCleanup()}}exports.SecureMCPServer=u,require.main===module&&(new u).run().catch(()=>{});
|