@eggjs/mcp-client-plugin 0.0.0 → 4.0.2-beta.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-present Alibaba Group Holding Limited and other contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ //#region \0@oxc-project+runtime@0.103.0/helpers/decorate.js
2
+ function __decorate(decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ }
8
+
9
+ //#endregion
10
+ export { __decorate };
@@ -0,0 +1,7 @@
1
+ //#region \0@oxc-project+runtime@0.103.0/helpers/decorateMetadata.js
2
+ function __decorateMetadata(k, v) {
3
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4
+ }
5
+
6
+ //#endregion
7
+ export { __decorateMetadata };
@@ -0,0 +1,9 @@
1
+ //#region \0@oxc-project+runtime@0.103.0/helpers/decorateParam.js
2
+ function __decorateParam(paramIndex, decorator) {
3
+ return function(target, key) {
4
+ decorator(target, key, paramIndex);
5
+ };
6
+ }
7
+
8
+ //#endregion
9
+ export { __decorateParam };
@@ -0,0 +1,4 @@
1
+ import { McpMethod } from "./lib/constants.js";
2
+ import { QualifierUtil } from "./lib/QualifierUtil.js";
3
+ import { HttpMCPClientFactory } from "./lib/HttpMCPClientFactory.js";
4
+ export { HttpMCPClientFactory, McpMethod, QualifierUtil };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { McpMethod } from "./lib/constants.js";
2
+ import { QualifierUtil } from "./lib/QualifierUtil.js";
3
+ import { HttpMCPClientFactory } from "./lib/HttpMCPClientFactory.js";
4
+
5
+ export { HttpMCPClientFactory, McpMethod, QualifierUtil };
@@ -0,0 +1,28 @@
1
+ import { Logger } from "@eggjs/tegg";
2
+ import { fetch } from "urllib";
3
+ import { HttpClientOptions, HttpMCPClient } from "@eggjs/mcp-client";
4
+
5
+ //#region src/lib/EggHttpMCPClient.d.ts
6
+ interface EggHttpMCPClientOptions {
7
+ clientName: string;
8
+ clientVersion: string;
9
+ logger: Logger;
10
+ transportOptions?: HttpClientOptions["transportOptions"];
11
+ requestOptions?: HttpClientOptions["requestOptions"];
12
+ fetch: typeof fetch;
13
+ transportType: HttpClientOptions["transportType"];
14
+ url: string;
15
+ }
16
+ declare class EggHttpMCPClient extends HttpMCPClient {
17
+ protected readonly logger: Logger;
18
+ constructor(options: EggHttpMCPClientOptions);
19
+ init(): Promise<void>;
20
+ listTools(params?: Parameters<HttpMCPClient["listTools"]>["0"], options?: Parameters<HttpMCPClient["listTools"]>["1"]): ReturnType<HttpMCPClient["listTools"]>;
21
+ listPrompts(params?: Parameters<HttpMCPClient["listPrompts"]>["0"], options?: Parameters<HttpMCPClient["listPrompts"]>["1"]): ReturnType<HttpMCPClient["listPrompts"]>;
22
+ listResources(params?: Parameters<HttpMCPClient["listResources"]>["0"], options?: Parameters<HttpMCPClient["listResources"]>["1"]): ReturnType<HttpMCPClient["listResources"]>;
23
+ connect(transport: Parameters<HttpMCPClient["connect"]>["0"], options?: Parameters<HttpMCPClient["connect"]>["1"]): ReturnType<HttpMCPClient["connect"]>;
24
+ notification(notification: Parameters<HttpMCPClient["notification"]>["0"], options?: Parameters<HttpMCPClient["notification"]>["1"]): ReturnType<HttpMCPClient["notification"]>;
25
+ callTool(params: Parameters<HttpMCPClient["callTool"]>["0"], resultSchema?: Parameters<HttpMCPClient["callTool"]>["1"], options?: Parameters<HttpMCPClient["callTool"]>["2"]): ReturnType<HttpMCPClient["callTool"]>;
26
+ }
27
+ //#endregion
28
+ export { EggHttpMCPClient, EggHttpMCPClientOptions };
@@ -0,0 +1,74 @@
1
+ import { McpMethod } from "./constants.js";
2
+ import { HttpMCPClient, mergeHeaders } from "@eggjs/mcp-client";
3
+ import { ContextHandler } from "@eggjs/tegg-runtime";
4
+
5
+ //#region src/lib/EggHttpMCPClient.ts
6
+ const MCP_METHOD = Symbol("Context#mcpMethod");
7
+ const MCP_TOOL = Symbol("Context#mcpTool");
8
+ var EggHttpMCPClient = class extends HttpMCPClient {
9
+ constructor(options) {
10
+ super({
11
+ name: options.clientName,
12
+ version: options.clientVersion
13
+ }, {
14
+ fetch: options.fetch,
15
+ transportType: options.transportType,
16
+ url: options.url,
17
+ logger: options.logger,
18
+ transportOptions: {
19
+ ...options.transportOptions,
20
+ get requestInit() {
21
+ return {
22
+ ...options.transportOptions?.requestInit,
23
+ get headers() {
24
+ return mergeHeaders(options.transportOptions?.requestInit?.headers);
25
+ }
26
+ };
27
+ }
28
+ },
29
+ requestOptions: options.requestOptions
30
+ });
31
+ this.logger = options.logger;
32
+ }
33
+ async init() {
34
+ await super.init();
35
+ }
36
+ async listTools(params, options) {
37
+ const context = ContextHandler.getContext();
38
+ if (context) context.set(MCP_METHOD, McpMethod.LIST_TOOLS);
39
+ return super.listTools(params, options);
40
+ }
41
+ async listPrompts(params, options) {
42
+ const context = ContextHandler.getContext();
43
+ if (context) context.set(MCP_METHOD, McpMethod.LIST_PROMPTS);
44
+ return super.listPrompts(params, options);
45
+ }
46
+ async listResources(params, options) {
47
+ const context = ContextHandler.getContext();
48
+ if (context) context.set(MCP_METHOD, McpMethod.LIST_RESOURCES);
49
+ return super.listResources(params, options);
50
+ }
51
+ async connect(transport, options) {
52
+ const context = ContextHandler.getContext();
53
+ if (context) context.set(MCP_METHOD, McpMethod.INITIALIZE);
54
+ return super.connect(transport, options);
55
+ }
56
+ async notification(notification, options) {
57
+ if (notification?.method === "notifications/initialized") {
58
+ const context = ContextHandler.getContext();
59
+ if (context) context.set(MCP_METHOD, McpMethod.NOTIFICATION_INIT);
60
+ }
61
+ return super.notification(notification, options);
62
+ }
63
+ async callTool(params, resultSchema, options) {
64
+ const context = ContextHandler.getContext();
65
+ if (context) {
66
+ context.set(MCP_TOOL, params?.name);
67
+ context.set(MCP_METHOD, McpMethod.CALL_TOOLS);
68
+ }
69
+ return super.callTool(params, resultSchema, options);
70
+ }
71
+ };
72
+
73
+ //#endregion
74
+ export { EggHttpMCPClient };
@@ -0,0 +1,10 @@
1
+ import { EggHttpMCPClient } from "./EggHttpMCPClient.js";
2
+ import { Logger, ModuleConfig, ObjectInfo } from "@eggjs/tegg";
3
+
4
+ //#region src/lib/EggHttpStaticMCPClient.d.ts
5
+ declare class EggHttpStaticMCPClient extends EggHttpMCPClient {
6
+ constructor(moduleConfig: ModuleConfig, logger: Logger, objInfo: ObjectInfo);
7
+ _init(): Promise<void>;
8
+ }
9
+ //#endregion
10
+ export { EggHttpStaticMCPClient };
@@ -0,0 +1,74 @@
1
+ import { QualifierUtil } from "./QualifierUtil.js";
2
+ import { EggHttpMCPClient } from "./EggHttpMCPClient.js";
3
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";
4
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";
5
+ import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateParam.js";
6
+ import { AccessLevel, Inject, LifecycleInit, MultiInstanceInfo, MultiInstanceProto, ObjectInitType } from "@eggjs/tegg";
7
+ import { fetch } from "urllib";
8
+ import { MCPClientInjectName, MCPClientQualifierAttribute, getMCPClientConfig, getMCPClientName } from "@eggjs/mcp-client";
9
+ import assert from "node:assert";
10
+ import { ModuleConfigUtil } from "@eggjs/tegg/helper";
11
+
12
+ //#region src/lib/EggHttpStaticMCPClient.ts
13
+ let EggHttpStaticMCPClient = class EggHttpStaticMCPClient$1 extends EggHttpMCPClient {
14
+ constructor(moduleConfig, logger, objInfo) {
15
+ const configName = getMCPClientName(objInfo);
16
+ const sseClientConfig = getMCPClientConfig(moduleConfig, objInfo);
17
+ const clientName = sseClientConfig.clientName ?? configName;
18
+ const mcpServerSubConfig = { ...sseClientConfig };
19
+ assert(mcpServerSubConfig.url, `not found mcpServerSubConfig.url for ${clientName}`);
20
+ super({
21
+ clientName,
22
+ clientVersion: sseClientConfig.version ?? "1.0.0",
23
+ transportType: mcpServerSubConfig.transportType,
24
+ url: mcpServerSubConfig.url,
25
+ logger,
26
+ fetch
27
+ });
28
+ }
29
+ async _init() {
30
+ await super.init();
31
+ }
32
+ };
33
+ __decorate([
34
+ LifecycleInit(),
35
+ __decorateMetadata("design:type", Function),
36
+ __decorateMetadata("design:paramtypes", []),
37
+ __decorateMetadata("design:returntype", Promise)
38
+ ], EggHttpStaticMCPClient.prototype, "_init", null);
39
+ EggHttpStaticMCPClient = __decorate([
40
+ MultiInstanceProto({
41
+ accessLevel: AccessLevel.PUBLIC,
42
+ initType: ObjectInitType.SINGLETON,
43
+ getObjects(ctx) {
44
+ const config = ModuleConfigUtil.loadModuleConfigSync(ctx.unitPath);
45
+ const moduleName = ModuleConfigUtil.readModuleNameSync(ctx.unitPath);
46
+ const clients = config?.mcp?.clients;
47
+ if (!clients) return [];
48
+ return Object.keys(clients).filter((clientName) => {
49
+ return clients[clientName].type === "http";
50
+ }).map((clientName) => {
51
+ const properQualifiers = { ...QualifierUtil.getModuleConfigQualifier(moduleName) };
52
+ return {
53
+ name: MCPClientInjectName,
54
+ qualifiers: [{
55
+ attribute: MCPClientQualifierAttribute,
56
+ value: clientName
57
+ }],
58
+ properQualifiers
59
+ };
60
+ });
61
+ }
62
+ }),
63
+ __decorateParam(0, Inject()),
64
+ __decorateParam(1, Inject()),
65
+ __decorateParam(2, MultiInstanceInfo([MCPClientQualifierAttribute])),
66
+ __decorateMetadata("design:paramtypes", [
67
+ Object,
68
+ Object,
69
+ Object
70
+ ])
71
+ ], EggHttpStaticMCPClient);
72
+
73
+ //#endregion
74
+ export { EggHttpStaticMCPClient };
@@ -0,0 +1,11 @@
1
+ import { EggHttpMCPClient } from "./EggHttpMCPClient.js";
2
+ import { HttpClientOptions } from "@eggjs/mcp-client";
3
+ import { Implementation } from "@modelcontextprotocol/sdk/types.js";
4
+
5
+ //#region src/lib/HttpMCPClientFactory.d.ts
6
+ declare class HttpMCPClientFactory {
7
+ private readonly logger;
8
+ build(clientInfo: Implementation, options: Omit<HttpClientOptions, "logger">): Promise<EggHttpMCPClient>;
9
+ }
10
+ //#endregion
11
+ export { HttpMCPClientFactory };
@@ -0,0 +1,29 @@
1
+ import { EggHttpMCPClient } from "./EggHttpMCPClient.js";
2
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js";
3
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js";
4
+ import { AccessLevel, Inject, SingletonProto } from "@eggjs/tegg";
5
+ import { fetch } from "urllib";
6
+
7
+ //#region src/lib/HttpMCPClientFactory.ts
8
+ let HttpMCPClientFactory = class HttpMCPClientFactory$1 {
9
+ logger;
10
+ async build(clientInfo, options) {
11
+ const httpMCPClient = new EggHttpMCPClient({
12
+ clientName: clientInfo.name,
13
+ clientVersion: clientInfo.version,
14
+ fetch,
15
+ ...options,
16
+ logger: this.logger
17
+ });
18
+ await httpMCPClient.init();
19
+ return httpMCPClient;
20
+ }
21
+ };
22
+ __decorate([Inject(), __decorateMetadata("design:type", Object)], HttpMCPClientFactory.prototype, "logger", void 0);
23
+ HttpMCPClientFactory = __decorate([SingletonProto({
24
+ accessLevel: AccessLevel.PUBLIC,
25
+ name: "httpMcpClientFactory"
26
+ })], HttpMCPClientFactory);
27
+
28
+ //#endregion
29
+ export { HttpMCPClientFactory };
@@ -0,0 +1,8 @@
1
+ import { QualifierInfo } from "@eggjs/tegg";
2
+
3
+ //#region src/lib/QualifierUtil.d.ts
4
+ declare class QualifierUtil {
5
+ static getModuleConfigQualifier(moduleName: string): Record<string, QualifierInfo[]>;
6
+ }
7
+ //#endregion
8
+ export { QualifierUtil };
@@ -0,0 +1,14 @@
1
+ import { ConfigSourceQualifierAttribute } from "@eggjs/tegg";
2
+
3
+ //#region src/lib/QualifierUtil.ts
4
+ var QualifierUtil = class {
5
+ static getModuleConfigQualifier(moduleName) {
6
+ return { moduleConfig: [{
7
+ attribute: ConfigSourceQualifierAttribute,
8
+ value: moduleName
9
+ }] };
10
+ }
11
+ };
12
+
13
+ //#endregion
14
+ export { QualifierUtil };
@@ -0,0 +1,12 @@
1
+ //#region src/lib/constants.d.ts
2
+ declare const McpMethod: {
3
+ readonly INITIALIZE: "initialize";
4
+ readonly NOTIFICATION_INIT: "notifications/initialized";
5
+ readonly LIST_TOOLS: "tools/list";
6
+ readonly CALL_TOOLS: "tools/call";
7
+ readonly LIST_PROMPTS: "prompts/list";
8
+ readonly LIST_RESOURCES: "resources/list";
9
+ };
10
+ type McpMethod = (typeof McpMethod)[keyof typeof McpMethod];
11
+ //#endregion
12
+ export { McpMethod };
@@ -0,0 +1,12 @@
1
+ //#region src/lib/constants.ts
2
+ const McpMethod = {
3
+ INITIALIZE: "initialize",
4
+ NOTIFICATION_INIT: "notifications/initialized",
5
+ LIST_TOOLS: "tools/list",
6
+ CALL_TOOLS: "tools/call",
7
+ LIST_PROMPTS: "prompts/list",
8
+ LIST_RESOURCES: "resources/list"
9
+ };
10
+
11
+ //#endregion
12
+ export { McpMethod };
package/package.json CHANGED
@@ -1,31 +1,75 @@
1
1
  {
2
2
  "name": "@eggjs/mcp-client-plugin",
3
- "version": "0.0.0",
4
- "description": "egg logger",
3
+ "version": "4.0.2-beta.0",
4
+ "description": "mcp client for egg",
5
5
  "keywords": [
6
6
  "egg",
7
- "logger"
7
+ "mcp",
8
+ "module",
9
+ "plugin",
10
+ "tegg",
11
+ "typescript"
8
12
  ],
9
- "homepage": "https://github.com/eggjs/egg/tree/next/packages/logger",
13
+ "homepage": "https://github.com/eggjs/egg/tree/next/tegg/plugin/mcp-client",
10
14
  "bugs": {
11
15
  "url": "https://github.com/eggjs/egg/issues"
12
16
  },
13
- "license": "MIT",
14
- "author": "fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)",
15
17
  "repository": {
16
18
  "type": "git",
17
19
  "url": "git+https://github.com/eggjs/egg.git",
18
- "directory": "packages/logger"
20
+ "directory": "tegg/plugin/mcp-client"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "type": "module",
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": "./dist/index.js",
31
+ "./lib/constants": "./dist/lib/constants.js",
32
+ "./lib/EggHttpMCPClient": "./dist/lib/EggHttpMCPClient.js",
33
+ "./lib/EggHttpStaticMCPClient": "./dist/lib/EggHttpStaticMCPClient.js",
34
+ "./lib/HttpMCPClientFactory": "./dist/lib/HttpMCPClientFactory.js",
35
+ "./lib/QualifierUtil": "./dist/lib/QualifierUtil.js",
36
+ "./package.json": "./package.json"
19
37
  },
20
38
  "publishConfig": {
21
39
  "access": "public"
22
40
  },
23
41
  "dependencies": {
42
+ "@modelcontextprotocol/sdk": "^1.23.0",
43
+ "urllib": "^4.8.2",
44
+ "@eggjs/mcp-client": "4.0.2-beta.0",
45
+ "@eggjs/tegg": "4.0.2-beta.0",
46
+ "@eggjs/tegg-runtime": "4.0.2-beta.0"
24
47
  },
25
48
  "devDependencies": {
49
+ "@types/node": "^24.10.2",
50
+ "typescript": "^5.9.3",
51
+ "zod": "^3.24.1",
52
+ "@eggjs/mock": "7.0.2-beta.0",
53
+ "@eggjs/controller-plugin": "4.0.2-beta.0",
54
+ "@eggjs/tegg-config": "4.0.2-beta.0"
55
+ },
56
+ "peerDependencies": {
57
+ "@eggjs/tegg-plugin": "4.0.2-beta.0",
58
+ "egg": "4.1.2-beta.0"
26
59
  },
27
60
  "engines": {
28
- "node": ">= 22.18.0"
61
+ "node": ">=22.18.0"
62
+ },
63
+ "eggModule": {
64
+ "name": "teggMcpClient"
65
+ },
66
+ "eggPlugin": {
67
+ "name": "teggMcpClient",
68
+ "dependencies": [
69
+ "tegg"
70
+ ]
71
+ },
72
+ "scripts": {
73
+ "typecheck": "tsgo --noEmit"
29
74
  }
30
- }
31
-
75
+ }