-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathmcploader.js
More file actions
126 lines (114 loc) · 4.86 KB
/
mcploader.js
File metadata and controls
126 lines (114 loc) · 4.86 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
// mcploader.js
// Copyright 2019-2026, Namhyeon Go <gnh1201@catswords.re.kr> and the WelsonJS contributors.
// SPDX-License-Identifier: GPL-3.0-or-later
// https://github.com/gnh1201/welsonjs
//
var StdioServer = require("lib/stdio-server");
var JsonRpc2 = require("lib/jsonrpc2");
function main(args) {
var server = StdioServer.create();
server.addEventListener("message", function(e) {
var message = e.target.receive();
e.target.send(
JsonRpc2.extract(message, function (method, params, id) {
var isError = false;
if (method == "initialize") {
return {
"protocolVersion": "2025-11-25",
"capabilities": {
"extensions": {
"io.modelcontextprotocol/ui": {
"mimeTypes": ["text/html;profile=mcp-app"]
}
}
},
"serverInfo": {
"name": "WelsonJS MCP",
"version": "1.0.0"
},
"isError": isError
};
}
if (method === "notifications/initialized") {
// DO NOT return anything
return false;
}
if (method == "tools/list") {
return {
"tools": [
{
"name": "add_both_numbers",
"title": "add both_numbers (add A and B)",
"description": "add two numbers (add A and B)",
"inputSchema": {
"type": "object",
"properties": {
"a": {
"type": "number"
},
"b": {
"type": "number"
}
},
"required": ["a", "b"]
}
},
{
"name": "evaluate_js_es3",
"title": "Evaluate JavaScript ES3",
"description": "Evaluate JavaScript with ES3 syntax (use ES3 syntax strictly)",
"inputSchema": {
"type": "object",
"properties": {
"script": {
"type": "string"
}
},
"required": ["script"]
}
}
],
"isError": isError
};
}
if (method == "tools/call") {
var function_calling_name = params.name;
if (function_calling_name == "add_both_numbers") {
return {
"content": [
{
"type": "text",
"text": "Result is " + (parseFloat(params.arguments.a) + parseFloat(params.arguments.b))
}
],
"isError": isError
};
}
if (function_calling_name == "evaluate_js_es3") {
return {
"content": [
{
"type": "text",
"text": (function(script) {
try {
return String(eval(script));
} catch (e) {
return "Error";
isError = true;
}
})(params.arguments.script)
}
]
}
}
}
isError = true;
return {
"isError": isError
};
})
);
});
server.listen();
}
exports.main = main;