@takch02/server-doctor 1.0.4 → 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 +41 -29
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,18 +3,23 @@
|
|
|
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
15
|
|
|
12
|
-
//
|
|
16
|
+
// AWS 서버 주소
|
|
13
17
|
const SERVER_URL = "http://ec2-52-79-247-25.ap-northeast-2.compute.amazonaws.com/mcp/sse";
|
|
14
18
|
|
|
15
19
|
global.EventSource = EventSource;
|
|
16
20
|
|
|
17
21
|
async function main() {
|
|
22
|
+
// 1. AWS Java 서버와 연결 (Client)
|
|
18
23
|
const transport = new SSEClientTransport(new URL(SERVER_URL));
|
|
19
24
|
const client = new Client(
|
|
20
25
|
{ name: "bridge-client", version: "1.0.0" },
|
|
@@ -23,45 +28,52 @@ async function main() {
|
|
|
23
28
|
|
|
24
29
|
try {
|
|
25
30
|
await client.connect(transport);
|
|
31
|
+
console.error("✅ AWS 서버 연결 성공");
|
|
26
32
|
} catch (err) {
|
|
27
33
|
console.error("❌ AWS 서버 연결 실패:", err);
|
|
28
34
|
process.exit(1);
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
version: "1.0.0",
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
server.tool(tool.name, tool.description, tool.inputSchema, async (args) => {
|
|
41
|
-
|
|
42
|
-
// 🔍 [디버깅] Claude가 보낸 데이터 확인
|
|
43
|
-
console.error(`[Bridge Log] Tool 호출됨: ${tool.name}`);
|
|
44
|
-
console.error(`[Bridge Log] 받은 인자(args):`, JSON.stringify(args));
|
|
37
|
+
// 2. Claude와 연결할 서버 생성 (Server - Low Level)
|
|
38
|
+
const server = new Server(
|
|
39
|
+
{ name: "ServerDoctor", version: "1.0.0" },
|
|
40
|
+
{
|
|
41
|
+
capabilities: {
|
|
42
|
+
tools: {}, // 도구 기능 활성화
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
);
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
});
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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));
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return result;
|
|
64
|
+
// Java 서버에게 실행 요청
|
|
65
|
+
const result = await client.callTool({
|
|
66
|
+
name: request.params.name,
|
|
67
|
+
arguments: request.params.arguments,
|
|
60
68
|
});
|
|
61
|
-
}
|
|
62
69
|
|
|
70
|
+
return result;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// 5. Claude와 통신 시작 (Stdio)
|
|
63
74
|
const stdioTransport = new StdioServerTransport();
|
|
64
75
|
await server.connect(stdioTransport);
|
|
76
|
+
console.error("🚀 Claude 연결 준비 완료 (Proxy Mode)");
|
|
65
77
|
}
|
|
66
78
|
|
|
67
79
|
main().catch((error) => {
|