@polytest/mcp 0.2.0 → 0.2.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.
- package/dist/failures.d.ts +1 -0
- package/dist/failures.js +10 -4
- package/dist/index.d.ts +1 -1
- package/dist/series.js +2 -1
- package/dist/tools.d.ts +12 -0
- package/dist/tools.js +14 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/failures.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Failure } from "@polytest/sdk";
|
|
2
2
|
export type Entry = "stdio" | "http_key" | "oauth";
|
|
3
|
+
export declare function reasonOf(text: string): string;
|
|
3
4
|
export declare function explainFailure(failure: Failure, entry: Entry): string;
|
|
4
5
|
export declare function explainError(error: unknown, entry: Entry): string;
|
|
5
6
|
export type RetryOptions = {
|
package/dist/failures.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isRetryable, PolyTestFailure, retryDelayMs } from "@polytest/sdk";
|
|
2
2
|
const KEYS_URL = "https://www.polytest.io/app/keys";
|
|
3
|
-
|
|
3
|
+
// An app directory may let a tool say what a plan covers and link plan details, but not point at billing or upgrades.
|
|
4
|
+
const PRICING_URL = "https://www.polytest.io/pricing";
|
|
4
5
|
const DOCS_URL = "https://www.polytest.io/docs/mcp";
|
|
5
6
|
// The SDK's error text when no key reached the client. Every other config failure names a bad key or option.
|
|
6
7
|
const NO_KEY = "Set POLYTEST_KEY or pass key.";
|
|
@@ -26,6 +27,11 @@ function sentence(text) {
|
|
|
26
27
|
const cut = clip(text);
|
|
27
28
|
return /[.!?]$/.test(cut) ? cut : `${cut}.`;
|
|
28
29
|
}
|
|
30
|
+
// The server's plan messages give the reason first and end with a call to upgrade or to pay, which is dropped.
|
|
31
|
+
export function reasonOf(text) {
|
|
32
|
+
const trimmed = text.trim();
|
|
33
|
+
return /^.*?[.!?](?=\s|$)/s.exec(trimmed)?.[0] ?? trimmed;
|
|
34
|
+
}
|
|
29
35
|
function wait(retryAfter) {
|
|
30
36
|
if (retryAfter === null)
|
|
31
37
|
return "Wait a few seconds, then retry.";
|
|
@@ -43,11 +49,11 @@ export function explainFailure(failure, entry) {
|
|
|
43
49
|
case "unauthorized":
|
|
44
50
|
return `PolyTest rejected the API key: ${sentence(failure.error)} ${KEY_FIX[entry]} Keys are listed at ${KEYS_URL}. Retrying with the same key will not help.`;
|
|
45
51
|
case "trial_exhausted":
|
|
46
|
-
return `The trial usage budget is used up. Its ${failure.dimension} limit of ${failure.limit} was reached.
|
|
52
|
+
return `The trial usage budget is used up. Its ${failure.dimension} limit of ${failure.limit} was reached. Plan details are at ${PRICING_URL}. Retrying will not help.`;
|
|
47
53
|
case "subscription_inactive":
|
|
48
|
-
return `
|
|
54
|
+
return `This PolyTest account has no active subscription or trial, so it cannot read data. Plan details are at ${PRICING_URL}. Retrying will not help until one is active.`;
|
|
49
55
|
case "forbidden":
|
|
50
|
-
return `PolyTest refused this request on the ${clip(failure.tier, 24)} plan: ${sentence(failure.message)} Call polytest_get_limits to see what the plan covers.
|
|
56
|
+
return `PolyTest refused this request on the ${clip(failure.tier, 24)} plan: ${sentence(reasonOf(failure.message))} Call polytest_get_limits to see what the plan covers. Plan details are at ${PRICING_URL}. Retrying will not help.`;
|
|
51
57
|
case "rate_limited":
|
|
52
58
|
return `The PolyTest rate limit was reached. ${wait(failure.retry_after)} Space out calls to avoid this.`;
|
|
53
59
|
case "concurrency_limited":
|
package/dist/index.d.ts
CHANGED
package/dist/series.js
CHANGED
|
@@ -2,7 +2,7 @@ import { PolyTestFailure } from "@polytest/sdk";
|
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
3
|
import { projectSnapshot } from "./budget.js";
|
|
4
4
|
import { sleep, withRetry } from "./failures.js";
|
|
5
|
-
import { optionalText, PRICE_DOWN, PRICE_UP, READ_ONLY, run } from "./tools.js";
|
|
5
|
+
import { optionalText, PRICE_DOWN, PRICE_UP, READ_ONLY, run, toolMeta } from "./tools.js";
|
|
6
6
|
const PACE_MS = 100;
|
|
7
7
|
const seriesInput = z.object({
|
|
8
8
|
market_id: z.string().describe("PolyTest market id from polytest_list_markets or polytest_get_market."),
|
|
@@ -139,5 +139,6 @@ export function registerPriceSeries(server, deps) {
|
|
|
139
139
|
inputSchema: seriesInput,
|
|
140
140
|
outputSchema: seriesOutput,
|
|
141
141
|
annotations: READ_ONLY,
|
|
142
|
+
...toolMeta(deps),
|
|
142
143
|
}, ({ market_id, samples, start_time, end_time }, ctx) => run(deps.entry, () => priceSeries(deps.client(), { market_id, samples, start_time, end_time }, { ...deps.retry, signal: ctx.mcpReq.signal, now: (deps.now ?? Date.now)() })));
|
|
143
144
|
}
|
package/dist/tools.d.ts
CHANGED
|
@@ -2,11 +2,23 @@ import type { CallToolResult, McpServer } from "@modelcontextprotocol/server";
|
|
|
2
2
|
import { type PolyTestClient } from "@polytest/sdk";
|
|
3
3
|
import * as z from "zod/v4";
|
|
4
4
|
import { type Entry, type RetryOptions } from "./failures.js";
|
|
5
|
+
export type SecurityScheme = {
|
|
6
|
+
type: "noauth";
|
|
7
|
+
} | {
|
|
8
|
+
type: "oauth2";
|
|
9
|
+
scopes: readonly string[];
|
|
10
|
+
};
|
|
5
11
|
export type ServerDeps = {
|
|
6
12
|
client: () => PolyTestClient;
|
|
7
13
|
entry: Entry;
|
|
8
14
|
retry?: RetryOptions;
|
|
9
15
|
now?: () => number;
|
|
16
|
+
securitySchemes?: readonly SecurityScheme[];
|
|
17
|
+
};
|
|
18
|
+
export declare function toolMeta(deps: ServerDeps): {
|
|
19
|
+
_meta?: {
|
|
20
|
+
securitySchemes: readonly SecurityScheme[];
|
|
21
|
+
};
|
|
10
22
|
};
|
|
11
23
|
export declare const READ_ONLY: {
|
|
12
24
|
readonly readOnlyHint: true;
|
package/dist/tools.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { MARKET_TYPES } from "@polytest/sdk";
|
|
2
2
|
import * as z from "zod/v4";
|
|
3
3
|
import { fitRows, MAX_OUTPUT_CHARS, projectMarket, projectMarketRow, projectSnapshot } from "./budget.js";
|
|
4
|
-
import { explainError, withRetry } from "./failures.js";
|
|
4
|
+
import { explainError, reasonOf, withRetry } from "./failures.js";
|
|
5
|
+
export function toolMeta(deps) {
|
|
6
|
+
return deps.securitySchemes === undefined ? {} : { _meta: { securitySchemes: deps.securitySchemes } };
|
|
7
|
+
}
|
|
5
8
|
export const READ_ONLY = {
|
|
6
9
|
readOnlyHint: true,
|
|
7
10
|
destructiveHint: false,
|
|
@@ -190,6 +193,10 @@ function note(parts) {
|
|
|
190
193
|
const text = parts.filter((part) => part !== undefined).join(" ");
|
|
191
194
|
return text === "" ? {} : { note: text };
|
|
192
195
|
}
|
|
196
|
+
// A server warning ends with a call to upgrade. Only its first sentence, which says what was left out, is kept.
|
|
197
|
+
function warningNote(warning) {
|
|
198
|
+
return warning === undefined ? undefined : reasonOf(warning);
|
|
199
|
+
}
|
|
193
200
|
// The newest market starting well before now means PolyTest has not loaded the most recent markets yet.
|
|
194
201
|
function ageNote(newest, nowMs) {
|
|
195
202
|
if (newest === undefined)
|
|
@@ -216,6 +223,7 @@ export function registerTools(server, deps) {
|
|
|
216
223
|
inputSchema: listMarketsInput,
|
|
217
224
|
outputSchema: listMarketsOutput,
|
|
218
225
|
annotations: READ_ONLY,
|
|
226
|
+
...toolMeta(deps),
|
|
219
227
|
}, ({ market_type, coin, start_time, end_time, limit, offset }, ctx) => run(deps.entry, async () => {
|
|
220
228
|
const client = deps.client();
|
|
221
229
|
const page = await withRetry(() => client.markets({ market_type, coin: coin.toLowerCase(), start_time, end_time, limit, offset }, { signal: ctx.mcpReq.signal }), deps.retry);
|
|
@@ -232,7 +240,7 @@ export function registerTools(server, deps) {
|
|
|
232
240
|
stop: fitted.truncated ? "more" : stop,
|
|
233
241
|
next_offset: fitted.truncated ? page.offset + fitted.rows.length : page.nextOffset,
|
|
234
242
|
truncated: fitted.truncated,
|
|
235
|
-
...note([page.warning, skippedNote(page.skipped), ageNote(newest, nowMs)]),
|
|
243
|
+
...note([warningNote(page.warning), skippedNote(page.skipped), ageNote(newest, nowMs)]),
|
|
236
244
|
};
|
|
237
245
|
}));
|
|
238
246
|
server.registerTool("polytest_get_market", {
|
|
@@ -241,6 +249,7 @@ export function registerTools(server, deps) {
|
|
|
241
249
|
inputSchema: getMarketInput,
|
|
242
250
|
outputSchema: getMarketOutput,
|
|
243
251
|
annotations: READ_ONLY,
|
|
252
|
+
...toolMeta(deps),
|
|
244
253
|
}, async ({ market_id, slug }, ctx) => {
|
|
245
254
|
const ref = marketRef(market_id, slug);
|
|
246
255
|
if (ref === null)
|
|
@@ -257,6 +266,7 @@ export function registerTools(server, deps) {
|
|
|
257
266
|
inputSchema: getSnapshotsInput,
|
|
258
267
|
outputSchema: getSnapshotsOutput,
|
|
259
268
|
annotations: READ_ONLY,
|
|
269
|
+
...toolMeta(deps),
|
|
260
270
|
}, ({ market_id, start_time, end_time, limit, offset, include_orderbook, orderbook_depth }, ctx) => run(deps.entry, async () => {
|
|
261
271
|
const sent = include_orderbook ? Math.min(limit, BOOK_PAGE_MAX) : limit;
|
|
262
272
|
const client = deps.client();
|
|
@@ -274,7 +284,7 @@ export function registerTools(server, deps) {
|
|
|
274
284
|
sent < limit
|
|
275
285
|
? `The limit was lowered from ${limit} to ${sent} because order books are included.`
|
|
276
286
|
: undefined,
|
|
277
|
-
page.warning,
|
|
287
|
+
warningNote(page.warning),
|
|
278
288
|
skippedNote(page.skipped),
|
|
279
289
|
]),
|
|
280
290
|
};
|
|
@@ -285,6 +295,7 @@ export function registerTools(server, deps) {
|
|
|
285
295
|
inputSchema: z.object({}),
|
|
286
296
|
outputSchema: getLimitsOutput,
|
|
287
297
|
annotations: READ_ONLY,
|
|
298
|
+
...toolMeta(deps),
|
|
288
299
|
}, (_args, ctx) => run(deps.entry, async () => {
|
|
289
300
|
const client = deps.client();
|
|
290
301
|
return projectLimits(await withRetry(() => client.limits({ signal: ctx.mcpReq.signal }), deps.retry));
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.2.
|
|
1
|
+
export declare const VERSION = "0.2.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.2.
|
|
1
|
+
export const VERSION = "0.2.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polytest/mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "MCP server for the PolyTest API. Read historical Polymarket crypto Up/Down market data from an MCP client.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.polytest.io/docs/mcp",
|