@wener/mcps 1.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 (141) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.mjs +15 -0
  3. package/dist/mcps-cli.mjs +174727 -0
  4. package/lib/chat/agent.js +187 -0
  5. package/lib/chat/agent.js.map +1 -0
  6. package/lib/chat/audit.js +238 -0
  7. package/lib/chat/audit.js.map +1 -0
  8. package/lib/chat/converters.js +467 -0
  9. package/lib/chat/converters.js.map +1 -0
  10. package/lib/chat/handler.js +1068 -0
  11. package/lib/chat/handler.js.map +1 -0
  12. package/lib/chat/index.js +12 -0
  13. package/lib/chat/index.js.map +1 -0
  14. package/lib/chat/types.js +35 -0
  15. package/lib/chat/types.js.map +1 -0
  16. package/lib/contracts/AuditContract.js +85 -0
  17. package/lib/contracts/AuditContract.js.map +1 -0
  18. package/lib/contracts/McpsContract.js +113 -0
  19. package/lib/contracts/McpsContract.js.map +1 -0
  20. package/lib/contracts/index.js +3 -0
  21. package/lib/contracts/index.js.map +1 -0
  22. package/lib/dev.server.js +7 -0
  23. package/lib/dev.server.js.map +1 -0
  24. package/lib/entities/ChatRequestEntity.js +318 -0
  25. package/lib/entities/ChatRequestEntity.js.map +1 -0
  26. package/lib/entities/McpRequestEntity.js +271 -0
  27. package/lib/entities/McpRequestEntity.js.map +1 -0
  28. package/lib/entities/RequestLogEntity.js +177 -0
  29. package/lib/entities/RequestLogEntity.js.map +1 -0
  30. package/lib/entities/ResponseEntity.js +150 -0
  31. package/lib/entities/ResponseEntity.js.map +1 -0
  32. package/lib/entities/index.js +11 -0
  33. package/lib/entities/index.js.map +1 -0
  34. package/lib/entities/types.js +11 -0
  35. package/lib/entities/types.js.map +1 -0
  36. package/lib/index.js +3 -0
  37. package/lib/index.js.map +1 -0
  38. package/lib/mcps-cli.js +44 -0
  39. package/lib/mcps-cli.js.map +1 -0
  40. package/lib/providers/McpServerHandlerDef.js +40 -0
  41. package/lib/providers/McpServerHandlerDef.js.map +1 -0
  42. package/lib/providers/findMcpServerDef.js +26 -0
  43. package/lib/providers/findMcpServerDef.js.map +1 -0
  44. package/lib/providers/prometheus/def.js +24 -0
  45. package/lib/providers/prometheus/def.js.map +1 -0
  46. package/lib/providers/prometheus/index.js +2 -0
  47. package/lib/providers/prometheus/index.js.map +1 -0
  48. package/lib/providers/relay/def.js +32 -0
  49. package/lib/providers/relay/def.js.map +1 -0
  50. package/lib/providers/relay/index.js +2 -0
  51. package/lib/providers/relay/index.js.map +1 -0
  52. package/lib/providers/sql/def.js +31 -0
  53. package/lib/providers/sql/def.js.map +1 -0
  54. package/lib/providers/sql/index.js +2 -0
  55. package/lib/providers/sql/index.js.map +1 -0
  56. package/lib/providers/tencent-cls/def.js +44 -0
  57. package/lib/providers/tencent-cls/def.js.map +1 -0
  58. package/lib/providers/tencent-cls/index.js +2 -0
  59. package/lib/providers/tencent-cls/index.js.map +1 -0
  60. package/lib/scripts/bundle.js +90 -0
  61. package/lib/scripts/bundle.js.map +1 -0
  62. package/lib/server/api-routes.js +96 -0
  63. package/lib/server/api-routes.js.map +1 -0
  64. package/lib/server/audit.js +274 -0
  65. package/lib/server/audit.js.map +1 -0
  66. package/lib/server/chat-routes.js +82 -0
  67. package/lib/server/chat-routes.js.map +1 -0
  68. package/lib/server/config.js +223 -0
  69. package/lib/server/config.js.map +1 -0
  70. package/lib/server/db.js +97 -0
  71. package/lib/server/db.js.map +1 -0
  72. package/lib/server/index.js +2 -0
  73. package/lib/server/index.js.map +1 -0
  74. package/lib/server/mcp-handler.js +167 -0
  75. package/lib/server/mcp-handler.js.map +1 -0
  76. package/lib/server/mcp-routes.js +112 -0
  77. package/lib/server/mcp-routes.js.map +1 -0
  78. package/lib/server/mcps-router.js +119 -0
  79. package/lib/server/mcps-router.js.map +1 -0
  80. package/lib/server/schema.js +129 -0
  81. package/lib/server/schema.js.map +1 -0
  82. package/lib/server/server.js +166 -0
  83. package/lib/server/server.js.map +1 -0
  84. package/lib/web/ChatPage.js +827 -0
  85. package/lib/web/ChatPage.js.map +1 -0
  86. package/lib/web/McpInspectorPage.js +214 -0
  87. package/lib/web/McpInspectorPage.js.map +1 -0
  88. package/lib/web/ServersPage.js +93 -0
  89. package/lib/web/ServersPage.js.map +1 -0
  90. package/lib/web/main.js +541 -0
  91. package/lib/web/main.js.map +1 -0
  92. package/package.json +83 -0
  93. package/src/chat/agent.ts +240 -0
  94. package/src/chat/audit.ts +377 -0
  95. package/src/chat/converters.test.ts +325 -0
  96. package/src/chat/converters.ts +459 -0
  97. package/src/chat/handler.test.ts +137 -0
  98. package/src/chat/handler.ts +1233 -0
  99. package/src/chat/index.ts +16 -0
  100. package/src/chat/types.ts +72 -0
  101. package/src/contracts/AuditContract.ts +93 -0
  102. package/src/contracts/McpsContract.ts +141 -0
  103. package/src/contracts/index.ts +18 -0
  104. package/src/dev.server.ts +7 -0
  105. package/src/entities/ChatRequestEntity.ts +157 -0
  106. package/src/entities/McpRequestEntity.ts +149 -0
  107. package/src/entities/RequestLogEntity.ts +78 -0
  108. package/src/entities/ResponseEntity.ts +75 -0
  109. package/src/entities/index.ts +12 -0
  110. package/src/entities/types.ts +188 -0
  111. package/src/index.ts +1 -0
  112. package/src/mcps-cli.ts +59 -0
  113. package/src/providers/McpServerHandlerDef.ts +105 -0
  114. package/src/providers/findMcpServerDef.ts +31 -0
  115. package/src/providers/prometheus/def.ts +21 -0
  116. package/src/providers/prometheus/index.ts +1 -0
  117. package/src/providers/relay/def.ts +31 -0
  118. package/src/providers/relay/index.ts +1 -0
  119. package/src/providers/relay/relay.test.ts +47 -0
  120. package/src/providers/sql/def.ts +33 -0
  121. package/src/providers/sql/index.ts +1 -0
  122. package/src/providers/tencent-cls/def.ts +38 -0
  123. package/src/providers/tencent-cls/index.ts +1 -0
  124. package/src/scripts/bundle.ts +82 -0
  125. package/src/server/api-routes.ts +98 -0
  126. package/src/server/audit.ts +310 -0
  127. package/src/server/chat-routes.ts +95 -0
  128. package/src/server/config.test.ts +162 -0
  129. package/src/server/config.ts +198 -0
  130. package/src/server/db.ts +115 -0
  131. package/src/server/index.ts +1 -0
  132. package/src/server/mcp-handler.ts +209 -0
  133. package/src/server/mcp-routes.ts +133 -0
  134. package/src/server/mcps-router.ts +133 -0
  135. package/src/server/schema.ts +175 -0
  136. package/src/server/server.ts +163 -0
  137. package/src/web/ChatPage.tsx +1005 -0
  138. package/src/web/McpInspectorPage.tsx +254 -0
  139. package/src/web/ServersPage.tsx +139 -0
  140. package/src/web/main.tsx +600 -0
  141. package/src/web/styles.css +15 -0
