@@ -15,7 +15,9 @@ import {
1515 LoggingMessageNotificationSchema ,
1616 type Notification ,
1717 ReadResourceResultSchema ,
18- type TextContent
18+ type TextContent ,
19+ UrlElicitationRequiredError ,
20+ ErrorCode
1921} from '../types.js' ;
2022import { completable } from './completable.js' ;
2123import { McpServer , ResourceTemplate } from './mcp.js' ;
@@ -1618,6 +1620,60 @@ describe('tool()', () => {
16181620 ) ;
16191621 } ) ;
16201622
1623+ /***
1624+ * Test: URL Elicitation Required Error Propagation
1625+ */
1626+ test ( 'should propagate UrlElicitationRequiredError to client callers' , async ( ) => {
1627+ const mcpServer = new McpServer ( {
1628+ name : 'test server' ,
1629+ version : '1.0'
1630+ } ) ;
1631+
1632+ const client = new Client (
1633+ {
1634+ name : 'test client' ,
1635+ version : '1.0'
1636+ } ,
1637+ {
1638+ capabilities : {
1639+ elicitation : {
1640+ url : { }
1641+ }
1642+ }
1643+ }
1644+ ) ;
1645+
1646+ const elicitationParams = {
1647+ mode : 'url' as const ,
1648+ elicitationId : 'elicitation-123' ,
1649+ url : 'https://mcp.example.com/connect' ,
1650+ message : 'Authorization required'
1651+ } ;
1652+
1653+ mcpServer . tool ( 'needs-authorization' , async ( ) => {
1654+ throw new UrlElicitationRequiredError ( [ elicitationParams ] , 'Confirmation required' ) ;
1655+ } ) ;
1656+
1657+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
1658+
1659+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
1660+
1661+ await client
1662+ . callTool ( {
1663+ name : 'needs-authorization'
1664+ } )
1665+ . then ( ( ) => {
1666+ throw new Error ( 'Expected callTool to throw UrlElicitationRequiredError' ) ;
1667+ } )
1668+ . catch ( error => {
1669+ expect ( error ) . toBeInstanceOf ( UrlElicitationRequiredError ) ;
1670+ if ( error instanceof UrlElicitationRequiredError ) {
1671+ expect ( error . code ) . toBe ( ErrorCode . UrlElicitationRequired ) ;
1672+ expect ( error . elicitations ) . toEqual ( [ elicitationParams ] ) ;
1673+ }
1674+ } ) ;
1675+ } ) ;
1676+
16211677 /***
16221678 * Test: Tool Registration with _meta field
16231679 */
0 commit comments