viewgate-mcp 1.0.1 → 1.0.2
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/index.js +13 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// MCP protocol over Stdio REQUIRES that stdout is ONLY used for JSON-RPC.
|
|
3
|
+
// We redirect all console.log to console.error as early as possible.
|
|
4
|
+
console.log = console.error;
|
|
5
|
+
// Also catch raw process.stdout.write to prevent pollution from dependencies
|
|
6
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
7
|
+
process.stdout.write = (...args) => {
|
|
8
|
+
const str = args[0].toString();
|
|
9
|
+
// Only allow JSON-RPC messages (which start with {)
|
|
10
|
+
if (str.startsWith('{')) {
|
|
11
|
+
return originalStdoutWrite(...args);
|
|
12
|
+
}
|
|
13
|
+
return process.stderr.write(...args);
|
|
14
|
+
};
|
|
2
15
|
import express from "express";
|
|
3
16
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
17
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -8,10 +21,6 @@ import fetch from "node-fetch";
|
|
|
8
21
|
import cors from "cors";
|
|
9
22
|
import dotenv from "dotenv";
|
|
10
23
|
dotenv.config();
|
|
11
|
-
// MCP protocol over Stdio REQUIRES that stdout is ONLY used for JSON-RPC.
|
|
12
|
-
// We redirect all console.log to console.error to avoid polluting stdout.
|
|
13
|
-
const originalLog = console.log;
|
|
14
|
-
console.log = console.error;
|
|
15
24
|
const port = process.env.PORT || 3000;
|
|
16
25
|
const BACKEND_URL = process.env.BACKEND_URL || "https://view-gate.vercel.app";
|
|
17
26
|
// Store active sessions for SSE: sessionId -> { server, transport }
|