FAQ
MCP Server
TypeScript Client Integration

TypeScript Client Integration

Use the TypeScript client to connect to your MCP server.

Installation

To install the required package:

npm install @modelcontextprotocol/sdk

Or with pnpm:

pnpm add @modelcontextprotocol/sdk

Caution: Treat your MCP server URL like a password! It can be used to run tools attached to this server and access your data.

Usage Example

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

// Initialize the client with your details
const client = new Client(
  {
    name: "mcp-typescript-client",
    version: "1.0.0",
  },
  {
    capabilities: {},
  }
);

// Replace with your viaSocket MCP server URL
const serverUrl =
  "https://mcp.viasocket.com/****************/sse";
const transport = new SSEClientTransport(new URL(serverUrl));

async function main() {
  // Connect to the server
  console.log("Connecting to viaSocket MCP server...");
  await client.connect(transport);
  console.log("Connected to viaSocket MCP server");

  // List available tools
  console.log("Fetching available tools...");
  const tools = await client.listTools();

  console.log("Available tools:", tools);
  // Tools returned would look like:
  //   No custom tools available yet. Add tools via the MCP UI.

  // Add tools to the server when none are configured
  console.log('No tools configured. Adding a sample tool...');
  const result = await client.callTool({
    name: 'add_tools',
    arguments: {
      instructions: "Add a new tool to the server"
    },
  });
  console.log("Add tools result:\n", result);

  // Close the connection
  await client.transport?.close();
  await client.close();
}

main();

Notes:

  • Server URL: Replace serverUrl with your viaSocket MCP server URL.

  • Tools Fetching: The listTools() method fetches available tools from your MCP server. If no tools are configured, you can add them with the callTool() method.

This setup will connect to the viaSocket MCP server, list available tools, and allow you to add new tools to the server.