MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / runClient

Function runClient

scripts/cli.ts:16–58  ·  view source on GitHub ↗
(url_or_command: string, args: string[])

Source from the content-addressed store, hash-verified

14import { ListResourcesResultSchema } from '../src/types.js';
15
16async function runClient(url_or_command: string, args: string[]) {
17 const client = new Client(
18 {
19 name: 'mcp-typescript test client',
20 version: '0.1.0'
21 },
22 {
23 capabilities: {
24 sampling: {}
25 }
26 }
27 );
28
29 let clientTransport;
30
31 let url: URL | undefined = undefined;
32 try {
33 url = new URL(url_or_command);
34 } catch {
35 // Ignore
36 }
37
38 if (url?.protocol === 'http:' || url?.protocol === 'https:') {
39 clientTransport = new SSEClientTransport(new URL(url_or_command));
40 } else if (url?.protocol === 'ws:' || url?.protocol === 'wss:') {
41 clientTransport = new WebSocketClientTransport(new URL(url_or_command));
42 } else {
43 clientTransport = new StdioClientTransport({
44 command: url_or_command,
45 args
46 });
47 }
48
49 console.log('Connected to server.');
50
51 await client.connect(clientTransport);
52 console.log('Initialized.');
53
54 await client.request({ method: 'resources/list' }, ListResourcesResultSchema);
55
56 await client.close();
57 console.log('Closed.');
58}
59
60async function runServer(port: number | null) {
61 if (port !== null) {

Callers 1

cli.tsFile · 0.85

Calls 2

connectMethod · 0.95
closeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…