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:
- Streamable HTTP
- SSE
- POST
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);
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
const transport = new SSEClientTransport(
// 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`,
}
},
eventSourceInit: {
fetch: (url, init) => {
return fetch(url, {
...(init || {}),
headers: {
...(init?.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);
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { PostClientTransport } from "@cloudbase/mcp/transport/client/post";
const transport = new PostClientTransport(
// 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",
},
});