Rocky_Mountain_Vending/.pnpm-store/v10/files/21/67399af2a3a151567d08ce5e97345c3efdaa595cce4d3ce475ef9143f518e2965fd72d2cfbc39da50498e63853d531f2c837fdf0743ab4f8eba33a7dd70f34
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

39 lines
No EOL
1.5 KiB
Text

import { getOrCreateMcpServer } from './get-or-create-mcp-server';
import { parseBody } from '../api-utils/node/parse-body';
import { StreamableHTTPServerTransport } from 'next/dist/compiled/@modelcontextprotocol/sdk/server/streamableHttp';
export function getMcpMiddleware(options) {
return async function(req, res, next) {
const { pathname } = new URL(req.url || '', 'http://n');
if (!pathname.startsWith('/_next/mcp')) {
return next();
}
const mcpServer = getOrCreateMcpServer(options);
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: undefined
});
try {
res.on('close', ()=>{
transport.close();
});
await mcpServer.connect(transport);
const parsedBody = await parseBody(req, 1024 * 1024) // 1MB limit
;
await transport.handleRequest(req, res, parsedBody);
} catch (error) {
if (!res.headersSent) {
res.statusCode = 500;
res.setHeader('Content-Type', 'application/json; charset=utf-8');
res.end(JSON.stringify({
jsonrpc: '2.0',
error: {
code: -32000,
message: 'Internal server error'
},
id: null
}));
}
}
};
}
//# sourceMappingURL=get-mcp-middleware.js.map