11// TypeScript SSE client example for rmcp_typescript
22// Closely mirrors the structure and flow of sse.rs from the core Rust SDK
33
4- import { JsTransport , JsTransportEnum , JsClientInfo , JsImplementation } from '../../index ' ;
4+ import { JsTransport , JsSseTransport , JsClientInfo , JsImplementation , JsClientCapabilities , JsExperimentalCapabilities , JsRootsCapabilities , JsClient } from 'rmcp-typescript ' ;
55
66// TODO: Replace 'any' with proper types from WASM/SDK when available
77// type ClientCapabilities = any;
@@ -13,52 +13,41 @@ async function main() {
1313
1414 // Step 2: Create transport
1515 const sseEndpoint = 'http://localhost:8000/sse' ;
16- const transport = new JsTransport ( JsTransportEnum . SSE , sseEndpoint ) ;
16+ const sseTransport = await JsSseTransport . start ( sseEndpoint ) ;
17+ console . log ( 'sseTransport:' , sseTransport ) ;
18+ const transport = JsTransport . fromSse ( sseTransport ) ;
19+ console . log ( 'transport:' , transport . kind ) ;
1720
1821 // Step 3: Define client info (mirror Rust structure)
19- const clientInfo : JsClientInfo = {
20- protocolVersion : '2024-11-05' , // TODO: Use ProtocolVersion.latest() if available
21- capabilities : { } , // TODO: Use proper ClientCapabilities
22- clientInfo : {
23- name : 'typescript-sse-client' ,
24- version : '0.0.1' ,
25- } ,
26- } ;
22+ const experimental = JsExperimentalCapabilities . new ( { } ) ;
23+ const roots = new JsRootsCapabilities ( ) ;
24+ const sampling = null ;
25+ console . log ( 'JsClientCapabilities.new args:' , { experimental, roots, sampling } ) ;
26+ const clientInfo = new JsClientInfo (
27+ '2024-11-05' ,
28+ new JsClientCapabilities ( experimental , roots , sampling ) ,
29+ new JsImplementation ( 'typescript-sse-client' , '0.0.1' )
30+ ) ;
2731
2832 try {
29- // Step 4: Connect and serve (stub for now)
30- transport . start (
31- ( data : string ) => {
32- console . log ( 'Received SSE message:' , data ) ;
33- // TODO: Parse and handle protocol messages here (initialize, tool list, etc.)
34- } ,
35- ( err : Event ) => {
36- console . error ( 'SSE error:' , err ) ;
37- }
38- ) ;
39-
40- // TODO: Replace with real async/await protocol flow when WASM/SDK methods are available
41- // Example (pseudo-code):
42- /*
43- const client = await clientInfo.serve(transport);
33+ // Step 4: Start the client and get peer info
34+ const clientObj = await clientInfo . serve ( transport ) ;
35+ const client = clientObj . inner as JsClient ;
4436 const serverInfo = client . peerInfo ( ) ;
4537 console . info ( 'Connected to server:' , serverInfo ) ;
4638
47- const tools = await client.listTools({});
39+ // Step 5: List available tools
40+ const tools = await client . listAllTools ( ) ;
4841 console . info ( 'Available tools:' , tools ) ;
4942
50- const toolResult = await client.callTool({
51- name: 'increment',
52- arguments: {},
53- });
54- console.info('Tool result:', toolResult);
43+ // Step 6: Call a tool (example)
44+
45+ const result = await client . callTool ( "increment" , { } ) ;
46+ console . info ( 'Tool result:' , result ) ;
5547
56- await client.cancel();
57- */
5848
59- // For now, keep connection open for demonstration
49+ // Keep connection open for demonstration
6050 setTimeout ( ( ) => {
61- transport . close ( ) ;
6251 console . info ( 'Connection closed.' ) ;
6352 } , 10000 ) ;
6453
0 commit comments