Skip to content

About

TypeScript SDK and MCP proxy for Requisition's lab /v1 API (byte-compatible with requisition-aws).

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

requisition-ts

A TypeScript SDK and an MCP proxy for Requisition's /v1 API. The proxy forwards an agent's tool call when Requisition has signed an allow for that call's exact arguments and the proxy has checked that signature against a pinned key file; it forwards no other tool call. The SDK's gate reports the same two facts to your code (decision.allowed, decision.signatureChecked); your code decides what to run, and the SDK cannot stop it.

The package is a port of the Python package requisition-aws: the requests it sends and the hashes it derives are the same bytes, and the refusals it gives carry the same codes plus one of its own, integer_out_of_range (see "The float refusal"). The repository's tests hold it to vectors generated by the Python package (test/vectors/python/).

Every Requisition feature this package uses belongs to Requisition's evaluation environment: the /v1 API, the records it signs (Ed25519, with an ML-DSA-87 co-signature when one is configured) and the execute call that spends an approval once.

Licence: Apache License 2.0 (LICENSE, NOTICE). Third-party test files keep their own licences; they are listed in THIRD-PARTY.md and none of them is in the npm package.

The pieces

file what it is
src/index.ts The public surface. package.json exports this file and no other.
src/canonical.ts The canonical encoder (encode), the act hash (actHash: SHA-384 over the encoded arguments with act_type put inside, label sha384+canonical_payload.v3), the display digest, and the intake rules (checkArguments, ArgsSchema). Intake refuses before anything is sent, and never by truncating or rounding.
src/json.ts The strict JSON reader (parseStrict): RFC 8259, a duplicate member name refused, a nesting depth limit, and a number that is not a safe integer kept as its text (NumberLexeme), so 1.0 is never read as 1.
src/client.ts The HTTP client (Client): propose, read a request, execute, report an outcome, fetch the key file. Plain http is refused unless the host is loopback, or a private address that the caller allowed. The credential is sent in the Authorization header and is left out of the client's printed forms.
src/store.ts The relying party's store (Store): one SQLite file through node:sqlite, created with mode 600, every change in a transaction. It holds the open proposals, the exact bytes of each execute call, and the memory of every signed record already read.
src/gate.ts The flow (Gate): propose, awaitDecision, execute, claim, reportOutcome. Every answer from Requisition is checked against what was sent before it is used. A failed check throws, and the caller must not act.
src/keys.ts The pinned key file (KeyRegistry) and the key rule: a key's status, its validity window against the record's signed time, and the accepted signers, all checked before the signature.
src/pq.ts ML-DSA-87 verification, for the co-signatures of Requisition's evaluation environment, through @noble/post-quantum. The installed packages must hash to a pinned digest, or every verification throws.
src/verify.ts The offline check of one record (verifyRecord), described below.
src/registry.ts, src/catalog.ts The tool to act type registry (ToolRegistry) and the digest of a tool's definition. A tool that is not registered is denied.
src/mcp/ The MCP proxy (McpProxy), its stdio and Streamable HTTP servers (serveStdio, startHttp) and its upstream clients (StdioUpstream, HttpUpstream).
bin/requisition-mcp-proxy.ts The proxy's command.

Install

npm install --save-exact requisition-ts@0.3.0

Node 22.18 or newer is required. The store uses node:sqlite, which Node provides. The package has two runtime dependencies, each pinned to an exact version: @noble/curves 2.4.0 and, for the ML-DSA-87 signatures of Requisition's evaluation environment, @noble/post-quantum 0.7.1.

The npm package carries the compiled JavaScript and its type declarations (dist/src/, dist/bin/), this page, LICENSE and NOTICE. It is an ES module. The sources, the tests and the test vectors are in the repository, not in the package.

The SDK

import { Client, Gate, KeyRegistry, Store, argumentsObject, idempotencyKey } from "requisition-ts";

const client = new Client({ baseUrl: "https://requisition.example", credential, principal });
const keys = KeyRegistry.fromFile("requisition-keys.json");    // the pinned key file
const store = new Store("relying-party.db");
const gate = new Gate(client, store, { approvalBaseUrl: "https://requisition.example", keys });

