iniciada creacion del mcp
All checks were successful
Deploy conversation layer / deploy (push) Successful in 6s
All checks were successful
Deploy conversation layer / deploy (push) Successful in 6s
This commit is contained in:
70
mcp/index.js
Normal file
70
mcp/index.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
||||
import express from "express";
|
||||
import { createServer } from "./createServer.js";
|
||||
|
||||
console.log('este no tiene variables de entorno, es un servidor MCP Planilla');
|
||||
|
||||
|
||||
async function main() {
|
||||
const useStdio = process.argv.includes("--stdio");
|
||||
if (useStdio) {
|
||||
// bootLog("Modo transporte: stdio");
|
||||
const server = createServer();
|
||||
const transport = new StdioServerTransport();
|
||||
await server.connect(transport);
|
||||
console.log("MCP Planilla server listo (stdio)");
|
||||
} else {
|
||||
// bootLog("Modo transporte: HTTP streamable");
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
app.use((req, _res, next) => {
|
||||
console.log(`[HTTP] ${req.method} ${req.originalUrl} ${req.statusCode} ${req.res.body}`);
|
||||
next();
|
||||
});
|
||||
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
app.post("/mcp", async (req, res) => {
|
||||
try {
|
||||
const server = createServer();
|
||||
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
||||
res.on("close", () => {
|
||||
transport.close();
|
||||
server.close();
|
||||
});
|
||||
await server.connect(transport);
|
||||
await transport.handleRequest(req, res, req.body);
|
||||
} catch (error) {
|
||||
console.error("Error handling MCP request:", error);
|
||||
if (!res.headersSent) {
|
||||
res.status(500).json({
|
||||
jsonrpc: "2.0",
|
||||
error: { code: -32603, message: "Internal server error" },
|
||||
id: null,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
["get", "delete"].forEach((m) =>
|
||||
app[m]("/mcp", (_req, res) =>
|
||||
res.status(405).json({
|
||||
jsonrpc: "2.0",
|
||||
error: { code: -32000, message: "Method not allowed." },
|
||||
id: null,
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`MCP Planilla HTTP server listening on port ${port}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error("Error fatal en MCP server:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user