@mcp-shark/mcp-shark 1.5.7 → 1.5.8
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.
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
2
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
3
|
+
import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Library for MCP transport creation utilities
|
|
7
|
+
* Pure utility - no dependencies on services or repositories
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create transport for MCP server based on config
|
|
12
|
+
* @param {Object} serverConfig - Server configuration
|
|
13
|
+
* @param {string} [serverConfig.type] - Transport type (stdio, http, websocket)
|
|
14
|
+
* @param {string} [serverConfig.url] - Server URL (for http/websocket)
|
|
15
|
+
* @param {Object} [serverConfig.headers] - HTTP headers
|
|
16
|
+
* @param {string} [serverConfig.command] - Command for stdio transport
|
|
17
|
+
* @param {Array} [serverConfig.args] - Command arguments
|
|
18
|
+
* @param {Object} [serverConfig.env] - Environment variables
|
|
19
|
+
* @param {string} [serverName] - Server name for error messages
|
|
20
|
+
* @returns {Object} Transport instance
|
|
21
|
+
* @throws {Error} If transport cannot be created
|
|
22
|
+
*/
|
|
23
|
+
export function createTransport(serverConfig, serverName = null) {
|
|
24
|
+
const type = serverConfig.type || (serverConfig.url ? 'http' : 'stdio');
|
|
25
|
+
const {
|
|
26
|
+
url,
|
|
27
|
+
headers: configHeaders = {},
|
|
28
|
+
command,
|
|
29
|
+
args = [],
|
|
30
|
+
env: configEnv = {},
|
|
31
|
+
} = serverConfig;
|
|
32
|
+
|
|
33
|
+
const env = {
|
|
34
|
+
...process.env,
|
|
35
|
+
...configEnv,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const requestInit = { headers: { ...configHeaders } };
|
|
39
|
+
|
|
40
|
+
const errorPrefix = serverName ? `Server ${serverName}: ` : '';
|
|
41
|
+
|
|
42
|
+
switch (type) {
|
|
43
|
+
case 'stdio':
|
|
44
|
+
if (!command) {
|
|
45
|
+
throw new Error(`${errorPrefix}command is required for stdio transport`);
|
|
46
|
+
}
|
|
47
|
+
return new StdioClientTransport({ command, args, env });
|
|
48
|
+
|
|
49
|
+
case 'http':
|
|
50
|
+
case 'sse':
|
|
51
|
+
case 'streamable-http':
|
|
52
|
+
if (!url) {
|
|
53
|
+
throw new Error(`${errorPrefix}url is required for ${type} transport`);
|
|
54
|
+
}
|
|
55
|
+
return new StreamableHTTPClientTransport(new URL(url), { requestInit });
|
|
56
|
+
|
|
57
|
+
case 'ws':
|
|
58
|
+
case 'websocket':
|
|
59
|
+
if (!url) {
|
|
60
|
+
throw new Error(`${errorPrefix}url is required for websocket transport`);
|
|
61
|
+
}
|
|
62
|
+
return new WebSocketClientTransport(new URL(url));
|
|
63
|
+
|
|
64
|
+
default:
|
|
65
|
+
if (command) {
|
|
66
|
+
return new StdioClientTransport({ command, args, env });
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`${errorPrefix}unsupported transport type: ${type}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
package/core/libraries/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { SerializationLibrary } from './SerializationLibrary.js';
|
|
6
6
|
export { LoggerLibrary } from './LoggerLibrary.js';
|
|
7
|
+
export { createTransport } from './TransportLibrary.js';
|
|
7
8
|
export { CompositeError, isError, getErrors } from './ErrorLibrary.js';
|
|
8
9
|
export {
|
|
9
10
|
ApplicationError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-shark/mcp-shark",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"description": "Aggregate multiple Model Context Protocol (MCP) servers into a single unified interface with a powerful monitoring UI. Prov deep visibility into every request and response.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./bin/mcp-shark.js",
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
2
|
-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
3
|
-
import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create transport for MCP server based on config
|
|
7
|
-
*/
|
|
8
|
-
export function createTransport(serverConfig, serverName) {
|
|
9
|
-
const type = serverConfig.type || (serverConfig.url ? 'http' : 'stdio');
|
|
10
|
-
const {
|
|
11
|
-
url,
|
|
12
|
-
headers: configHeaders = {},
|
|
13
|
-
command,
|
|
14
|
-
args = [],
|
|
15
|
-
env: configEnv = {},
|
|
16
|
-
} = serverConfig;
|
|
17
|
-
|
|
18
|
-
const env = {
|
|
19
|
-
...process.env,
|
|
20
|
-
...configEnv,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const requestInit = { headers: { ...configHeaders } };
|
|
24
|
-
|
|
25
|
-
switch (type) {
|
|
26
|
-
case 'stdio':
|
|
27
|
-
if (!command) {
|
|
28
|
-
throw new Error(`Server ${serverName}: command is required for stdio transport`);
|
|
29
|
-
}
|
|
30
|
-
return new StdioClientTransport({ command, args, env });
|
|
31
|
-
|
|
32
|
-
case 'http':
|
|
33
|
-
case 'sse':
|
|
34
|
-
case 'streamable-http':
|
|
35
|
-
if (!url) {
|
|
36
|
-
throw new Error(`Server ${serverName}: url is required for ${type} transport`);
|
|
37
|
-
}
|
|
38
|
-
return new StreamableHTTPClientTransport(new URL(url), { requestInit });
|
|
39
|
-
|
|
40
|
-
case 'ws':
|
|
41
|
-
case 'websocket':
|
|
42
|
-
if (!url) {
|
|
43
|
-
throw new Error(`Server ${serverName}: url is required for websocket transport`);
|
|
44
|
-
}
|
|
45
|
-
return new WebSocketClientTransport(new URL(url));
|
|
46
|
-
|
|
47
|
-
default:
|
|
48
|
-
if (command) {
|
|
49
|
-
return new StdioClientTransport({ command, args, env });
|
|
50
|
-
}
|
|
51
|
-
throw new Error(`Server ${serverName}: unsupported transport type: ${type}`);
|
|
52
|
-
}
|
|
53
|
-
}
|