使用说明
@skyflow/mcp-sdk
MCP(模型上下文协议)应用程序的简单PII/PHI去标识。
此SDK封装了 Skyflow 去标识API提供了一个易于使用的界面,用于保护AI/LLM应用程序中的敏感数据。
安装
npm install @skyflow/mcp-sdk
# or
pnpm add @skyflow/mcp-sdk
快速开始
import { SkyflowMCP } from '@skyflow/mcp-sdk';
// Initialize the client
const client = new SkyflowMCP({
vaultId: 'your-vault-id',
vaultUrl: 'https://abc123.vault.skyflowapis.com',
credentials: { token: 'your-bearer-token' },
});
// Deidentify sensitive data
const { processedText } = await client.deidentify("My email is john@example.com");
// processedText: "My email is [EMAIL_ADDRESS_abc123]"
// Restore original data
const { processedText: restored } = await client.reidentify(processedText);
// restored: "My email is john@example.com"
常见用例
包裹API调用
在发送到外部API之前保护敏感数据:
const result = await client.wrap(
"My SSN is 123-45-6789",
async (protectedText) => {
const response = await fetch('https://api.example.com/process', {
method: 'POST',
body: JSON.stringify({ text: protectedText }),
});
return response.json().then(r => r.output);
}
);
// Result is automatically reidentified with original SSN
数据库操作
存储受保护的数据,使用原始值检索:
// Before saving to database
const { processedText: protectedEmail } = await client.deidentify(userEmail);
await db.users.create({ email: protectedEmail });
// When retrieving from database
const user = await db.users.findById(userId);
const { processedText: originalEmail } = await client.reidentify(user.email);
MCP服务器集成
将预构建的Skyflow工具添加到您的MCP服务器:
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { registerSkyflowTools } from '@skyflow/mcp-sdk/mcp';
const server = new McpServer({ name: 'my-server', version: '1.0.0' });
await registerSkyflowTools(server, {
vaultId: 'vault-id',
vaultUrl: 'https://abc123.vault.skyflowapis.com',
credentials: { token: 'bearer-token' },
});
// Server now has 'deidentify' and 'reidentify' tools available
配置
必需参数
| 参数 | 说明 |
|---|---|
vaultId |
您的Skyflow保险库标识符 |
vaultUrl |
保险库URL(例如。, https://abc123.vault.skyflowapis.com) |
credentials |
要么 { token: 'bearer-token' } 或 { apiKey: 'api-key' } |
可选参数
| 参数 | 说明 |
|---|---|
accountId |
skyflow帐户ID |
workspaceId |
Skyflow工作区ID |
options.defaultTokenType |
默认令牌格式: 'VAULT_TOKEN', 'ENTITY_UNIQUE_COUNTER',或 'ENTITY_ONLY' |
options.defaultEntities |
要检测的默认实体类型(例如。, ['email_address', 'ssn']) |
环境变量
使用 createFromEnv() 从环境进行配置:
import { createFromEnv } from '@skyflow/mcp-sdk';
// Reads from:
// - SKYFLOW_VAULT_ID
// - SKYFLOW_VAULT_URL
// - SKYFLOW_BEARER_TOKEN or SKYFLOW_API_KEY
// - SKYFLOW_ACCOUNT_ID (optional)
// - SKYFLOW_WORKSPACE_ID (optional)
const client = createFromEnv();
API 参考
SkyflowMCP
主要客户类别。
deidentify(text, options?)
用保管库令牌替换敏感数据。
const result = await client.deidentify("Contact me at john@example.com", {
tokenType: 'VAULT_TOKEN', // optional
entities: ['email_address', 'phone_number'], // optional
});
// Result:
// {
// processedText: "Contact me at [EMAIL_ADDRESS_abc123]",
// entities: [...],
// wordCount: 4,
// charCount: 35
// }
reidentify(text)
将vault令牌还原为原始值。
const result = await client.reidentify("Contact me at [EMAIL_ADDRESS_abc123]");
// Result: { processedText: "Contact me at john@example.com" }
wrap(input, operation, options?)
神化的便捷方法→ 操作→ 重新识别模式。
const result = await client.wrap(
inputText,
async (protectedText) => callExternalAPI(protectedText),
{ reidentifyOutput: true } // default
);
错误处理
import { DeidentifyError, ReidentifyError, ConfigurationError } from '@skyflow/mcp-sdk';
try {
await client.deidentify(text);
} catch (error) {
if (error instanceof DeidentifyError) {
console.error('Deidentify failed:', error.message);
console.error('HTTP code:', error.httpCode);
console.error('Details:', error.details);
}
}
支持的实体类型
SDK支持67种实体类型,包括:
- 个人的:
name,email_address,phone_number,ssn,dob - 财务:
credit_card,bank_account,cvv,routing_number - 医疗:
medical_code,drug,condition,blood_type - 地点:
location,location_address,location_city,location_country - 身份:
driver_license,passport_number,healthcare_number
看 ENTITY_TYPES 导出完整列表。
需求
- Node.js>=18.0.0
- 启用了身份识别的Skyflow保险库
许可证
麻省理工学院