gexinsofts-mcp 0.0.1

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.
Files changed (2) hide show
  1. package/index.js +344 -0
  2. package/package.json +7 -0
package/index.js ADDED
@@ -0,0 +1,344 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __esm = (fn, res) => function __init() {
3
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
+ };
5
+ var __commonJS = (cb, mod) => function __require() {
6
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
7
+ };
8
+
9
+ // src/core/errors/ConnectorError.ts
10
+ var ConnectorError;
11
+ var init_ConnectorError = __esm({
12
+ "src/core/errors/ConnectorError.ts"() {
13
+ "use strict";
14
+ ConnectorError = class extends Error {
15
+ };
16
+ }
17
+ });
18
+
19
+ // src/core/errors/ConfigurationError.ts
20
+ var ConfigurationError;
21
+ var init_ConfigurationError = __esm({
22
+ "src/core/errors/ConfigurationError.ts"() {
23
+ "use strict";
24
+ init_ConnectorError();
25
+ ConfigurationError = class extends ConnectorError {
26
+ constructor(name) {
27
+ super(`\u51ED\u8BC1\u6570\u636E\u4E0D\u5B8C\u6574\uFF0C\u7F3A\u5C11\u5B57\u6BB5\uFF1A${name}`);
28
+ }
29
+ };
30
+ }
31
+ });
32
+
33
+ // src/core/errors/HttpRequestError.ts
34
+ var HttpRequestError;
35
+ var init_HttpRequestError = __esm({
36
+ "src/core/errors/HttpRequestError.ts"() {
37
+ "use strict";
38
+ init_ConnectorError();
39
+ HttpRequestError = class extends ConnectorError {
40
+ constructor(error) {
41
+ const codes = ["ECONNABORTED", "ETIMEDOUT", "ERR_NETWORK"];
42
+ const message = error.code && codes.includes(error.code) ? "\u65E0\u6CD5\u8FDE\u63A5\u81F3 ERP \u670D\u52A1\u5668\uFF0C\u5EFA\u8BAE\u68C0\u67E5\u7F51\u7EDC" : "ERP \u670D\u52A1\u5668\u8BF7\u6C42\u51FA\u9519\uFF0C\u5EFA\u8BAE\u7A0D\u540E\u91CD\u8BD5";
43
+ super(message);
44
+ this.error = error;
45
+ }
46
+ error;
47
+ };
48
+ }
49
+ });
50
+
51
+ // src/core/errors/HttpResponseError.ts
52
+ import { isObjectLike } from "es-toolkit/compat";
53
+ var HttpResponseError;
54
+ var init_HttpResponseError = __esm({
55
+ "src/core/errors/HttpResponseError.ts"() {
56
+ "use strict";
57
+ init_ConnectorError();
58
+ HttpResponseError = class extends ConnectorError {
59
+ constructor(response) {
60
+ const message = isObjectLike(response.data) ? `ERP \u8FD4\u56DE\u4E1A\u52A1\u9519\u8BEF\u4FE1\u606F\uFF1A${response.data.msg}` : "\u670D\u52A1\u5668\u9519\u8BEF\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5";
61
+ super(message);
62
+ this.response = response;
63
+ }
64
+ response;
65
+ };
66
+ }
67
+ });
68
+
69
+ // src/core/errors/UnauthorizedError.ts
70
+ var UnauthorizedError;
71
+ var init_UnauthorizedError = __esm({
72
+ "src/core/errors/UnauthorizedError.ts"() {
73
+ "use strict";
74
+ init_ConnectorError();
75
+ UnauthorizedError = class extends ConnectorError {
76
+ constructor(error) {
77
+ super("\u767B\u5F55\u72B6\u6001\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55");
78
+ this.error = error;
79
+ }
80
+ error;
81
+ };
82
+ }
83
+ });
84
+
85
+ // src/core/errors/index.ts
86
+ var init_errors = __esm({
87
+ "src/core/errors/index.ts"() {
88
+ "use strict";
89
+ init_ConfigurationError();
90
+ init_HttpRequestError();
91
+ init_HttpResponseError();
92
+ init_UnauthorizedError();
93
+ }
94
+ });
95
+
96
+ // src/core/http-client/interceptor.ts
97
+ import { isAxiosError, isCancel } from "axios";
98
+ function useAuthorizationInterceptor(instance) {
99
+ instance.interceptors.request.use((request) => {
100
+ const token = process.env.TOKEN;
101
+ if (token && request.withAuthorization !== false) {
102
+ request.headers.setAuthorization(`Bearer ${token}`);
103
+ }
104
+ return request;
105
+ });
106
+ }
107
+ function useRejectionInterceptor(instance, _) {
108
+ instance.interceptors.request.use(void 0, (rejection) => {
109
+ if (isAxiosError(rejection)) {
110
+ throw new HttpRequestError(rejection);
111
+ }
112
+ throw rejection;
113
+ });
114
+ instance.interceptors.response.use(void 0, (rejection) => {
115
+ if (!isAxiosError(rejection) || isCancel(rejection)) {
116
+ throw rejection;
117
+ }
118
+ if (rejection.response) {
119
+ throw new HttpResponseError(rejection.response);
120
+ }
121
+ throw new HttpRequestError(rejection);
122
+ });
123
+ }
124
+ function useStandardResponseInterceptor(axios2, policies) {
125
+ axios2.interceptors.response.use((response) => {
126
+ const data = response.data;
127
+ if (policies.validator.isValidJsonData(data)) {
128
+ if (!policies.validator.isValidCode(data.code)) {
129
+ if (policies.validator.isSessionExpired(data)) {
130
+ throw new UnauthorizedError(response);
131
+ }
132
+ throw new HttpResponseError(response);
133
+ }
134
+ if (response.config.unwrapResponse !== false) {
135
+ response.data = data.data;
136
+ }
137
+ }
138
+ return response;
139
+ });
140
+ }
141
+ var init_interceptor = __esm({
142
+ "src/core/http-client/interceptor.ts"() {
143
+ "use strict";
144
+ init_errors();
145
+ }
146
+ });
147
+
148
+ // src/core/http-client/providers/policy.ts
149
+ function createHttpClientDefaultPolicies() {
150
+ return {
151
+ validator: createHttpClientValidator()
152
+ };
153
+ }
154
+ function createHttpClientValidator() {
155
+ const isValidCode = (code) => {
156
+ return code === "00000";
157
+ };
158
+ const isSessionExpired = (data) => {
159
+ return data.code === "A0230";
160
+ };
161
+ const isValidJsonData = (response) => {
162
+ if (response === null || typeof response !== "object") {
163
+ return false;
164
+ }
165
+ return Reflect.has(response, "code") && Reflect.has(response, "msg");
166
+ };
167
+ return { isSessionExpired, isValidCode, isValidJsonData };
168
+ }
169
+ var init_policy = __esm({
170
+ "src/core/http-client/providers/policy.ts"() {
171
+ "use strict";
172
+ }
173
+ });
174
+
175
+ // src/core/http-client/utils/factory.ts
176
+ import axios from "axios";
177
+ function createHttpClient(policies) {
178
+ const httpClient2 = axios.create({
179
+ baseURL: process.env.SERVER_URL,
180
+ headers: {
181
+ "Content-Type": "application/json"
182
+ },
183
+ timeout: 1e3 * 10
184
+ });
185
+ useAuthorizationInterceptor(httpClient2);
186
+ useStandardResponseInterceptor(httpClient2, policies);
187
+ useRejectionInterceptor(httpClient2, policies);
188
+ return httpClient2;
189
+ }
190
+ var httpClient;
191
+ var init_factory = __esm({
192
+ "src/core/http-client/utils/factory.ts"() {
193
+ "use strict";
194
+ init_interceptor();
195
+ init_policy();
196
+ httpClient = createHttpClient(createHttpClientDefaultPolicies());
197
+ }
198
+ });
199
+
200
+ // src/core/http-client/utils/signal.ts
201
+ function useSignal() {
202
+ const controller = new AbortController();
203
+ const { signal } = controller;
204
+ const abort = () => controller.abort();
205
+ return { abort, signal };
206
+ }
207
+ var init_signal = __esm({
208
+ "src/core/http-client/utils/signal.ts"() {
209
+ "use strict";
210
+ }
211
+ });
212
+
213
+ // src/core/http-client/index.ts
214
+ function defineQuery(query, defaultConfig) {
215
+ return (data, config) => {
216
+ const { abort, signal } = useSignal();
217
+ const payload = data ?? {};
218
+ const request = query(httpClient, payload, {
219
+ ...defaultConfig,
220
+ ...config,
221
+ signal
222
+ });
223
+ const result = request.then(({ data: data2 }) => data2);
224
+ return { abort, result, signal };
225
+ };
226
+ }
227
+ function defineQueryNoData(query, defaultConfig) {
228
+ return (config) => {
229
+ const { abort, signal } = useSignal();
230
+ const request = query(httpClient, { ...defaultConfig, ...config, signal });
231
+ const result = request.then(({ data }) => data);
232
+ return { abort, result, signal };
233
+ };
234
+ }
235
+ var init_http_client = __esm({
236
+ "src/core/http-client/index.ts"() {
237
+ "use strict";
238
+ init_factory();
239
+ init_signal();
240
+ }
241
+ });
242
+
243
+ // src/api/auth/index.ts
244
+ import JSEncrypt from "jsencrypt";
245
+ var getPublicKey, login, AuthApi;
246
+ var init_auth = __esm({
247
+ "src/api/auth/index.ts"() {
248
+ "use strict";
249
+ init_http_client();
250
+ getPublicKey = defineQueryNoData((httpClient2, config) => {
251
+ return httpClient2.get("/api/Next/getPublicKey", config);
252
+ });
253
+ login = defineQuery(
254
+ async (httpClient2, data, config) => {
255
+ const { RSA_PUBLICKEY } = await getPublicKey({
256
+ withAuthorization: false
257
+ }).result;
258
+ const publicKey = `-----BEGIN PUBLIC KEY-----
259
+ ${RSA_PUBLICKEY}
260
+ -----END PUBLIC KEY-----`;
261
+ const encryptor = new JSEncrypt();
262
+ encryptor.setPublicKey(publicKey);
263
+ const formData = new FormData();
264
+ formData.set("username", data.username);
265
+ formData.set("password", encryptor.encrypt(data.password));
266
+ formData.set("isMobile", "false");
267
+ formData.set("rememberMe", "false");
268
+ return httpClient2.post("/apiLogin", formData, {
269
+ ...config,
270
+ withAuthorization: false
271
+ });
272
+ }
273
+ );
274
+ AuthApi = { login };
275
+ }
276
+ });
277
+
278
+ // src/features/token.ts
279
+ import { isNil } from "es-toolkit";
280
+ async function initAuthToken() {
281
+ const username = process.env.USERNAME;
282
+ const password = process.env.PASSWORD;
283
+ if (isNil(username)) {
284
+ throw new ConfigurationError("\u7528\u6237\u540D(USERNAME)");
285
+ }
286
+ if (isNil(password)) {
287
+ throw new ConfigurationError("\u5BC6\u7801(PASSWORD)");
288
+ }
289
+ const authResult = await AuthApi.login({ password, username }).result;
290
+ const token = authResult?.token;
291
+ if (!token) {
292
+ throw new Error("ERP \u767B\u5F55\u672A\u8FD4\u56DE\u6709\u6548 token\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458");
293
+ }
294
+ process.env.TOKEN = token;
295
+ return token;
296
+ }
297
+ var init_token = __esm({
298
+ "src/features/token.ts"() {
299
+ "use strict";
300
+ init_auth();
301
+ init_errors();
302
+ }
303
+ });
304
+
305
+ // src/tools/test.ts
306
+ import * as z from "zod/v4";
307
+ function useTestTool(server) {
308
+ server.registerTool(
309
+ "test",
310
+ {
311
+ description: "\u9A8C\u8BC1 ERP \u8FDE\u63A5\u548C\u767B\u5F55\u72B6\u6001",
312
+ inputSchema: z.object({ message: z.string().optional() })
313
+ },
314
+ async ({ message }) => {
315
+ await initAuthToken();
316
+ return {
317
+ content: [{ text: message ?? "", type: "text" }]
318
+ };
319
+ }
320
+ );
321
+ }
322
+ var init_test = __esm({
323
+ "src/tools/test.ts"() {
324
+ "use strict";
325
+ init_token();
326
+ }
327
+ });
328
+
329
+ // src/index.ts
330
+ import { McpServer } from "@modelcontextprotocol/server";
331
+ import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
332
+ var require_index = __commonJS({
333
+ "src/index.ts"() {
334
+ init_test();
335
+ async function main() {
336
+ const server = new McpServer({ name: "greeting-server", version: "1.0.0" });
337
+ useTestTool(server);
338
+ const transport = new StdioServerTransport();
339
+ await server.connect(transport);
340
+ }
341
+ main();
342
+ }
343
+ });
344
+ export default require_index();
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "gexinsofts-mcp",
3
+ "version": "0.0.1",
4
+ "description": "革新软件 Workbuddy MCP 工具",
5
+ "type": "module",
6
+ "main": "index.js"
7
+ }