@@ -0,0 +1,177 @@
1
+ import { _ as _apply_decs_2203_r } from "@swc/helpers/_/_apply_decs_2203_r";
2
+ var _dec, _initClass, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _init_id, /** Unique request ID */ _init_requestId, /** Request timestamp */ _init_timestamp, /** HTTP method */ _init_method, /** Request path */ _init_path, /** Request type (chat, mcp, api, etc) */ _init_requestType, /** Server name (for MCP) or model (for Chat) */ _init_serverName, /** Server type */ _init_serverType, /** HTTP status code */ _init_status, /** Request duration in ms */ _init_durationMs, /** Error message */ _init_error, /** Client IP */ _init_clientIp, /** User agent */ _init_userAgent, /** Request headers (JSON) */ _init_requestHeaders, /** Request body summary (JSON) */ _init_requestBody, /** Response body summary (JSON) */ _init_responseBody, /** Additional metadata (JSON) */ _init_metadata, _init_createdAt, _initProto;
3
+ import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/es';
4
+ let _RequestLogEntity;
5
+ _dec = Entity({
6
+ tableName: 'request_log'
7
+ }), _dec1 = PrimaryKey({
8
+ type: 'integer'
9
+ }), _dec2 = Property({
10
+ type: 'string'
11
+ }), _dec3 = Property({
12
+ type: 'datetime'
13
+ }), _dec4 = Property({
14
+ type: 'string'
15
+ }), _dec5 = Property({
16
+ type: 'string'
17
+ }), _dec6 = Property({
18
+ type: 'string',
19
+ nullable: true
20
+ }), _dec7 = Property({
21
+ type: 'string',
22
+ nullable: true
23
+ }), _dec8 = Property({
24
+ type: 'string',
25
+ nullable: true
26
+ }), _dec9 = Property({
27
+ type: 'integer',
28
+ nullable: true
29
+ }), _dec10 = Property({
30
+ type: 'integer',
31
+ nullable: true
32
+ }), _dec11 = Property({
33
+ type: 'text',
34
+ nullable: true
35
+ }), _dec12 = Property({
36
+ type: 'string',
37
+ nullable: true
38
+ }), _dec13 = Property({
39
+ type: 'string',
40
+ nullable: true
41
+ }), _dec14 = Property({
42
+ type: 'json',
43
+ nullable: true
44
+ }), _dec15 = Property({
45
+ type: 'json',
46
+ nullable: true
47
+ }), _dec16 = Property({
48
+ type: 'json',
49
+ nullable: true
50
+ }), _dec17 = Property({
51
+ type: 'json',
52
+ nullable: true
53
+ }), _dec18 = Property({
54
+ type: 'datetime'
55
+ });
56
+ let RequestLogEntity = class RequestLogEntity {
57
+ static{
58
+ ({ e: [_init_id, _init_requestId, _init_timestamp, _init_method, _init_path, _init_requestType, _init_serverName, _init_serverType, _init_status, _init_durationMs, _init_error, _init_clientIp, _init_userAgent, _init_requestHeaders, _init_requestBody, _init_responseBody, _init_metadata, _init_createdAt, _initProto], c: [_RequestLogEntity, _initClass] } = _apply_decs_2203_r(this, [
59
+ [
60
+ _dec1,
61
+ 0,
62
+ "id"
63
+ ],
64
+ [
65
+ _dec2,
66
+ 0,
67
+ "requestId"
68
+ ],
69
+ [
70
+ _dec3,
71
+ 0,
72
+ "timestamp"
73
+ ],
74
+ [
75
+ _dec4,
76
+ 0,
77
+ "method"
78
+ ],
79
+ [
80
+ _dec5,
81
+ 0,
82
+ "path"
83
+ ],
84
+ [
85
+ _dec6,
86
+ 0,
87
+ "requestType"
88
+ ],
89
+ [
90
+ _dec7,
91
+ 0,
92
+ "serverName"
93
+ ],
94
+ [
95
+ _dec8,
96
+ 0,
97
+ "serverType"
98
+ ],
99
+ [
100
+ _dec9,
101
+ 0,
102
+ "status"
103
+ ],
104
+ [
105
+ _dec10,
106
+ 0,
107
+ "durationMs"
108
+ ],
109
+ [
110
+ _dec11,
111
+ 0,
112
+ "error"
113
+ ],
114
+ [
115
+ _dec12,
116
+ 0,
117
+ "clientIp"
118
+ ],
119
+ [
120
+ _dec13,
121
+ 0,
122
+ "userAgent"
123
+ ],
124
+ [
125
+ _dec14,
126
+ 0,
127
+ "requestHeaders"
128
+ ],
129
+ [
130
+ _dec15,
131
+ 0,
132
+ "requestBody"
133
+ ],
134
+ [
135
+ _dec16,
136
+ 0,
137
+ "responseBody"
138
+ ],
139
+ [
140
+ _dec17,
141
+ 0,
142
+ "metadata"
143
+ ],
144
+ [
145
+ _dec18,
146
+ 0,
147
+ "createdAt"
148
+ ]
149
+ ], [
150
+ _dec
151
+ ]));
152
+ }
153
+ id = (_initProto(this), _init_id(this));
154
+ requestId = _init_requestId(this);
155
+ timestamp = _init_timestamp(this, new Date());
156
+ method = _init_method(this);
157
+ path = _init_path(this);
158
+ requestType = _init_requestType(this);
159
+ serverName = _init_serverName(this);
160
+ serverType = _init_serverType(this);
161
+ status = _init_status(this);
162
+ durationMs = _init_durationMs(this);
163
+ error = _init_error(this);
164
+ clientIp = _init_clientIp(this);
165
+ userAgent = _init_userAgent(this);
166
+ requestHeaders = _init_requestHeaders(this);
167
+ requestBody = _init_requestBody(this);
168
+ responseBody = _init_responseBody(this);
169
+ metadata = _init_metadata(this);
170
+ createdAt = _init_createdAt(this, new Date());
171
+ static{
172
+ _initClass();
173
+ }
174
+ };
175
+ export { _RequestLogEntity as RequestLogEntity };
176
+
177
+ //# sourceMappingURL=RequestLogEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/entities/RequestLogEntity.ts"],"sourcesContent":["import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/es';\n\n/**\n * Generic HTTP Request Log Entity\n * For general request auditing\n */\n@Entity({ tableName: 'request_log' })\nexport class RequestLogEntity {\n\t@PrimaryKey({ type: 'integer' })\n\tid!: number;\n\n\t/** Unique request ID */\n\t@Property({ type: 'string' })\n\trequestId!: string;\n\n\t/** Request timestamp */\n\t@Property({ type: 'datetime' })\n\ttimestamp: Date = new Date();\n\n\t/** HTTP method */\n\t@Property({ type: 'string' })\n\tmethod!: string;\n\n\t/** Request path */\n\t@Property({ type: 'string' })\n\tpath!: string;\n\n\t/** Request type (chat, mcp, api, etc) */\n\t@Property({ type: 'string', nullable: true })\n\trequestType?: string;\n\n\t/** Server name (for MCP) or model (for Chat) */\n\t@Property({ type: 'string', nullable: true })\n\tserverName?: string;\n\n\t/** Server type */\n\t@Property({ type: 'string', nullable: true })\n\tserverType?: string;\n\n\t/** HTTP status code */\n\t@Property({ type: 'integer', nullable: true })\n\tstatus?: number;\n\n\t/** Request duration in ms */\n\t@Property({ type: 'integer', nullable: true })\n\tdurationMs?: number;\n\n\t/** Error message */\n\t@Property({ type: 'text', nullable: true })\n\terror?: string;\n\n\t/** Client IP */\n\t@Property({ type: 'string', nullable: true })\n\tclientIp?: string;\n\n\t/** User agent */\n\t@Property({ type: 'string', nullable: true })\n\tuserAgent?: string;\n\n\t/** Request headers (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\trequestHeaders?: Record<string, string>;\n\n\t/** Request body summary (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\trequestBody?: Record<string, unknown>;\n\n\t/** Response body summary (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\tresponseBody?: Record<string, unknown>;\n\n\t/** Additional metadata (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\tmetadata?: Record<string, unknown>;\n\n\t@Property({ type: 'datetime' })\n\tcreatedAt: Date = new Date();\n}\n"],"names":["id","requestId","timestamp","method","path","requestType","serverName","serverType","status","durationMs","error","clientIp","userAgent","requestHeaders","requestBody","responseBody","metadata","createdAt","Entity","PrimaryKey","Property","tableName","type","nullable","RequestLogEntity","Date"],"mappings":";6JAQC,AACAA,UAEA,sBAAsB,GACtB,AACAC,iBAEA,sBAAsB,GACtB,AACAC,iBAEA,gBAAgB,GAChB,AACAC,cAEA,iBAAiB,GACjB,AACAC,YAEA,uCAAuC,GACvC,AACAC,mBAEA,8CAA8C,GAC9C,AACAC,kBAEA,gBAAgB,GAChB,AACAC,kBAEA,qBAAqB,GACrB,AACAC,cAEA,2BAA2B,GAC3B,AACAC,kBAEA,kBAAkB,GAClB,AACAC,aAEA,cAAc,GACd,AACAC,gBAEA,eAAe,GACf,AACAC,iBAEA,2BAA2B,GAC3B,AACAC,sBAEA,gCAAgC,GAChC,AACAC,mBAEA,iCAAiC,GACjC,AACAC,oBAEA,+BAA+B,GAC/B,AACAC,gBAEA,AACAC;AA5ED,SAASC,MAAM,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,2BAA2B;;OAMvEF,OAAO;IAAEG,WAAW;AAAc,YAEjCF,WAAW;IAAEG,MAAM;AAAU,YAI7BF,SAAS;IAAEE,MAAM;AAAS,YAI1BF,SAAS;IAAEE,MAAM;AAAW,YAI5BF,SAAS;IAAEE,MAAM;AAAS,YAI1BF,SAAS;IAAEE,MAAM;AAAS,YAI1BF,SAAS;IAAEE,MAAM;IAAUC,UAAU;AAAK,YAI1CH,SAAS;IAAEE,MAAM;IAAUC,UAAU;AAAK,YAI1CH,SAAS;IAAEE,MAAM;IAAUC,UAAU;AAAK,YAI1CH,SAAS;IAAEE,MAAM;IAAWC,UAAU;AAAK,aAI3CH,SAAS;IAAEE,MAAM;IAAWC,UAAU;AAAK,aAI3CH,SAAS;IAAEE,MAAM;IAAQC,UAAU;AAAK,aAIxCH,SAAS;IAAEE,MAAM;IAAUC,UAAU;AAAK,aAI1CH,SAAS;IAAEE,MAAM;IAAUC,UAAU;AAAK,aAI1CH,SAAS;IAAEE,MAAM;IAAQC,UAAU;AAAK,aAIxCH,SAAS;IAAEE,MAAM;IAAQC,UAAU;AAAK,aAIxCH,SAAS;IAAEE,MAAM;IAAQC,UAAU;AAAK,aAIxCH,SAAS;IAAEE,MAAM;IAAQC,UAAU;AAAK,aAGxCH,SAAS;IAAEE,MAAM;AAAW;AApEvB,IAAA,AAAME,mBAAN,MAAMA;;eAEZxB,UAIAC,iBAIAC,iBAIAC,cAIAC,YAIAC,mBAIAC,kBAIAC,kBAIAC,cAIAC,kBAIAC,aAIAC,gBAIAC,iBAIAC,sBAIAC,mBAIAC,oBAIAC,gBAGAC;;;;gBAnEAjB;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAGAC;;;;;;IAnEAjB,wBAAAA,gBAAY;IAIZC,YAAAA,sBAAmB;IAInBC,YAAAA,sBAAkB,IAAIuB,QAAO;IAI7BtB,SAAAA,mBAAgB;IAIhBC,OAAAA,iBAAc;IAIdC,cAAAA,wBAAqB;IAIrBC,aAAAA,uBAAoB;IAIpBC,aAAAA,uBAAoB;IAIpBC,SAAAA,mBAAgB;IAIhBC,aAAAA,uBAAoB;IAIpBC,QAAAA,kBAAe;IAIfC,WAAAA,qBAAkB;IAIlBC,YAAAA,sBAAmB;IAInBC,iBAAAA,2BAAwC;IAIxCC,cAAAA,wBAAsC;IAItCC,eAAAA,yBAAuC;IAIvCC,WAAAA,qBAAmC;IAGnCC,YAAAA,sBAAkB,IAAIQ,QAAO;;;;AAC9B;SAtEA,AAAaD,qBAAAA,gBAsEZ"}
@@ -0,0 +1,150 @@
1
+ import { _ as _apply_decs_2203_r } from "@swc/helpers/_/_apply_decs_2203_r";
2
+ var _dec, _initClass, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _init_id, /** Response ID (e.g., resp_xxx) */ _init_responseId, /** Model name */ _init_model, /** Response status */ _init_status, /** Input (request) - stored as JSON */ _init_input, /** Output items - stored as JSON */ _init_output, /** Usage statistics */ _init_usage, /** Instructions/system prompt */ _init_instructions, /** Previous response ID for conversation chaining */ _init_previousResponseId, /** Tools configuration */ _init_tools, /** Tool choice */ _init_toolChoice, /** Metadata */ _init_metadata, /** Error information */ _init_error, /** Created timestamp */ _init_createdAt, /** Request duration in ms */ _init_durationMs, _initProto;
3
+ import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/es';
4
+ let _ResponseEntity;
5
+ _dec = Entity({
6
+ tableName: 'response'
7
+ }), _dec1 = PrimaryKey({
8
+ type: 'integer'
9
+ }), _dec2 = Property({
10
+ type: 'string',
11
+ unique: true
12
+ }), _dec3 = Property({
13
+ type: 'string'
14
+ }), _dec4 = Property({
15
+ type: 'string'
16
+ }), _dec5 = Property({
17
+ type: 'json'
18
+ }), _dec6 = Property({
19
+ type: 'json'
20
+ }), _dec7 = Property({
21
+ type: 'json',
22
+ nullable: true
23
+ }), _dec8 = Property({
24
+ type: 'text',
25
+ nullable: true
26
+ }), _dec9 = Property({
27
+ type: 'string',
28
+ nullable: true
29
+ }), _dec10 = Property({
30
+ type: 'json',
31
+ nullable: true
32
+ }), _dec11 = Property({
33
+ type: 'json',
34
+ nullable: true
35
+ }), _dec12 = Property({
36
+ type: 'json',
37
+ nullable: true
38
+ }), _dec13 = Property({
39
+ type: 'json',
40
+ nullable: true
41
+ }), _dec14 = Property({
42
+ type: 'datetime'
43
+ }), _dec15 = Property({
44
+ type: 'integer',
45
+ nullable: true
46
+ });
47
+ let ResponseEntity = class ResponseEntity {
48
+ static{
49
+ ({ e: [_init_id, _init_responseId, _init_model, _init_status, _init_input, _init_output, _init_usage, _init_instructions, _init_previousResponseId, _init_tools, _init_toolChoice, _init_metadata, _init_error, _init_createdAt, _init_durationMs, _initProto], c: [_ResponseEntity, _initClass] } = _apply_decs_2203_r(this, [
50
+ [
51
+ _dec1,
52
+ 0,
53
+ "id"
54
+ ],
55
+ [
56
+ _dec2,
57
+ 0,
58
+ "responseId"
59
+ ],
60
+ [
61
+ _dec3,
62
+ 0,
63
+ "model"
64
+ ],
65
+ [
66
+ _dec4,
67
+ 0,
68
+ "status"
69
+ ],
70
+ [
71
+ _dec5,
72
+ 0,
73
+ "input"
74
+ ],
75
+ [
76
+ _dec6,
77
+ 0,
78
+ "output"
79
+ ],
80
+ [
81
+ _dec7,
82
+ 0,
83
+ "usage"
84
+ ],
85
+ [
86
+ _dec8,
87
+ 0,
88
+ "instructions"
89
+ ],
90
+ [
91
+ _dec9,
92
+ 0,
93
+ "previousResponseId"
94
+ ],
95
+ [
96
+ _dec10,
97
+ 0,
98
+ "tools"
99
+ ],
100
+ [
101
+ _dec11,
102
+ 0,
103
+ "toolChoice"
104
+ ],
105
+ [
106
+ _dec12,
107
+ 0,
108
+ "metadata"
109
+ ],
110
+ [
111
+ _dec13,
112
+ 0,
113
+ "error"
114
+ ],
115
+ [
116
+ _dec14,
117
+ 0,
118
+ "createdAt"
119
+ ],
120
+ [
121
+ _dec15,
122
+ 0,
123
+ "durationMs"
124
+ ]
125
+ ], [
126
+ _dec
127
+ ]));
128
+ }
129
+ id = (_initProto(this), _init_id(this));
130
+ responseId = _init_responseId(this);
131
+ model = _init_model(this);
132
+ status = _init_status(this);
133
+ input = _init_input(this);
134
+ output = _init_output(this);
135
+ usage = _init_usage(this);
136
+ instructions = _init_instructions(this);
137
+ previousResponseId = _init_previousResponseId(this);
138
+ tools = _init_tools(this);
139
+ toolChoice = _init_toolChoice(this);
140
+ metadata = _init_metadata(this);
141
+ error = _init_error(this);
142
+ createdAt = _init_createdAt(this, new Date());
143
+ durationMs = _init_durationMs(this);
144
+ static{
145
+ _initClass();
146
+ }
147
+ };
148
+ export { _ResponseEntity as ResponseEntity };
149
+
150
+ //# sourceMappingURL=ResponseEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/entities/ResponseEntity.ts"],"sourcesContent":["import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/es';\n\n/**\n * Response Entity for storing Responses API responses\n * Enables previous_response_id support\n */\n@Entity({ tableName: 'response' })\nexport class ResponseEntity {\n\t@PrimaryKey({ type: 'integer' })\n\tid!: number;\n\n\t/** Response ID (e.g., resp_xxx) */\n\t@Property({ type: 'string', unique: true })\n\tresponseId!: string;\n\n\t/** Model name */\n\t@Property({ type: 'string' })\n\tmodel!: string;\n\n\t/** Response status */\n\t@Property({ type: 'string' })\n\tstatus!: string;\n\n\t/** Input (request) - stored as JSON */\n\t@Property({ type: 'json' })\n\tinput!: unknown;\n\n\t/** Output items - stored as JSON */\n\t@Property({ type: 'json' })\n\toutput!: unknown[];\n\n\t/** Usage statistics */\n\t@Property({ type: 'json', nullable: true })\n\tusage?: {\n\t\tprompt_tokens?: number;\n\t\tcompletion_tokens?: number;\n\t\ttotal_tokens?: number;\n\t};\n\n\t/** Instructions/system prompt */\n\t@Property({ type: 'text', nullable: true })\n\tinstructions?: string;\n\n\t/** Previous response ID for conversation chaining */\n\t@Property({ type: 'string', nullable: true })\n\tpreviousResponseId?: string;\n\n\t/** Tools configuration */\n\t@Property({ type: 'json', nullable: true })\n\ttools?: unknown[];\n\n\t/** Tool choice */\n\t@Property({ type: 'json', nullable: true })\n\ttoolChoice?: unknown;\n\n\t/** Metadata */\n\t@Property({ type: 'json', nullable: true })\n\tmetadata?: Record<string, unknown>;\n\n\t/** Error information */\n\t@Property({ type: 'json', nullable: true })\n\terror?: {\n\t\ttype?: string;\n\t\tmessage?: string;\n\t\tcode?: string;\n\t};\n\n\t/** Created timestamp */\n\t@Property({ type: 'datetime' })\n\tcreatedAt: Date = new Date();\n\n\t/** Request duration in ms */\n\t@Property({ type: 'integer', nullable: true })\n\tdurationMs?: number;\n}\n"],"names":["id","responseId","model","status","input","output","usage","instructions","previousResponseId","tools","toolChoice","metadata","error","createdAt","durationMs","Entity","PrimaryKey","Property","tableName","type","unique","nullable","ResponseEntity","Date"],"mappings":";qIAQC,AACAA,UAEA,iCAAiC,GACjC,AACAC,kBAEA,eAAe,GACf,AACAC,aAEA,oBAAoB,GACpB,AACAC,cAEA,qCAAqC,GACrC,AACAC,aAEA,kCAAkC,GAClC,AACAC,cAEA,qBAAqB,GACrB,AACAC,aAMA,+BAA+B,GAC/B,AACAC,oBAEA,mDAAmD,GACnD,AACAC,0BAEA,wBAAwB,GACxB,AACAC,aAEA,gBAAgB,GAChB,AACAC,kBAEA,aAAa,GACb,AACAC,gBAEA,sBAAsB,GACtB,AACAC,aAMA,sBAAsB,GACtB,AACAC,iBAEA,2BAA2B,GAC3B,AACAC;AAzED,SAASC,MAAM,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,2BAA2B;;OAMvEF,OAAO;IAAEG,WAAW;AAAW,YAE9BF,WAAW;IAAEG,MAAM;AAAU,YAI7BF,SAAS;IAAEE,MAAM;IAAUC,QAAQ;AAAK,YAIxCH,SAAS;IAAEE,MAAM;AAAS,YAI1BF,SAAS;IAAEE,MAAM;AAAS,YAI1BF,SAAS;IAAEE,MAAM;AAAO,YAIxBF,SAAS;IAAEE,MAAM;AAAO,YAIxBF,SAAS;IAAEE,MAAM;IAAQE,UAAU;AAAK,YAQxCJ,SAAS;IAAEE,MAAM;IAAQE,UAAU;AAAK,YAIxCJ,SAAS;IAAEE,MAAM;IAAUE,UAAU;AAAK,aAI1CJ,SAAS;IAAEE,MAAM;IAAQE,UAAU;AAAK,aAIxCJ,SAAS;IAAEE,MAAM;IAAQE,UAAU;AAAK,aAIxCJ,SAAS;IAAEE,MAAM;IAAQE,UAAU;AAAK,aAIxCJ,SAAS;IAAEE,MAAM;IAAQE,UAAU;AAAK,aAQxCJ,SAAS;IAAEE,MAAM;AAAW,aAI5BF,SAAS;IAAEE,MAAM;IAAWE,UAAU;AAAK;AAjEtC,IAAA,AAAMC,iBAAN,MAAMA;;eAEZtB,UAIAC,kBAIAC,aAIAC,cAIAC,aAIAC,cAIAC,aAQAC,oBAIAC,0BAIAC,aAIAC,kBAIAC,gBAIAC,aAQAC,iBAIAC;;;;gBAhEAd;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAQAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAQAC;;;;;gBAIAC;;;;;;IAhEAd,wBAAAA,gBAAY;IAIZC,aAAAA,uBAAoB;IAIpBC,QAAAA,kBAAe;IAIfC,SAAAA,mBAAgB;IAIhBC,QAAAA,kBAAgB;IAIhBC,SAAAA,mBAAmB;IAInBC,QAAAA,kBAIE;IAIFC,eAAAA,yBAAsB;IAItBC,qBAAAA,+BAA4B;IAI5BC,QAAAA,kBAAkB;IAIlBC,aAAAA,uBAAqB;IAIrBC,WAAAA,qBAAmC;IAInCC,QAAAA,kBAIE;IAIFC,YAAAA,sBAAkB,IAAIU,QAAO;IAI7BT,aAAAA,uBAAoB;;;;AACrB;SAnEA,AAAaQ,mBAAAA,cAmEZ"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Entity type definitions
3
+ * These are pure TypeScript types without decorators
4
+ * Can be used with any ORM or database layer
5
+ */ export * from "./types.js";
6
+ // MikroORM Entities
7
+ export { ChatRequestEntity, ChatProtocolType, RequestStatus } from "./ChatRequestEntity.js";
8
+ export { McpRequestEntity, McpServerType, McpRequestType } from "./McpRequestEntity.js";
9
+ export { RequestLogEntity } from "./RequestLogEntity.js";
10
+ export { ResponseEntity } from "./ResponseEntity.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/entities/index.ts"],"sourcesContent":["/**\n * Entity type definitions\n * These are pure TypeScript types without decorators\n * Can be used with any ORM or database layer\n */\nexport * from './types';\n\n// MikroORM Entities\nexport { ChatRequestEntity, ChatProtocolType, RequestStatus } from './ChatRequestEntity';\nexport { McpRequestEntity, McpServerType, McpRequestType } from './McpRequestEntity';\nexport { RequestLogEntity } from './RequestLogEntity';\nexport { ResponseEntity } from './ResponseEntity';\n"],"names":["ChatRequestEntity","ChatProtocolType","RequestStatus","McpRequestEntity","McpServerType","McpRequestType","RequestLogEntity","ResponseEntity"],"mappings":"AAAA;;;;CAIC,GACD,cAAc,UAAU;AAExB,oBAAoB;AACpB,SAASA,iBAAiB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,sBAAsB;AACzF,SAASC,gBAAgB,EAAEC,aAAa,EAAEC,cAAc,QAAQ,qBAAqB;AACrF,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,cAAc,QAAQ,mBAAmB"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Entity Type Definitions
3
+ * These types can be used with MikroORM or other ORMs
4
+ * Avoids decorator issues in test environments
5
+ */ /**
6
+ * Base entity fields
7
+ */ /**
8
+ * MCP audit statistics
9
+ */ export { };
10
+
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/entities/types.ts"],"sourcesContent":["/**\n * Entity Type Definitions\n * These types can be used with MikroORM or other ORMs\n * Avoids decorator issues in test environments\n */\n\n/**\n * Base entity fields\n */\nexport interface BaseEntity {\n\tid: number;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\n/**\n * Request status\n */\nexport type RequestStatus = 'pending' | 'success' | 'error' | 'timeout';\n\n/**\n * Chat protocol type\n */\nexport type ChatProtocolType = 'openai' | 'anthropic' | 'gemini';\n\n/**\n * MCP server type\n */\nexport type McpServerType = 'tencent-cls' | 'sql' | 'prometheus' | 'relay' | 'custom';\n\n/**\n * MCP request type\n */\nexport type McpRequestType =\n\t| 'initialize'\n\t| 'tools/list'\n\t| 'tools/call'\n\t| 'resources/list'\n\t| 'resources/read'\n\t| 'prompts/list'\n\t| 'prompts/get'\n\t| 'completion/complete'\n\t| 'logging/setLevel'\n\t| 'ping'\n\t| 'other';\n\n/**\n * Chat request entity for auditing and metering\n */\nexport interface ChatRequest extends BaseEntity {\n\t/** Unique request ID for tracing */\n\trequestId: string;\n\t/** Request timestamp */\n\trequestedAt: Date;\n\t/** Response timestamp */\n\tcompletedAt?: Date;\n\t/** Request status */\n\tstatus: RequestStatus;\n\t/** HTTP method */\n\tmethod: string;\n\t/** Request path/endpoint */\n\tendpoint: string;\n\t/** Input protocol (client-facing) */\n\tinputProtocol: ChatProtocolType;\n\t/** Output protocol (upstream provider) */\n\toutputProtocol: ChatProtocolType;\n\t/** Model name requested */\n\tmodel: string;\n\t/** Resolved model name */\n\tresolvedModel?: string;\n\t/** Provider name */\n\tprovider?: string;\n\t/** Upstream base URL */\n\tupstreamUrl?: string;\n\t/** Whether request was streaming */\n\tstreaming: boolean;\n\t/** Input token count */\n\tinputTokens?: number;\n\t/** Output token count */\n\toutputTokens?: number;\n\t/** Total token count */\n\ttotalTokens?: number;\n\t/** Request duration in ms */\n\tdurationMs?: number;\n\t/** Time to first token in ms */\n\tttftMs?: number;\n\t/** HTTP status code */\n\thttpStatus?: number;\n\t/** Error message */\n\terrorMessage?: string;\n\t/** Error code */\n\terrorCode?: string;\n\t/** Client IP */\n\tclientIp?: string;\n\t/** User agent */\n\tuserAgent?: string;\n\t/** User ID */\n\tuserId?: string;\n\t/** Organization ID */\n\torgId?: string;\n\t/** API key ID (not the actual key) */\n\tapiKeyId?: string;\n\t/** Request metadata */\n\trequestMeta?: Record<string, unknown>;\n\t/** Response metadata */\n\tresponseMeta?: Record<string, unknown>;\n\t/** Cost in credits */\n\tcost?: string;\n\t/** Currency */\n\tcurrency?: string;\n}\n\n/**\n * MCP request entity for auditing\n */\nexport interface McpRequest extends BaseEntity {\n\t/** Unique request ID */\n\trequestId: string;\n\t/** MCP session ID */\n\tsessionId?: string;\n\t/** Request timestamp */\n\trequestedAt: Date;\n\t/** Response timestamp */\n\tcompletedAt?: Date;\n\t/** Request status */\n\tstatus: RequestStatus;\n\t/** HTTP method */\n\tmethod: string;\n\t/** Request path */\n\tpath: string;\n\t/** MCP server name */\n\tserverName: string;\n\t/** MCP server type */\n\tserverType: McpServerType;\n\t/** MCP request type */\n\tmcpMethod: McpRequestType;\n\t/** Tool name (for tools/call) */\n\ttoolName?: string;\n\t/** Resource URI (for resources/read) */\n\tresourceUri?: string;\n\t/** Prompt name (for prompts/get) */\n\tpromptName?: string;\n\t/** Request duration in ms */\n\tdurationMs?: number;\n\t/** HTTP status code */\n\thttpStatus?: number;\n\t/** Error message */\n\terrorMessage?: string;\n\t/** Error code */\n\terrorCode?: string;\n\t/** Client IP */\n\tclientIp?: string;\n\t/** User agent */\n\tuserAgent?: string;\n\t/** User ID */\n\tuserId?: string;\n\t/** Request headers */\n\trequestHeaders?: Record<string, string>;\n\t/** Request body */\n\trequestBody?: Record<string, unknown>;\n\t/** Response metadata */\n\tresponseMeta?: Record<string, unknown>;\n}\n\n/**\n * Chat audit statistics\n */\nexport interface ChatAuditStats {\n\ttotalRequests: number;\n\tsuccessfulRequests: number;\n\tfailedRequests: number;\n\ttotalInputTokens: number;\n\ttotalOutputTokens: number;\n\tavgDurationMs: number;\n\tbyModel: { model: string; count: number; tokens: number }[];\n\tbyProvider: { provider: string; count: number; tokens: number }[];\n}\n\n/**\n * MCP audit statistics\n */\nexport interface McpAuditStats {\n\ttotalRequests: number;\n\ttotalErrors: number;\n\tavgDurationMs: number;\n\tbyServer: { name: string; count: number }[];\n\tbyMethod: { method: string; count: number }[];\n}\n"],"names":[],"mappings":"AAAA;;;;CAIC,GAED;;CAEC,GA0KD;;CAEC,GACD,WAMC"}
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {};\n"],"names":[],"mappings":"AAAA,WAAU"}
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * MCPS - MCP Proxy Server CLI
4
+ *
5
+ * A unified MCP server that supports:
6
+ * - Tencent CLS (Cloud Log Service)
7
+ * - SQL (MySQL, PostgreSQL, SQLite)
8
+ * - Prometheus
9
+ * - Relay (proxy to other MCP servers)
10
+ */ import { serve } from "@hono/node-server";
11
+ import { Command } from "commander";
12
+ import consola from "consola";
13
+ import { createServer } from "./server/server.js";
14
+ const log = consola.withTag("mcps");
15
+ const program = new Command();
16
+ program.name("mcps").description("MCP Proxy Server - Unified MCP service with relay, SQL, CLS, and Prometheus support").version("0.1.0").option("-p, --port <port>", "Port to listen on", "8036").option("-c, --cwd <path>", "Working directory for config files", process.cwd()).option("--discovery-config", "Enable server config discovery endpoints", false).action(async (options) => {
17
+ const port = Number.parseInt(options.port, 10);
18
+ const { app } = createServer({
19
+ cwd: options.cwd,
20
+ port,
21
+ discoveryConfig: options.discoveryConfig
22
+ });
23
+ log.info(`Starting MCPS server on port ${port}`);
24
+ serve({
25
+ fetch: app.fetch,
26
+ port,
27
+ hostname: "0.0.0.0"
28
+ });
29
+ log.success(`MCPS server running at http://localhost:${port}`);
30
+ });
31
+ // Handle graceful shutdown
32
+ process.on("SIGINT", () => {
33
+ log.info("Shutting down...");
34
+ process.exit(130);
35
+ });
36
+ process.on("SIGTERM", () => {
37
+ log.info("Shutting down...");
38
+ process.exit(143);
39
+ });
40
+ program.parseAsync(process.argv).catch((error) => {
41
+ log.error(error.message);
42
+ process.exit(1);
43
+ });
44
+ //# sourceMappingURL=mcps-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcps-cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * MCPS - MCP Proxy Server CLI\n *\n * A unified MCP server that supports:\n * - Tencent CLS (Cloud Log Service)\n * - SQL (MySQL, PostgreSQL, SQLite)\n * - Prometheus\n * - Relay (proxy to other MCP servers)\n */\nimport { serve } from '@hono/node-server';\nimport { Command } from 'commander';\nimport consola from 'consola';\nimport { createServer } from './server/server';\n\nconst log = consola.withTag('mcps');\n\nconst program = new Command();\n\nprogram\n\t.name('mcps')\n\t.description('MCP Proxy Server - Unified MCP service with relay, SQL, CLS, and Prometheus support')\n\t.version('0.1.0')\n\t.option('-p, --port <port>', 'Port to listen on', '8036')\n\t.option('-c, --cwd <path>', 'Working directory for config files', process.cwd())\n\t.option('--discovery-config', 'Enable server config discovery endpoints', false)\n\t.action(async (options) => {\n\t\tconst port = Number.parseInt(options.port, 10);\n\t\tconst { app } = createServer({\n\t\t\tcwd: options.cwd,\n\t\t\tport,\n\t\t\tdiscoveryConfig: options.discoveryConfig,\n\t\t});\n\n\t\tlog.info(`Starting MCPS server on port ${port}`);\n\n\t\tserve({\n\t\t\tfetch: app.fetch,\n\t\t\tport,\n\t\t\thostname: '0.0.0.0',\n\t\t});\n\n\t\tlog.success(`MCPS server running at http://localhost:${port}`);\n\t});\n\n// Handle graceful shutdown\nprocess.on('SIGINT', () => {\n\tlog.info('Shutting down...');\n\tprocess.exit(130);\n});\nprocess.on('SIGTERM', () => {\n\tlog.info('Shutting down...');\n\tprocess.exit(143);\n});\n\nprogram.parseAsync(process.argv).catch((error) => {\n\tlog.error(error.message);\n\tprocess.exit(1);\n});\n"],"names":["serve","Command","consola","createServer","log","withTag","program","name","description","version","option","process","cwd","action","options","port","Number","parseInt","app","discoveryConfig","info","fetch","hostname","success","on","exit","parseAsync","argv","catch","error","message"],"mappings":";AACA;;;;;;;;CAQC,GACD,SAASA,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,OAAO,QAAQ,YAAY;AACpC,OAAOC,aAAa,UAAU;AAC9B,SAASC,YAAY,QAAQ,kBAAkB;AAE/C,MAAMC,MAAMF,QAAQG,OAAO,CAAC;AAE5B,MAAMC,UAAU,IAAIL;AAEpBK,QACEC,IAAI,CAAC,QACLC,WAAW,CAAC,uFACZC,OAAO,CAAC,SACRC,MAAM,CAAC,qBAAqB,qBAAqB,QACjDA,MAAM,CAAC,oBAAoB,sCAAsCC,QAAQC,GAAG,IAC5EF,MAAM,CAAC,sBAAsB,4CAA4C,OACzEG,MAAM,CAAC,OAAOC;IACd,MAAMC,OAAOC,OAAOC,QAAQ,CAACH,QAAQC,IAAI,EAAE;IAC3C,MAAM,EAAEG,GAAG,EAAE,GAAGf,aAAa;QAC5BS,KAAKE,QAAQF,GAAG;QAChBG;QACAI,iBAAiBL,QAAQK,eAAe;IACzC;IAEAf,IAAIgB,IAAI,CAAC,CAAC,6BAA6B,EAAEL,MAAM;IAE/Cf,MAAM;QACLqB,OAAOH,IAAIG,KAAK;QAChBN;QACAO,UAAU;IACX;IAEAlB,IAAImB,OAAO,CAAC,CAAC,wCAAwC,EAAER,MAAM;AAC9D;AAED,2BAA2B;AAC3BJ,QAAQa,EAAE,CAAC,UAAU;IACpBpB,IAAIgB,IAAI,CAAC;IACTT,QAAQc,IAAI,CAAC;AACd;AACAd,QAAQa,EAAE,CAAC,WAAW;IACrBpB,IAAIgB,IAAI,CAAC;IACTT,QAAQc,IAAI,CAAC;AACd;AAEAnB,QAAQoB,UAAU,CAACf,QAAQgB,IAAI,EAAEC,KAAK,CAAC,CAACC;IACvCzB,IAAIyB,KAAK,CAACA,MAAMC,OAAO;IACvBnB,QAAQc,IAAI,CAAC;AACd"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Define an MCP server handler by wrapping a base McpServerDef with HTTP header handling
3
+ */ export function defineMcpServerHandler(base, options) {
4
+ return {
5
+ base,
6
+ name: base.name,
7
+ title: base.title,
8
+ description: base.description,
9
+ version: base.version,
10
+ tags: [
11
+ ...base.tags
12
+ ],
13
+ metadata: {
14
+ ...base.metadata
15
+ },
16
+ headerMappings: options.headerMappings,
17
+ resolveConfig: options.resolveConfig,
18
+ validateOptions: base.validateOptions,
19
+ getCacheKey: base.getCacheKey,
20
+ create: base.create
21
+ };
22
+ }
23
+ const _all = [];
24
+ /**
25
+ * Register an MCP server handler definition
26
+ */ export function registerMcpServerHandler(def) {
27
+ _all.push(def);
28
+ }
29
+ /**
30
+ * Get all registered MCP server handler definitions
31
+ */ export function getAllMcpServerHandlerDefs() {
32
+ return _all;
33
+ }
34
+ /**
35
+ * Find MCP server handler definition by name
36
+ */ export function getMcpServerHandlerDef(name) {
37
+ return _all.find((def)=>def.name === name);
38
+ }
39
+
40
+ //# sourceMappingURL=McpServerHandlerDef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/providers/McpServerHandlerDef.ts"],"sourcesContent":["import type { McpServerDef, McpServerInstance, ValidationResult } from '@wener/ai/mcp';\n\n/**\n * Header to config property mapping\n */\nexport interface HeaderMapping {\n\t/** Header name (e.g., 'X-CLS-SECRET-ID') */\n\theader: string;\n\t/** Config property name (e.g., 'clientId') */\n\tproperty: string;\n\t/** Whether this header/property is required */\n\trequired?: boolean;\n\t/** Default value if not provided */\n\tdefault?: string;\n}\n\n/**\n * MCP Server Handler Definition - wraps a McpServerDef with HTTP header handling\n */\nexport interface McpServerHandlerDef<TOptions = any, TConfig = any> {\n\t/** Reference to the base MCP server definition */\n\tbase: McpServerDef<TOptions>;\n\n\t/** Unique server type name */\n\tname: string;\n\t/** Display name */\n\ttitle: string;\n\t/** Server description */\n\tdescription: string;\n\t/** Server version */\n\tversion: string;\n\t/** Tags for categorization */\n\ttags: string[];\n\t/** Additional metadata */\n\tmetadata: Record<string, any>;\n\n\t/** Header mappings for dynamic endpoint */\n\theaderMappings?: HeaderMapping[];\n\n\t/** Resolve config from ServerConfig and optional Headers */\n\tresolveConfig: (config: TConfig, headers?: Headers) => TOptions | null;\n\n\t/** Validate resolved options */\n\tvalidateOptions: (options: Partial<TOptions>) => ValidationResult;\n\n\t/** Generate cache key for server instance caching */\n\tgetCacheKey: (options: TOptions) => string;\n\n\t/** Factory function to create the server instance */\n\tcreate: (options: TOptions) => McpServerInstance;\n}\n\nexport interface DefineMcpServerHandlerOptions<TOptions = any, TConfig = any> {\n\t/** Header mappings for dynamic endpoint */\n\theaderMappings?: HeaderMapping[];\n\n\t/** Resolve config from ServerConfig and optional Headers */\n\tresolveConfig: (config: TConfig, headers?: Headers) => TOptions | null;\n}\n\n/**\n * Define an MCP server handler by wrapping a base McpServerDef with HTTP header handling\n */\nexport function defineMcpServerHandler<TOptions = any, TConfig = any>(\n\tbase: McpServerDef<TOptions>,\n\toptions: DefineMcpServerHandlerOptions<TOptions, TConfig>,\n): McpServerHandlerDef<TOptions, TConfig> {\n\treturn {\n\t\tbase,\n\t\tname: base.name,\n\t\ttitle: base.title,\n\t\tdescription: base.description,\n\t\tversion: base.version,\n\t\ttags: [...base.tags],\n\t\tmetadata: { ...base.metadata },\n\t\theaderMappings: options.headerMappings,\n\t\tresolveConfig: options.resolveConfig,\n\t\tvalidateOptions: base.validateOptions,\n\t\tgetCacheKey: base.getCacheKey,\n\t\tcreate: base.create,\n\t};\n}\n\nconst _all: McpServerHandlerDef[] = [];\n\n/**\n * Register an MCP server handler definition\n */\nexport function registerMcpServerHandler(def: McpServerHandlerDef): void {\n\t_all.push(def);\n}\n\n/**\n * Get all registered MCP server handler definitions\n */\nexport function getAllMcpServerHandlerDefs(): McpServerHandlerDef[] {\n\treturn _all;\n}\n\n/**\n * Find MCP server handler definition by name\n */\nexport function getMcpServerHandlerDef(name: string): McpServerHandlerDef | undefined {\n\treturn _all.find((def) => def.name === name);\n}\n"],"names":["defineMcpServerHandler","base","options","name","title","description","version","tags","metadata","headerMappings","resolveConfig","validateOptions","getCacheKey","create","_all","registerMcpServerHandler","def","push","getAllMcpServerHandlerDefs","getMcpServerHandlerDef","find"],"mappings":"AA4DA;;CAEC,GACD,OAAO,SAASA,uBACfC,IAA4B,EAC5BC,OAAyD;IAEzD,OAAO;QACND;QACAE,MAAMF,KAAKE,IAAI;QACfC,OAAOH,KAAKG,KAAK;QACjBC,aAAaJ,KAAKI,WAAW;QAC7BC,SAASL,KAAKK,OAAO;QACrBC,MAAM;eAAIN,KAAKM,IAAI;SAAC;QACpBC,UAAU;YAAE,GAAGP,KAAKO,QAAQ;QAAC;QAC7BC,gBAAgBP,QAAQO,cAAc;QACtCC,eAAeR,QAAQQ,aAAa;QACpCC,iBAAiBV,KAAKU,eAAe;QACrCC,aAAaX,KAAKW,WAAW;QAC7BC,QAAQZ,KAAKY,MAAM;IACpB;AACD;AAEA,MAAMC,OAA8B,EAAE;AAEtC;;CAEC,GACD,OAAO,SAASC,yBAAyBC,GAAwB;IAChEF,KAAKG,IAAI,CAACD;AACX;AAEA;;CAEC,GACD,OAAO,SAASE;IACf,OAAOJ;AACR;AAEA;;CAEC,GACD,OAAO,SAASK,uBAAuBhB,IAAY;IAClD,OAAOW,KAAKM,IAAI,CAAC,CAACJ,MAAQA,IAAIb,IAAI,KAAKA;AACxC"}
@@ -0,0 +1,26 @@
1
+ import { getAllMcpServerHandlerDefs } from "./McpServerHandlerDef.js";
2
+ // Import all server definitions to ensure they are registered
3
+ import "./prometheus/def.js";
4
+ import "./tencent-cls/def.js";
5
+ import "./sql/def.js";
6
+ import "./relay/def.js";
7
+ /**
8
+ * Find MCP server definitions matching a predicate
9
+ */ export function findMcpServerDef(predicate) {
10
+ const all = getAllMcpServerHandlerDefs();
11
+ if (!predicate) {
12
+ return all;
13
+ }
14
+ return all.filter(predicate);
15
+ }
16
+ /**
17
+ * Resolve a single MCP server definition by name
18
+ */ export function resolveMcpServerDef(name) {
19
+ return findMcpServerDef((v) => v.name === name)[0];
20
+ }
21
+ /**
22
+ * Get total count of registered MCP server types
23
+ */ export function getMcpServerDefCount() {
24
+ return getAllMcpServerHandlerDefs().length;
25
+ }
26
+ //# sourceMappingURL=findMcpServerDef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/providers/findMcpServerDef.ts"],"sourcesContent":["import { getAllMcpServerHandlerDefs, type McpServerHandlerDef } from './McpServerHandlerDef';\n// Import all server definitions to ensure they are registered\nimport './prometheus/def';\nimport './tencent-cls/def';\nimport './sql/def';\nimport './relay/def';\n\n/**\n * Find MCP server definitions matching a predicate\n */\nexport function findMcpServerDef(predicate?: (def: McpServerHandlerDef) => boolean): McpServerHandlerDef[] {\n\tconst all = getAllMcpServerHandlerDefs();\n\tif (!predicate) {\n\t\treturn all;\n\t}\n\treturn all.filter(predicate);\n}\n\n/**\n * Resolve a single MCP server definition by name\n */\nexport function resolveMcpServerDef(name: string): McpServerHandlerDef | undefined {\n\treturn findMcpServerDef((v) => v.name === name)[0];\n}\n\n/**\n * Get total count of registered MCP server types\n */\nexport function getMcpServerDefCount(): number {\n\treturn getAllMcpServerHandlerDefs().length;\n}\n"],"names":["getAllMcpServerHandlerDefs","findMcpServerDef","predicate","all","filter","resolveMcpServerDef","name","v","getMcpServerDefCount","length"],"mappings":"AAAA,SAASA,0BAA0B,QAAkC,wBAAwB;AAC7F,8DAA8D;AAC9D,OAAO,mBAAmB;AAC1B,OAAO,oBAAoB;AAC3B,OAAO,YAAY;AACnB,OAAO,cAAc;AAErB;;CAEC,GACD,OAAO,SAASC,iBAAiBC,SAAiD;IACjF,MAAMC,MAAMH;IACZ,IAAI,CAACE,WAAW;QACf,OAAOC;IACR;IACA,OAAOA,IAAIC,MAAM,CAACF;AACnB;AAEA;;CAEC,GACD,OAAO,SAASG,oBAAoBC,IAAY;IAC/C,OAAOL,iBAAiB,CAACM,IAAMA,EAAED,IAAI,KAAKA,KAAK,CAAC,EAAE;AACnD;AAEA;;CAEC,GACD,OAAO,SAASE;IACf,OAAOR,6BAA6BS,MAAM;AAC3C"}
@@ -0,0 +1,24 @@
1
+ import { PrometheusMcpServerDef } from "@wener/ai/mcp/prometheus";
2
+ import { HeaderNames } from "../../server/schema.js";
3
+ import { defineMcpServerHandler, registerMcpServerHandler } from "../McpServerHandlerDef.js";
4
+ export const PrometheusMcpServerHandlerDef = defineMcpServerHandler(PrometheusMcpServerDef, {
5
+ headerMappings: [
6
+ {
7
+ header: HeaderNames.SERVICE_URL,
8
+ property: "url",
9
+ required: true
10
+ }
11
+ ],
12
+ resolveConfig(config, headers) {
13
+ const url = config.url || headers?.get(HeaderNames.SERVICE_URL) || config.headers?.[HeaderNames.SERVICE_URL];
14
+ if (!url)
15
+ return null;
16
+ return {
17
+ url
18
+ };
19
+ }
20
+ });
21
+ registerMcpServerHandler(PrometheusMcpServerHandlerDef);
22
+ // backward compatibility
23
+ export { PrometheusMcpServerHandlerDef as PrometheusMcpServerDef };
24
+ //# sourceMappingURL=def.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/providers/prometheus/def.ts"],"sourcesContent":["import { PrometheusMcpServerDef, type CreatePrometheusMcpServerOptions } from '@wener/ai/mcp/prometheus';\nimport { HeaderNames, type PrometheusConfig } from '../../server/schema';\nimport { defineMcpServerHandler, registerMcpServerHandler } from '../McpServerHandlerDef';\n\nexport const PrometheusMcpServerHandlerDef = defineMcpServerHandler<CreatePrometheusMcpServerOptions, PrometheusConfig>(\n\tPrometheusMcpServerDef,\n\t{\n\t\theaderMappings: [{ header: HeaderNames.SERVICE_URL, property: 'url', required: true }],\n\n\t\tresolveConfig(config, headers) {\n\t\t\tconst url = config.url || headers?.get(HeaderNames.SERVICE_URL) || config.headers?.[HeaderNames.SERVICE_URL];\n\t\t\tif (!url) return null;\n\t\t\treturn { url };\n\t\t},\n\t},\n);\n\nregisterMcpServerHandler(PrometheusMcpServerHandlerDef);\n\n// backward compatibility\nexport { PrometheusMcpServerHandlerDef as PrometheusMcpServerDef };\n"],"names":["PrometheusMcpServerDef","HeaderNames","defineMcpServerHandler","registerMcpServerHandler","PrometheusMcpServerHandlerDef","headerMappings","header","SERVICE_URL","property","required","resolveConfig","config","headers","url","get"],"mappings":"AAAA,SAASA,sBAAsB,QAA+C,2BAA2B;AACzG,SAASC,WAAW,QAA+B,sBAAsB;AACzE,SAASC,sBAAsB,EAAEC,wBAAwB,QAAQ,yBAAyB;AAE1F,OAAO,MAAMC,gCAAgCF,uBAC5CF,wBACA;IACCK,gBAAgB;QAAC;YAAEC,QAAQL,YAAYM,WAAW;YAAEC,UAAU;YAAOC,UAAU;QAAK;KAAE;IAEtFC,eAAcC,MAAM,EAAEC,OAAO;QAC5B,MAAMC,MAAMF,OAAOE,GAAG,IAAID,SAASE,IAAIb,YAAYM,WAAW,KAAKI,OAAOC,OAAO,EAAE,CAACX,YAAYM,WAAW,CAAC;QAC5G,IAAI,CAACM,KAAK,OAAO;QACjB,OAAO;YAAEA;QAAI;IACd;AACD,GACC;AAEFV,yBAAyBC;AAEzB,yBAAyB;AACzB,SAASA,iCAAiCJ,sBAAsB,GAAG"}
@@ -0,0 +1,2 @@
1
+ export { PrometheusMcpServerDef, PrometheusMcpServerHandlerDef } from "./def.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/providers/prometheus/index.ts"],"sourcesContent":["export { PrometheusMcpServerDef, PrometheusMcpServerHandlerDef } from './def';\n"],"names":["PrometheusMcpServerDef","PrometheusMcpServerHandlerDef"],"mappings":"AAAA,SAASA,sBAAsB,EAAEC,6BAA6B,QAAQ,QAAQ"}
@@ -0,0 +1,32 @@
1
+ import { RelayMcpServerDef } from "@wener/ai/mcp/relay";
2
+ import { HeaderNames } from "../../server/schema.js";
3
+ import { defineMcpServerHandler, registerMcpServerHandler } from "../McpServerHandlerDef.js";
4
+ export const RelayMcpServerHandlerDef = defineMcpServerHandler(RelayMcpServerDef, {
5
+ headerMappings: [
6
+ {
7
+ header: HeaderNames.MCP_URL,
8
+ property: "url",
9
+ required: true
10
+ },
11
+ {
12
+ header: HeaderNames.MCP_TYPE,
13
+ property: "transport",
14
+ default: "http"
15
+ }
16
+ ],
17
+ resolveConfig(config, headers) {
18
+ const url = config.url || headers?.get(HeaderNames.MCP_URL) || config.headers?.[HeaderNames.MCP_URL];
19
+ const transport = config.transport || headers?.get(HeaderNames.MCP_TYPE) || config.headers?.[HeaderNames.MCP_TYPE] || "http";
20
+ if (!url)
21
+ return null;
22
+ return {
23
+ url,
24
+ transport,
25
+ headers: config.headers
26
+ };
27
+ }
28
+ });
29
+ registerMcpServerHandler(RelayMcpServerHandlerDef);
30
+ // backward compatibility
31
+ export { RelayMcpServerHandlerDef as RelayMcpServerDef };
32
+ //# sourceMappingURL=def.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/providers/relay/def.ts"],"sourcesContent":["import { RelayMcpServerDef, type CreateRelayMcpServerOptions } from '@wener/ai/mcp/relay';\nimport { HeaderNames, type RelayConfig } from '../../server/schema';\nimport { defineMcpServerHandler, registerMcpServerHandler } from '../McpServerHandlerDef';\n\nexport const RelayMcpServerHandlerDef = defineMcpServerHandler<CreateRelayMcpServerOptions, RelayConfig>(\n\tRelayMcpServerDef,\n\t{\n\t\theaderMappings: [\n\t\t\t{ header: HeaderNames.MCP_URL, property: 'url', required: true },\n\t\t\t{ header: HeaderNames.MCP_TYPE, property: 'transport', default: 'http' },\n\t\t],\n\n\t\tresolveConfig(config, headers) {\n\t\t\tconst url = config.url || headers?.get(HeaderNames.MCP_URL) || config.headers?.[HeaderNames.MCP_URL];\n\t\t\tconst transport =\n\t\t\t\t(config.transport as 'http' | 'sse') ||\n\t\t\t\t(headers?.get(HeaderNames.MCP_TYPE) as 'http' | 'sse') ||\n\t\t\t\t(config.headers?.[HeaderNames.MCP_TYPE] as 'http' | 'sse') ||\n\t\t\t\t'http';\n\n\t\t\tif (!url) return null;\n\n\t\t\treturn { url, transport, headers: config.headers };\n\t\t},\n\t},\n);\n\nregisterMcpServerHandler(RelayMcpServerHandlerDef);\n\n// backward compatibility\nexport { RelayMcpServerHandlerDef as RelayMcpServerDef };\n"],"names":["RelayMcpServerDef","HeaderNames","defineMcpServerHandler","registerMcpServerHandler","RelayMcpServerHandlerDef","headerMappings","header","MCP_URL","property","required","MCP_TYPE","default","resolveConfig","config","headers","url","get","transport"],"mappings":"AAAA,SAASA,iBAAiB,QAA0C,sBAAsB;AAC1F,SAASC,WAAW,QAA0B,sBAAsB;AACpE,SAASC,sBAAsB,EAAEC,wBAAwB,QAAQ,yBAAyB;AAE1F,OAAO,MAAMC,2BAA2BF,uBACvCF,mBACA;IACCK,gBAAgB;QACf;YAAEC,QAAQL,YAAYM,OAAO;YAAEC,UAAU;YAAOC,UAAU;QAAK;QAC/D;YAAEH,QAAQL,YAAYS,QAAQ;YAAEF,UAAU;YAAaG,SAAS;QAAO;KACvE;IAEDC,eAAcC,MAAM,EAAEC,OAAO;QAC5B,MAAMC,MAAMF,OAAOE,GAAG,IAAID,SAASE,IAAIf,YAAYM,OAAO,KAAKM,OAAOC,OAAO,EAAE,CAACb,YAAYM,OAAO,CAAC;QACpG,MAAMU,YACL,AAACJ,OAAOI,SAAS,IAChBH,SAASE,IAAIf,YAAYS,QAAQ,KACjCG,OAAOC,OAAO,EAAE,CAACb,YAAYS,QAAQ,CAAC,IACvC;QAED,IAAI,CAACK,KAAK,OAAO;QAEjB,OAAO;YAAEA;YAAKE;YAAWH,SAASD,OAAOC,OAAO;QAAC;IAClD;AACD,GACC;AAEFX,yBAAyBC;AAEzB,yBAAyB;AACzB,SAASA,4BAA4BJ,iBAAiB,GAAG"}
@@ -0,0 +1,2 @@
1
+ export { RelayMcpServerDef, RelayMcpServerHandlerDef } from "./def.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/providers/relay/index.ts"],"sourcesContent":["export { RelayMcpServerDef, RelayMcpServerHandlerDef } from './def';\n"],"names":["RelayMcpServerDef","RelayMcpServerHandlerDef"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,wBAAwB,QAAQ,QAAQ"}