MCPcopy
hub / github.com/vercel/next.js / callMcpTool

Function callMcpTool

test/development/mcp-server/mcp-server-telemetry.test.ts:13–37  ·  view source on GitHub ↗
(
    toolName: string,
    params: Record<string, any> = {}
  )

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 6

textMethod · 0.65
matchMethod · 0.65
fetchFunction · 0.50
stringifyMethod · 0.45
nowMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected