雪松-政策- mcp-schema-生成器-wasm
WASM 绑定 雪松政策- mcp-schema-生成器,显示 SchemaGenerator 到 Java 脚本和 TypeScript 通过 wasm-bindgen。 。 。 .
这使得Node.js和浏览器环境能够从 MCP 工具描述中生成 Cedar 授权计划 完全一样的行为 包括正确处理:
- 贾森
number作为Long或者说Decimal(可配置) additionalProperties作为锡达标记的实体- 嵌入对象的空格类型分解
使用量
安装 npm 包 :
npm install @cedar-policy/mcp-schema-generator-wasm
const { generateSchema } = require('@cedar-policy/mcp-schema-generator-wasm');
const stub = `
namespace MyServer {
@mcp_principal
entity User;
@mcp_resource
entity McpServer;
action "call_tool" appliesTo {
principal: [User],
resource: [McpServer]
};
}
`;
const tools = JSON.stringify([
{
name: 'read_file',
description: 'Read a file from disk',
inputSchema: {
type: 'object',
properties: { path: { type: 'string' } },
required: ['path'],
},
},
]);
const result = JSON.parse(generateSchema(stub, tools));
if (result.isOk) {
console.log(result.schema); // Human-readable .cedarschema
console.log(result.schemaJson); // JSON for Cedar WASM isAuthorized()
} else {
console.error(result.error);
}
API 密码
generateSchema(schemaStub, toolsJson, configJson?)
| 参数 | 类型 | 说明 |
|---|---|---|
schemaStub | string | 锡达计程车 @mcp_principal 财务报告和审定财务报表 @mcp_resource 说明 |
toolsJson | string | MCP工具描述为 JSON( tools 阵列从 tools/list(中文(简体) ) |
configJson | string? | 可选配置为 JSON |
回返情况: JSON 有字段的字符串 :
| 外地 | 类型 | 说明 |
|---|---|---|
schema | string | null | 生成 Cedar 计划 .cedarschema 文本 |
schemaJson | string | null | 作为JSON(用于 isAuthorized()(中文(简体) ) |
error | string | null | 如果生成失败, 错误消息 |
isOk | boolean | 世代是否成功 |
配置
{
"includeOutputs": false,
"objectsAsRecords": false,
"eraseAnnotations": true,
"flattenNamespaces": false,
"numbersAsDecimal": false,
"deduplicateEntityTypes": false
}
| 选项 | 默认 | 说明 |
|---|---|---|
includeOutputs | false | 在动作中包含工具输出计划 |
objectsAsRecords | false | 对没有对象使用记录而不是实体 additionalProperties |
eraseAnnotations | true | 删除 @mcp_* 产出的说明 |
flattenNamespaces | false | 将所有类型平整为单一命名空间 |
numbersAsDecimal | false | 编码 JSON number 作为锡达 Decimal 改为 Long |
deduplicateEntityTypes | false | 将各种工具的相同实体类型合并到最小的共同祖先名称空间 |
generateRequest(schemaStub, toolsJson, inputJson, principalType, principalId, resourceType, resourceId, configJson?)
从 MCP 工具调用中生成 Cedar 授权请求组件 .
| 参数 | 类型 | 说明 |
|---|---|---|
schemaStub | string | Cedar schema stub (和 generateSchema(中文(简体) ) |
toolsJson | string | MCP 工具描述为 JSON |
inputJson | string | MCP 工具调用输入{"params": {"tool": "...", "args": {...}}}(中文(简体) ) |
principalType | string | 本金的锡达实体类型(例如, "User"(中文(简体) ) |
principalId | string | 主要标识符(例如:, "alice"(中文(简体) ) |
resourceType | string | 用于资源的锡达实体类型(例如, "McpServer"(中文(简体) ) |
resourceId | string | 资源标识符(例如, "my-server"(中文(简体) ) |
configJson | string? | 可选配置为 JSON |
回返情况: JSON 有字段的字符串 :
| 外地 | 类型 | 说明 |
|---|---|---|
principal | string | null | 主要实体(例如, MyServer::User::"alice"(中文(简体) ) |
action | string | null | 行动实体(例如, MyServer::Action::"read_file"(中文(简体) ) |
resource | string | null | 资源实体(例如, MyServer::McpServer::"my-server"(中文(简体) ) |
entitiesJson | string | null | 作为 JSON 数组字符串的实体 |
error | string | null | 如果生成失败, 错误消息 |
isOk | boolean | 世代是否成功 |
示例
const { generateRequest } = require('@cedar-policy/mcp-schema-generator-wasm');
const stub = `
namespace MyServer {
@mcp_principal
entity User;
@mcp_resource
entity McpServer;
action "call_tool" appliesTo {
principal: [User],
resource: [McpServer]
};
}
`;
const tools = JSON.stringify([
{
name: 'read_file',
description: 'Read a file from disk',
inputSchema: {
type: 'object',
properties: { path: { type: 'string' } },
required: ['path'],
},
},
]);
const input = JSON.stringify({
params: { tool: 'read_file', args: { path: '/etc/config.yaml' } },
});
const result = JSON.parse(
generateRequest(stub, tools, input, 'User', 'alice', 'McpServer', 'my-server')
);
if (result.isOk) {
console.log(result.principal); // MyServer::User::"alice"
console.log(result.action); // MyServer::Action::"read_file"
console.log(result.resource); // MyServer::McpServer::"my-server"
console.log(result.entitiesJson); // JSON array of entities for isAuthorized()
} else {
console.error(result.error);
}
大楼
# Install wasm-pack
cargo install wasm-pack
# Build for Node.js
wasm-pack build --target nodejs --scope cedar-policy
# Build for browsers
wasm-pack build --target web --scope cedar-policy
npm 发布
Npm 包名为:
@cedar-policy/mcp-schema-generator-wasm
拉斯特箱子的名字还在 cedar-policy-mcp-schema-generator-wasm期间
释放, 生成 wasm-pack 软件包元数据已正常化, 因此 npm
软件包使用上方的更短的名称,同时保留 Cargo.toml 版本.
释放是手动完成的
Publish MCP schema generator WASM to npm GitHub 动作工作流程 。 工作流程:
- 验证它是从
main· ; - 验证窗体标记
cedar-policy-mcp-schema-generator-wasm-v<MAJOR>.<MINOR>.<PATCH>· ; - 检查标签版本是否匹配此箱子
Cargo.toml· ; - 运行
wasm-pack build --target nodejs --scope cedar-policy· ; - 使生成的 npm 包元数据正常化;
- 运行
npm pack --dry-run; 和 : - 计算正确的 npm 二分位;和
- 出版单位
npm publish --access public --tag <tag> --provenance。 。 。 .
工作流程预计 npm 认证将使用 npm 信任的发布方式
存储器的释放环境。 它不需要一个 NPM_TOKEN 暗号.
与Rust发电机的关系
这个箱子很薄 wasm-bindgen 围绕现有的 cedar-policy-mcp-schema-generator 破烂的箱子。 所有计划生成逻辑、类型映射和边缘案件处理都委托给Rust执行。 WASM绑定没有添加独立的逻辑.
许可证
阿帕奇 - 2.0