@malloy-publisher/server 0.0.226 → 0.0.227
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/README.md +2 -11
- package/dist/package_load_worker.mjs +86 -24
- package/dist/server.mjs +655 -6994
- package/package.json +1 -4
- package/src/health.ts +3 -8
- package/src/mcp/error_messages.ts +8 -37
- package/src/mcp/handler_utils.ts +10 -129
- package/src/mcp/mcp_constants.ts +0 -16
- package/src/mcp/{agent_server.protocol.spec.ts → server.protocol.spec.ts} +14 -12
- package/src/mcp/server.ts +29 -37
- package/src/mcp/skills/build_skills_bundle.ts +1 -1
- package/src/mcp/skills/skills_bundle.json +1 -1
- package/src/mcp/tools/docs_search_tool.ts +1 -1
- package/src/mcp/tools/execute_query_tool.ts +2 -2
- package/src/mcp/tools/get_context_eval.ts +3 -3
- package/src/mcp/tools/get_context_tool.spec.ts +196 -1
- package/src/mcp/tools/get_context_tool.ts +165 -67
- package/src/package_load/package_load_pool.ts +3 -0
- package/src/package_load/package_load_worker.ts +68 -24
- package/src/package_load/protocol.ts +16 -0
- package/src/package_load/rpc_wait_accountant.spec.ts +109 -0
- package/src/package_load/rpc_wait_accountant.ts +76 -0
- package/src/package_load_metrics.spec.ts +114 -0
- package/src/package_load_metrics.ts +127 -0
- package/src/pg_helpers.spec.ts +2 -206
- package/src/pg_helpers.ts +4 -120
- package/src/server.ts +0 -16
- package/src/service/environment.ts +1 -1
- package/src/service/package.ts +82 -42
- package/src/test_helpers/metrics_harness.ts +40 -0
- package/tests/harness/mcp_test_setup.ts +1 -1
- package/tests/integration/mcp/mcp_transport.integration.spec.ts +7 -31
- package/tests/integration/watch-mode/watch_mode.integration.spec.ts +0 -6
- package/dxt/malloy_bridge.py +0 -354
- package/dxt/manifest.json +0 -22
- package/src/dto/connection.dto.spec.ts +0 -186
- package/src/dto/connection.dto.ts +0 -308
- package/src/dto/index.ts +0 -2
- package/src/dto/package.dto.spec.ts +0 -42
- package/src/dto/package.dto.ts +0 -27
- package/src/dto/validate.spec.ts +0 -76
- package/src/dto/validate.ts +0 -31
- package/src/ducklake_version.spec.ts +0 -43
- package/src/ducklake_version.ts +0 -26
- package/src/mcp/agent_server.spec.ts +0 -18
- package/src/mcp/agent_server.ts +0 -144
- package/src/mcp/prompts/handlers.ts +0 -84
- package/src/mcp/prompts/index.ts +0 -11
- package/src/mcp/prompts/prompt_definitions.ts +0 -160
- package/src/mcp/prompts/prompt_service.ts +0 -67
- package/src/mcp/prompts/utils.ts +0 -62
- package/src/mcp/resource_metadata.ts +0 -47
- package/src/mcp/resources/environment_resource.ts +0 -187
- package/src/mcp/resources/model_resource.ts +0 -155
- package/src/mcp/resources/notebook_resource.ts +0 -137
- package/src/mcp/resources/package_resource.ts +0 -373
- package/src/mcp/resources/query_resource.ts +0 -122
- package/src/mcp/resources/source_resource.ts +0 -141
- package/src/mcp/resources/view_resource.ts +0 -136
- package/src/mcp/tools/discovery_tools.ts +0 -280
- package/src/storage/BaseRepository.ts +0 -31
- package/src/storage/StorageManager.mock.ts +0 -50
- package/tests/harness/e2e.ts +0 -96
- package/tests/harness/mocks.ts +0 -39
- package/tests/harness/uris.ts +0 -31
- package/tests/integration/mcp/mcp_resource.integration.spec.ts +0 -655
- package/tests/integration/mcp/setup.spec.ts +0 -5
- package/tests/unit/mcp/prompt_definitions.test.ts +0 -102
- package/tests/unit/mcp/prompt_happy.test.ts +0 -51
|
@@ -34,32 +34,20 @@ describe.serial("MCP Transport Tests (E2E Integration)", () => {
|
|
|
34
34
|
|
|
35
35
|
describe("Basic Protocol", () => {
|
|
36
36
|
it(
|
|
37
|
-
"should handle a simple
|
|
37
|
+
"should handle a simple listTools request",
|
|
38
38
|
async () => {
|
|
39
39
|
if (!env) throw new Error("Test environment not initialized");
|
|
40
|
-
const result = await mcpClient.
|
|
40
|
+
const result = await mcpClient.listTools();
|
|
41
41
|
// Assert based on actual successful response structure
|
|
42
|
-
expect(result).toHaveProperty("
|
|
43
|
-
expect(Array.isArray(result.
|
|
42
|
+
expect(result).toHaveProperty("tools");
|
|
43
|
+
expect(Array.isArray(result.tools)).toBe(true);
|
|
44
|
+
expect(
|
|
45
|
+
result.tools.some((t) => t.name === "malloy_executeQuery"),
|
|
46
|
+
).toBe(true);
|
|
44
47
|
},
|
|
45
48
|
{ timeout: 30000 },
|
|
46
49
|
);
|
|
47
50
|
|
|
48
|
-
it("should receive InvalidParams error when calling a known method with invalid params", async () => {
|
|
49
|
-
if (!env) throw new Error("Test environment not initialized");
|
|
50
|
-
expect.assertions(2);
|
|
51
|
-
try {
|
|
52
|
-
// Use the client from the test environment
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
-
await mcpClient.readResource({} as any); // Force invalid params
|
|
55
|
-
} catch (error) {
|
|
56
|
-
expect(error).toBeInstanceOf(Error);
|
|
57
|
-
// Check error code and message
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
-
expect((error as any).code).toBe(ErrorCode.InternalError);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
51
|
it("should receive MethodNotFound error for unknown methods", async () => {
|
|
64
52
|
if (!env) throw new Error("Test environment not initialized");
|
|
65
53
|
expect.assertions(2); // Expecting error instance and specific code
|
|
@@ -84,18 +72,6 @@ describe.serial("MCP Transport Tests (E2E Integration)", () => {
|
|
|
84
72
|
});
|
|
85
73
|
|
|
86
74
|
describe("Connection Management & Bridge Logic", () => {
|
|
87
|
-
// DELETED - Test irrelevant in stateless mode
|
|
88
|
-
// it("should maintain session across multiple sequential requests", async () => {
|
|
89
|
-
// ...
|
|
90
|
-
// });
|
|
91
|
-
|
|
92
|
-
// DELETED - Test irrelevant in stateless mode
|
|
93
|
-
// it("should handle reconnection after close", async () => {
|
|
94
|
-
// ...
|
|
95
|
-
// });
|
|
96
|
-
|
|
97
|
-
// --- Bridge Error Handling ---
|
|
98
|
-
|
|
99
75
|
it("should return 405 Method Not Allowed for GET requests", async () => {
|
|
100
76
|
if (!env) throw new Error("Test environment not initialized");
|
|
101
77
|
const getUrl = new URL(`${env.serverUrl}/mcp`); // No session ID needed
|
|
@@ -116,11 +116,6 @@ async function startServer(opts: { watch: boolean }): Promise<TestServer> {
|
|
|
116
116
|
const port = await getFreePort();
|
|
117
117
|
let mcpPort = await getFreePort();
|
|
118
118
|
while (mcpPort === port) mcpPort = await getFreePort();
|
|
119
|
-
// The agent MCP server binds its own listener; give it a distinct free port
|
|
120
|
-
// too, otherwise every spawned child binds the fixed default and collides.
|
|
121
|
-
let agentMcpPort = await getFreePort();
|
|
122
|
-
while (agentMcpPort === port || agentMcpPort === mcpPort)
|
|
123
|
-
agentMcpPort = await getFreePort();
|
|
124
119
|
const baseUrl = `http://127.0.0.1:${port}`;
|
|
125
120
|
|
|
126
121
|
const env: NodeJS.ProcessEnv = {
|
|
@@ -129,7 +124,6 @@ async function startServer(opts: { watch: boolean }): Promise<TestServer> {
|
|
|
129
124
|
PUBLISHER_HOST: "127.0.0.1",
|
|
130
125
|
PUBLISHER_PORT: String(port),
|
|
131
126
|
MCP_PORT: String(mcpPort),
|
|
132
|
-
AGENT_MCP_PORT: String(agentMcpPort),
|
|
133
127
|
};
|
|
134
128
|
if (opts.watch) env.PUBLISHER_WATCH = ENV_NAME;
|
|
135
129
|
|
package/dxt/malloy_bridge.py
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import sys
|
|
3
|
-
import json
|
|
4
|
-
import urllib.request
|
|
5
|
-
import urllib.parse
|
|
6
|
-
import urllib.error
|
|
7
|
-
import logging
|
|
8
|
-
import time
|
|
9
|
-
import signal
|
|
10
|
-
from typing import Dict, Any, Optional
|
|
11
|
-
|
|
12
|
-
# Set up logging with more detailed format
|
|
13
|
-
logging.basicConfig(
|
|
14
|
-
filename='/tmp/malloy_bridge.log',
|
|
15
|
-
level=logging.DEBUG,
|
|
16
|
-
format='%(asctime)s - %(levelname)s - %(funcName)s:%(lineno)d - %(message)s'
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
class ImprovedMalloyMCPBridge:
|
|
20
|
-
def __init__(self):
|
|
21
|
-
self.mcp_url = "http://localhost:4040/mcp"
|
|
22
|
-
# No tool name mapping needed - server already uses underscore format
|
|
23
|
-
|
|
24
|
-
# Set stdin/stdout to line buffered mode for better responsiveness
|
|
25
|
-
try:
|
|
26
|
-
sys.stdin.reconfigure(line_buffering=True)
|
|
27
|
-
sys.stdout.reconfigure(line_buffering=True)
|
|
28
|
-
except AttributeError:
|
|
29
|
-
# reconfigure not available in older Python versions
|
|
30
|
-
pass
|
|
31
|
-
|
|
32
|
-
# Set up signal handlers for graceful shutdown
|
|
33
|
-
signal.signal(signal.SIGTERM, self.signal_handler)
|
|
34
|
-
signal.signal(signal.SIGINT, self.signal_handler)
|
|
35
|
-
logging.info("Bridge initialized with improved stdio handling")
|
|
36
|
-
|
|
37
|
-
def signal_handler(self, signum, frame):
|
|
38
|
-
logging.info(f"Received signal {signum}, shutting down gracefully")
|
|
39
|
-
sys.exit(0)
|
|
40
|
-
|
|
41
|
-
def parse_sse_response(self, response, request_id: Optional[Any] = None) -> Dict[str, Any]:
|
|
42
|
-
"""Parse Server-Sent Events response format with improved error handling"""
|
|
43
|
-
logging.debug(f"Starting SSE parsing for request {request_id}")
|
|
44
|
-
|
|
45
|
-
try:
|
|
46
|
-
# Read response with size limit to prevent memory issues
|
|
47
|
-
max_size = 1024 * 1024 # 1MB limit
|
|
48
|
-
response_text = ""
|
|
49
|
-
bytes_read = 0
|
|
50
|
-
|
|
51
|
-
# Read response in chunks to avoid memory issues
|
|
52
|
-
while True:
|
|
53
|
-
chunk = response.read(8192) # 8KB chunks
|
|
54
|
-
if not chunk:
|
|
55
|
-
break
|
|
56
|
-
bytes_read += len(chunk)
|
|
57
|
-
if bytes_read > max_size:
|
|
58
|
-
logging.warning(f"Response too large ({bytes_read} bytes), truncating")
|
|
59
|
-
break
|
|
60
|
-
response_text += chunk.decode('utf-8')
|
|
61
|
-
|
|
62
|
-
logging.debug(f"Read {bytes_read} bytes from SSE response")
|
|
63
|
-
|
|
64
|
-
lines = response_text.strip().split('\n')
|
|
65
|
-
data_line = None
|
|
66
|
-
|
|
67
|
-
# Look for data line in SSE format
|
|
68
|
-
for line in lines:
|
|
69
|
-
if line.startswith('data: '):
|
|
70
|
-
data_line = line[6:] # Remove 'data: ' prefix
|
|
71
|
-
break
|
|
72
|
-
|
|
73
|
-
# If no SSE format, try parsing the entire response as JSON
|
|
74
|
-
if not data_line:
|
|
75
|
-
data_line = response_text.strip()
|
|
76
|
-
|
|
77
|
-
if data_line:
|
|
78
|
-
try:
|
|
79
|
-
parsed_data = json.loads(data_line)
|
|
80
|
-
# Ensure the response has a proper ID
|
|
81
|
-
if 'id' not in parsed_data or parsed_data['id'] is None:
|
|
82
|
-
parsed_data['id'] = request_id
|
|
83
|
-
|
|
84
|
-
logging.debug(f"Successfully parsed response for request {request_id}")
|
|
85
|
-
return parsed_data
|
|
86
|
-
|
|
87
|
-
except json.JSONDecodeError as e:
|
|
88
|
-
logging.error(f"JSON decode error for request {request_id}: {e}")
|
|
89
|
-
logging.error(f"Raw data that failed to parse: {data_line[:200]}...")
|
|
90
|
-
return {
|
|
91
|
-
"jsonrpc": "2.0",
|
|
92
|
-
"error": {
|
|
93
|
-
"code": -32603,
|
|
94
|
-
"message": f"Failed to parse response: {str(e)}"
|
|
95
|
-
},
|
|
96
|
-
"id": request_id
|
|
97
|
-
}
|
|
98
|
-
else:
|
|
99
|
-
logging.error(f"No data found in response for request {request_id}")
|
|
100
|
-
return {
|
|
101
|
-
"jsonrpc": "2.0",
|
|
102
|
-
"error": {
|
|
103
|
-
"code": -32603,
|
|
104
|
-
"message": "No data found in response"
|
|
105
|
-
},
|
|
106
|
-
"id": request_id
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
except Exception as e:
|
|
110
|
-
logging.error(f"Error reading SSE response for request {request_id}: {e}")
|
|
111
|
-
return {
|
|
112
|
-
"jsonrpc": "2.0",
|
|
113
|
-
"error": {
|
|
114
|
-
"code": -32603,
|
|
115
|
-
"message": f"SSE parsing error: {str(e)}"
|
|
116
|
-
},
|
|
117
|
-
"id": request_id
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
def send_request(self, request: Dict[str, Any]) -> Dict[str, Any]:
|
|
121
|
-
"""Send a JSON-RPC request to the Malloy MCP endpoint with improved timeout handling"""
|
|
122
|
-
request_id = request.get("id")
|
|
123
|
-
method = request.get("method", "unknown")
|
|
124
|
-
start_time = time.time()
|
|
125
|
-
|
|
126
|
-
logging.debug(f"Sending request {request_id} ({method}) to Malloy server")
|
|
127
|
-
|
|
128
|
-
# Log ALL method calls for debugging
|
|
129
|
-
logging.info(f"METHOD CALL - Request {request_id}: method='{method}'")
|
|
130
|
-
if method == "tools/call":
|
|
131
|
-
tool_name = request.get("params", {}).get("name", "unknown")
|
|
132
|
-
logging.info(f"TOOL CALL - Request {request_id}: tool_name='{tool_name}'")
|
|
133
|
-
logging.info(f"FULL REQUEST - {json.dumps(request)}")
|
|
134
|
-
|
|
135
|
-
try:
|
|
136
|
-
# Ensure the request has proper structure
|
|
137
|
-
if "jsonrpc" not in request:
|
|
138
|
-
request["jsonrpc"] = "2.0"
|
|
139
|
-
|
|
140
|
-
# Prepare the request with longer timeout for tools/list
|
|
141
|
-
timeout = 10 if method == "tools/list" else 3
|
|
142
|
-
data = json.dumps(request).encode('utf-8')
|
|
143
|
-
req = urllib.request.Request(
|
|
144
|
-
self.mcp_url,
|
|
145
|
-
data=data,
|
|
146
|
-
headers={
|
|
147
|
-
'Content-Type': 'application/json',
|
|
148
|
-
'Accept': 'application/json, text/event-stream',
|
|
149
|
-
'Connection': 'close' # Don't keep connections open
|
|
150
|
-
}
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
logging.debug(f"Using timeout of {timeout}s for method {method}")
|
|
154
|
-
|
|
155
|
-
with urllib.request.urlopen(req, timeout=timeout) as response:
|
|
156
|
-
# Handle SSE response directly from the response object
|
|
157
|
-
content_type = response.headers.get('Content-Type', '')
|
|
158
|
-
|
|
159
|
-
if 'text/event-stream' in content_type:
|
|
160
|
-
logging.debug("Handling SSE response")
|
|
161
|
-
parsed_response = self.parse_sse_response(response, request_id)
|
|
162
|
-
else:
|
|
163
|
-
logging.debug("Handling JSON response")
|
|
164
|
-
response_text = response.read().decode('utf-8')
|
|
165
|
-
try:
|
|
166
|
-
parsed_response = json.loads(response_text)
|
|
167
|
-
if 'id' not in parsed_response or parsed_response['id'] is None:
|
|
168
|
-
parsed_response['id'] = request_id
|
|
169
|
-
except json.JSONDecodeError as e:
|
|
170
|
-
logging.error(f"Failed to parse JSON response: {e}")
|
|
171
|
-
parsed_response = {
|
|
172
|
-
"jsonrpc": "2.0",
|
|
173
|
-
"error": {
|
|
174
|
-
"code": -32603,
|
|
175
|
-
"message": f"Invalid JSON response: {str(e)}"
|
|
176
|
-
},
|
|
177
|
-
"id": request_id
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
# Log server response for debugging
|
|
181
|
-
if "error" in parsed_response:
|
|
182
|
-
logging.error(f"SERVER ERROR - Request {request_id} ({method}): {parsed_response}")
|
|
183
|
-
elif method == "tools/call":
|
|
184
|
-
logging.info(f"TOOL CALL - Server response: {str(parsed_response)[:500]}...")
|
|
185
|
-
|
|
186
|
-
elapsed = time.time() - start_time
|
|
187
|
-
logging.debug(f"Request {request_id} completed in {elapsed:.2f}s")
|
|
188
|
-
return parsed_response
|
|
189
|
-
|
|
190
|
-
except urllib.error.HTTPError as e:
|
|
191
|
-
elapsed = time.time() - start_time
|
|
192
|
-
error_message = f"HTTP {e.code}: {e.reason}"
|
|
193
|
-
try:
|
|
194
|
-
error_body = e.read().decode('utf-8')
|
|
195
|
-
error_message += f" - {error_body}"
|
|
196
|
-
except:
|
|
197
|
-
pass
|
|
198
|
-
|
|
199
|
-
logging.error(f"HTTP error for request {request_id} after {elapsed:.2f}s: {error_message}")
|
|
200
|
-
return {
|
|
201
|
-
"jsonrpc": "2.0",
|
|
202
|
-
"error": {
|
|
203
|
-
"code": e.code,
|
|
204
|
-
"message": error_message
|
|
205
|
-
},
|
|
206
|
-
"id": request_id
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
except urllib.error.URLError as e:
|
|
210
|
-
elapsed = time.time() - start_time
|
|
211
|
-
error_msg = f"Connection error: {str(e)}"
|
|
212
|
-
logging.error(f"URL error for request {request_id} after {elapsed:.2f}s: {error_msg}")
|
|
213
|
-
return {
|
|
214
|
-
"jsonrpc": "2.0",
|
|
215
|
-
"error": {
|
|
216
|
-
"code": -32603,
|
|
217
|
-
"message": error_msg
|
|
218
|
-
},
|
|
219
|
-
"id": request_id
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
except Exception as e:
|
|
223
|
-
elapsed = time.time() - start_time
|
|
224
|
-
error_msg = f"Unexpected error: {str(e)}"
|
|
225
|
-
logging.error(f"Unexpected error for request {request_id} after {elapsed:.2f}s: {error_msg}")
|
|
226
|
-
return {
|
|
227
|
-
"jsonrpc": "2.0",
|
|
228
|
-
"error": {
|
|
229
|
-
"code": -32603,
|
|
230
|
-
"message": error_msg
|
|
231
|
-
},
|
|
232
|
-
"id": request_id
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
def safe_print(self, data):
|
|
236
|
-
"""Print with improved error handling and immediate flushing"""
|
|
237
|
-
try:
|
|
238
|
-
output = json.dumps(data)
|
|
239
|
-
print(output, flush=True) # Use flush=True for immediate output
|
|
240
|
-
logging.debug(f"Successfully sent response: {len(output)} chars")
|
|
241
|
-
|
|
242
|
-
except BrokenPipeError:
|
|
243
|
-
logging.error("Broken pipe error - client disconnected")
|
|
244
|
-
sys.exit(0)
|
|
245
|
-
|
|
246
|
-
except Exception as e:
|
|
247
|
-
logging.error(f"Print error: {e}")
|
|
248
|
-
# Don't exit on print errors, just log them
|
|
249
|
-
|
|
250
|
-
def process_request(self, line: str) -> None:
|
|
251
|
-
"""Process a single request line with improved error handling"""
|
|
252
|
-
try:
|
|
253
|
-
request = json.loads(line)
|
|
254
|
-
request_id = request.get("id", "unknown")
|
|
255
|
-
method = request.get("method", "unknown")
|
|
256
|
-
|
|
257
|
-
logging.debug(f"Processing request {request_id}: {method}")
|
|
258
|
-
|
|
259
|
-
# Validate required fields
|
|
260
|
-
if not isinstance(request, dict):
|
|
261
|
-
raise ValueError("Request must be a JSON object")
|
|
262
|
-
|
|
263
|
-
if "method" not in request:
|
|
264
|
-
raise ValueError("Request must have a 'method' field")
|
|
265
|
-
|
|
266
|
-
# Handle notifications/initialized locally (Malloy server doesn't support it)
|
|
267
|
-
if method == "notifications/initialized":
|
|
268
|
-
logging.info(f"Handling notifications/initialized locally for request {request_id}")
|
|
269
|
-
# For notifications, we don't send a response (notifications are one-way)
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
# Ensure ID is present and valid
|
|
273
|
-
if "id" not in request:
|
|
274
|
-
request["id"] = 1 # Default ID
|
|
275
|
-
elif request["id"] is None:
|
|
276
|
-
request["id"] = 1 # Replace null with default
|
|
277
|
-
|
|
278
|
-
# Send request and get response
|
|
279
|
-
response = self.send_request(request)
|
|
280
|
-
|
|
281
|
-
# Send response immediately
|
|
282
|
-
self.safe_print(response)
|
|
283
|
-
|
|
284
|
-
except json.JSONDecodeError as e:
|
|
285
|
-
logging.error(f"JSON parse error: {e}")
|
|
286
|
-
error_response = {
|
|
287
|
-
"jsonrpc": "2.0",
|
|
288
|
-
"error": {
|
|
289
|
-
"code": -32700,
|
|
290
|
-
"message": f"Parse error: {str(e)}"
|
|
291
|
-
},
|
|
292
|
-
"id": None
|
|
293
|
-
}
|
|
294
|
-
self.safe_print(error_response)
|
|
295
|
-
|
|
296
|
-
except ValueError as e:
|
|
297
|
-
logging.error(f"Request validation error: {e}")
|
|
298
|
-
error_response = {
|
|
299
|
-
"jsonrpc": "2.0",
|
|
300
|
-
"error": {
|
|
301
|
-
"code": -32600,
|
|
302
|
-
"message": f"Invalid Request: {str(e)}"
|
|
303
|
-
},
|
|
304
|
-
"id": None
|
|
305
|
-
}
|
|
306
|
-
self.safe_print(error_response)
|
|
307
|
-
|
|
308
|
-
except Exception as e:
|
|
309
|
-
logging.error(f"Unexpected error processing request: {e}")
|
|
310
|
-
error_response = {
|
|
311
|
-
"jsonrpc": "2.0",
|
|
312
|
-
"error": {
|
|
313
|
-
"code": -32603,
|
|
314
|
-
"message": f"Internal error: {str(e)}"
|
|
315
|
-
},
|
|
316
|
-
"id": None
|
|
317
|
-
}
|
|
318
|
-
self.safe_print(error_response)
|
|
319
|
-
|
|
320
|
-
def run(self):
|
|
321
|
-
"""Main loop with improved stdin handling"""
|
|
322
|
-
logging.info("Starting main processing loop")
|
|
323
|
-
|
|
324
|
-
try:
|
|
325
|
-
# Process stdin line by line with immediate handling
|
|
326
|
-
for line in sys.stdin:
|
|
327
|
-
line = line.strip()
|
|
328
|
-
if not line:
|
|
329
|
-
continue
|
|
330
|
-
|
|
331
|
-
# Process each request immediately
|
|
332
|
-
self.process_request(line)
|
|
333
|
-
|
|
334
|
-
except KeyboardInterrupt:
|
|
335
|
-
logging.info("Received keyboard interrupt, shutting down")
|
|
336
|
-
sys.exit(0)
|
|
337
|
-
|
|
338
|
-
except BrokenPipeError:
|
|
339
|
-
logging.info("Broken pipe detected, client disconnected")
|
|
340
|
-
sys.exit(0)
|
|
341
|
-
|
|
342
|
-
except Exception as e:
|
|
343
|
-
logging.error(f"Fatal error in main loop: {e}")
|
|
344
|
-
sys.exit(1)
|
|
345
|
-
|
|
346
|
-
logging.info("Main loop completed")
|
|
347
|
-
|
|
348
|
-
if __name__ == "__main__":
|
|
349
|
-
try:
|
|
350
|
-
bridge = ImprovedMalloyMCPBridge()
|
|
351
|
-
bridge.run()
|
|
352
|
-
except Exception as e:
|
|
353
|
-
logging.error(f"Failed to start bridge: {e}")
|
|
354
|
-
sys.exit(1)
|
package/dxt/manifest.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"dxt_version": "0.1",
|
|
3
|
-
"name": "Malloy",
|
|
4
|
-
"version": "1.0.0",
|
|
5
|
-
"description": "Connect to Malloy Publisher, allowing you to write & run Malloy data queries.",
|
|
6
|
-
"author": {
|
|
7
|
-
"name": "Josh Sacks"
|
|
8
|
-
},
|
|
9
|
-
"server": {
|
|
10
|
-
"type": "python",
|
|
11
|
-
"entry_point": "malloy_bridge.py",
|
|
12
|
-
"mcp_config": {
|
|
13
|
-
"command": "python",
|
|
14
|
-
"args": ["${__dirname}/malloy_bridge.py"],
|
|
15
|
-
"env": {
|
|
16
|
-
"PYTHONPATH": "server/lib"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"keywords": ["sql", "malloy", "data", "queries", "charts"],
|
|
21
|
-
"license": "MIT"
|
|
22
|
-
}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { expect, it, describe } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { plainToInstance } from "class-transformer";
|
|
4
|
-
import { validate } from "class-validator";
|
|
5
|
-
import {
|
|
6
|
-
BigqueryConnectionDto,
|
|
7
|
-
ConnectionDto,
|
|
8
|
-
DatabricksConnectionDto,
|
|
9
|
-
PostgresConnectionDto,
|
|
10
|
-
SnowflakeConnectionDto,
|
|
11
|
-
MysqlConnectionDto,
|
|
12
|
-
} from "./connection.dto";
|
|
13
|
-
|
|
14
|
-
describe("dto/connection", () => {
|
|
15
|
-
describe("Connection Validation", () => {
|
|
16
|
-
it("should validate a valid MysqlConnection object", async () => {
|
|
17
|
-
const validData = {
|
|
18
|
-
host: "localhost",
|
|
19
|
-
port: 3306,
|
|
20
|
-
database: "testdb",
|
|
21
|
-
user: "user",
|
|
22
|
-
password: "pass",
|
|
23
|
-
};
|
|
24
|
-
const mysqlConnection = plainToInstance(MysqlConnectionDto, validData);
|
|
25
|
-
|
|
26
|
-
const errors = await validate(mysqlConnection);
|
|
27
|
-
expect(errors).toHaveLength(0);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should validate a valid PostgresConnection object", async () => {
|
|
31
|
-
const validData = {
|
|
32
|
-
host: "localhost",
|
|
33
|
-
port: 5432,
|
|
34
|
-
databaseName: "testdb",
|
|
35
|
-
userName: "user",
|
|
36
|
-
password: "pass",
|
|
37
|
-
connectionString: "postgres://user:pass@localhost:5432/testdb",
|
|
38
|
-
};
|
|
39
|
-
const postgresConnection = plainToInstance(
|
|
40
|
-
PostgresConnectionDto,
|
|
41
|
-
validData,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const errors = await validate(postgresConnection);
|
|
45
|
-
expect(errors).toHaveLength(0);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should return errors for invalid PostgresConnection object", async () => {
|
|
49
|
-
const invalidData = {
|
|
50
|
-
host: 123, // Invalid type
|
|
51
|
-
port: "not-a-number", // Invalid type
|
|
52
|
-
};
|
|
53
|
-
const postgresConnection = plainToInstance(
|
|
54
|
-
PostgresConnectionDto,
|
|
55
|
-
invalidData,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const errors = await validate(postgresConnection);
|
|
59
|
-
expect(errors).not.toHaveLength(0);
|
|
60
|
-
expect(errors).toHaveLength(2);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should validate a valid BigqueryConnection object", async () => {
|
|
64
|
-
const validData = {
|
|
65
|
-
defaultProjectId: "default-project",
|
|
66
|
-
billingProjectId: "billing-project",
|
|
67
|
-
location: "US",
|
|
68
|
-
serviceAccountKeyJson: "{}",
|
|
69
|
-
maximumBytesBilled: "1000000",
|
|
70
|
-
queryTimeoutMilliseconds: "1000",
|
|
71
|
-
};
|
|
72
|
-
const bigqueryConnection = plainToInstance(
|
|
73
|
-
BigqueryConnectionDto,
|
|
74
|
-
validData,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const errors = await validate(bigqueryConnection);
|
|
78
|
-
expect(errors).toHaveLength(0);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should validate a valid SnowflakeConnection object", async () => {
|
|
82
|
-
const validData = {
|
|
83
|
-
account: "my-account",
|
|
84
|
-
username: "user",
|
|
85
|
-
password: "pass",
|
|
86
|
-
privateKey:
|
|
87
|
-
"-----BEGIN PRIVATE KEY-----\\nabc\\n-----END PRIVATE KEY-----",
|
|
88
|
-
privateKeyPass: "secret",
|
|
89
|
-
warehouse: "my-warehouse",
|
|
90
|
-
database: "my-database",
|
|
91
|
-
schema: "my-schema",
|
|
92
|
-
role: "analyst",
|
|
93
|
-
responseTimeoutMilliseconds: 5000,
|
|
94
|
-
};
|
|
95
|
-
const snowflakeConnection = plainToInstance(
|
|
96
|
-
SnowflakeConnectionDto,
|
|
97
|
-
validData,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const errors = await validate(snowflakeConnection);
|
|
101
|
-
expect(errors).toHaveLength(0);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it("should validate a valid DatabricksConnection object", async () => {
|
|
105
|
-
const validData = {
|
|
106
|
-
host: "dbc-xxxxxxxx-xxxx.cloud.databricks.com",
|
|
107
|
-
path: "/sql/1.0/warehouses/abc123",
|
|
108
|
-
token: "dapiXXXX",
|
|
109
|
-
oauthClientId: "client-id",
|
|
110
|
-
oauthClientSecret: "client-secret",
|
|
111
|
-
defaultCatalog: "main",
|
|
112
|
-
defaultSchema: "default",
|
|
113
|
-
setupSQL: "USE CATALOG main",
|
|
114
|
-
};
|
|
115
|
-
const databricksConnection = plainToInstance(
|
|
116
|
-
DatabricksConnectionDto,
|
|
117
|
-
validData,
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
const errors = await validate(databricksConnection);
|
|
121
|
-
expect(errors).toHaveLength(0);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("should return errors for invalid DatabricksConnection object", async () => {
|
|
125
|
-
const invalidData = {
|
|
126
|
-
host: 123, // Invalid type
|
|
127
|
-
path: false, // Invalid type
|
|
128
|
-
};
|
|
129
|
-
const databricksConnection = plainToInstance(
|
|
130
|
-
DatabricksConnectionDto,
|
|
131
|
-
invalidData,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
const errors = await validate(databricksConnection);
|
|
135
|
-
expect(errors).toHaveLength(2);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("should validate a valid Connection object with databricks type", async () => {
|
|
139
|
-
const validData = {
|
|
140
|
-
name: "My Databricks Connection",
|
|
141
|
-
type: "databricks",
|
|
142
|
-
databricksConnection: {
|
|
143
|
-
host: "dbc-xxxxxxxx-xxxx.cloud.databricks.com",
|
|
144
|
-
path: "/sql/1.0/warehouses/abc123",
|
|
145
|
-
token: "dapiXXXX",
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
const connection = plainToInstance(ConnectionDto, validData);
|
|
149
|
-
|
|
150
|
-
const errors = await validate(connection);
|
|
151
|
-
expect(errors).toHaveLength(0);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("should validate a valid Connection object with postgres type", async () => {
|
|
155
|
-
const validData = {
|
|
156
|
-
name: "My Postgres Connection",
|
|
157
|
-
type: "postgres",
|
|
158
|
-
postgresConnection: {
|
|
159
|
-
host: "localhost",
|
|
160
|
-
port: 5432,
|
|
161
|
-
databaseName: "testdb",
|
|
162
|
-
userName: "user",
|
|
163
|
-
password: "pass",
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
const connection = plainToInstance(ConnectionDto, validData);
|
|
167
|
-
|
|
168
|
-
const errors = await validate(connection);
|
|
169
|
-
expect(errors).toHaveLength(0);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("should return errors for invalid Connection object", async () => {
|
|
173
|
-
const invalidData = {
|
|
174
|
-
type: "invalid-type", // Invalid enum value
|
|
175
|
-
postgresConnection: {
|
|
176
|
-
port: "invalid-port", // Invalid type
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
const connection = plainToInstance(ConnectionDto, invalidData);
|
|
180
|
-
|
|
181
|
-
const errors = await validate(connection);
|
|
182
|
-
expect(errors).not.toHaveLength(0);
|
|
183
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|