@@ -49,6 +49,21 @@ function expectResponseErrorMessage(
4949 expect ( responseBody . error ) . to . include ( messageFragment ) ;
5050}
5151
52+ type ToolCallParams = {
53+ name : string ;
54+ arguments ?: Record < string , unknown > ;
55+ } ;
56+
57+ const MCP_TOOL_AUTH = {
58+ authInfo : {
59+ scopes : [ "epcis.read" , "epcis.write" ] ,
60+ } ,
61+ } as const ;
62+
63+ function callToolWithAuth ( client : Client , params : ToolCallParams ) {
64+ return client . callTool ( params , undefined , MCP_TOOL_AUTH as any ) ;
65+ }
66+
5267describe ( "@dkg/plugin-epcis checks" , function ( ) {
5368 let mockMcpServer : McpServer ;
5469 let mockMcpClient : Client ;
@@ -311,7 +326,7 @@ describe("@dkg/plugin-epcis checks", function () {
311326 describe ( "MCP Tools" , ( ) => {
312327 it ( "epcis-query returns assembly event results" , async ( ) => {
313328 dkgQueryStub . resolves ( makeDkgQueryResult ( ASSEMBLY_EVENTS ) ) ;
314- const result = await mockMcpClient . callTool ( {
329+ const result = await callToolWithAuth ( mockMcpClient , {
315330 name : "epcis-query" ,
316331 arguments : { bizStep : "assembling" } ,
317332 } ) ;
@@ -325,7 +340,7 @@ describe("@dkg/plugin-epcis checks", function () {
325340
326341 it ( "epcis-track-item returns journey timeline with numbered steps" , async ( ) => {
327342 dkgQueryStub . resolves ( makeDkgQueryResult ( BICYCLE_TRACE_EVENTS ) ) ;
328- const result = await mockMcpClient . callTool ( {
343+ const result = await callToolWithAuth ( mockMcpClient , {
329344 name : "epcis-track-item" ,
330345 arguments : { epc : bicycleEpc } ,
331346 } ) ;
@@ -345,7 +360,7 @@ describe("@dkg/plugin-epcis checks", function () {
345360
346361 it ( "epcis-capture captures valid document and returns capture details" , async ( ) => {
347362 fetchStub . resolves ( publisherQueuedResponse ( 501 ) ) ;
348- const result = await mockMcpClient . callTool ( {
363+ const result = await callToolWithAuth ( mockMcpClient , {
349364 name : "epcis-capture" ,
350365 arguments : event1 ,
351366 } ) ;
@@ -359,7 +374,7 @@ describe("@dkg/plugin-epcis checks", function () {
359374 } ) ;
360375
361376 it ( "epcis-capture returns validation error for invalid document" , async ( ) => {
362- const result = await mockMcpClient . callTool ( {
377+ const result = await callToolWithAuth ( mockMcpClient , {
363378 name : "epcis-capture" ,
364379 arguments : { epcisDocument : { type : "NotAnEPCIS" } } ,
365380 } ) ;
@@ -372,7 +387,7 @@ describe("@dkg/plugin-epcis checks", function () {
372387 it ( "epcis-capture returns publisher error when publisher is unavailable" , async function ( ) {
373388 this . timeout ( 15000 ) ;
374389 fetchStub . rejects ( new Error ( "publisher down" ) ) ;
375- const result = await mockMcpClient . callTool ( {
390+ const result = await callToolWithAuth ( mockMcpClient , {
376391 name : "epcis-capture" ,
377392 arguments : event1 ,
378393 } ) ;
@@ -391,7 +406,7 @@ describe("@dkg/plugin-epcis checks", function () {
391406 "2024-03-01T16:30:00.000Z" ,
392407 ) ,
393408 ) ;
394- const result = await mockMcpClient . callTool ( {
409+ const result = await callToolWithAuth ( mockMcpClient , {
395410 name : "epcis-capture-status" ,
396411 arguments : { captureID : "123" } ,
397412 } ) ;
@@ -405,7 +420,7 @@ describe("@dkg/plugin-epcis checks", function () {
405420
406421 it ( "epcis-capture-status returns error when capture is not found" , async ( ) => {
407422 fetchStub . resolves ( jsonResponse ( { error : "not found" } , 404 ) ) ;
408- const result = await mockMcpClient . callTool ( {
423+ const result = await callToolWithAuth ( mockMcpClient , {
409424 name : "epcis-capture-status" ,
410425 arguments : { captureID : "404" } ,
411426 } ) ;
@@ -418,7 +433,7 @@ describe("@dkg/plugin-epcis checks", function () {
418433
419434 it ( "epcis-capture-status returns timeout error on publisher timeout" , async ( ) => {
420435 fetchStub . rejects ( new DOMException ( "Timed out" , "TimeoutError" ) ) ;
421- const result = await mockMcpClient . callTool ( {
436+ const result = await callToolWithAuth ( mockMcpClient , {
422437 name : "epcis-capture-status" ,
423438 arguments : { captureID : "888" } ,
424439 } ) ;
@@ -434,7 +449,7 @@ describe("@dkg/plugin-epcis checks", function () {
434449 it ( "returns the same query event data for epcis-query and GET /epcis/events" , async ( ) => {
435450 dkgQueryStub . resolves ( makeDkgQueryResult ( ASSEMBLY_EVENTS ) ) ;
436451
437- const mcpResult = await mockMcpClient . callTool ( {
452+ const mcpResult = await callToolWithAuth ( mockMcpClient , {
438453 name : "epcis-query" ,
439454 arguments : { bizStep : "assembling" } ,
440455 } ) ;
@@ -453,7 +468,7 @@ describe("@dkg/plugin-epcis checks", function () {
453468 fetchStub . onFirstCall ( ) . resolves ( publisherQueuedResponse ( 777 ) ) ;
454469 fetchStub . onSecondCall ( ) . resolves ( publisherQueuedResponse ( 777 ) ) ;
455470
456- const mcpResult = await mockMcpClient . callTool ( {
471+ const mcpResult = await callToolWithAuth ( mockMcpClient , {
457472 name : "epcis-capture" ,
458473 arguments : event1 ,
459474 } ) ;
@@ -535,7 +550,7 @@ describe("@dkg/plugin-epcis checks", function () {
535550 } ) ;
536551
537552 it ( "returns MCP error when epcis-query has no filters" , async ( ) => {
538- const result = await mockMcpClient . callTool ( {
553+ const result = await callToolWithAuth ( mockMcpClient , {
539554 name : "epcis-query" ,
540555 arguments : { } ,
541556 } ) ;
@@ -549,7 +564,7 @@ describe("@dkg/plugin-epcis checks", function () {
549564
550565 it ( "returns MCP error when DKG query fails" , async ( ) => {
551566 dkgQueryStub . rejects ( new Error ( "query exploded" ) ) ;
552- const result = await mockMcpClient . callTool ( {
567+ const result = await callToolWithAuth ( mockMcpClient , {
553568 name : "epcis-query" ,
554569 arguments : { bizStep : "receiving" } ,
555570 } ) ;
0 commit comments