@elsium-ai/mcp 0.3.0 → 0.4.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/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Tool } from '@elsium-ai/tools';
2
- export interface MCPClientConfig {
2
+ export interface MCPClientStdioConfig {
3
3
  name: string;
4
4
  transport: 'stdio';
5
5
  command: string;
@@ -7,6 +7,14 @@ export interface MCPClientConfig {
7
7
  env?: Record<string, string>;
8
8
  timeoutMs?: number;
9
9
  }
10
+ export interface MCPClientHttpConfig {
11
+ name: string;
12
+ transport: 'http';
13
+ url: string;
14
+ headers?: Record<string, string>;
15
+ timeoutMs?: number;
16
+ }
17
+ export type MCPClientConfig = MCPClientStdioConfig | MCPClientHttpConfig;
10
18
  export interface MCPToolInfo {
11
19
  name: string;
12
20
  description: string;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAoC,MAAM,kBAAkB,CAAA;AAE9E,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC;AAgBD,MAAM,WAAW,SAAS;IACzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3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CAAC,CAAA;IACxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,SAAS,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACvE,aAAa,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAC3B;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAKlE"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { createMCPClient } from './client';
2
- export type { MCPClient, MCPClientConfig, MCPToolInfo } from './client';
3
- export { createMCPServer } from './server';
4
- export type { MCPServer, MCPServerConfig } from './server';
2
+ export type { MCPClient, MCPClientConfig, MCPClientStdioConfig, MCPClientHttpConfig, MCPToolInfo, } from './client';
3
+ export { createMCPServer, createMCPHttpHandler } from './server';
4
+ export type { MCPServer, MCPServerConfig, MCPHttpHandlerConfig, MCPHttpHandler } from './server';
5
+ export type { JsonRpcRequest, JsonRpcResponse, MCPTransport } from './types';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAGvE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,YAAY,EACX,SAAS,EACT,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,GACX,MAAM,UAAU,CAAA;AAGjB,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAChE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAGhG,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -150,6 +150,159 @@ var log2 = createLogger();
150
150
  var BLOCKED_KEYS = new Set(["__proto__", "constructor", "prototype"]);
151
151
  // src/client.ts
152
152
  function createMCPClient(config) {
153
+ if (config.transport === "http") {
154
+ return createHttpMCPClient(config);
155
+ }
156
+ return createStdioMCPClient(config);
157
+ }
158
+ function assertConnected(connected) {
159
+ if (!connected) {
160
+ throw new ElsiumError({
161
+ code: "NETWORK_ERROR",
162
+ message: "MCP HTTP client not connected",
163
+ retryable: false
164
+ });
165
+ }
166
+ }
167
+ function parseHttpResponse(json) {
168
+ if (json.error) {
169
+ throw new ElsiumError({
170
+ code: "PROVIDER_ERROR",
171
+ message: `MCP error: ${json.error.message}`,
172
+ retryable: false,
173
+ metadata: { code: json.error.code }
174
+ });
175
+ }
176
+ return json.result;
177
+ }
178
+ function handleFetchError(error, timeoutMs) {
179
+ if (error instanceof ElsiumError)
180
+ throw error;
181
+ if (error instanceof Error && error.name === "AbortError") {
182
+ throw new ElsiumError({
183
+ code: "TIMEOUT",
184
+ message: `MCP HTTP request timed out after ${timeoutMs}ms`,
185
+ retryable: true
186
+ });
187
+ }
188
+ throw error;
189
+ }
190
+ function createHttpMCPClient(config) {
191
+ let connected = false;
192
+ let requestId = 0;
193
+ const timeoutMs = config.timeoutMs ?? 30000;
194
+ async function sendRequest(method, params) {
195
+ assertConnected(connected);
196
+ const id = ++requestId;
197
+ const body = {
198
+ jsonrpc: "2.0",
199
+ id,
200
+ method,
201
+ ...params ? { params } : {}
202
+ };
203
+ const controller = new AbortController;
204
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
205
+ try {
206
+ const response = await fetch(config.url, {
207
+ method: "POST",
208
+ headers: {
209
+ "Content-Type": "application/json",
210
+ ...config.headers ?? {}
211
+ },
212
+ body: JSON.stringify(body),
213
+ signal: controller.signal
214
+ });
215
+ if (!response.ok) {
216
+ throw new ElsiumError({
217
+ code: "PROVIDER_ERROR",
218
+ message: `MCP HTTP error: ${response.status}`,
219
+ retryable: response.status >= 500
220
+ });
221
+ }
222
+ const json = await response.json();
223
+ return parseHttpResponse(json);
224
+ } catch (error) {
225
+ handleFetchError(error, timeoutMs);
226
+ } finally {
227
+ clearTimeout(timer);
228
+ }
229
+ }
230
+ return {
231
+ get connected() {
232
+ return connected;
233
+ },
234
+ async connect() {
235
+ if (connected)
236
+ return;
237
+ await sendRequest.call({ connected: true }, "initialize", {
238
+ protocolVersion: "2024-11-05",
239
+ capabilities: {},
240
+ clientInfo: { name: `elsium-mcp-${config.name}`, version: "0.1.0" }
241
+ }).catch(() => {});
242
+ connected = true;
243
+ await sendRequest("initialize", {
244
+ protocolVersion: "2024-11-05",
245
+ capabilities: {},
246
+ clientInfo: { name: `elsium-mcp-${config.name}`, version: "0.1.0" }
247
+ });
248
+ },
249
+ async disconnect() {
250
+ connected = false;
251
+ },
252
+ async listTools() {
253
+ const result = await sendRequest("tools/list");
254
+ return result.tools ?? [];
255
+ },
256
+ async callTool(name, args) {
257
+ const result = await sendRequest("tools/call", { name, arguments: args });
258
+ const textContent = result.content?.filter((c) => c.type === "text").map((c) => c.text).join(`
259
+ `);
260
+ return textContent ?? result;
261
+ },
262
+ async toElsiumTools() {
263
+ const mcpTools = await this.listTools();
264
+ const client = this;
265
+ return mcpTools.map((mcpTool) => {
266
+ const tool = {
267
+ name: mcpTool.name,
268
+ description: mcpTool.description,
269
+ inputSchema: { _def: { typeName: "ZodObject" } },
270
+ rawSchema: mcpTool.inputSchema,
271
+ timeoutMs,
272
+ async execute(input, partialCtx) {
273
+ const toolCallId = partialCtx?.toolCallId ?? generateId("tc");
274
+ const startTime = performance.now();
275
+ try {
276
+ const result = await client.callTool(mcpTool.name, input ?? {});
277
+ return {
278
+ success: true,
279
+ data: result,
280
+ toolCallId,
281
+ durationMs: Math.round(performance.now() - startTime)
282
+ };
283
+ } catch (error) {
284
+ return {
285
+ success: false,
286
+ error: error instanceof Error ? error.message : String(error),
287
+ toolCallId,
288
+ durationMs: Math.round(performance.now() - startTime)
289
+ };
290
+ }
291
+ },
292
+ toDefinition() {
293
+ return {
294
+ name: mcpTool.name,
295
+ description: mcpTool.description,
296
+ inputSchema: mcpTool.inputSchema
297
+ };
298
+ }
299
+ };
300
+ return tool;
301
+ });
302
+ }
303
+ };
304
+ }
305
+ function createStdioMCPClient(config) {
153
306
  let process2 = null;
154
307
  let connected = false;
155
308
  let requestId = 0;
@@ -528,7 +681,118 @@ function createMCPServer(config) {
528
681
  }
529
682
  };
530
683
  }
684
+ function createMCPHttpHandler(config) {
685
+ const toolMap = new Map(config.tools.map((t) => [t.name, t]));
686
+ function handleSyncRequest(request) {
687
+ const id = request.id ?? 0;
688
+ switch (request.method) {
689
+ case "initialize":
690
+ return {
691
+ jsonrpc: "2.0",
692
+ id,
693
+ result: {
694
+ protocolVersion: "2024-11-05",
695
+ capabilities: { tools: {} },
696
+ serverInfo: {
697
+ name: config.name,
698
+ version: config.version ?? "0.1.0"
699
+ }
700
+ }
701
+ };
702
+ case "notifications/initialized":
703
+ return null;
704
+ case "tools/list":
705
+ return {
706
+ jsonrpc: "2.0",
707
+ id,
708
+ result: {
709
+ tools: config.tools.map((t) => {
710
+ const def = t.toDefinition();
711
+ return {
712
+ name: def.name,
713
+ description: def.description,
714
+ inputSchema: def.inputSchema
715
+ };
716
+ })
717
+ }
718
+ };
719
+ default:
720
+ return {
721
+ jsonrpc: "2.0",
722
+ id,
723
+ error: {
724
+ code: -32601,
725
+ message: `Method not found: ${request.method}`
726
+ }
727
+ };
728
+ }
729
+ }
730
+ async function handleToolCall(request) {
731
+ const id = request.id ?? 0;
732
+ const name = request.params?.name;
733
+ const args = request.params?.arguments ?? {};
734
+ const tool = toolMap.get(name);
735
+ if (!tool) {
736
+ return {
737
+ jsonrpc: "2.0",
738
+ id,
739
+ error: { code: -32602, message: `Unknown tool: ${name}` }
740
+ };
741
+ }
742
+ const result = await tool.execute(args, { toolCallId: generateId("tc") });
743
+ if (result.success) {
744
+ return {
745
+ jsonrpc: "2.0",
746
+ id,
747
+ result: {
748
+ content: [
749
+ {
750
+ type: "text",
751
+ text: typeof result.data === "string" ? result.data : JSON.stringify(result.data, null, 2)
752
+ }
753
+ ]
754
+ }
755
+ };
756
+ }
757
+ return {
758
+ jsonrpc: "2.0",
759
+ id,
760
+ result: {
761
+ content: [{ type: "text", text: result.error ?? "Tool execution failed" }],
762
+ isError: true
763
+ }
764
+ };
765
+ }
766
+ return async (request) => {
767
+ if (request.method !== "POST") {
768
+ return new Response(JSON.stringify({ error: "Method not allowed" }), {
769
+ status: 405,
770
+ headers: { "Content-Type": "application/json" }
771
+ });
772
+ }
773
+ let body;
774
+ try {
775
+ body = await request.json();
776
+ } catch {
777
+ return new Response(JSON.stringify({ jsonrpc: "2.0", id: 0, error: { code: -32700, message: "Parse error" } }), { status: 400, headers: { "Content-Type": "application/json" } });
778
+ }
779
+ let response;
780
+ if (body.method === "tools/call") {
781
+ response = await handleToolCall(body);
782
+ } else {
783
+ response = handleSyncRequest(body);
784
+ }
785
+ if (!response) {
786
+ return new Response(null, { status: 204 });
787
+ }
788
+ return new Response(JSON.stringify(response), {
789
+ status: 200,
790
+ headers: { "Content-Type": "application/json" }
791
+ });
792
+ };
793
+ }
531
794
  export {
532
795
  createMCPServer,
796
+ createMCPHttpHandler,
533
797
  createMCPClient
534
798
  };
package/dist/server.d.ts CHANGED
@@ -10,4 +10,11 @@ export interface MCPServer {
10
10
  readonly running: boolean;
11
11
  }
12
12
  export declare function createMCPServer(config: MCPServerConfig): MCPServer;
13
+ export interface MCPHttpHandlerConfig {
14
+ name: string;
15
+ version?: string;
16
+ tools: Tool[];
17
+ }
18
+ export type MCPHttpHandler = (request: Request) => Promise<Response>;
19
+ export declare function createMCPHttpHandler(config: MCPHttpHandlerConfig): MCPHttpHandler;
13
20
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAI5C,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,IAAI,EAAE,CAAA;CACb;AAgBD,MAAM,WAAW,SAAS;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,IAAI,IAAI,IAAI,CAAA;IACZ,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CACzB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAmMlE"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAK5C,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,IAAI,EAAE,CAAA;CACb;AAgBD,MAAM,WAAW,SAAS;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,IAAI,IAAI,IAAI,CAAA;IACZ,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CACzB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAmMlE;AAID,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,IAAI,EAAE,CAAA;CACb;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEpE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAmIjF"}
@@ -0,0 +1,18 @@
1
+ export interface JsonRpcRequest {
2
+ jsonrpc: '2.0';
3
+ id?: number;
4
+ method: string;
5
+ params?: Record<string, unknown>;
6
+ }
7
+ export interface JsonRpcResponse {
8
+ jsonrpc: '2.0';
9
+ id: number;
10
+ result?: unknown;
11
+ error?: {
12
+ code: number;
13
+ message: string;
14
+ data?: unknown;
15
+ };
16
+ }
17
+ export type MCPTransport = 'stdio' | 'http';
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,KAAK,CAAA;IACd,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,KAAK,CAAA;IACd,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CACzD;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elsium-ai/mcp",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Model Context Protocol (MCP) support for ElsiumAI — bidirectional bridge",
5
5
  "license": "MIT",
6
6
  "author": "Eric Utrera <ebutrera9103@gmail.com>",
@@ -26,8 +26,8 @@
26
26
  "dev": "bun --watch src/index.ts"
27
27
  },
28
28
  "dependencies": {
29
- "@elsium-ai/core": "^0.3.0",
30
- "@elsium-ai/tools": "^0.3.0"
29
+ "@elsium-ai/core": "^0.4.1",
30
+ "@elsium-ai/tools": "^0.4.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "typescript": "^5.7.0"