next
Version:
The React Framework
42 lines (41 loc) • 1.88 kB
JavaScript
import z from 'next/dist/compiled/zod';
import { getRequestInsightsSnapshot, isRequestInsightsEnabled } from '../../lib/trace/request-insights';
import { mcpTelemetryTracker } from '../mcp-telemetry-tracker';
export function registerGetRequestInsightsTool(server) {
server.registerTool('get_request_insights', {
description: 'Get recent App Router request insights captured by the local Next.js span recorder. Useful for debugging slow renders, server fetches, cache behavior, and request timelines without an external OTEL collector. Requires experimental.requestInsights.',
inputSchema: {
requestId: z.string().optional(),
htmlRequestId: z.string().optional()
}
}, async (request)=>{
mcpTelemetryTracker.recordToolCall('mcp/get_request_insights');
if (!isRequestInsightsEnabled()) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
error: 'Request Insights is not enabled. Set experimental.requestInsights = true in next.config.js and restart next dev.'
})
}
]
};
}
const snapshot = getRequestInsightsSnapshot();
const requests = snapshot.requests.filter((insight)=>{
return (request.requestId === undefined || insight.requestId === request.requestId) && (request.htmlRequestId === undefined || insight.htmlRequestId === request.htmlRequestId);
});
return {
content: [
{
type: 'text',
text: JSON.stringify({
requests
}, null, 2)
}
]
};
});
}
//# sourceMappingURL=get-request-insights.js.map