add very simple test client
This commit is contained in:
parent
b7709c07ed
commit
fb3482530d
3 changed files with 995 additions and 14 deletions
47
examples/clients/typescript/test1.ts
Normal file
47
examples/clients/typescript/test1.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||||
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
const serverUrl = process.argv[2];
|
||||||
|
|
||||||
|
if (!serverUrl) {
|
||||||
|
console.error('Usage: test-client <server-url>');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Connecting to MCP server at: ${serverUrl}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const client = new Client({
|
||||||
|
name: 'test-client',
|
||||||
|
version: '1.0.0'
|
||||||
|
}, {
|
||||||
|
capabilities: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const transport = new StreamableHTTPClientTransport(
|
||||||
|
new URL(serverUrl)
|
||||||
|
);
|
||||||
|
|
||||||
|
await client.connect(transport);
|
||||||
|
console.log('✅ Successfully connected to MCP server');
|
||||||
|
|
||||||
|
await client.listTools();
|
||||||
|
console.log('✅ Successfully listed tools');
|
||||||
|
|
||||||
|
await transport.close();
|
||||||
|
console.log('✅ Connection closed successfully');
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Failed to connect to MCP server:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((error) => {
|
||||||
|
console.error('Unhandled error:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
959
package-lock.json
generated
959
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -13,5 +13,8 @@
|
||||||
"ts-jest": "^29.1.1",
|
"ts-jest": "^29.1.1",
|
||||||
"tsx": "^4.7.0",
|
"tsx": "^4.7.0",
|
||||||
"typescript": "^5.3.0"
|
"typescript": "^5.3.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@modelcontextprotocol/sdk": "^1.20.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue