11#!/usr/bin/env node
22/**
3- * stdio -bridge.js
4- * Wrapper che permette a Claude Desktop (stdio) di parlare
5- * con il container ckan-mcp-server (HTTP/SSE).
3+ * ckan-mcp -bridge.js
4+ * Wrapper that allows Claude Desktop (stdio) to communicate
5+ * with the ckan-mcp-server container (HTTP/SSE).
66 *
7- * Claude Desktop <--stdio--> questo script <--HTTP--> container Docker
7+ * Claude Desktop <--stdio--> this script <--HTTP--> Docker container
88 */
99
1010const http = require ( "http" ) ;
1111const https = require ( "https" ) ;
1212
13- /*CHANGE LOCALHOST WITH IP*/
1413const MCP_URL = process . env . MCP_URL || "http://localhost:3000/mcp" ;
1514
1615const url = new URL ( MCP_URL ) ;
@@ -35,7 +34,7 @@ function sendToServer(body) {
3534 let raw = "" ;
3635 res . on ( "data" , ( chunk ) => ( raw += chunk ) ) ;
3736 res . on ( "end" , ( ) => {
38- // Gestisce sia risposte JSON pure che SSE (data: {...})
37+ // Handle both plain JSON responses and SSE (data: {...})
3938 const lines = raw . split ( "\n" ) ;
4039 for ( const line of lines ) {
4140 const trimmed = line . trim ( ) ;
@@ -54,7 +53,7 @@ function sendToServer(body) {
5453 } catch { }
5554 }
5655 }
57- // Fallback: prova a parsare tutto il body
56+ // Fallback: try to parse the entire body
5857 try {
5958 resolve ( JSON . parse ( raw ) ) ;
6059 } catch {
@@ -69,13 +68,13 @@ function sendToServer(body) {
6968 } ) ;
7069}
7170
72- // Legge messaggi JSON-RPC da stdin (uno per riga )
71+ // Read JSON-RPC messages from stdin (one per line )
7372let buffer = "" ;
7473process . stdin . setEncoding ( "utf8" ) ;
7574process . stdin . on ( "data" , async ( chunk ) => {
7675 buffer += chunk ;
7776 const lines = buffer . split ( "\n" ) ;
78- buffer = lines . pop ( ) ; // l'ultima riga potrebbe essere incompleta
77+ buffer = lines . pop ( ) ; // last line may be incomplete
7978
8079 for ( const line of lines ) {
8180 const trimmed = line . trim ( ) ;
@@ -85,7 +84,7 @@ process.stdin.on("data", async (chunk) => {
8584 const response = await sendToServer ( message ) ;
8685 process . stdout . write ( JSON . stringify ( response ) + "\n" ) ;
8786 } catch ( err ) {
88- // Invia un errore JSON-RPC valido in caso di problema
87+ // Send a valid JSON-RPC error on failure
8988 const errResponse = {
9089 jsonrpc : "2.0" ,
9190 error : { code : - 32603 , message : err . message } ,
0 commit comments