@trinaryex/mcp 3.3.1

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.
Files changed (47) hide show
  1. package/README.md +146 -0
  2. package/dist/capture.d.ts +38 -0
  3. package/dist/capture.js +58 -0
  4. package/dist/capture.js.map +1 -0
  5. package/dist/context.d.ts +25 -0
  6. package/dist/context.js +44 -0
  7. package/dist/context.js.map +1 -0
  8. package/dist/env.d.ts +27 -0
  9. package/dist/env.js +40 -0
  10. package/dist/env.js.map +1 -0
  11. package/dist/http.d.ts +5 -0
  12. package/dist/http.js +120 -0
  13. package/dist/http.js.map +1 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +33 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/logging.d.ts +10 -0
  18. package/dist/logging.js +43 -0
  19. package/dist/logging.js.map +1 -0
  20. package/dist/prepare.d.ts +71 -0
  21. package/dist/prepare.js +79 -0
  22. package/dist/prepare.js.map +1 -0
  23. package/dist/registry.d.ts +18 -0
  24. package/dist/registry.js +24 -0
  25. package/dist/registry.js.map +1 -0
  26. package/dist/result.d.ts +16 -0
  27. package/dist/result.js +32 -0
  28. package/dist/result.js.map +1 -0
  29. package/dist/schemas.d.ts +31 -0
  30. package/dist/schemas.js +37 -0
  31. package/dist/schemas.js.map +1 -0
  32. package/dist/server.d.ts +10 -0
  33. package/dist/server.js +41 -0
  34. package/dist/server.js.map +1 -0
  35. package/dist/tools/prepare.d.ts +2 -0
  36. package/dist/tools/prepare.js +297 -0
  37. package/dist/tools/prepare.js.map +1 -0
  38. package/dist/tools/read.d.ts +7 -0
  39. package/dist/tools/read.js +152 -0
  40. package/dist/tools/read.js.map +1 -0
  41. package/dist/tools/types.d.ts +20 -0
  42. package/dist/tools/types.js +2 -0
  43. package/dist/tools/types.js.map +1 -0
  44. package/dist/version.d.ts +7 -0
  45. package/dist/version.js +20 -0
  46. package/dist/version.js.map +1 -0
  47. package/package.json +98 -0
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @trinaryex/mcp
2
+
3
+ A **keyless, multi-tenant MCP server** for [Trinary Exchange](https://trinary.exchange) — market reads and unsigned transaction preparation for EVE Frontier trading agents.
4
+
5
+ Released in lockstep with [`@trinaryex/sdk`](https://www.npmjs.com/package/@trinaryex/sdk): **the MCP version always equals the SDK version it wraps.**
6
+
7
+ ## Two invariants
8
+
9
+ 1. **No private keys.** The server never signs and never submits. Write-shaped tools return *unsigned* transaction bytes; you sponsor, sign and submit them with your own key. Full compromise of this service cannot move funds.
10
+ 2. **No stored credentials.** Every request carries its own API key in a header. The server forwards it upstream for that request and retains nothing — no key store, no tenant table, no database.
11
+
12
+ That is what makes one shared deployment safe for a whole fleet of agents.
13
+
14
+ ## Quick start
15
+
16
+ ```bash
17
+ docker run -p 8080:8080 \
18
+ -e TRIEX_MCP_MODE=prepare \
19
+ -e SUI_GRPC_URL=https://fullnode.testnet.sui.io:443 \
20
+ ghcr.io/loash-industries/triex-mcp:latest
21
+ ```
22
+
23
+ Point an MCP client at `POST /mcp` and send your API key as `x-api-key`.
24
+
25
+ ## Configuration
26
+
27
+ All configuration is **non-secret** — note the absence of any key, address, or database setting.
28
+
29
+ | Variable | Default | Purpose |
30
+ |---|---|---|
31
+ | `TRIEX_MCP_MODE` | `prepare` | `read` registers read tools only; `prepare` adds the prepare tools |
32
+ | `PORT` / `HOST` | `8080` / `0.0.0.0` | Listen address |
33
+ | `SUI_GRPC_URL` | testnet fullnode | Fullnode used for object resolution and PTB builds |
34
+ | `TRIEX_API_URL` | SDK default | Indexer base URL override |
35
+ | `TRIEX_NETWORK` | `testnet` | Network preset |
36
+ | `MAX_CONCURRENCY_PER_KEY` | `8` | Fairness cap so one caller cannot starve the fleet |
37
+ | `TLS_CERT_PATH` / `TLS_KEY_PATH` | — | Serve HTTPS directly; set both or neither |
38
+
39
+ ## Endpoints
40
+
41
+ | Route | Purpose |
42
+ |---|---|
43
+ | `POST /mcp` | MCP Streamable HTTP (stateless). Requires `x-api-key` |
44
+ | `GET /healthz` | Liveness |
45
+ | `GET /readyz` | Readiness, mode and network |
46
+
47
+ `GET`/`DELETE` on `/mcp` return 405: the server runs stateless, so there are no sessions and no server-initiated streams.
48
+
49
+ ## Tools
50
+
51
+ **Read** — `market_discover`, `market_search_items`, `market_hub`, `market_items_at_hub`, `market_orderbook`, `market_pool_metadata`, `account_resolve`, `account_balances_at_hub`, `account_sweepable`, `orders_open`, `orders_fills`, `orders_trades`.
52
+
53
+ **Prepare** — `prepare_create_account`, `prepare_deposit_currency`, `prepare_deposit_items`, `prepare_withdraw_currency`, `prepare_withdraw_items`, `prepare_claim_settled`, `prepare_limit_order`, `prepare_market_order`, `prepare_cancel_order`, `prepare_cancel_all_orders`, `prepare_modify_order`.
54
+
55
+ u64-ish values (prices, quantities, amounts) cross the MCP boundary as **decimal strings**, never JSON numbers.
56
+
57
+ ## The prepare contract
58
+
59
+ Every `prepare_*` tool returns:
60
+
61
+ ```jsonc
62
+ {
63
+ "txKindBytes": "<base64 BCS TransactionKind, onlyTransactionKind>",
64
+ "sender": "0x…",
65
+ "intent": {
66
+ "action": "limit_order",
67
+ "targets": ["0x…::multicoin_pool::place_limit_order"],
68
+ "worstCaseSpend": { "asset": "CRED", "amount": "125625000", "kind": "currency" },
69
+ "params": { "side": "buy", "price": "12500000", "quantity": "10" }
70
+ },
71
+ "pinnedObjects": [{ "objectId": "0x…", "version": "42", "kind": "owned" }],
72
+ "builtAtMs": 1757500000000,
73
+ "notes": ["Verify before signing: …", "Sign promptly. …"]
74
+ }
75
+ ```
76
+
77
+ ### Verify before you sign
78
+
79
+ `intent.targets` is extracted from the **built transaction**, not reconstructed from your arguments — so checking bytes against intent is meaningful. Before signing:
80
+
81
+ 1. Decode `txKindBytes` and confirm its Move call targets equal `intent.targets`.
82
+ 2. Confirm every target is on your allowlist. **Package ids are normalized to full 32-byte form** (`0x2` → `0x000…002`); normalize your allowlist the same way or it will never match.
83
+ 3. Bound the spend against `intent.worstCaseSpend`.
84
+ 4. Dry-run, and compare the balance deltas to the declared intent.
85
+
86
+ Never blind-sign bytes produced by another process — including this one.
87
+
88
+ ### Staleness
89
+
90
+ `pinnedObjects` records the object versions the build resolved. Sign promptly, and never hold two prepared transactions over the same owned objects, or you risk equivocation. `builtAtMs` supports programmatic freshness checks.
91
+
92
+ ### Signing and submitting
93
+
94
+ Take `txKindBytes` to a gas station for sponsorship, or build gas yourself:
95
+
96
+ ```ts
97
+ import { Transaction } from '@mysten/sui/transactions'
98
+
99
+ const tx = Transaction.fromKind(Buffer.from(txKindBytes, 'base64'))
100
+ tx.setSender(sender)
101
+ tx.setGasOwner(sponsorAddress)
102
+ tx.setGasPayment(gasCoins)
103
+ // …verify, then sign with your key and submit
104
+ ```
105
+
106
+ ## Development
107
+
108
+ ```bash
109
+ npm ci
110
+ npm test # unit, parity, schema-snapshot and tenancy suites
111
+ npm run tscheck
112
+ npm run lint:check && npm run prettier:check
113
+ npm run check:parity # readable lock-step report (builds first)
114
+ npm run build && npm start
115
+ ```
116
+
117
+ ### Lock-step with the SDK
118
+
119
+ The tool surface is checked against the SDK's **shipped type declarations**, not against a hand-maintained list. `scripts/sdk-surface.mjs` parses `@trinaryex/sdk`'s `.d.ts` with the TypeScript compiler, which gives three things for free:
120
+
121
+ - `private` helpers are excluded **structurally** — nothing to keep in sync;
122
+ - each method's **return type classifies it**: `Promise<TxResult>` (or `EnsureAccountResult`) is a write, everything else is a read;
123
+ - it describes the **published contract**, which is what consumers actually see.
124
+
125
+ The check then enforces that every SDK method is either wrapped by a tool **of the matching kind** — writes by a `prepare_*` tool, reads by a read tool — or listed in `EXCLUDED_SDK_PATHS` with a reason. Covering a write with a read tool fails just as loudly as not covering it at all.
126
+
127
+ `npm run check:parity` prints the full report:
128
+
129
+ ```
130
+ SDK surface: 25 methods (14 read, 11 write)
131
+ MCP tools: 23 · explicitly excluded: 2
132
+
133
+ ✓ write orders.limit prepare_limit_order
134
+ ✓ read market.orderbook market_orderbook
135
+ – read market.resolvePool (excluded)
136
+ …
137
+ MCP covers the SDK surface in lock-step.
138
+ ```
139
+
140
+ The same checks run in `test/parity.test.ts` on every PR — and that suite includes cases driving the comparison with doctored inputs, so the gate is proven to fail when it should. CI runs it on **all** PRs, not just ones touching `mcp/`, because the drift it catches usually originates in an SDK change.
141
+
142
+ The **schema snapshot** turns any consumer-visible input change into a reviewable diff.
143
+
144
+ ## License
145
+
146
+ MIT
@@ -0,0 +1,38 @@
1
+ import type { Transaction } from '@mysten/sui/transactions';
2
+ import type { TransactionExecutor } from '@trinaryex/sdk';
3
+ /**
4
+ * Signal thrown by the capture executor to unwind an SDK write call once the
5
+ * transaction has been fully built, *before* anything is signed or submitted.
6
+ *
7
+ * The SDK's `executeAndNormalize` rethrows unrecognized executor errors
8
+ * untouched (it only wraps `TriexClientError` and Move-abort-shaped messages),
9
+ * so this class must never carry a message matching `/MoveAbort|abort code/i`.
10
+ */
11
+ export declare class TransactionCaptured extends Error {
12
+ readonly transaction: Transaction;
13
+ constructor(transaction: Transaction);
14
+ }
15
+ /**
16
+ * Raised when an SDK call completed without ever handing a transaction to the
17
+ * executor — meaning there was nothing to prepare (e.g. `account.ensure()` on
18
+ * an address that already has a balance manager).
19
+ */
20
+ export declare class NothingToPrepare extends Error {
21
+ readonly result: unknown;
22
+ constructor(result: unknown);
23
+ }
24
+ /**
25
+ * An executor that never executes. Handed to a `TriexClient` in place of a
26
+ * signing executor, it intercepts the fully-built PTB and aborts the call.
27
+ *
28
+ * This is what makes the server keyless: transaction *construction* runs here,
29
+ * transaction *commitment* stays with whoever holds the private key.
30
+ */
31
+ export declare const captureExecutor: TransactionExecutor;
32
+ /**
33
+ * Run an SDK write call and return the transaction it built instead of
34
+ * executing it.
35
+ *
36
+ * @throws {NothingToPrepare} when the call finished without building a tx.
37
+ */
38
+ export declare function captureTransaction(run: () => Promise<unknown>): Promise<Transaction>;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Signal thrown by the capture executor to unwind an SDK write call once the
3
+ * transaction has been fully built, *before* anything is signed or submitted.
4
+ *
5
+ * The SDK's `executeAndNormalize` rethrows unrecognized executor errors
6
+ * untouched (it only wraps `TriexClientError` and Move-abort-shaped messages),
7
+ * so this class must never carry a message matching `/MoveAbort|abort code/i`.
8
+ */
9
+ export class TransactionCaptured extends Error {
10
+ transaction;
11
+ constructor(transaction) {
12
+ super('triex-mcp: transaction captured for preparation');
13
+ this.name = 'TransactionCaptured';
14
+ this.transaction = transaction;
15
+ }
16
+ }
17
+ /**
18
+ * Raised when an SDK call completed without ever handing a transaction to the
19
+ * executor — meaning there was nothing to prepare (e.g. `account.ensure()` on
20
+ * an address that already has a balance manager).
21
+ */
22
+ export class NothingToPrepare extends Error {
23
+ result;
24
+ constructor(result) {
25
+ super('triex-mcp: the requested action needs no transaction');
26
+ this.name = 'NothingToPrepare';
27
+ this.result = result;
28
+ }
29
+ }
30
+ /**
31
+ * An executor that never executes. Handed to a `TriexClient` in place of a
32
+ * signing executor, it intercepts the fully-built PTB and aborts the call.
33
+ *
34
+ * This is what makes the server keyless: transaction *construction* runs here,
35
+ * transaction *commitment* stays with whoever holds the private key.
36
+ */
37
+ export const captureExecutor = (tx) => {
38
+ throw new TransactionCaptured(tx);
39
+ };
40
+ /**
41
+ * Run an SDK write call and return the transaction it built instead of
42
+ * executing it.
43
+ *
44
+ * @throws {NothingToPrepare} when the call finished without building a tx.
45
+ */
46
+ export async function captureTransaction(run) {
47
+ let result;
48
+ try {
49
+ result = await run();
50
+ }
51
+ catch (e) {
52
+ if (e instanceof TransactionCaptured)
53
+ return e.transaction;
54
+ throw e;
55
+ }
56
+ throw new NothingToPrepare(result);
57
+ }
58
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,WAAW,CAAa;IAEjC,YAAY,WAAwB;QAClC,KAAK,CAAC,iDAAiD,CAAC,CAAA;QACxD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;QACjC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,MAAM,CAAS;IAExB,YAAY,MAAe;QACzB,KAAK,CAAC,sDAAsD,CAAC,CAAA;QAC7D,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwB,CAAC,EAAe,EAAE,EAAE;IACtE,MAAM,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAA;AACnC,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,GAA2B;IAE3B,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,GAAG,EAAE,CAAA;IACtB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,mBAAmB;YAAE,OAAO,CAAC,CAAC,WAAW,CAAA;QAC1D,MAAM,CAAC,CAAA;IACT,CAAC;IACD,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { ClientWithCoreApi } from '@mysten/sui/client';
2
+ import { ReadOnlyClient, TriexClient } from '@trinaryex/sdk';
3
+ import type { ServerConfig } from './env.js';
4
+ /**
5
+ * Per-request state. Constructed fresh for every MCP call and discarded when
6
+ * it completes — the server holds no cross-request tenant state at all.
7
+ */
8
+ export interface RequestContext {
9
+ /** The caller's TriEx API key, taken from the request headers. */
10
+ readonly apiKey: string;
11
+ readonly config: ServerConfig;
12
+ /** A read client bound to this caller's key. */
13
+ readClient(): ReadOnlyClient;
14
+ /**
15
+ * A client capable of *building* writes for `sender`. Its executor is the
16
+ * capture executor, so it can build but never submit.
17
+ */
18
+ writeClient(sender: string): TriexClient;
19
+ /** The shared, credential-free Sui client used for PTB resolution. */
20
+ suiClient(): ClientWithCoreApi;
21
+ }
22
+ export declare function getSuiClient(config: ServerConfig): ClientWithCoreApi;
23
+ /** Test seam: drop the shared client so a suite can swap transports. */
24
+ export declare function resetSuiClient(): void;
25
+ export declare function createContext(apiKey: string, config: ServerConfig, suiClientOverride?: ClientWithCoreApi): RequestContext;
@@ -0,0 +1,44 @@
1
+ import { SuiGrpcClient } from '@mysten/sui/grpc';
2
+ import { ReadOnlyClient, TriexClient } from '@trinaryex/sdk';
3
+ import { captureExecutor } from './capture.js';
4
+ /**
5
+ * The Sui client carries no credentials and is identical for every caller, so
6
+ * one instance is shared process-wide. Everything credential-bearing is built
7
+ * per request. This is why there is no credential-keyed cache to get wrong.
8
+ */
9
+ let sharedSuiClient = null;
10
+ export function getSuiClient(config) {
11
+ if (!sharedSuiClient) {
12
+ sharedSuiClient = new SuiGrpcClient({
13
+ network: config.network,
14
+ baseUrl: config.grpcUrl,
15
+ });
16
+ }
17
+ return sharedSuiClient;
18
+ }
19
+ /** Test seam: drop the shared client so a suite can swap transports. */
20
+ export function resetSuiClient() {
21
+ sharedSuiClient = null;
22
+ }
23
+ export function createContext(apiKey, config, suiClientOverride) {
24
+ const sui = () => suiClientOverride ?? getSuiClient(config);
25
+ return {
26
+ apiKey,
27
+ config,
28
+ suiClient: sui,
29
+ readClient: () => new ReadOnlyClient({
30
+ apiKey,
31
+ network: config.network,
32
+ ...(config.indexerUrl ? { indexerUrl: config.indexerUrl } : {}),
33
+ }),
34
+ writeClient: (sender) => new TriexClient({
35
+ suiClient: sui(),
36
+ apiKey,
37
+ address: sender,
38
+ executor: captureExecutor,
39
+ network: config.network,
40
+ ...(config.indexerUrl ? { indexerUrl: config.indexerUrl } : {}),
41
+ }),
42
+ };
43
+ }
44
+ //# sourceMappingURL=context.js.map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,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,CAAC;KACL,CAAA;AACH,CAAC"}
package/dist/env.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { TriexNetwork } from '@trinaryex/sdk';
2
+ export type ServerMode = 'read' | 'prepare';
3
+ export interface ServerConfig {
4
+ host: string;
5
+ port: number;
6
+ /** `read` registers read tools only; `prepare` adds the prepare tools. */
7
+ mode: ServerMode;
8
+ network: TriexNetwork;
9
+ /** Sui fullnode gRPC base URL used for object resolution and PTB builds. */
10
+ grpcUrl: string;
11
+ /** Indexer base URL override; the SDK default applies when unset. */
12
+ indexerUrl?: string;
13
+ /** Max concurrent in-flight tool calls per API key. Fairness, not security. */
14
+ maxConcurrencyPerKey: number;
15
+ tls?: {
16
+ certPath: string;
17
+ keyPath: string;
18
+ };
19
+ }
20
+ /**
21
+ * Read server configuration from the environment.
22
+ *
23
+ * Note what is absent: no API key, no address, no private key, no database.
24
+ * Everything here is non-secret. Credentials arrive per request (see
25
+ * `context.ts`) and are never stored.
26
+ */
27
+ export declare function loadConfig(env?: NodeJS.ProcessEnv): ServerConfig;
package/dist/env.js ADDED
@@ -0,0 +1,40 @@
1
+ const DEFAULT_GRPC_URL = 'https://fullnode.testnet.sui.io:443';
2
+ function intFromEnv(name, fallback) {
3
+ const raw = process.env[name];
4
+ if (!raw)
5
+ return fallback;
6
+ const parsed = Number.parseInt(raw, 10);
7
+ if (!Number.isFinite(parsed) || parsed <= 0) {
8
+ throw new Error(`${name} must be a positive integer, got: ${raw}`);
9
+ }
10
+ return parsed;
11
+ }
12
+ /**
13
+ * Read server configuration from the environment.
14
+ *
15
+ * Note what is absent: no API key, no address, no private key, no database.
16
+ * Everything here is non-secret. Credentials arrive per request (see
17
+ * `context.ts`) and are never stored.
18
+ */
19
+ export function loadConfig(env = process.env) {
20
+ const mode = (env.TRIEX_MCP_MODE ?? 'prepare');
21
+ if (mode !== 'read' && mode !== 'prepare') {
22
+ throw new Error(`TRIEX_MCP_MODE must be "read" or "prepare", got: ${mode}`);
23
+ }
24
+ const certPath = env.TLS_CERT_PATH;
25
+ const keyPath = env.TLS_KEY_PATH;
26
+ if ((certPath && !keyPath) || (!certPath && keyPath)) {
27
+ throw new Error('TLS_CERT_PATH and TLS_KEY_PATH must be set together');
28
+ }
29
+ return {
30
+ host: env.HOST ?? '0.0.0.0',
31
+ port: intFromEnv('PORT', 8080),
32
+ mode,
33
+ network: (env.TRIEX_NETWORK ?? 'testnet'),
34
+ grpcUrl: env.SUI_GRPC_URL ?? DEFAULT_GRPC_URL,
35
+ ...(env.TRIEX_API_URL ? { indexerUrl: env.TRIEX_API_URL } : {}),
36
+ maxConcurrencyPerKey: intFromEnv('MAX_CONCURRENCY_PER_KEY', 8),
37
+ ...(certPath && keyPath ? { tls: { certPath, keyPath } } : {}),
38
+ };
39
+ }
40
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAmBA,MAAM,gBAAgB,GAAG,qCAAqC,CAAA;AAE9D,SAAS,UAAU,CAAC,IAAY,EAAE,QAAgB;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,IAAI,CAAC,GAAG;QAAE,OAAO,QAAQ,CAAA;IACzB,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,qCAAqC,GAAG,EAAE,CAAC,CAAA;IACpE,CAAC;IACD,OAAO,MAAM,CAAA;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fig } from './env.js';
3
+ /** Pull the caller's API key out of the request. Never logged, never stored. */
4
+ export declare function extractApiKey(req: Request): string | null;
5
+ export declare function createApp(config: ServerConfig): Express;
package/dist/http.js ADDED
@@ -0,0 +1,120 @@
1
+ import express from 'express';
2
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
3
+ import { createContext } from './context.js';
4
+ import { log, tenantLabel } from './logging.js';
5
+ import { createServer } from './server.js';
6
+ import { packageVersion } from './version.js';
7
+ /** In-flight calls per tenant. Fairness against noisy neighbours, not security. */
8
+ const inFlight = new Map();
9
+ function acquire(label, max) {
10
+ const current = inFlight.get(label) ?? 0;
11
+ if (current >= max)
12
+ return false;
13
+ inFlight.set(label, current + 1);
14
+ return true;
15
+ }
16
+ function release(label) {
17
+ const current = inFlight.get(label) ?? 0;
18
+ if (current <= 1)
19
+ inFlight.delete(label);
20
+ else
21
+ inFlight.set(label, current - 1);
22
+ }
23
+ /** Pull the caller's API key out of the request. Never logged, never stored. */
24
+ export function extractApiKey(req) {
25
+ const header = req.header('x-api-key');
26
+ if (header && header.trim())
27
+ return header.trim();
28
+ const auth = req.header('authorization');
29
+ if (auth?.toLowerCase().startsWith('bearer ')) {
30
+ const token = auth.slice(7).trim();
31
+ if (token)
32
+ return token;
33
+ }
34
+ return null;
35
+ }
36
+ export function createApp(config) {
37
+ const app = express();
38
+ app.use(express.json({ limit: '1mb' }));
39
+ app.get('/healthz', (_req, res) => {
40
+ res.json({ status: 'ok', version: packageVersion() });
41
+ });
42
+ app.get('/readyz', (_req, res) => {
43
+ res.json({
44
+ status: 'ok',
45
+ mode: config.mode,
46
+ network: config.network,
47
+ version: packageVersion(),
48
+ });
49
+ });
50
+ app.post('/mcp', async (req, res) => {
51
+ const apiKey = extractApiKey(req);
52
+ if (!apiKey) {
53
+ // Rejected before any upstream call is made.
54
+ res.status(401).json({
55
+ jsonrpc: '2.0',
56
+ error: {
57
+ code: -32001,
58
+ message: 'Missing credential. Send your Trinary Exchange API key as an x-api-key header.',
59
+ },
60
+ id: null,
61
+ });
62
+ return;
63
+ }
64
+ const label = tenantLabel(apiKey);
65
+ if (!acquire(label, config.maxConcurrencyPerKey)) {
66
+ res.status(429).json({
67
+ jsonrpc: '2.0',
68
+ error: {
69
+ code: -32002,
70
+ message: `Too many concurrent requests for this API key (limit ${config.maxConcurrencyPerKey}). Retry shortly.`,
71
+ },
72
+ id: null,
73
+ });
74
+ return;
75
+ }
76
+ // Stateless mode: a fresh server and transport per request, so no tenant
77
+ // state can outlive the request or leak into another caller's.
78
+ const transport = new StreamableHTTPServerTransport({
79
+ sessionIdGenerator: undefined,
80
+ });
81
+ const server = createServer(createContext(apiKey, config));
82
+ res.on('close', () => {
83
+ release(label);
84
+ void transport.close();
85
+ void server.close();
86
+ });
87
+ try {
88
+ await server.connect(transport);
89
+ await transport.handleRequest(req, res, req.body);
90
+ }
91
+ catch (e) {
92
+ log('error', 'mcp request failed', {
93
+ tenant: label,
94
+ error: e instanceof Error ? e.message : String(e),
95
+ });
96
+ if (!res.headersSent) {
97
+ res.status(500).json({
98
+ jsonrpc: '2.0',
99
+ error: { code: -32603, message: 'Internal server error' },
100
+ id: null,
101
+ });
102
+ }
103
+ }
104
+ });
105
+ // Stateless mode has no server-initiated streams and no sessions to delete.
106
+ const methodNotAllowed = (_req, res) => {
107
+ res.status(405).json({
108
+ jsonrpc: '2.0',
109
+ error: {
110
+ code: -32000,
111
+ message: 'This server runs stateless; use POST /mcp.',
112
+ },
113
+ id: null,
114
+ });
115
+ };
116
+ app.get('/mcp', methodNotAllowed);
117
+ app.delete('/mcp', methodNotAllowed);
118
+ return app;
119
+ }
120
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAA;AAClG,OAAO,EA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AAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;oBACnB,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,uBAAuB,EAAE;oBACzD,EAAE,EAAE,IAAI;iBACT,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,4EAA4E;IAC5E,MAAM,gBAAgB,GAAG,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;QACxD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,OAAO,EAAE,KAAK;YACd,KAAK,EAAE;gBACL,IAAI,EAAE,CAAC,KAAK;gBACZ,OAAO,EAAE,4CAA4C;aACtD;YACD,EAAE,EAAE,IAAI;SACT,CAAC,CAAA;IACJ,CAAC,CAAA;IACD,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IACjC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAEpC,OAAO,GAAG,CAAA;AACZ,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { createServer as createHttpsServer } from 'node:https';
4
+ import { createApp } from './http.js';
5
+ import { loadConfig } from './env.js';
6
+ import { log } from './logging.js';
7
+ import { toolsForMode } from './registry.js';
8
+ import { packageVersion } from './version.js';
9
+ function main() {
10
+ const config = loadConfig();
11
+ const app = createApp(config);
12
+ const tools = toolsForMode(config.mode).map((t) => t.name);
13
+ const onListening = () => log('info', 'triex-mcp listening', {
14
+ version: packageVersion(),
15
+ mode: config.mode,
16
+ network: config.network,
17
+ host: config.host,
18
+ port: config.port,
19
+ tls: !!config.tls,
20
+ tools: tools.length,
21
+ });
22
+ if (config.tls) {
23
+ createHttpsServer({
24
+ cert: readFileSync(config.tls.certPath),
25
+ key: readFileSync(config.tls.keyPath),
26
+ }, app).listen(config.port, config.host, onListening);
27
+ }
28
+ else {
29
+ app.listen(config.port, config.host, onListening);
30
+ }
31
+ }
32
+ main();
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,SAAS,IAAI;IACX,MAAM,MAAM,GAAG,UAAU,EAAE,CAAA;IAC3B,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;IAC7B,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAE1D,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,GAAG,CAAC,MAAM,EAAE,qBAAqB,EAAE;QACjC,OAAO,EAAE,cAAc,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG;QACjB,KAAK,EAAE,KAAK,CAAC,MAAM;KACpB,CAAC,CAAA;IAEJ,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,iBAAiB,CACf;YACE,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACvC,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;SACtC,EACD,GAAG,CACJ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;IACjD,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;IACnD,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A stable, non-reversible tenant label for metrics and logs.
3
+ *
4
+ * Truncated SHA-256 — enough to correlate a caller's requests, useless for
5
+ * recovering the key.
6
+ */
7
+ export declare function tenantLabel(apiKey: string): string;
8
+ /** Strip credential-bearing entries from an object before logging it. */
9
+ export declare function redact(value: Record<string, unknown>): Record<string, unknown>;
10
+ export declare function log(level: 'info' | 'warn' | 'error', message: string, fields?: Record<string, unknown>): void;
@@ -0,0 +1,43 @@
1
+ import { createHash } from 'node:crypto';
2
+ /**
3
+ * Header and field names that must never reach a log line. The tenancy test
4
+ * asserts this list is honoured.
5
+ */
6
+ const REDACTED_KEYS = new Set([
7
+ 'x-api-key',
8
+ 'authorization',
9
+ 'apikey',
10
+ 'api_key',
11
+ 'cookie',
12
+ 'set-cookie',
13
+ ]);
14
+ /**
15
+ * A stable, non-reversible tenant label for metrics and logs.
16
+ *
17
+ * Truncated SHA-256 — enough to correlate a caller's requests, useless for
18
+ * recovering the key.
19
+ */
20
+ export function tenantLabel(apiKey) {
21
+ return createHash('sha256').update(apiKey).digest('hex').slice(0, 12);
22
+ }
23
+ /** Strip credential-bearing entries from an object before logging it. */
24
+ export function redact(value) {
25
+ const out = {};
26
+ for (const [key, val] of Object.entries(value)) {
27
+ out[key] = REDACTED_KEYS.has(key.toLowerCase()) ? '[redacted]' : val;
28
+ }
29
+ return out;
30
+ }
31
+ export function log(level, message, fields = {}) {
32
+ const line = JSON.stringify({
33
+ level,
34
+ message,
35
+ ts: new Date().toISOString(),
36
+ ...redact(fields),
37
+ });
38
+ if (level === 'error')
39
+ console.error(line);
40
+ else
41
+ console.log(line);
42
+ }
43
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC;;;GAGG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,WAAW;IACX,eAAe;IACf,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,YAAY;CACb,CAAC,CAAA;AAEF;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AACvE,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,MAAM,CACpB,KAA8B;IAE9B,MAAM,GAAG,GAA4B,EAAE,CAAA;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/C,GAAG,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAA;IACtE,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,KAAgC,EAChC,OAAe,EACf,SAAkC,EAAE;IAEpC,MAAM,IAAI,GAAG,I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