Skip to main content

Invocation via SDK

Install dependencies:

npm i @cloudbase/mcp @modelcontextprotocol/sdk

Go to Cloud Development Platform to get API KEY.

Connect to the MCP Server based on its Transport type:

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const transport = new StreamableHTTPClientTransport(
// Replace "your-env-id" in the link with your CloudBase environment id
// Replace "your-service-name" in the link with your Cloud Hosting service name
new URL(
"https://your-env-id.api.tcloudbasegateway.com/v1/cloudrun/your-service-name/messages"
),
{
requestInit: {
headers: {
// Replace "your-api-key" with your actual API KEY
Authorization: `Bearer your-api-key`,
},
},
}
);

const client = new Client(
{
name: "your-mcp-name",
version: "1.0.0",
},
{
capabilities: {
tools: {},
},
}
);

await client.connect(transport);

Retrieve the tool list from MCP Server:

const prompts = await client.listTools();

Initiate tool invocation:

const result = await client.callTool({
name: "example-tool",
arguments: {
arg1: "value",
},
});