@coinrithm/mcp-trading 0.7.14 → 0.7.15

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.
package/dist/client.js CHANGED
@@ -71,6 +71,9 @@ const applyAgentTraceHeaders = (headers, trace) => {
71
71
  const traceFromBody = (body) => body && typeof body === "object" && "agentTrace" in body
72
72
  ? body.agentTrace
73
73
  : undefined;
74
+ // Where a user mints an API key (Settings -> API Keys). Named in every
75
+ // missing-key error so an assistant can tell its user where to go.
76
+ export const API_KEY_MINT_URL = "https://www.coinrithm.com/en/settings/api-keys";
74
77
  export class CoinRithmClient {
75
78
  // Default key for the stdio (single-user) path. Undefined in the multi-user
76
79
  // HTTP path, where every call must pass a per-request `apiKey` override.
@@ -88,8 +91,10 @@ export class CoinRithmClient {
88
91
  status: 401,
89
92
  data: {
90
93
  error: "missing_api_key",
91
- message: "No API key for this request. On the hosted MCP, send " +
92
- "`Authorization: Bearer crk_live_…` with your own key.",
94
+ message: "No API key for this request. Mint a free key at " +
95
+ `${API_KEY_MINT_URL}, then on the hosted MCP send ` +
96
+ "`Authorization: Bearer crk_live_…`. Public data tools " +
97
+ "(pm_data_*, get_arena_*, get_crypto_movers) need no key.",
93
98
  },
94
99
  };
95
100
  }
@@ -337,6 +342,13 @@ export class CoinRithmClient {
337
342
  getCandles(coinId, query, apiKey, agentTrace) {
338
343
  return this.request("GET", `/api/agent/market/${encodeURIComponent(coinId)}/candles`, { query, apiKey, agentTrace });
339
344
  }
345
+ getNews(query, apiKey, agentTrace) {
346
+ return this.request("GET", "/api/agent/news", {
347
+ query,
348
+ apiKey,
349
+ agentTrace,
350
+ });
351
+ }
340
352
  discoverPmMarkets(query, apiKey, agentTrace) {
341
353
  return this.request("GET", "/api/agent/pm/discover", {
342
354
  query,
@@ -364,15 +376,15 @@ export class CoinRithmClient {
364
376
  agentTrace,
365
377
  });
366
378
  }
367
- // Agent Arena (public leaderboard). The key is sent but ignored by these
368
- // endpoints — they expose only public agent names + realized performance.
369
- getArenaLeaderboard(query, apiKey) {
370
- return this.request("GET", "/api/arena", { query, apiKey });
379
+ // Agent Arena (public leaderboard): public agent names + realized
380
+ // performance only, served keyless by the API. These used to go through
381
+ // the keyed path, so a keyless MCP client got a 401 for public data
382
+ // (21 of 44 keyless tool calls failed in 14.6h, audit 2026-09-29).
383
+ getArenaLeaderboard(query) {
384
+ return this.publicRequest("/api/arena", query);
371
385
  }
372
- getArenaAgent(handle, apiKey) {
373
- return this.request("GET", `/api/arena/${encodeURIComponent(handle)}`, {
374
- apiKey,
375
- });
386
+ getArenaAgent(handle) {
387
+ return this.publicRequest(`/api/arena/${encodeURIComponent(handle)}`);
376
388
  }
377
389
  listOpenOrders(query, apiKey, agentTrace) {
378
390
  return this.request("GET", "/api/agent/orders/open", {
package/dist/http.d.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { CoinRithmClient } from "./client.js";
4
4
  import { type CompletionLogger } from "./httpCompletion.js";
5
+ export declare const MALFORMED_MCP_LINK: RegExp;
5
6
  export declare function createHttpApp(client: CoinRithmClient, options?: {
6
7
  completionLogger?: CompletionLogger;
7
8
  createServer?: () => McpServer;
package/dist/http.js CHANGED
@@ -34,6 +34,7 @@
34
34
  // Transport is stateless: a fresh McpServer + transport per request, which is
35
35
  // the correct isolation model for a multi-user, per-request-keyed surface — no
36
36
  // session state is shared between users.
37
+ import { SERVER_INSTRUCTIONS } from "./instructions.js";
37
38
  import express from "express";
38
39
  import { pathToFileURL } from "node:url";
39
40
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -42,6 +43,9 @@ import { CoinRithmClient, bearerFromHeader, loadHttpConfig, log, } from "./clien
42
43
  import { registerTools } from "./tools.js";
43
44
  import { SERVER_VERSION } from "./version.js";
44
45
  import { observeHttpCompletion, } from "./httpCompletion.js";
46
+ // "/mcp" immediately followed by the markdown "](" of a pasted link, literal or
47
+ // percent-encoded. Anything else under /mcp is not this family.
48
+ export const MALFORMED_MCP_LINK = /^\/mcp(?:\]|%5d)(?:\(|%28)/i;
45
49
  // Factory permits isolated localhost SDK tests without opening a listener on import.
46
50
  export function createHttpApp(client, options = {}) {
47
51
  const app = express();
@@ -108,13 +112,24 @@ export function createHttpApp(client, options = {}) {
108
112
  app.get("/robots.txt", (_req, res) => {
109
113
  res.type("text/plain").send("User-agent: *\nDisallow: /\n");
110
114
  });
115
+ // Recover one observed malformed URL family. A markdown link to this
116
+ // endpoint circulates with its "](https://…)" suffix pasted into the path,
117
+ // e.g. GET /mcp](https:/mcp.coinrithm.com/mcp): 408 such requests on
118
+ // 2026-09-25, all Claude-User web fetches that received Express's default
119
+ // 404. GET/HEAD go to the service descriptor. POST is served as MCP below:
120
+ // on 2026-09-26, 127 Claude-User connector POSTs in 6 h hit the same path
121
+ // and got 404, so a user who pasted that URL into a connector could never
122
+ // initialize. Every other unknown path behaves as before.
123
+ app.get(MALFORMED_MCP_LINK, (_req, res) => {
124
+ res.redirect(302, "/");
125
+ });
111
126
  app.get("/mcp", (_req, res) => {
112
127
  res.status(405).json({
113
128
  error: "method_not_allowed",
114
129
  message: "This is a POST-only streamable-HTTP MCP endpoint. Connect with an MCP client, or GET / for service info.",
115
130
  });
116
131
  });
117
- app.post("/mcp", async (req, res) => {
132
+ app.post(["/mcp", MALFORMED_MCP_LINK], async (req, res) => {
118
133
  // Per-request auth: read THIS caller's key from the Authorization header,
119
134
  // or from Smithery's non-reserved forwarding header.
120
135
  // It is optional at the transport layer so registries can initialize the
@@ -132,7 +147,7 @@ export function createHttpApp(client, options = {}) {
132
147
  new McpServer({
133
148
  name: "coinrithm-trading",
134
149
  version: SERVER_VERSION,
135
- });
150
+ }, { instructions: SERVER_INSTRUCTIONS });
136
151
  if (!options.createServer)
137
152
  registerTools(server, client);
138
153
  const transport = new StreamableHTTPServerTransport({
@@ -1,6 +1,6 @@
1
1
  import type { IncomingMessage, ServerResponse } from "node:http";
2
2
  import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
3
- export declare const COMPLETION_TOOL_NAMES: readonly ["whoami", "get_portfolio", "get_wallet", "list_open_orders", "get_positions", "resolve_symbol", "get_equity_curve", "get_my_trades", "get_market_context", "get_candles", "discover_pm_markets", "get_performance", "get_agent_ledger", "export_agent_ledger", "export_run_evidence", "get_arena_leaderboard", "get_arena_agent", "futures_quote", "pm_quote", "spot_quote", "place_spot_order", "cancel_spot_order", "open_futures_position", "set_futures_sl_tp", "close_futures_position", "open_pm_position", "report_pm_opportunity", "pm_data_overview", "pm_data_sources", "pm_data_sources_health", "pm_data_events", "pm_data_event", "pm_data_whales", "pm_data_whale_wallets", "pm_data_whale_wallet", "pm_data_disagreements", "pm_data_calibration", "pm_data_canonical", "pm_data_volume_history", "get_crypto_movers"];
3
+ export declare const COMPLETION_TOOL_NAMES: readonly ["whoami", "get_portfolio", "get_wallet", "list_open_orders", "get_positions", "resolve_symbol", "get_equity_curve", "get_my_trades", "get_market_context", "get_candles", "get_news", "discover_pm_markets", "get_performance", "get_agent_ledger", "export_agent_ledger", "export_run_evidence", "get_arena_leaderboard", "get_arena_agent", "futures_quote", "pm_quote", "spot_quote", "place_spot_order", "cancel_spot_order", "open_futures_position", "set_futures_sl_tp", "close_futures_position", "open_pm_position", "report_pm_opportunity", "pm_data_overview", "pm_data_sources", "pm_data_sources_health", "pm_data_events", "pm_data_event", "pm_data_whales", "pm_data_whale_wallets", "pm_data_whale_wallet", "pm_data_disagreements", "pm_data_calibration", "pm_data_canonical", "pm_data_volume_history", "get_crypto_movers"];
4
4
  type Operation = "initialize" | "tools_list" | "tools_call" | "notification" | "other" | "invalid";
5
5
  type Outcome = "result" | "tool_error" | "protocol_error" | "no_response" | "not_applicable";
6
6
  type ToolName = (typeof COMPLETION_TOOL_NAMES)[number] | "unknown" | null;
@@ -13,6 +13,7 @@ export const COMPLETION_TOOL_NAMES = [
13
13
  "get_my_trades",
14
14
  "get_market_context",
15
15
  "get_candles",
16
+ "get_news",
16
17
  "discover_pm_markets",
17
18
  "get_performance",
18
19
  "get_agent_ledger",
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@
10
10
  // COINRITHM_API_URL (optional) base URL; defaults to https://api.coinrithm.com
11
11
  //
12
12
  // stdout is the JSON-RPC channel — we log ONLY to stderr.
13
+ import { SERVER_INSTRUCTIONS } from "./instructions.js";
13
14
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
14
15
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
15
16
  import { CoinRithmClient, loadConfig, log } from "./client.js";
@@ -21,7 +22,7 @@ async function main() {
21
22
  const server = new McpServer({
22
23
  name: "coinrithm-trading",
23
24
  version: SERVER_VERSION,
24
- });
25
+ }, { instructions: SERVER_INSTRUCTIONS });
25
26
  registerTools(server, client);
26
27
  const transport = new StdioServerTransport();
27
28
  await server.connect(transport);
@@ -0,0 +1 @@
1
+ export declare const SERVER_INSTRUCTIONS: string;
@@ -0,0 +1,16 @@
1
+ import { API_KEY_MINT_URL } from "./client.js";
2
+ import { PAPER_NOTE } from "./tools.js";
3
+ // Sent once in the MCP `initialize` result. Guidance that used to be repeated
4
+ // on every tool description lives here, so the tool list stays small enough to
5
+ // fit an assistant's context (tools/list was 114,668 bytes with the ~512-char
6
+ // paper disclaimer on 25 tools, audit 2026-09-29).
7
+ export const SERVER_INSTRUCTIONS = [
8
+ "CoinRithm MCP: crypto and prediction-market data from 12 venues, plus paper trading.",
9
+ "Start keyless: the pm_data_* tools, get_arena_leaderboard, get_arena_agent and get_crypto_movers need no API key.",
10
+ "pm_data_events returns open markets by default; pass status=closed or status=all for history.",
11
+ `Tools that read or act on an account need a key. The user mints one at ${API_KEY_MINT_URL}; start with a read-only key.`,
12
+ "Every tool returns { httpStatus, ok, ledgerEventId, ledgerStatus, body }: httpStatus is CoinRithm's HTTP status (0 = network error), ok means 2xx, body is the parsed response.",
13
+ "Always quote before a paper write (spot_quote, futures_quote or pm_quote), then open with that quote.",
14
+ "Prediction-market probabilities are venue prices, not CoinRithm forecasts. referenceProbability is a cross-venue consensus with a disagreement band (spreadPoints).",
15
+ PAPER_NOTE,
16
+ ].join("\n");
package/dist/tools.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { CoinRithmClient } from "./client.js";
3
3
  export declare const PAPER_NOTE: string;
4
+ export declare const PAPER_NOTE_SHORT: string;
4
5
  /**
5
6
  * Keep keyless discovery calls small enough for an agent context window.
6
7
  * Full event evidence remains available from pm_data_event.