const args = argumentsObject("refund-agent", "session-1", "payments.refund_send",
  { amount_minor: 1250, currency: "USD", account: "acct-7781", reason: "duplicate charge" });

let sanction = await gate.propose("payments.refund_send", args);
console.log("approve at", sanction.approvalUrl);                // status is "pending"
sanction = await gate.awaitDecision(sanction, args, { deadlineMs: 10 * 60 * 1000 });

if (sanction.status === "sanctioned") {
  const key = idempotencyKey("my-service", "call-0001", sanction.actHash);
  const decision = await gate.execute(sanction, args, key);
  if (decision.allowed && decision.signatureChecked && gate.runnable(decision)) {
    gate.claim(decision, sanction, { tool: "payments_refund_send" });   // throws if already claimed
    const result = await sendRefund(args.args);                         // your own code: the effect
    await gate.reportOutcome(decision, true, result);
  }
}

What each step does:

  • propose runs the intake rules, derives the act hash and files a sanction request. A second propose of the same act finds the open request instead of filing another. Given caller (a non-empty string naming who asks; the proxy passes the caller its transport verified), proposals are kept per caller and act hash: a propose for another caller never finds this one, even with the same arguments, and files its own. Requisition's act-hash lookup, which answers every request of the principal and cannot tell callers apart, is then not used. Without caller, a propose files its own request too, unless the Gate was built with adoptOpenRequests: true: then an open request of the principal found through that lookup is adopted. That includes requests a proxy filed for its callers, so a principal used with adoptOpenRequests must never be shared with a proxy; the Gate says so once, on standard error (or through warn), when it is built, and a proxy refuses such a Gate.
  • awaitDecision polls until the request is sanctioned or refused, or until the deadline, when it returns the pending answer. A sanctioned answer carries the signed statement; the gate checks that the statement names the request, the principal, the act type, the act hash and the display digest that were proposed, and that its signature verifies under the pinned key file.
  • execute sends the execute call and returns the signed decision, allow or deny. The bytes of the call are stored under key before they are sent, and a retry with the same key sends the same bytes. Requisition answers an exact retry with the same signed decision and says so in the answer (replayed: true, with the same release_id). An allow is returned only when this store holds its release (its release_id and the decision's receipt hash). The store writes a release only from an answer that says replayed: false (the first answer), so the instance that received it acts, also on its own later retry. Any other allow throws ReleaseRefused: a retry answered to a second instance with its own store (release_replayed), or an answer in which replayed is not a JSON boolean or release_id is not a lower-case UUID (release_unreadable), or a release_id that is not the signed decision's subject_id (release_mismatch). Never act on it. decision.released is true on an allow that was returned.
  • runnable says whether an allow can still be acted on: it is released and its signed exec_not_after has not passed.
  • claim records, in the store and before it returns, that this approval is being acted on. A second claim of the same statement, or of another statement for the same approval, throws FenceRefused. An allow whose exec_not_after has passed by then throws AllowExpired and is not claimed: call claim immediately before acting, after every slow step.
  • reportOutcome sends the caller's report of what happened and returns a short status: recorded, unsupported (the server has no outcome route) or not recorded: .... It does not throw: the effect has happened.

A Gate built without keys checks no signature, and decision.signatureChecked is then false. Give it a key file. With requirePq: true, a record of Requisition's evaluation environment without a valid ML-DSA-87 signature or co-signature is refused; this option needs a key file.

The MCP proxy

requisition-mcp-proxy stands between an MCP client and an MCP server. It holds every tools/call of a registered tool, proposes it to Requisition, and forwards it to the server when it holds a checked allow and has claimed it in its store.

requisition-mcp-proxy --config proxy.json --stdio
requisition-mcp-proxy --config proxy.json --http --port 8808

The configuration is a JSON file:

member meaning
requisition url, credential_file, principal, keys_file (required), approval_base_url; optional require_pq (true or false, default true), allow_classical_only (true or false, default false), accept_signers (the signer labels a key may carry: default ["kms"]; "any" lifts it), keys_max_age_seconds (a number above zero and at most 86400, default 300: the key file is read again at least that often), unix_socket (a path), allow_plaintext_private (true or false, default false).
store The path of the proxy's SQLite store.
allow_single_instance_store Required: true. The store is one SQLite file on this host, and this package has no store shared between instances. The setting says that exactly one instance of this proxy_id runs (or that every instance opens the same store file on one host). Absent, false or any other value: the command refuses to start.
seed, tools The seed file that describes the registered act types, and the map from tool name to act type. One act type is reached through one tool: two tool names bound to one act type refuse to start, because an approval names the act type, not the tool.
agent, session, proxy_id Names put into the proposed arguments and into the proxy's idempotency keys. proxy_id is required, a string that is not empty or only blanks; it also scopes every caller's proposals.
upstream The MCP server, required: exactly {command, args, env, pass_env} for a child process (args a list of strings, the last three optional), or exactly {url} for Streamable HTTP; no other member. url is an absolute http(s) URL with no user name or password, https unless the host is loopback (or a private IP literal with allow_plaintext_private: true), as requisition.url is judged. The child gets PATH, HOME, LANG, LC_ALL, TZ and TMPDIR from the proxy's environment, the names listed in pass_env (a list of variable names), and the values written in env (an object of names to strings); nothing else of the proxy's environment. A value that holds the proxy's credential refuses to start. A redirect from url is refused, never followed. At most 1 MiB of one answer is read (an HTTP answer, JSON or a whole SSE stream, or one line from the child); a longer answer is refused unread and the proxy says the call's outcome is unknown.
caller_id The caller's name over stdio, a string that is not empty or only blanks (default local). Every process started with one configuration is ONE caller under this name and shares its approvals (a second client of the same configuration can use an approval the first asked for). Give each client its own caller_id, that is its own configuration. The command names the caller on standard error when it starts over stdio.
http For --http: tokens_file (a JSON object from the SHA-256, in hex, of a bearer token to a caller name; each caller name once, since two tokens on one name would be one caller sharing its approvals), and optional allowed_origins (a list of strings) and path (a string starting with /, default /mcp).

Accepted values only. A switch takes the JSON booleans true or false; "true", "false", 1, 0, "" and null are refused. A member that is not in the table above (at the top level, in requisition, http, upstream, or a tools entry), for example a misspelt switch, refuses to start, naming it. Every name and path (store, seed, agent, session, proxy_id, caller_id, requisition.credential_file, principal, keys_file, http.tokens_file) is a string that is not empty or only blanks; requisition.url and approval_base_url are absolute http(s) URLs with no user name or password (url https unless loopback, a private IP literal with allow_plaintext_private, or over unix_socket); tools maps tool names to an act type or to {act_type, tool_digest}. keys_max_age_seconds takes a JSON number above zero and at most 86400 (one day). When present, unix_socket must be a non-empty string and allowed_origins a list of non-empty strings. The tokens file must map 64 hex digits to a non-empty caller name, each digest once (the same digest in upper and lower case is refused) and each caller name once. --host must be a host name or an IP literal; without it the proxy listens on 127.0.0.1. --port must be a decimal port from 0 to 65535 (0, the default: any free port); an argument the command cannot parse exits 78 too. Any other value refuses to start (exit 78) and names the setting. A wrong value never falls back to the weaker setting.

How it answers a tools/call:

  • A tool that is not registered is denied, and nothing is forwarded.
  • An approval belongs to the caller who asked for it (over HTTP the caller its bearer token names, over stdio caller_id). A call from another caller never uses it, even with the same arguments: that caller gets its own request. A request pending in a store written by 0.2.0 is not found after the upgrade (it was kept without a caller); the call asks for approval again. Two instances with separate stores do not share a request either: each asks for its own.
  • The tool forwarded is the one the approval was asked for through: the proposal and the stored execute call keep the tool's name, and a call of another tool (a configuration changed over the same store) is refused before it is executed and again before it is forwarded. An execute call stored by 0.2.0 names no tool and is not forwarded: its retry is refused, and a new call (a new JSON-RPC id) asks for approval again.
  • While the request is pending, the answer is an error result that says awaiting approval, with the request id and the approval link. The tool did not run. The client calls again once it is approved.
  • A refused request, a signed deny, an allow whose exec_not_after has passed (checked again immediately before the claim, after the upstream's tool listings), a failed check and an unreachable Requisition or store all give an error result that says the tool did not run.
  • What is forwarded is built by the proxy from what was approved: the tool's name and the approved arguments, and in _meta only the proxy's own protocol members (as on its tools/list) and the caller's progressToken (a string of at most 256 bytes, or a safe integer; otherwise it is dropped). Every other _meta key, task, and any other member of params is dropped. Of the client's notifications, only notifications/initialized is passed on (without the client's params), and a notifications/cancelled for a call in flight becomes the proxy's own cancel of its upstream request. The other requests it passes on are built by the proxy too, since every caller shares one upstream: initialize carries the proxy's own client name and empty capabilities, with a protocol version from the proxy's list (the one asked for when it is on the list, else the newest); tools/list carries only a cursor of at most 1024 bytes; ping and server/discover carry nothing of the client's. A page asked for with a cursor never replaces the tool definitions the proxy holds.
  • On a checked allow, the proxy claims the approval in its store and then forwards the call. From that moment no answer says that the tool did not run: if the server's answer is lost, the proxy says the outcome is unknown and that the call must not be repeated for this approval.
  • A repeated call (the same caller, JSON-RPC id and arguments) is answered from the stored result while the stored execute call is still valid, and with an error result after that. The tool does not run a second time.

tools/list shows the registered tools and leaves the others out. The Streamable HTTP server accepts POST, requires a bearer token that maps to a caller name, checks the Origin header against the allowed origins, and does not mint a session. Over stdio, standard output carries MCP messages and nothing else. The command exits 78 on a bad configuration and 70 on an internal error.

What the proxy does not prevent, stated so an operator can plan for it:

  • The upstream child and the credential. The child gets an allow-listed environment (above); that allow-list is the control. The check that no value handed to the child holds the credential is a best-effort byte-substring check: the credential encoded (base64, other case, percent-encoded) or split over two variables passes it. The child runs as the same operating-system user as the proxy, so it can read requisition.credential_file itself. If the credential must be out of the child's reach, run the child as another user.
  • A second pending request with the same display. A propose whose answer is lost on the way, or the same call sent to a second instance with its own store, files a second request that shows the approver exactly the same display. Approving both gives two effects (two approvals, one each). Approvers should reject a duplicate they did not mean to approve twice.
  • One over-long line from a stdio child. A line over 1 MiB from the upstream child cannot be matched to the call it answers, so every call in flight on that child fails, other callers' included, and each is answered "outcome unknown".
  • Delivery after exec_not_after. The deadline is checked immediately before the claim; nothing slow runs between the claim and the forward. The forward itself (a TCP or TLS connection, or a child that is not reading its input) can deliver the call up to the upstream timeout (30 seconds) after exec_not_after, and a stalled child can read it later still.
  • Token rotation. The tokens file takes one token per caller name, so a caller's old and new tokens cannot run side by side: rotate by replacing the token's entry in the tokens file and restarting the proxy, not by adding a second entry for the same name.
  • The shared upstream's initialize. Each caller's initialize is passed to the one upstream every caller shares, built by the proxy with its own fixed parameters (its client name, no capabilities). An upstream may answer a second initialize with an error, and a tool that needs roots, sampling or elicitation from the client does not get them through this proxy.

The float refusal

Requisition's canonical encoding has no decimal numbers, so this package refuses one instead of guessing how it would be written:

  • checkArguments, which propose and the proxy run before anything is sent, throws IntakeRefusal("float_refused", path) at the first float in the arguments, before every other intake check. path names the member, for example args.amount.
  • encode and actHash throw CanonicalRefusal("float_refused", path).
  • The proxy answers arguments refused before sending (float_refused at <path>); nothing was proposed.

What counts as a float: a number that is not an integer (12.5, NaN, the infinities), and, in JSON text read by parseStrict, any number written with a fraction or an exponent (1.0, 1e5). The reader keeps such a number as its text, so 1.0 in an MCP message is refused and is never turned into 1. JavaScript itself has one number type: a value written 1.0 in JavaScript source is the integer 1 by the time this package sees it.

An integer outside ±(2^53 − 1) is refused too. Given as a JavaScript number, the encoder refuses it integer_out_of_range. Written in JSON text read by parseStrict, it is kept as its text, as a float is, and the encoder refuses it float_refused. At intake it is refused malformed_member.

Send amounts as integers in a minor unit (amount_minor: 1250) or as strings.

Checking a record offline

verifyRecord (in src/verify.ts) checks one signed record against a pinned key file. It makes no network call.

import { KeyRegistry, verifyRecord } from "requisition-ts";

const keys = KeyRegistry.fromFile("requisition-keys.json");
const result = verifyRecord(
  { record, cosignature },                       // cosignature may be left out
  { keys, expect: { actType: "payments.refund_send", args, principal } },
);
if (!result.ok) console.error(result.codes, result.failures);

Read the record file with parseBounded (exported; KeyRegistry and verifyRecord read the key file and the signed bytes with it), so that a record is read as every Requisition verifier reads it: no unpaired surrogate in a string or a member name, no negative zero written with an exponent and no fraction (-0e5), no repeated member name, no integer outside +-(2^53-1), nesting at most 64 deep, and a number written with a fraction or an exponent kept as written.

expect is an argument: an act that cannot be derived (an empty act type, arguments that are not an object) throws before the record is read. Then it checks, and lists every failure in failures, each with its code in codes (one code per failure, in the same order):

  • that record is the four-field envelope (signature, key_id, signed_payload, receipt_hash) (record_malformed), that signed_payload holds no unpaired surrogate (it would have no UTF-8 bytes) and is read by the rule above (signed_payload_unreadable), that receipt_hash is the SHA-256 of signed_payload (receipt_hash_mismatch), and that the signed bytes carry a metadata object (signed_metadata_missing);
  • that every member displayed beside the envelope whose name is a top-level member of the signed bytes equals that signed member, by type and value (an integer is not a float, true is not 1, -0.0 is not 0.0) (displayed_field_mismatch); a displayed member the signed bytes do not carry, and public_key, are ignored;
  • the signature under the key file and the key rule (signature: ok, invalid or unknown_key; the code is the reason: registry_missing_key (the key file does not name the key id), key_fingerprint_mismatch for a key entry whose public_key is not canonical base64 or whose public_key_fingerprint is absent or not the lower-case SHA-256 of it, key_public_key_malformed, key_not_prime_order, key_file_malformed for a key file with another entry that fails its own form (not an object; no key_id that is text; no public_key that is canonical base64 of its algorithm's length; a fingerprint that is not the SHA-256 of those bytes; a valid_from that is not an instant, or a valid_to that is neither null nor one: such an entry is never dropped from its key's standing), the key rule's reasons, signature_malformed for a signature that is not canonical base64 of the algorithm's length, signature_invalid);
  • the co-signature rules of Requisition's evaluation environment for ML-DSA-87 (pq: checked, absent or invalid): a co-signature must cover the record's own bytes, be named by the record's signed cosign member and verify under the key file (cosignature_invalid; cosignature_malformed when it has no canonical bytes), and a record that says it is co-signed and arrives without its co-signature (none, or a value that is not a four-field envelope of text members: null, empty, another type) fails as stripped (cosignature_stripped);
  • whether post-quantum is expected and met (pq_missing, after any co-signature failure);
  • with expect, that the record binds the expected act (binding, act_hash_mismatch): the act type, the act hash recomputed from args, the hash label, the principal when given, and the display digest of a statement or a decision. A record with no act_hash_alg member fails.

The key file is read whole first: an entry whose algorithm is not exactly ed25519 or mldsa87 makes it unread (KeyFileError with code key_algorithm_unknown, naming the entry); a key id named twice is registry_duplicate_key.

Post-quantum: requirePq: true expects a checked ML-DSA-87 signature (the record's own, or a valid co-signature over the same bytes). Without it, the pinned key file decides: when it holds an ML-DSA-87 entry (whatever that entry's signer, status or window, and whatever the record says), a record without such a signature fails, unless allowClassicalOnly: true is given. requirePq wins over allowClassicalOnly.

kind is the record's signed receipt_type. For an outcome record, outcomeNote says that the outcome was reported by the caller and is not proof that the effect happened. ok says that the checks above passed. It does not say that the record is an allow: verifyRecord does not read the verdict.

One default accept set: KeyRegistry.fromBytes, KeyRegistry.fromFile and the constructor accept the signer kms alone unless given acceptSigners (a list of signer labels, or null for every signer), as keysFromConfig already did: a development key's record fails signer_not_accepted unless acceptSigners: ["dev"] is given (since 0.3.0; before, their default was every signer). A pass under a key that is not a lab KMS key is a lab pass, never a trust root: lab is true in verifyRecord's result (and in the gate's Decision and Sanction), and KeyRegistry.judge answers { reason, lab }.

Every code above is a row of one table shared by every public verifier of these records, test/vectors/conformance/codes.json. The codes this package's record check and key file give, as the table lists them (test/readme-codes.test.ts checks these lines against it):

  • ts_lib (verifyRecord and KeyRegistry): act_hash_mismatch, cosignature_invalid, cosignature_malformed, cosignature_stripped, displayed_field_mismatch, key_algorithm_unknown, key_config_invalid, key_file_malformed, key_file_unreadable, key_fingerprint_mismatch, key_id_mismatch, key_not_prime_order, key_not_valid_at_signing, key_public_key_malformed, key_revoked, key_status_unusable, key_window_unreadable, pq_missing, receipt_hash_mismatch, record_malformed, registry_duplicate_key, registry_missing_key, signature_invalid, signature_malformed, signed_instant_unreadable, signed_metadata_missing, signed_payload_unreadable, signer_not_accepted.

Tests

npm ci
npm test

The tests run the TypeScript sources directly with Node, against a local fake of the /v1 API. They need no network, no Requisition server and no other repository.

Limits, stated

  • Authorization, not execution. A signed allow shows that the act was authorized. It does not show that it ran. The outcome record is the caller's report.
  • The key file. A key file fetched from the server is served by the party whose signatures it checks. Pin the file you verify against.
  • The store. The store is one SQLite file on one host. The claim that an approval was acted on is as durable as that file, and a second host with its own store does not see it. There is no store shared between hosts; the proxy command refuses to start unless its configuration says allow_single_instance_store: true.
  • One approval, one instance. An allow is acted on only through the store that received Requisition's first answer for it (replayed: false). That store writes that it holds the release as soon as the answer arrives and binds the call that was sent, before the signature is checked. The release is keyed on the pair (release_id, the decision's receipt hash) and counts only for a decision that then passes every check and has that receipt hash. release_id must be a nonce claim id in the form Requisition issues them (a lower-case UUID), and the client reads at most 1 MiB of any answer (the largest legitimate one measured is under 16 KB; a longer one is refused unread), so what an answer that does not verify can write is bounded: one small row per answer read. An answer whose signed payload is not the genuine one leaves nothing a later answer can use, and it does not stand in the way of the genuine first answer, which writes its own row. If the instance fails or stops after the release is written and before it claims the approval (the step just before forwarding), a retry of the same call on that store, by the same instance or by the instance started again on the same store file, runs the tool once. A retry on an instance with another store is refused. If the first answer never arrives (a lost connection), or arrives altered so that it does not bind the call, or the store cannot write the release, or a forged answer was read here after the call had reached Requisition, a retry is refused on every instance and the call needs a new approval. A failure after the claim and before the call is forwarded (the store write that marks the call as being forwarded) also uses up the approval: the call is not forwarded, and its retry is refused (approval_already_used). That can never run the tool twice. replayed and release_id are unsigned members of the answer: release_id is checked against the signed decision's subject_id, replayed is taken from the answer as received over the connection to Requisition. A Requisition server that does not send these members has every allow refused here.
  • TLS to Requisition is what keeps replayed honest. Nothing signs replayed. Whoever can alter the bytes between Requisition and the proxy can turn a genuine retry answer's replayed: true into false; with per-instance stores, a second instance then acts on the same approval, and the tool runs twice. With plain http (loopback, or a private address allowed with allow_plaintext_private), nothing in this package stands against that: keep the connection to Requisition on TLS, or on a path nobody else can write to.
  • Client.execute is not the gate. Client.execute returns Requisition's answer as received, with no signature check and no release check, so code that acts on that answer instead of on Gate.execute's decision bypasses the gate.
  • Interactive tools. A tool that asks for interactive input (input_required) is not supported by the proxy: the call is forwarded, its approval is used, and the answer is an error result.

About

TypeScript SDK and MCP proxy for Requisition's lab /v1 API (byte-compatible with requisition-aws).

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages