@niroai/mcp-server 1.0.0 → 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.
Files changed (2) hide show
  1. package/index.js +39 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -44,11 +44,15 @@ let sessionId = null;
44
44
  */
45
45
  function connectSse() {
46
46
  return new Promise((resolve, reject) => {
47
- const sseUrl = `${API_URL}/mcp/sse`;
48
- process.stderr.write(`[niro-mcp] Connecting to ${sseUrl}\n`);
47
+ const sseUrl = `${API_URL}/mcp/sse?api_key=${encodeURIComponent(API_KEY)}&project_id=${encodeURIComponent(PROJECT_ID)}`;
48
+ process.stderr.write(`[niro-mcp] Connecting to ${API_URL}/mcp/sse\n`);
49
49
 
50
50
  const req = httpModule.get(sseUrl, {
51
- headers: { "Accept": "text/event-stream" },
51
+ headers: {
52
+ "Accept": "text/event-stream",
53
+ "X-Niro-Api-Key": API_KEY,
54
+ "X-Niro-Project-Id": PROJECT_ID,
55
+ },
52
56
  }, (res) => {
53
57
  if (res.statusCode !== 200) {
54
58
  reject(new Error(`SSE connection failed: HTTP ${res.statusCode}`));
@@ -57,31 +61,41 @@ function connectSse() {
57
61
 
58
62
  let buffer = "";
59
63
 
64
+ let currentEvent = null;
65
+ let currentData = "";
66
+
60
67
  res.on("data", (chunk) => {
61
68
  buffer += chunk.toString();
62
- const lines = buffer.split("\n");
63
- buffer = lines.pop(); // Keep incomplete line in buffer
64
-
65
- let eventName = null;
66
- for (const line of lines) {
67
- if (line.startsWith("event:")) {
68
- eventName = line.slice(6).trim();
69
- } else if (line.startsWith("data:")) {
70
- const data = line.slice(5).trim();
71
-
72
- if (eventName === "endpoint") {
73
- // First event: receive the message endpoint URL with sessionId
74
- const match = data.match(/sessionId=([a-f0-9-]+)/);
75
- if (match) {
76
- sessionId = match[1];
77
- process.stderr.write(`[niro-mcp] Session established: ${sessionId}\n`);
78
- resolve();
79
- }
80
- } else if (eventName === "message") {
81
- // Response from the server — write to stdout
82
- process.stdout.write(data + "\n");
69
+
70
+ // SSE events are delimited by double newline
71
+ let doubleNewline;
72
+ while ((doubleNewline = buffer.indexOf("\n\n")) !== -1) {
73
+ const block = buffer.slice(0, doubleNewline);
74
+ buffer = buffer.slice(doubleNewline + 2);
75
+
76
+ // Parse the SSE block
77
+ let eventName = null;
78
+ let dataLines = [];
79
+ for (const line of block.split("\n")) {
80
+ if (line.startsWith("event:")) {
81
+ eventName = line.slice(6).trim();
82
+ } else if (line.startsWith("data:")) {
83
+ dataLines.push(line.slice(5));
84
+ }
85
+ }
86
+
87
+ const data = dataLines.join("\n").trim();
88
+ if (!eventName || !data) continue;
89
+
90
+ if (eventName === "endpoint") {
91
+ const match = data.match(/sessionId=([a-f0-9-]+)/);
92
+ if (match) {
93
+ sessionId = match[1];
94
+ process.stderr.write(`[niro-mcp] Session established: ${sessionId}\n`);
95
+ resolve();
83
96
  }
84
- eventName = null;
97
+ } else if (eventName === "message") {
98
+ process.stdout.write(data + "\n");
85
99
  }
86
100
  }
87
101
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niroai/mcp-server",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Niro MCP Server — code intelligence for AI coding assistants",
5
5
  "bin": {
6
6
  "mcp-server": "index.js"