@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.
- package/LICENSE +21 -0
- package/dist/index.mjs +15 -0
- package/dist/mcps-cli.mjs +174727 -0
- package/lib/chat/agent.js +187 -0
- package/lib/chat/agent.js.map +1 -0
- package/lib/chat/audit.js +238 -0
- package/lib/chat/audit.js.map +1 -0
- package/lib/chat/converters.js +467 -0
- package/lib/chat/converters.js.map +1 -0
- package/lib/chat/handler.js +1068 -0
- package/lib/chat/handler.js.map +1 -0
- package/lib/chat/index.js +12 -0
- package/lib/chat/index.js.map +1 -0
- package/lib/chat/types.js +35 -0
- package/lib/chat/types.js.map +1 -0
- package/lib/contracts/AuditContract.js +85 -0
- package/lib/contracts/AuditContract.js.map +1 -0
- package/lib/contracts/McpsContract.js +113 -0
- package/lib/contracts/McpsContract.js.map +1 -0
- package/lib/contracts/index.js +3 -0
- package/lib/contracts/index.js.map +1 -0
- package/lib/dev.server.js +7 -0
- package/lib/dev.server.js.map +1 -0
- package/lib/entities/ChatRequestEntity.js +318 -0
- package/lib/entities/ChatRequestEntity.js.map +1 -0
- package/lib/entities/McpRequestEntity.js +271 -0
- package/lib/entities/McpRequestEntity.js.map +1 -0
- package/lib/entities/RequestLogEntity.js +177 -0
- package/lib/entities/RequestLogEntity.js.map +1 -0
- package/lib/entities/ResponseEntity.js +150 -0
- package/lib/entities/ResponseEntity.js.map +1 -0
- package/lib/entities/index.js +11 -0
- package/lib/entities/index.js.map +1 -0
- package/lib/entities/types.js +11 -0
- package/lib/entities/types.js.map +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/lib/mcps-cli.js +44 -0
- package/lib/mcps-cli.js.map +1 -0
- package/lib/providers/McpServerHandlerDef.js +40 -0
- package/lib/providers/McpServerHandlerDef.js.map +1 -0
- package/lib/providers/findMcpServerDef.js +26 -0
- package/lib/providers/findMcpServerDef.js.map +1 -0
- package/lib/providers/prometheus/def.js +24 -0
- package/lib/providers/prometheus/def.js.map +1 -0
- package/lib/providers/prometheus/index.js +2 -0
- package/lib/providers/prometheus/index.js.map +1 -0
- package/lib/providers/relay/def.js +32 -0
- package/lib/providers/relay/def.js.map +1 -0
- package/lib/providers/relay/index.js +2 -0
- package/lib/providers/relay/index.js.map +1 -0
- package/lib/providers/sql/def.js +31 -0
- package/lib/providers/sql/def.js.map +1 -0
- package/lib/providers/sql/index.js +2 -0
- package/lib/providers/sql/index.js.map +1 -0
- package/lib/providers/tencent-cls/def.js +44 -0
- package/lib/providers/tencent-cls/def.js.map +1 -0
- package/lib/providers/tencent-cls/index.js +2 -0
- package/lib/providers/tencent-cls/index.js.map +1 -0
- package/lib/scripts/bundle.js +90 -0
- package/lib/scripts/bundle.js.map +1 -0
- package/lib/server/api-routes.js +96 -0
- package/lib/server/api-routes.js.map +1 -0
- package/lib/server/audit.js +274 -0
- package/lib/server/audit.js.map +1 -0
- package/lib/server/chat-routes.js +82 -0
- package/lib/server/chat-routes.js.map +1 -0
- package/lib/server/config.js +223 -0
- package/lib/server/config.js.map +1 -0
- package/lib/server/db.js +97 -0
- package/lib/server/db.js.map +1 -0
- package/lib/server/index.js +2 -0
- package/lib/server/index.js.map +1 -0
- package/lib/server/mcp-handler.js +167 -0
- package/lib/server/mcp-handler.js.map +1 -0
- package/lib/server/mcp-routes.js +112 -0
- package/lib/server/mcp-routes.js.map +1 -0
- package/lib/server/mcps-router.js +119 -0
- package/lib/server/mcps-router.js.map +1 -0
- package/lib/server/schema.js +129 -0
- package/lib/server/schema.js.map +1 -0
- package/lib/server/server.js +166 -0
- package/lib/server/server.js.map +1 -0
- package/lib/web/ChatPage.js +827 -0
- package/lib/web/ChatPage.js.map +1 -0
- package/lib/web/McpInspectorPage.js +214 -0
- package/lib/web/McpInspectorPage.js.map +1 -0
- package/lib/web/ServersPage.js +93 -0
- package/lib/web/ServersPage.js.map +1 -0
- package/lib/web/main.js +541 -0
- package/lib/web/main.js.map +1 -0
- package/package.json +83 -0
- package/src/chat/agent.ts +240 -0
- package/src/chat/audit.ts +377 -0
- package/src/chat/converters.test.ts +325 -0
- package/src/chat/converters.ts +459 -0
- package/src/chat/handler.test.ts +137 -0
- package/src/chat/handler.ts +1233 -0
- package/src/chat/index.ts +16 -0
- package/src/chat/types.ts +72 -0
- package/src/contracts/AuditContract.ts +93 -0
- package/src/contracts/McpsContract.ts +141 -0
- package/src/contracts/index.ts +18 -0
- package/src/dev.server.ts +7 -0
- package/src/entities/ChatRequestEntity.ts +157 -0
- package/src/entities/McpRequestEntity.ts +149 -0
- package/src/entities/RequestLogEntity.ts +78 -0
- package/src/entities/ResponseEntity.ts +75 -0
- package/src/entities/index.ts +12 -0
- package/src/entities/types.ts +188 -0
- package/src/index.ts +1 -0
- package/src/mcps-cli.ts +59 -0
- package/src/providers/McpServerHandlerDef.ts +105 -0
- package/src/providers/findMcpServerDef.ts +31 -0
- package/src/providers/prometheus/def.ts +21 -0
- package/src/providers/prometheus/index.ts +1 -0
- package/src/providers/relay/def.ts +31 -0
- package/src/providers/relay/index.ts +1 -0
- package/src/providers/relay/relay.test.ts +47 -0
- package/src/providers/sql/def.ts +33 -0
- package/src/providers/sql/index.ts +1 -0
- package/src/providers/tencent-cls/def.ts +38 -0
- package/src/providers/tencent-cls/index.ts +1 -0
- package/src/scripts/bundle.ts +82 -0
- package/src/server/api-routes.ts +98 -0
- package/src/server/audit.ts +310 -0
- package/src/server/chat-routes.ts +95 -0
- package/src/server/config.test.ts +162 -0
- package/src/server/config.ts +198 -0
- package/src/server/db.ts +115 -0
- package/src/server/index.ts +1 -0
- package/src/server/mcp-handler.ts +209 -0
- package/src/server/mcp-routes.ts +133 -0
- package/src/server/mcps-router.ts +133 -0
- package/src/server/schema.ts +175 -0
- package/src/server/server.ts +163 -0
- package/src/web/ChatPage.tsx +1005 -0
- package/src/web/McpInspectorPage.tsx +254 -0
- package/src/web/ServersPage.tsx +139 -0
- package/src/web/main.tsx +600 -0
- package/src/web/styles.css +15 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
openaiToAnthropicMessages,
|
|
4
|
+
openaiToAnthropicRequest,
|
|
5
|
+
anthropicToOpenaiResponse,
|
|
6
|
+
openaiToGeminiContents,
|
|
7
|
+
openaiToGeminiRequest,
|
|
8
|
+
geminiToOpenaiResponse,
|
|
9
|
+
} from './converters';
|
|
10
|
+
import type { ChatMessage } from '@wener/ai/openai/schema';
|
|
11
|
+
import type { MessagesResponse } from '@wener/ai/anthropic/schema';
|
|
12
|
+
import type { GenerateContentResponse } from '@wener/ai/google/schema';
|
|
13
|
+
|
|
14
|
+
describe('OpenAI to Anthropic conversion', () => {
|
|
15
|
+
it('should convert system message to system prompt', () => {
|
|
16
|
+
const messages: ChatMessage[] = [
|
|
17
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
18
|
+
{ role: 'user', content: 'Hello!' },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const result = openaiToAnthropicMessages(messages);
|
|
22
|
+
|
|
23
|
+
expect(result.system).toBe('You are a helpful assistant.');
|
|
24
|
+
expect(result.messages).toHaveLength(1);
|
|
25
|
+
expect(result.messages[0]).toEqual({ role: 'user', content: 'Hello!' });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should merge multiple system messages', () => {
|
|
29
|
+
const messages: ChatMessage[] = [
|
|
30
|
+
{ role: 'system', content: 'You are helpful.' },
|
|
31
|
+
{ role: 'system', content: 'Be concise.' },
|
|
32
|
+
{ role: 'user', content: 'Hi' },
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const result = openaiToAnthropicMessages(messages);
|
|
36
|
+
|
|
37
|
+
expect(result.system).toBe('You are helpful.\n\nBe concise.');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should convert tool calls to tool_use blocks', () => {
|
|
41
|
+
const messages: ChatMessage[] = [
|
|
42
|
+
{ role: 'user', content: 'What is the weather?' },
|
|
43
|
+
{
|
|
44
|
+
role: 'assistant',
|
|
45
|
+
content: null,
|
|
46
|
+
tool_calls: [
|
|
47
|
+
{
|
|
48
|
+
id: 'call_123',
|
|
49
|
+
type: 'function',
|
|
50
|
+
function: {
|
|
51
|
+
name: 'get_weather',
|
|
52
|
+
arguments: '{"location": "NYC"}',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const result = openaiToAnthropicMessages(messages);
|
|
60
|
+
|
|
61
|
+
expect(result.messages[1]).toEqual({
|
|
62
|
+
role: 'assistant',
|
|
63
|
+
content: [
|
|
64
|
+
{
|
|
65
|
+
type: 'tool_use',
|
|
66
|
+
id: 'call_123',
|
|
67
|
+
name: 'get_weather',
|
|
68
|
+
input: { location: 'NYC' },
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should convert tool message to tool_result', () => {
|
|
75
|
+
const messages: ChatMessage[] = [
|
|
76
|
+
{ role: 'user', content: 'What is the weather?' },
|
|
77
|
+
{ role: 'tool', tool_call_id: 'call_123', content: 'Sunny, 72°F' },
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const result = openaiToAnthropicMessages(messages);
|
|
81
|
+
|
|
82
|
+
expect(result.messages[1]).toEqual({
|
|
83
|
+
role: 'user',
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
type: 'tool_result',
|
|
87
|
+
tool_use_id: 'call_123',
|
|
88
|
+
content: 'Sunny, 72°F',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should convert full request with tools', () => {
|
|
95
|
+
const request = {
|
|
96
|
+
model: 'claude-3-opus',
|
|
97
|
+
messages: [
|
|
98
|
+
{ role: 'system' as const, content: 'You are helpful.' },
|
|
99
|
+
{ role: 'user' as const, content: 'Hi' },
|
|
100
|
+
],
|
|
101
|
+
max_tokens: 1024,
|
|
102
|
+
temperature: 0.7,
|
|
103
|
+
tools: [
|
|
104
|
+
{
|
|
105
|
+
type: 'function' as const,
|
|
106
|
+
function: {
|
|
107
|
+
name: 'get_weather',
|
|
108
|
+
description: 'Get weather info',
|
|
109
|
+
parameters: {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: { location: { type: 'string' } },
|
|
112
|
+
required: ['location'],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
tool_choice: 'auto' as const,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const result = openaiToAnthropicRequest(request);
|
|
121
|
+
|
|
122
|
+
expect(result.model).toBe('claude-3-opus');
|
|
123
|
+
expect(result.system).toBe('You are helpful.');
|
|
124
|
+
expect(result.max_tokens).toBe(1024);
|
|
125
|
+
expect(result.temperature).toBe(0.7);
|
|
126
|
+
expect(result.tools).toHaveLength(1);
|
|
127
|
+
expect(result.tools?.[0].name).toBe('get_weather');
|
|
128
|
+
expect(result.tool_choice).toEqual({ type: 'auto' });
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('Anthropic to OpenAI conversion', () => {
|
|
133
|
+
it('should convert text response', () => {
|
|
134
|
+
const response: MessagesResponse = {
|
|
135
|
+
id: 'msg_123',
|
|
136
|
+
type: 'message',
|
|
137
|
+
role: 'assistant',
|
|
138
|
+
content: [{ type: 'text', text: 'Hello there!' }],
|
|
139
|
+
model: 'claude-3-opus',
|
|
140
|
+
stop_reason: 'end_turn',
|
|
141
|
+
usage: { input_tokens: 10, output_tokens: 5 },
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const result = anthropicToOpenaiResponse(response, 'claude-3-opus');
|
|
145
|
+
|
|
146
|
+
expect(result.id).toBe('msg_123');
|
|
147
|
+
expect(result.object).toBe('chat.completion');
|
|
148
|
+
expect(result.choices[0].message.content).toBe('Hello there!');
|
|
149
|
+
expect(result.choices[0].finish_reason).toBe('stop');
|
|
150
|
+
expect(result.usage).toEqual({
|
|
151
|
+
prompt_tokens: 10,
|
|
152
|
+
completion_tokens: 5,
|
|
153
|
+
total_tokens: 15,
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should convert tool use response', () => {
|
|
158
|
+
const response: MessagesResponse = {
|
|
159
|
+
id: 'msg_456',
|
|
160
|
+
type: 'message',
|
|
161
|
+
role: 'assistant',
|
|
162
|
+
content: [
|
|
163
|
+
{
|
|
164
|
+
type: 'tool_use',
|
|
165
|
+
id: 'tool_123',
|
|
166
|
+
name: 'get_weather',
|
|
167
|
+
input: { location: 'NYC' },
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
model: 'claude-3-opus',
|
|
171
|
+
stop_reason: 'tool_use',
|
|
172
|
+
usage: { input_tokens: 20, output_tokens: 10 },
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const result = anthropicToOpenaiResponse(response, 'claude-3-opus');
|
|
176
|
+
|
|
177
|
+
expect(result.choices[0].finish_reason).toBe('tool_calls');
|
|
178
|
+
expect(result.choices[0].message.tool_calls).toHaveLength(1);
|
|
179
|
+
expect(result.choices[0].message.tool_calls?.[0]).toEqual({
|
|
180
|
+
id: 'tool_123',
|
|
181
|
+
type: 'function',
|
|
182
|
+
function: {
|
|
183
|
+
name: 'get_weather',
|
|
184
|
+
arguments: '{"location":"NYC"}',
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('OpenAI to Gemini conversion', () => {
|
|
191
|
+
it('should convert system message to systemInstruction', () => {
|
|
192
|
+
const messages: ChatMessage[] = [
|
|
193
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
194
|
+
{ role: 'user', content: 'Hello!' },
|
|
195
|
+
];
|
|
196
|
+
|
|
197
|
+
const result = openaiToGeminiContents(messages);
|
|
198
|
+
|
|
199
|
+
expect(result.systemInstruction).toBeDefined();
|
|
200
|
+
expect(result.systemInstruction?.parts[0]).toEqual({ text: 'You are a helpful assistant.' });
|
|
201
|
+
expect(result.contents).toHaveLength(1);
|
|
202
|
+
expect(result.contents[0].role).toBe('user');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('should convert assistant messages to model role', () => {
|
|
206
|
+
const messages: ChatMessage[] = [
|
|
207
|
+
{ role: 'user', content: 'Hi' },
|
|
208
|
+
{ role: 'assistant', content: 'Hello!' },
|
|
209
|
+
];
|
|
210
|
+
|
|
211
|
+
const result = openaiToGeminiContents(messages);
|
|
212
|
+
|
|
213
|
+
expect(result.contents[1].role).toBe('model');
|
|
214
|
+
expect(result.contents[1].parts[0]).toEqual({ text: 'Hello!' });
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('should convert tool calls to functionCall', () => {
|
|
218
|
+
const messages: ChatMessage[] = [
|
|
219
|
+
{ role: 'user', content: 'Weather?' },
|
|
220
|
+
{
|
|
221
|
+
role: 'assistant',
|
|
222
|
+
content: null,
|
|
223
|
+
tool_calls: [
|
|
224
|
+
{
|
|
225
|
+
id: 'call_1',
|
|
226
|
+
type: 'function',
|
|
227
|
+
function: { name: 'get_weather', arguments: '{"city":"NYC"}' },
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
},
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
const result = openaiToGeminiContents(messages);
|
|
234
|
+
|
|
235
|
+
expect(result.contents[1].parts[0]).toEqual({
|
|
236
|
+
functionCall: { name: 'get_weather', args: { city: 'NYC' } },
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should convert full request', () => {
|
|
241
|
+
const request = {
|
|
242
|
+
model: 'gemini-pro',
|
|
243
|
+
messages: [
|
|
244
|
+
{ role: 'system' as const, content: 'Be helpful.' },
|
|
245
|
+
{ role: 'user' as const, content: 'Hello' },
|
|
246
|
+
],
|
|
247
|
+
temperature: 0.8,
|
|
248
|
+
max_tokens: 500,
|
|
249
|
+
tools: [
|
|
250
|
+
{
|
|
251
|
+
type: 'function' as const,
|
|
252
|
+
function: {
|
|
253
|
+
name: 'search',
|
|
254
|
+
description: 'Search the web',
|
|
255
|
+
parameters: { type: 'object', properties: { q: { type: 'string' } } },
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const result = openaiToGeminiRequest(request);
|
|
262
|
+
|
|
263
|
+
expect(result.systemInstruction).toBeDefined();
|
|
264
|
+
expect(result.generationConfig?.temperature).toBe(0.8);
|
|
265
|
+
expect(result.generationConfig?.maxOutputTokens).toBe(500);
|
|
266
|
+
expect(result.tools).toHaveLength(1);
|
|
267
|
+
expect(result.tools?.[0]?.functionDeclarations?.[0]?.name).toBe('search');
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('Gemini to OpenAI conversion', () => {
|
|
272
|
+
it('should convert text response', () => {
|
|
273
|
+
const response: GenerateContentResponse = {
|
|
274
|
+
candidates: [
|
|
275
|
+
{
|
|
276
|
+
content: {
|
|
277
|
+
role: 'model',
|
|
278
|
+
parts: [{ text: 'Hello!' }],
|
|
279
|
+
},
|
|
280
|
+
finishReason: 'STOP',
|
|
281
|
+
index: 0,
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
usageMetadata: {
|
|
285
|
+
promptTokenCount: 10,
|
|
286
|
+
candidatesTokenCount: 5,
|
|
287
|
+
totalTokenCount: 15,
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const result = geminiToOpenaiResponse(response, 'gemini-pro');
|
|
292
|
+
|
|
293
|
+
expect(result.object).toBe('chat.completion');
|
|
294
|
+
expect(result.choices[0].message.content).toBe('Hello!');
|
|
295
|
+
expect(result.choices[0].finish_reason).toBe('stop');
|
|
296
|
+
expect(result.usage?.total_tokens).toBe(15);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('should convert function call response', () => {
|
|
300
|
+
const response: GenerateContentResponse = {
|
|
301
|
+
candidates: [
|
|
302
|
+
{
|
|
303
|
+
content: {
|
|
304
|
+
role: 'model',
|
|
305
|
+
parts: [
|
|
306
|
+
{
|
|
307
|
+
functionCall: {
|
|
308
|
+
name: 'get_weather',
|
|
309
|
+
args: { location: 'NYC' },
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
finishReason: 'STOP',
|
|
315
|
+
index: 0,
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const result = geminiToOpenaiResponse(response, 'gemini-pro');
|
|
321
|
+
|
|
322
|
+
expect(result.choices[0].message.tool_calls).toHaveLength(1);
|
|
323
|
+
expect(result.choices[0].message.tool_calls?.[0]?.function?.name).toBe('get_weather');
|
|
324
|
+
});
|
|
325
|
+
});
|