@treeseed/sdk 0.13.0-rc.16 → 0.13.0-rc.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,44 @@
1
1
  const MCP_PROTOCOL_VERSION = "2026-07-28";
2
+ function encodeConfirmationState(state) {
3
+ const bytes = new TextEncoder().encode(JSON.stringify(state));
4
+ let binary = "";
5
+ for (const byte of bytes) binary += String.fromCharCode(byte);
6
+ return btoa(binary).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/gu, "");
7
+ }
8
+ const TREESEED_MCP_PROMPTS = [
9
+ { name: "operate", description: "Operate TreeSeed through currently discoverable capabilities.", argumentSchemaId: "treeseed.prompt.objective/v1", requiredScopes: ["treeseed:read"] },
10
+ { name: "research", description: "Research a governed TreeSeed question and accumulate knowledge.", argumentSchemaId: "treeseed.prompt.objective/v1", requiredScopes: ["treeseed:read"] },
11
+ { name: "governance-review", description: "Review a proposal or decision using current governance evidence.", argumentSchemaId: "treeseed.prompt.objective/v1", requiredScopes: ["treeseed:read"] },
12
+ { name: "workday-planning", description: "Plan a time-based workday without bypassing API authority.", argumentSchemaId: "treeseed.prompt.objective/v1", requiredScopes: ["treeseed:read"] },
13
+ { name: "project-agent-chat", description: "Prepare an explicit governed project-agent chat invocation.", argumentSchemaId: "treeseed.prompt.objective/v1", requiredScopes: ["treeseed:read"] }
14
+ ];
15
+ function resourcePath(restPath) {
16
+ const [root, version, ...segments] = restPath.split("/");
17
+ if (root !== "" || version !== "v1" || segments.length === 0) throw new Error(`MCP resource requires a versioned control-plane REST path: ${restPath}`);
18
+ const path = segments.join("/");
19
+ if (path === "me") return "accounts/current";
20
+ return path.replace(/^platform\/operations(?=\/|$)/u, "operations").replace(/^capacity-plans(?=\/|$)/u, "plans").replace(/\/workday-runs(?=\/|$)/u, "/workdays").replace(/\/capacity\/assignments(?=\/|$)/u, "/assignments");
21
+ }
22
+ function operationToMcpResource(operation) {
23
+ if (!operation.surfaces.includes("mcp_resource")) return null;
24
+ if (operation.kind !== "read" || operation.rest.method !== "GET") {
25
+ throw new Error(`MCP resource operation ${operation.operationId} must be a read-only GET operation.`);
26
+ }
27
+ const uriTemplate = `treeseed://${resourcePath(operation.rest.path)}`;
28
+ const parameters = (value) => [...value.matchAll(/\{([^}]+)\}/gu)].map((match) => match[1]).sort();
29
+ if (JSON.stringify(parameters(uriTemplate)) !== JSON.stringify(parameters(operation.rest.path))) {
30
+ throw new Error(`MCP resource ${operation.operationId} must preserve its REST path parameter names.`);
31
+ }
32
+ return {
33
+ uriTemplate,
34
+ name: operation.operationId,
35
+ description: operation.description,
36
+ mimeType: "application/json",
37
+ operationId: operation.operationId,
38
+ subscribable: true,
39
+ ...operation.operationId === "status.show" ? { cacheTtlSeconds: 10 } : {}
40
+ };
41
+ }
2
42
  function operationToMcpTool(operation) {
3
43
  if (!operation.surfaces.includes("mcp_tool")) return null;
4
44
  return {
@@ -16,8 +56,29 @@ function operationToMcpTool(operation) {
16
56
  function buildMcpTools(operations) {
17
57
  return operations.map(operationToMcpTool).filter((tool) => tool !== null).sort((left, right) => left.name.localeCompare(right.name));
18
58
  }
59
+ function buildMcpResources(operations) {
60
+ const resources = operations.map(operationToMcpResource).filter((resource) => resource !== null).sort((left, right) => left.uriTemplate.localeCompare(right.uriTemplate));
61
+ const uriTemplates = new Set(resources.map(({ uriTemplate }) => uriTemplate));
62
+ if (uriTemplates.size !== resources.length) throw new Error("MCP resource URI templates must be unique.");
63
+ return resources;
64
+ }
65
+ function buildMcpCatalog(operations) {
66
+ return {
67
+ schemaVersion: "treeseed.mcp-catalog/v1",
68
+ protocolVersion: MCP_PROTOCOL_VERSION,
69
+ tools: buildMcpTools(operations),
70
+ resources: buildMcpResources(operations),
71
+ prompts: [...TREESEED_MCP_PROMPTS],
72
+ capabilities: { completion: true, progress: true, cancellation: true, inputRequired: true, resourceSubscriptions: true }
73
+ };
74
+ }
19
75
  export {
20
76
  MCP_PROTOCOL_VERSION,
77
+ TREESEED_MCP_PROMPTS,
78
+ buildMcpCatalog,
79
+ buildMcpResources,
21
80
  buildMcpTools,
81
+ encodeConfirmationState,
82
+ operationToMcpResource,
22
83
  operationToMcpTool
23
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.13.0-rc.16",
3
+ "version": "0.13.0-rc.18",
4
4
  "description": "Portable TreeSeed contracts, standards, and typed remote control-plane clients.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {