02 · Reference implementation

Runtime SDK

The reference TypeScript implementation of runtime/0.1: validation, authority, policy, provider resolution, execution, evidence and receipts — with HTTP, MCP and events bindings.

At a glancePublic

github.com/Company-Runtime/runtime-sdk

Package
@runtime-protocol/sdk
Implements
runtime/0.1
Conformance
58/58 cases
Runtime
Node.js ≥ 22.18
Maturity
Experimental
License
Apache-2.0
What it is

Reference implementation.

The SDK turns the protocol into a working runtime you can embed. You name an intent; it validates the request, evaluates authority and policy before any provider is involved, resolves an eligible provider deterministically, dispatches, and completes the execution only when the required evidence exists.

It never defines vocabulary. The registry, schemas and conformance cases are generated from a protocol commit pinned in protocol.lock.json, and the SDK passes the whole conformance suite at that commit, at the runtime level — 58 of 58 cases.

Install it to run a runtime in your own service, call a remote one, expose one to MCP clients, or write a provider for a system of your own.

What's inside

One package, six entry points.

Import only the binding you need. Persistent stores stay yours: implement ExecutionStore.

  • @runtime-protocol/sdk

    Types, registry, validation, authority, policy, credentials, the resolver, createRuntime and the provider SDK (defineProvider, fetchJson).

  • …/http

    http/0.1: the runtime API handler and client, the provider API, remote providers and a Node.js serve(). The provider API can leave discovery and health public (publicRoutes) and build its credential broker from each request.

  • …/mcp

    mcp/0.1: a runtime as an MCP server over stdio, MCP tools as adapters, and federation with another runtime.

  • …/events

    events/0.1: a lossless CloudEvents mapping and sinks for execution events.

  • …/reference

    An in-process reference provider for communication.send, knowledge.search and reasoning.classify.

  • …/conformance

    The conformance runner, scripted providers and the provider harness, also as the runtime-conformance CLI.

How to use it

5 steps, from zero to running.

Commands and code come from the repository's own README and examples. Replace <commit> with the commit you pin.

  1. 01

    Install from Git

    The package is not on npm yet: install it at a commit. It builds itself on install, which pnpm 10 must be allowed to do.

    terminal · package.json
    pnpm add github:Company-Runtime/runtime-sdk#<commit>
    
    // package.json
    { "pnpm": { "onlyBuiltDependencies": ["@runtime-protocol/sdk"] } }
  2. 02

    Create a runtime and execute an intent

    Authority is deny-by-default: only granted capabilities can be requested. Credential bindings hold references; the key stays in the environment and is materialized only at dispatch.

    runtime.ts
    import {
      createRuntime,
      EnvCredentialBroker,
      GrantAuthority,
      verifyReceipt,
    } from "@runtime-protocol/sdk";
    import { createReferenceProvider } from "@runtime-protocol/sdk/reference";
    
    const runtime = createRuntime({
      providers: [createReferenceProvider()],
      authority: new GrantAuthority([
        {
          id: "support",
          authority: "authority://company/support-manager",
          subjects: ["identity://agent/support-agent"],
          capabilities: ["communication.send"],
        },
      ]),
      // The key lives in RUNTIME_SECRET_ORGANIZATION_PROVIDERS_REFERENCE.
      credentials: {
        bindings: [
          { provider: "reference", ref: "secret://organization/providers/reference" },
        ],
        broker: new EnvCredentialBroker(),
      },
    });
    
    const outcome = await runtime.execute({
      capability: "communication.send",
      profile: "email",
      traits: { required: ["delivery_receipt"] },
      actor: "identity://agent/support-agent",
      input: {
        recipients: ["identity://customer/981"],
        subject: "Account update",
        content: "Your account has been updated.",
      },
      evidence: { require: ["execution", "delivery"] },
    });
    
    // "completed" — only because execution and delivery were proven
    outcome.execution.state;
    verifyReceipt(outcome.receipt!); // true
  3. 03

    Write a provider for your system

    defineProvider validates input against the capability schema before your handler runs. Throw ProviderFailure when nothing happened; any other error is reported as unknown and reconciled, never blindly retried.

    provider.ts
    import { defineProvider, ProviderFailure } from "@runtime-protocol/sdk";
    
    export const provider = defineProvider({
      id: "acme-mail",
      capabilities: [
        {
          capability: "communication.send",
          profiles: ["email"],
          traits: ["delivery_receipt", "idempotency"],
        },
      ],
      credentials: { required: true, accepts: ["organization"] },
      handlers: {
        "communication.send": async (input, ctx) => {
          const key = await ctx.credential(); // never log or return it
          const receipt = await sendThroughYourSystem(input, key, {
            idempotencyKey: ctx.idempotencyKey,
            signal: ctx.signal,
          });
          if (receipt.rejected) {
            throw new ProviderFailure("the recipient was rejected before sending");
          }
          return {
            output: {
              message: { ref: `resource://acme-mail/messages/${receipt.id}` },
              accepted_recipients: input.recipients,
            },
            evidence: [
              ctx.evidence.providerReceipt(["execution", "delivery"], {
                message_id: receipt.id,
              }),
            ],
          };
        },
      },
    });
  4. 04

    Prove conformance

    Check a provider against requirements PC-001–PC-010, or run the bundled suite against the runtime itself.

    terminal
    runtime-conformance provider ./dist/provider.js \
      --export provider --samples samples.yaml
    
    # inside a clone of runtime-sdk
    pnpm conformance
  5. 05

    Serve it over HTTP or MCP

    The same runtime answers any binding. Over MCP, resolvable capabilities become tools (communication__send) and the actor comes from the session, never from tool arguments.

    serve.ts
    import { createHttpHandler, serve } from "@runtime-protocol/sdk/http";
    import { createMcpServer, serveStdio } from "@runtime-protocol/sdk/mcp";
    
    // HTTP: authenticate establishes who the caller may act as.
    const handler = createHttpHandler(runtime, { authenticate });
    const { url } = await serve(handler, { port: 8080 });
    
    // MCP over stdio, for one session actor.
    const actor = { ref: "identity://agent/support-agent" };
    await serveStdio(createMcpServer(runtime, { actor }));
Guarantees

What the runtime will not do.

These hold for every execution, whichever provider and binding it goes through.

  • 01

    Authority first

    Authority is deny-by-default and evaluated, with policy, before any provider is involved.

  • 02

    No completion without proof

    completed requires evidence for every required claim; a mutating execution without it is unknown.

  • 03

    Uncertainty is reconciled

    unknown is reconciled, never blindly retried. Idempotency keys are always forwarded for mutating capabilities.

  • 04

    Secrets never travel

    Requests, manifests, results, evidence, receipts, events and errors are checked for secrets; error messages are redacted.

  • 05

    Receipts are verifiable

    Receipts are canonical and integrity-protected. They record who owned the credential, never the credential.

  • 06

    Honest failures

    A request that never left is provider_unavailable; a 4xx answer is a failure; a 5xx, an interruption after sending or a remote answer over maxResponseBytes (1 MiB by default) is unknown.

Good to know
  • Sources are TypeScript run natively by Node.js; pnpm build emits JavaScript and declarations to dist/.
  • Keep the SDK in step with the protocol: pnpm protocol:sync --from ../runtime-protocol regenerates the bundle, pnpm protocol:check verifies it against the lock.
  • Not in scope: persistent stores, a policy language beyond policy sets, provider marketplaces, billing and product UI.
  • Company Runtime's connector marketplace is built on the SDK, not part of it: it runs third-party providers as container images serving the http/0.1 provider API from …/http.