| 11 | }) |
| 12 | |
| 13 | async function callMcpTool( |
| 14 | toolName: string, |
| 15 | params: Record<string, any> = {} |
| 16 | ) { |
| 17 | const response = await fetch(`${next.url}/_next/mcp`, { |
| 18 | method: 'POST', |
| 19 | headers: { |
| 20 | 'Content-Type': 'application/json', |
| 21 | Accept: 'application/json, text/event-stream', |
| 22 | }, |
| 23 | body: JSON.stringify({ |
| 24 | jsonrpc: '2.0', |
| 25 | id: `telemetry-test-${Date.now()}`, |
| 26 | method: 'tools/call', |
| 27 | params: { name: toolName, arguments: params }, |
| 28 | }), |
| 29 | }) |
| 30 | |
| 31 | const text = await response.text() |
| 32 | const match = text.match(/data: ({.*})/s) |
| 33 | if (!match) { |
| 34 | throw new Error(`Failed to parse response for tool ${toolName}`) |
| 35 | } |
| 36 | return JSON.parse(match[1]) |
| 37 | } |
| 38 | |
| 39 | it('should record MCP tool usage telemetry on server shutdown', async () => { |
| 40 | // Call different MCP tools |