Add debugging
This commit is contained in:
@@ -6,6 +6,10 @@ import { fileURLToPath } from "url";
|
|||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
function delay(ms) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
// Get command line arguments
|
// Get command line arguments
|
||||||
const [, , command, ...mcpServerArgs] = process.argv;
|
const [, , command, ...mcpServerArgs] = process.argv;
|
||||||
@@ -64,7 +68,7 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
await Promise.any([server, client]);
|
await Promise.any([server, client]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!cancelled) throw e;
|
if (!cancelled || process.env.DEBUG) throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const createTransport = async (query: express.Request["query"]) => {
|
|||||||
const command = query.command as string;
|
const command = query.command as string;
|
||||||
const args = (query.args as string).split(/\s+/);
|
const args = (query.args as string).split(/\s+/);
|
||||||
const env = query.env ? JSON.parse(query.env as string) : undefined;
|
const env = query.env ? JSON.parse(query.env as string) : undefined;
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`Stdio transport: command=${command}, args=${args}, env=${JSON.stringify(env)}`,
|
`Stdio transport: command=${command}, args=${args}, env=${JSON.stringify(env)}`,
|
||||||
);
|
);
|
||||||
@@ -48,14 +49,18 @@ const createTransport = async (query: express.Request["query"]) => {
|
|||||||
env,
|
env,
|
||||||
stderr: "pipe",
|
stderr: "pipe",
|
||||||
});
|
});
|
||||||
|
|
||||||
await transport.start();
|
await transport.start();
|
||||||
|
|
||||||
console.log("Spawned stdio transport");
|
console.log("Spawned stdio transport");
|
||||||
return transport;
|
return transport;
|
||||||
} else if (transportType === "sse") {
|
} else if (transportType === "sse") {
|
||||||
const url = query.url as string;
|
const url = query.url as string;
|
||||||
console.log(`SSE transport: url=${url}`);
|
console.log(`SSE transport: url=${url}`);
|
||||||
|
|
||||||
const transport = new SSEClientTransport(new URL(url));
|
const transport = new SSEClientTransport(new URL(url));
|
||||||
await transport.start();
|
await transport.start();
|
||||||
|
|
||||||
console.log("Connected to SSE transport");
|
console.log("Connected to SSE transport");
|
||||||
return transport;
|
return transport;
|
||||||
} else {
|
} else {
|
||||||
@@ -99,6 +104,7 @@ app.get("/sse", async (req, res) => {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Set up MCP proxy");
|
console.log("Set up MCP proxy");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in /sse route:", error);
|
console.error("Error in /sse route:", error);
|
||||||
@@ -126,6 +132,7 @@ app.post("/message", async (req, res) => {
|
|||||||
app.get("/config", (req, res) => {
|
app.get("/config", (req, res) => {
|
||||||
try {
|
try {
|
||||||
const defaultEnvironment = getDefaultEnvironment();
|
const defaultEnvironment = getDefaultEnvironment();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
defaultEnvironment,
|
defaultEnvironment,
|
||||||
defaultCommand: values.env,
|
defaultCommand: values.env,
|
||||||
@@ -138,4 +145,4 @@ app.get("/config", (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
app.listen(PORT, () => { });
|
app.listen(PORT, () => {});
|
||||||
|
|||||||
Reference in New Issue
Block a user