Skip to content

SDK Return Values

SDK code generated by MCP follows the return value conventions below. Understanding them helps you handle data correctly.

On success

SDK methods return the contents of the data field directly:

TypeScript
// API 完整响应: { success: true, data: { id: 123, name: "..." }, msg: "" }
// SDK 返回: { id: 123, name: "..." }
const result = await client.models.customer.create({ name: "张三" });
console.log(result.id); // 直接访问数据

On failure

The SDK throws a LovrabetError:

TypeScript
try {
  const result = await client.models.customer.create({ name: "" });
} catch (error) {
  if (error instanceof LovrabetError) {
    console.error("错误信息:", error.message);
    console.error("HTTP 状态码:", error.status);
    console.error("业务错误码:", error.code);
    console.error("完整响应:", error.data);
  }
}

SQL queries

SQL queries return a different structure — check the execution status:

TypeScript
const data = await client.api.executeSql("sql-code", { param1: "value" });

// 必须检查执行状态
if (!data.execSuccess) {
  throw new Error(data.execError || "SQL 执行失败");
}

// 获取结果
const results = data.execResult || [];

What's New in v1.2.0

Modernized Architecture

v1.2.0 delivers a major upgrade to the MCP SDK architecture:

  • McpServer API: Migrated from the deprecated Server API to the officially recommended McpServer API
  • Tool metadata: All 8 tools support title and annotations (readOnlyHint, destructiveHint, idempotentHint)
  • Full test coverage: 17 end-to-end automated test cases

Enhanced SDK Code Generation

A new aliasHint field provides smarter model access guidance:

TypeScript
aliasHint: {
  defaultAlias: "customer",           // 默认别名(camelCase 表名)
  datasetSDKKey: "dataset_customer",  // SDK key(需要 SDK >= 1.2.0)
  note: "检查 createClient 或 registerModels 中的自定义 alias",
  versionNote: "使用别名访问需要 @lovrabet/sdk >= 1.2.0"
}

Two Access Modes

ModeFormatDescription
Standardclient.models.dataset_[code].operation()Stable, no configuration needed
Aliasclient.models.[alias].operation()Human-friendly, requires SDK >= 1.2.0

Enriched Field Metadata

Field info now includes database type fields:

TypeScript
{
  name: "customer_id",
  type: "NUMBER",
  dbType: "BIGINT",        // 数据库类型
  dbTypeLen: 20,           // 类型长度
  autoIncrement: true,     // 自增标识
}

基于飞书知识库同步生成,内容以飞书源文档为准