@perfecxion/secure-mcp-client
v1.0.0
Published
Client SDK for Secure MCP Server
Maintainers
Readme
Secure MCP Client SDK
Official client SDK for the Secure MCP Server.
Installation
npm install @perfecxion/secure-mcp-clientQuick Start
import { SecureMCPClient } from '@perfecxion/secure-mcp-client';
// Initialize client
const client = new SecureMCPClient({
serverUrl: 'https://mcp.example.com',
apiKey: 'your-api-key',
debug: true
});
// Connect via WebSocket
await client.connect();
// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools);
// Execute a tool
const result = await client.executeTool('search', {
query: 'machine learning papers'
});
// Subscribe to events
client.subscribe('notification', (data) => {
console.log('Notification:', data);
});
// Disconnect when done
client.disconnect();Features
- ✅ WebSocket and HTTP transport
- ✅ Automatic reconnection
- ✅ JWT and API key authentication
- ✅ Event subscription
- ✅ TypeScript support
- ✅ Promise-based API
- ✅ Request queuing
API Reference
Constructor
new SecureMCPClient(config: MCPClientConfig)Config Options:
serverUrl: MCP server URL (required)apiKey: API key for authenticationjwt: JWT token for authenticationtimeout: Request timeout in ms (default: 30000)reconnectionAttempts: Max reconnection attempts (default: 5)debug: Enable debug logging (default: false)
Methods
connect()
Connect to the MCP server via WebSocket.
await client.connect();disconnect()
Disconnect from the MCP server.
client.disconnect();request(method, params)
Send a generic request to the MCP server.
const response = await client.request('custom/method', { data: 'value' });listTools()
Get list of available tools.
const tools = await client.listTools();executeTool(name, params)
Execute a specific tool.
const result = await client.executeTool('search', { query: 'test' });listResources()
Get list of available resources.
const resources = await client.listResources();readResource(uri)
Read a specific resource.
const content = await client.readResource('file:///path/to/resource');complete(prompt, options)
Send a completion request.
const response = await client.complete('Generate a summary of...', {
temperature: 0.7,
maxTokens: 1000
});subscribe(event, handler)
Subscribe to server events.
client.subscribe('update', (data) => {
console.log('Update received:', data);
});Events
connected: Fired when connected to serverdisconnected: Fired when disconnected from servererror: Fired on connection or request errormessage: Fired for all incoming messages
Authentication
API Key
const client = new SecureMCPClient({
serverUrl: 'https://mcp.example.com',
apiKey: 'your-api-key'
});JWT Token
const client = new SecureMCPClient({
serverUrl: 'https://mcp.example.com',
jwt: 'your-jwt-token'
});Error Handling
try {
await client.connect();
const result = await client.executeTool('tool', {});
} catch (error) {
console.error('MCP Error:', error.message);
}License
Apache-2.0
