@takch02/server-doctor 1.0.3 → 1.0.5
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/index.js +57 -45
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,68 +3,80 @@
|
|
|
3
3
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
4
4
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js"; // McpServer 대신 Server 사용
|
|
7
|
+
import {
|
|
8
|
+
ListToolsRequestSchema,
|
|
9
|
+
CallToolRequestSchema,
|
|
10
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
7
11
|
import { createRequire } from "module";
|
|
8
12
|
|
|
9
13
|
const require = createRequire(import.meta.url);
|
|
10
14
|
const EventSource = require("eventsource");
|
|
11
|
-
global.EventSource = EventSource;
|
|
12
15
|
|
|
16
|
+
// AWS 서버 주소
|
|
13
17
|
const SERVER_URL = "http://ec2-52-79-247-25.ap-northeast-2.compute.amazonaws.com/mcp/sse";
|
|
14
18
|
|
|
19
|
+
global.EventSource = EventSource;
|
|
15
20
|
|
|
16
21
|
async function main() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// 1. AWS Java 서버와 연결 (Client)
|
|
23
|
+
const transport = new SSEClientTransport(new URL(SERVER_URL));
|
|
24
|
+
const client = new Client(
|
|
25
|
+
{ name: "bridge-client", version: "1.0.0" },
|
|
26
|
+
{ capabilities: {} }
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await client.connect(transport);
|
|
31
|
+
console.error("✅ AWS 서버 연결 성공");
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error("❌ AWS 서버 연결 실패:", err);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
// 2. Claude와 연결할 서버 생성 (Server - Low Level)
|
|
38
|
+
const server = new Server(
|
|
39
|
+
{ name: "ServerDoctor", version: "1.0.0" },
|
|
40
|
+
{
|
|
41
|
+
capabilities: {
|
|
42
|
+
tools: {}, // 도구 기능 활성화
|
|
43
|
+
},
|
|
30
44
|
}
|
|
45
|
+
);
|
|
31
46
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
// 3. [핵심] 도구 목록 요청(ListTools)이 오면 Java 서버의 응답을 그대로 전달
|
|
48
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
49
|
+
// Java 서버에게 "도구 목록 줘" 요청
|
|
50
|
+
const result = await client.listTools();
|
|
51
|
+
|
|
52
|
+
// [디버깅] Java가 준 스키마 확인
|
|
53
|
+
console.error("[Bridge] Java에서 받은 도구 개수:", result.tools.length);
|
|
54
|
+
|
|
55
|
+
// 변환 과정 없이 그대로 Claude에게 리턴 (Schema 깨짐 방지)
|
|
56
|
+
return { tools: result.tools };
|
|
57
|
+
});
|
|
37
58
|
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
// 4. [핵심] 도구 실행 요청(CallTool)이 오면 그대로 Java 서버로 전달
|
|
60
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
61
|
+
console.error(`[Bridge] 호출 요청: ${request.params.name}`);
|
|
62
|
+
console.error(`[Bridge] 인자 확인:`, JSON.stringify(request.params.arguments));
|
|
40
63
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
console.error(`[Bridge Debug] RawArgs:`, JSON.stringify(rawArgs));
|
|
47
|
-
|
|
48
|
-
let realArgs = rawArgs;
|
|
64
|
+
// Java 서버에게 실행 요청
|
|
65
|
+
const result = await client.callTool({
|
|
66
|
+
name: request.params.name,
|
|
67
|
+
arguments: request.params.arguments,
|
|
68
|
+
});
|
|
49
69
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
realArgs = {};
|
|
53
|
-
}
|
|
54
|
-
const result = await client.callTool({
|
|
55
|
-
name: tool.name,
|
|
56
|
-
arguments: realArgs, // 정제된 인자 전송
|
|
57
|
-
});
|
|
58
|
-
return result;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
70
|
+
return result;
|
|
71
|
+
});
|
|
61
72
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
// 5. Claude와 통신 시작 (Stdio)
|
|
74
|
+
const stdioTransport = new StdioServerTransport();
|
|
75
|
+
await server.connect(stdioTransport);
|
|
76
|
+
console.error("🚀 Claude 연결 준비 완료 (Proxy Mode)");
|
|
65
77
|
}
|
|
66
78
|
|
|
67
79
|
main().catch((error) => {
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
console.error("❌ Bridge 오류 발생:", error);
|
|
81
|
+
process.exit(1);
|
|
70
82
|
});
|