Skip to content

Commit 9c58518

Browse files
committed
Update TypeScript bindings and examples with latest changes
1 parent 77fafe7 commit 9c58518

17 files changed

+2510
-60
lines changed

bindings/typescript/examples/clients/package-lock.json

Lines changed: 777 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "rmcp-typescript-example",
3+
"version": "1.0.0",
4+
"type": "commonjs",
5+
"scripts": {
6+
"start": "ts-node-esm src/sse.ts"
7+
},
8+
"dependencies": {
9+
"rmcp-typescript": "file:../.."
10+
},
11+
"devDependencies": {
12+
"@types/node": "^22.15.18",
13+
"ts-node": "^10.9.2",
14+
"tsx": "^4.19.4",
15+
"typescript": "^5.8.3"
16+
}
17+
}

bindings/typescript/examples/clients/src/sse.ts

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "CommonJS",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"strict": true,
8+
"skipLibCheck": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"resolveJsonModule": true,
11+
"isolatedModules": true,
12+
"noEmit": true,
13+
"allowJs": true,
14+
"types": ["node"]
15+
},
16+
"ts-node": {
17+
"esm": true,
18+
"experimentalSpecifierResolution": "node"
19+
}
20+
}

0 commit comments

Comments
 (0)