@@ -11,9 +11,6 @@ const assert = require('node:assert')
1111const { removeModules } = require ( '../../lib/cache-buster' )
1212const helper = require ( '../../lib/agent_helper' )
1313const { assertPackageMetrics, assertSegments, assertSpanKind } = require ( '../../lib/custom-assertions' )
14- const { readFile } = require ( 'node:fs/promises' )
15- const path = require ( 'node:path' )
16-
1714const {
1815 MCP
1916} = require ( '../../../lib/metrics/names' )
@@ -28,18 +25,14 @@ test.beforeEach(async (ctx) => {
2825
2926 const { Client } = require ( '@modelcontextprotocol/sdk/client/index.js' )
3027 const { StreamableHTTPClientTransport } = require ( '@modelcontextprotocol/sdk/client/streamableHttp.js' )
31- const pkg = await readFile ( path . join ( __dirname , '/node_modules/@modelcontextprotocol/sdk/package.json' ) )
32- const { version : pkgVersion } = JSON . parse ( pkg . toString ( ) )
33- ctx . nr . pkgVersion = pkgVersion
34-
3528 // Set up server
3629 const McpTestServer = require ( './streaming-server' )
3730 ctx . nr . mcpServer = new McpTestServer ( )
38- await ctx . nr . mcpServer . start ( )
31+ const port = await ctx . nr . mcpServer . start ( )
3932
4033 // Set up client
4134 ctx . nr . transport = new StreamableHTTPClientTransport (
42- new URL ( ' http://localhost:3000 /mcp' )
35+ new URL ( ` http://localhost:${ port } /mcp` )
4336 )
4437 ctx . nr . client = new Client (
4538 {
@@ -51,18 +44,24 @@ test.beforeEach(async (ctx) => {
5144} )
5245
5346test . afterEach ( async ( ctx ) => {
47+ await ctx . nr . client . close ( )
48+ await ctx . nr . transport . close ( )
5449 await ctx . nr . mcpServer . stop ( )
55- ctx . nr . client . close ( )
5650 helper . unloadAgent ( ctx . nr . agent )
5751 removeModules ( [
5852 '@modelcontextprotocol/sdk/client/index.js' ,
59- '@modelcontextprotocol/sdk/client/streamableHttp.js' ,
60- './streaming-server.js'
53+ '@modelcontextprotocol/sdk/client/streamableHttp.js'
6154 ] )
6255} )
6356
57+ test ( 'should log package tracking metrics' , ( t ) => {
58+ const { agent } = t . nr
59+ const version = helper . readPackageVersion ( __dirname , '@modelcontextprotocol/sdk' )
60+ assertPackageMetrics ( { agent, pkg : '@modelcontextprotocol/sdk' , version } )
61+ } )
62+
6463test ( 'should create span for callTool' , ( t , end ) => {
65- const { agent, client, pkgVersion } = t . nr
64+ const { agent, client } = t . nr
6665 helper . runInTransaction ( agent , async ( tx ) => {
6766 const result = await client . callTool ( {
6867 name : 'echo' ,
@@ -80,14 +79,13 @@ test('should create span for callTool', (t, end) => {
8079 { name, kind : 'internal' }
8180 ]
8281 } )
83- assertPackageMetrics ( { agent, pkg : '@modelcontextprotocol/sdk' , version : pkgVersion } )
8482
8583 end ( )
8684 } )
8785} )
8886
8987test ( 'should create span for readResource' , ( t , end ) => {
90- const { agent, client, pkgVersion } = t . nr
88+ const { agent, client } = t . nr
9189 helper . runInTransaction ( agent , async ( tx ) => {
9290 const resource = await client . readResource ( {
9391 uri : 'echo://hello-world' ,
@@ -106,14 +104,12 @@ test('should create span for readResource', (t, end) => {
106104 ]
107105 } )
108106
109- assertPackageMetrics ( { agent, pkg : '@modelcontextprotocol/sdk' , version : pkgVersion } )
110-
111107 end ( )
112108 } )
113109} )
114110
115111test ( 'should create span for getPrompt' , ( t , end ) => {
116- const { agent, client, pkgVersion } = t . nr
112+ const { agent, client } = t . nr
117113 helper . runInTransaction ( agent , async ( tx ) => {
118114 const prompt = await client . getPrompt ( {
119115 name : 'echo' ,
@@ -135,8 +131,6 @@ test('should create span for getPrompt', (t, end) => {
135131 ]
136132 } )
137133
138- assertPackageMetrics ( { agent, pkg : '@modelcontextprotocol/sdk' , version : pkgVersion } )
139-
140134 end ( )
141135 } )
142136} )
0 commit comments