Skip to content

Commit 8984639

Browse files
betegonclaude
andcommitted
test(e2e): add e2e test coverage for registerTool instrumentation
Call echo-register tool in SSE transport tests across node-express, node-express-v5, and tsx-express, verifying that tools/call transactions are recorded for handlers registered via registerTool. Co-Authored-By: claude-sonnet-4-6 <noreply@anthropic.com>
1 parent be87373 commit 8984639

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

dev-packages/e2e-tests/test-applications/node-express-v5/tests/mcp.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,38 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
6060
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
6161
});
6262

63+
await test.step('registerTool handler', async () => {
64+
const postTransactionPromise = waitForTransaction('node-express-v5', transactionEvent => {
65+
return transactionEvent.transaction === 'POST /messages';
66+
});
67+
const toolTransactionPromise = waitForTransaction('node-express-v5', transactionEvent => {
68+
return transactionEvent.transaction === 'tools/call echo-register';
69+
});
70+
71+
const toolResult = await client.callTool({
72+
name: 'echo-register',
73+
arguments: {
74+
message: 'foobar',
75+
},
76+
});
77+
78+
expect(toolResult).toMatchObject({
79+
content: [
80+
{
81+
text: 'registerTool echo: foobar',
82+
type: 'text',
83+
},
84+
],
85+
});
86+
87+
const postTransaction = await postTransactionPromise;
88+
expect(postTransaction).toBeDefined();
89+
90+
const toolTransaction = await toolTransactionPromise;
91+
expect(toolTransaction).toBeDefined();
92+
expect(toolTransaction.contexts?.trace?.data?.['mcp.tool.name']).toEqual('echo-register');
93+
});
94+
6395
await test.step('resource handler', async () => {
6496
const postTransactionPromise = waitForTransaction('node-express-v5', transactionEvent => {
6597
return transactionEvent.transaction === 'POST /messages';

dev-packages/e2e-tests/test-applications/node-express/tests/mcp.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,41 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
6262
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
6363
});
6464

65+
await test.step('registerTool handler', async () => {
66+
const postTransactionPromise = waitForTransaction('node-express', transactionEvent => {
67+
return transactionEvent.transaction === 'POST /messages';
68+
});
69+
const toolTransactionPromise = waitForTransaction('node-express', transactionEvent => {
70+
return transactionEvent.transaction === 'tools/call echo-register';
71+
});
72+
73+
const toolResult = await client.callTool({
74+
name: 'echo-register',
75+
arguments: {
76+
message: 'foobar',
77+
},
78+
});
79+
80+
expect(toolResult).toMatchObject({
81+
content: [
82+
{
83+
text: 'registerTool echo: foobar',
84+
type: 'text',
85+
},
86+
],
87+
});
88+
89+
const postTransaction = await postTransactionPromise;
90+
expect(postTransaction).toBeDefined();
91+
expect(postTransaction.contexts?.trace?.op).toEqual('http.server');
92+
93+
const toolTransaction = await toolTransactionPromise;
94+
expect(toolTransaction).toBeDefined();
95+
expect(toolTransaction.contexts?.trace?.op).toEqual('mcp.server');
96+
expect(toolTransaction.contexts?.trace?.data?.['mcp.method.name']).toEqual('tools/call');
97+
expect(toolTransaction.contexts?.trace?.data?.['mcp.tool.name']).toEqual('echo-register');
98+
});
99+
65100
await test.step('resource handler', async () => {
66101
const postTransactionPromise = waitForTransaction('node-express', transactionEvent => {
67102
return transactionEvent.transaction === 'POST /messages';

dev-packages/e2e-tests/test-applications/tsx-express/tests/mcp.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,40 @@ test('Records transactions for mcp handlers', async ({ baseURL }) => {
6363
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
6464
});
6565

66+
await test.step('registerTool handler', async () => {
67+
const postTransactionPromise = waitForTransaction('tsx-express', transactionEvent => {
68+
return transactionEvent.transaction === 'POST /messages';
69+
});
70+
const toolTransactionPromise = waitForTransaction('tsx-express', transactionEvent => {
71+
return transactionEvent.transaction === 'tools/call echo-register';
72+
});
73+
74+
const toolResult = await client.callTool({
75+
name: 'echo-register',
76+
arguments: {
77+
message: 'foobar',
78+
},
79+
});
80+
81+
expect(toolResult).toMatchObject({
82+
content: [
83+
{
84+
text: 'registerTool echo: foobar',
85+
type: 'text',
86+
},
87+
],
88+
});
89+
90+
const postTransaction = await postTransactionPromise;
91+
expect(postTransaction).toBeDefined();
92+
93+
const toolTransaction = await toolTransactionPromise;
94+
expect(toolTransaction).toBeDefined();
95+
expect(toolTransaction.contexts?.trace?.op).toEqual('mcp.server');
96+
expect(toolTransaction.contexts?.trace?.data?.['mcp.method.name']).toEqual('tools/call');
97+
expect(toolTransaction.contexts?.trace?.data?.['mcp.tool.name']).toEqual('echo-register');
98+
});
99+
66100
await test.step('resource handler', async () => {
67101
const postTransactionPromise = waitForTransaction('tsx-express', transactionEvent => {
68102
return transactionEvent.transaction === 'POST /messages';

0 commit comments

Comments
 (0)