UNPKG

@thorium-dev-group/x402-mcp-extension

Version:
70 lines • 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testClientServerCommunication = testClientServerCommunication; const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js"); const X402MCPClient_1 = require("../../client/X402MCPClient"); const x402PKWalletProvider_1 = require("../../client/x402PKWalletProvider"); const accounts_1 = require("viem/accounts"); const InMemoryStorage_1 = require("../../shared/services/InMemoryStorage"); async function testClientServerCommunication() { console.log('šŸš€ Starting X402 MCP Client Test'); const privateKey = (0, accounts_1.generatePrivateKey)(); const viemWalletProvider = new x402PKWalletProvider_1.X402PKWalletProvider(privateKey); const client = new X402MCPClient_1.X402MCPClient({ name: 'test-x402-client', version: '1.0.0', wallet: viemWalletProvider, auditStorage: InMemoryStorage_1.InMemoryStorage.getInstance(), guardrails: { maxPaymentPerCall: 0.001, }, }); const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp')); await client.connect(transport); console.log('āœ… Client connected to server'); console.log('āœ… Session ID:', transport.sessionId); try { console.log('\nšŸ“‹ Test 1: Free calculator (no payment required)'); const freeResult = await client.callTool({ name: 'free-calculator', arguments: { operation: 'add', a: 5, b: 3 } }); console.log('āœ… Free calculator result:', freeResult); console.log('\nšŸ“‹ Test 2: Paid calculator (payment required)'); try { const paidResult = await client.callTool({ name: 'add-numbers', arguments: { a: 10, b: 20 } }); console.log('āœ… Paid calculator result:', paidResult); } catch (error) { console.log('āŒ Expected payment error:', error.message); } console.log('\nšŸ“‹ Test 3: Multiply numbers (higher payment)'); try { const multiplyResult = await client.callTool({ name: 'multiply-numbers', arguments: { a: 7, b: 8 } }); console.log('āœ… Multiply result:', multiplyResult); } catch (error) { console.log('āŒ Expected payment error:', error.message); } console.log('\nšŸ“‹ Test 4: List available tools'); const toolsResult = await client.listTools({}); console.log('āœ… Available tools:', JSON.stringify(toolsResult, null, 2)); } catch (error) { console.error('āŒ Test failed:', error); } finally { await transport.close(); console.log('āœ… Client disconnected'); } } if (require.main === module) { testClientServerCommunication().catch(console.error); } //# sourceMappingURL=client.js.map