diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index 8bd67ee..5b90fd1 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "cloro", "displayName": "cloro", - "version": "0.7.0", + "version": "0.9.0", "description": "Query ChatGPT, Gemini, Google AI Mode, Bing AI Mode, Google Search, Google News and Bing Search as agent tools, with country and state-level geo-targeting.", "author": { "name": "cloro", diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0a169c..bc4caf0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: run: npm run build # The build is only useful if the server still speaks MCP. Run a real - # initialize + tools/list handshake over stdio and assert the ten tools + # initialize + tools/list handshake over stdio and assert the twelve tools # are registered, so a broken tool module fails here rather than in a # client. - name: Smoke test the MCP handshake @@ -48,8 +48,8 @@ jobs: .find((m) => m.id === 2)?.result?.tools; if (!tools) throw new Error("no tools/list response"); console.log(`${tools.length} tools: ${tools.map((t) => t.name).join(", ")}`); - if (tools.length !== 10) { - throw new Error(`expected 10 tools, got ${tools.length}`); + if (tools.length !== 12) { + throw new Error(`expected 12 tools, got ${tools.length}`); } }); ' diff --git a/README.md b/README.md index e279c4e..49bca76 100644 --- a/README.md +++ b/README.md @@ -65,13 +65,17 @@ OAuth is off unless you set `CLERK_ISSUER`. The hosted server sets it to `https: | `scrape_bing` | [`POST /v1/monitor/bing`](https://cloro.dev/docs/api-reference/endpoint/monitor-bing) | | `scrape_google_news` | [`POST /v1/monitor/google/news`](https://cloro.dev/docs/api-reference/endpoint/monitor-google-news) | | `resolve_google_redirect` | [`POST /v1/monitor/google/goto`](https://cloro.dev/docs/api-reference/endpoint/google/resolve-goto) | +| `get_google_product` | [`POST /v1/monitor/google/product`](https://cloro.dev/docs/api-reference/endpoint/google/product) | | `list_countries` | [`GET /v1/countries`](https://cloro.dev/docs/api-reference/endpoint/countries) | | `list_states` | [`GET /v1/states`](https://cloro.dev/docs/api-reference/endpoint/states) | +| `get_credits` | [`GET /v1/credits`](https://cloro.dev/docs/api-reference/endpoint/get-credits) | The assistant tools take a `prompt` and a `country` (ISO 3166-1 alpha-2), plus an optional `state` for US state-level targeting. The Google tools take `gl` for the result geography and an optional `hl` for the interface language; `country` still works as a deprecated alias for `gl`. `scrape_google_ai_mode` targets sub-country with `location` or `uule` rather than `state`. `scrape_google` runs either from a `query` plus `gl`, or from a complete `google.com/search` URL that carries the query and pagination itself, and accepts `include.aioverview` for Google's AI Overview. `scrape_bing` takes a `query` and a `country`, which picks Bing's market, plus an optional `pages` and `first`. It has no `state` or `device` option, and accepts `include.aioverview` for Bing's AI Overview. Every tool takes an optional `include` object for heavier payload fields; leave it unset for the leanest response. A Google result `link` can come back empty, or as a `google.com/goto` URL, with a `redirectLink` beside it. Pass the `redirectLink` to `resolve_google_redirect` to get the destination. +A shopping card or inline product from `scrape_google` or `scrape_google_ai_mode` can carry a `productResultToken`. Pass it to `get_google_product` within 5 minutes of that scrape to get the full product: offers, images, specifications and reviews. + There is no Grok tool. Grok is discontinued: grok.com shows a sign-up wall to logged-out visitors, and the cloro API rejects Grok calls with a `400` (`MODEL_UNAVAILABLE`). There are no Copilot or Perplexity tools. Both are discontinued: they block access for logged-out sessions, and the cloro API rejects their calls with a `400` (`MODEL_UNAVAILABLE`). These calls cost no credits. @@ -92,7 +96,7 @@ No. `mcp.cloro.dev` is hosted and is the path most people should take. This repo ### Does it cost credits? -Yes. The scrape tools call the sync API, so each call costs the API rate plus a 2-credit sync surcharge. For example, a ChatGPT call costs 7 credits (5 + 2). Each tool description states its cost, and each result returns the credits charged and remaining. `resolve_google_redirect` costs 1 credit, with no surcharge. `list_countries` and `list_states` read fixed reference lists and charge nothing. See [pricing](https://cloro.dev/pricing/). +Yes. The scrape tools call the sync API, so each call costs the API rate plus a 2-credit sync surcharge. For example, a ChatGPT call costs 7 credits (5 + 2). Each tool description states its cost, and each result returns the credits charged and remaining. `get_google_product` costs 1 credit plus the surcharge, and only when the product is returned. `resolve_google_redirect`, `get_credits`, `list_countries` and `list_states` charge nothing. See [pricing](https://cloro.dev/pricing/). ### Why is my API key in the URL? diff --git a/package.json b/package.json index b206b65..3b0c11c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cloro/mcp-server", - "version": "0.7.0", + "version": "0.9.0", "description": "MCP server for the cloro API. Query ChatGPT, Gemini, Google AI Mode, Bing AI Mode, Google Search, Google News and Bing Search as agent tools.", "license": "MIT", "type": "module", diff --git a/server.json b/server.json index f29e703..c62b63f 100644 --- a/server.json +++ b/server.json @@ -3,7 +3,7 @@ "name": "dev.cloro/cloro", "title": "cloro", "description": "Scrape AI answer engines, Google Search/News and Bing Search with country and state geo-targeting.", - "version": "0.7.0", + "version": "0.9.0", "websiteUrl": "https://cloro.dev/docs/integrations/mcp", "repository": { "url": "https://github.com/cloro-dev/mcp-server", diff --git a/src/schemas/chatgpt.schema.ts b/src/schemas/chatgpt.schema.ts index 8540c7b..0a06811 100644 --- a/src/schemas/chatgpt.schema.ts +++ b/src/schemas/chatgpt.schema.ts @@ -6,6 +6,7 @@ import { ALL_COUNTRY_CODES } from "./all-countries"; import { getAvailableCountries } from "./utils"; const CHATGPT_BLOCKED_COUNTRIES: string[] = [ + "BY", // Belarus "CN", // China "HK", // Hong Kong "IR", // Iran diff --git a/src/schemas/google-product.schema.ts b/src/schemas/google-product.schema.ts new file mode 100644 index 0000000..6d6612d --- /dev/null +++ b/src/schemas/google-product.schema.ts @@ -0,0 +1,5 @@ +import { z } from "zod"; + +export const googleProductSchema = z.strictObject({ + productResultToken: z.string().trim().min(1).max(512), +}); diff --git a/src/schemas/google-url.ts b/src/schemas/google-url.ts index fee8f25..3d8103d 100644 --- a/src/schemas/google-url.ts +++ b/src/schemas/google-url.ts @@ -8,8 +8,8 @@ * the location encoding — so the worker needs no knowledge of `url` mode to * serve the request. * - * The supported set is closed: `q`, `gl`, `hl`, `uule`, `start`, `tbs`, `safe` - * (plus `num`, read as depth). Params outside it are dropped rather than + * The supported set is closed: `q`, `gl`, `hl`, `uule`, `start`, `tbs`, `safe`, + * `udm` (plus `num`, read as depth). Params outside it are dropped rather than * forwarded, so the queue message stays a typed contract the worker can rely * on instead of an arbitrary bag whose keys nothing validates. * @@ -61,6 +61,8 @@ export type GoogleUrlParsed = { tbs: string | null; /** `safe` — SafeSearch setting, passed through untouched. */ safe: string | null; + /** `udm` — the results tab. Only 14, the Web tab, is read. */ + udm: 14 | null; }; export type GoogleUrlParseResult = @@ -161,5 +163,6 @@ export const parseGoogleSearchUrl = (raw: string): GoogleUrlParseResult => { ), tbs: readTrimmed(url.searchParams, "tbs"), safe: readTrimmed(url.searchParams, "safe"), + udm: readTrimmed(url.searchParams, "udm") === "14" ? 14 : null, }; }; diff --git a/src/schemas/google.schema.ts b/src/schemas/google.schema.ts index 175e47e..3a16d09 100644 --- a/src/schemas/google.schema.ts +++ b/src/schemas/google.schema.ts @@ -51,6 +51,9 @@ export const googleSchema = z // "caller sent pages" from "caller sent nothing". The default is applied in // the transform, so parsed output is unchanged for structured requests. pages: z.number().positive().max(10).optional(), + // Google's `udm`, the results tab to search. 14 is the Web tab, the only + // one served besides the default. + udm: z.literal(14).optional(), include: z .object({ html: z.boolean(), @@ -59,6 +62,14 @@ export const googleSchema = z z .object({ markdown: z.boolean(), + /** + * Store the HTML page with the AI Overview opened ("Show more" + * clicked). By default the page shows it as a browser does + * after load: Google opens some itself and leaves others + * collapsed. Desktop only: on phones "Show more" opens AI Mode. + * The parsed `aioverview` is the full answer either way. + */ + expand: z.boolean(), }) .partial(), ]), @@ -78,6 +89,9 @@ export const googleSchema = z }) .partial() .optional(), + // Temporary (ENG-1238): asks for the datacenter worker fleet. Only cloro's + // own organization is routed there. + datacenter: z.boolean().optional(), }) .refine((data) => !(data.location && data.uule), { message: "Cannot set both location and uule; provide only one", @@ -230,5 +244,8 @@ export const googleSchema = z startOffset: parsed.startOffset as number | undefined, tbs: parsed.tbs ?? undefined, safe: parsed.safe ?? undefined, + // The body's `udm` and the URL's can each only be 14, so they cannot + // disagree the way `hl` / `gl` can. + udm: data.udm ?? parsed.udm ?? undefined, }; }); diff --git a/src/schemas/index.ts b/src/schemas/index.ts index e456c76..7069125 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -17,6 +17,7 @@ export * from "./gemini.schema"; export * from "./google.schema"; export * from "./google-news.schema"; export * from "./google-goto.schema"; +export * from "./google-product.schema"; export * from "./grok.schema"; export * from "./perplexity.schema"; export * from "./country.schema"; diff --git a/src/server.test.ts b/src/server.test.ts index 9555cb5..074dcf3 100644 --- a/src/server.test.ts +++ b/src/server.test.ts @@ -15,17 +15,23 @@ import { buildServer } from "./server"; import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js"; +// Free reads of cloro's own data: no credit cost, no live engine. +const isReferenceTool = (name: string): boolean => + name.startsWith("list_") || name === "get_credits"; + const EXPECTED_TOOLS = [ "scrape_chatgpt", "scrape_gemini", - "scrape_google_ai_mode", "scrape_bing_aimode", + "scrape_google_ai_mode", "scrape_google", "scrape_bing", "scrape_google_news", "resolve_google_redirect", + "get_google_product", "list_countries", "list_states", + "get_credits", ]; type ToolSchema = { @@ -82,8 +88,8 @@ describe("cloro MCP server", () => { expect(tool.annotations?.readOnlyHint, tool.name).toBe(true); expect(tool.annotations?.destructiveHint, tool.name).toBe(false); // Monitor tools hit live external engines and re-charge on every - // call; reference lookups read fixed lists and are free to repeat. - const isReference = tool.name.startsWith("list_"); + // call; reference lookups read cloro's own data and are free to repeat. + const isReference = isReferenceTool(tool.name); expect(tool.annotations?.openWorldHint, tool.name).toBe(!isReference); expect(tool.annotations?.idempotentHint, tool.name).toBe( isReference ? true : undefined, @@ -103,7 +109,7 @@ describe("cloro MCP server", () => { // conform, so only the tools with a fixed response shape declare one. it("declares an outputSchema only on the reference tools", () => { for (const tool of tools) { - const isReference = tool.name.startsWith("list_"); + const isReference = isReferenceTool(tool.name); expect(Boolean(tool.outputSchema), tool.name).toBe(isReference); } }); @@ -153,6 +159,16 @@ describe("cloro MCP server", () => { expect(tool.inputSchema.required ?? []).toEqual([]); }); + it("keeps the internal datacenter flag off scrape_google", () => { + const tool = tools.find((t) => t.name === "scrape_google")!; + expect(tool.inputSchema.properties).not.toHaveProperty("datacenter"); + }); + + it("offers udm on scrape_google, with 14 as its only value", () => { + const tool = tools.find((t) => t.name === "scrape_google")!; + expect(tool.inputSchema.properties?.udm).toMatchObject({ const: 14 }); + }); + it("advertises scrape_google's public include flags", () => { const tool = tools.find((t) => t.name === "scrape_google")!; const includeProps = tool.inputSchema.properties?.include?.properties; @@ -435,7 +451,7 @@ describe("cloro MCP server", () => { it("states the credit cost in every monitor tool description", async () => { const { tools: listed } = await client.listTools(); for (const tool of listed) { - if (tool.name.startsWith("list_")) continue; + if (isReferenceTool(tool.name)) continue; expect(tool.description, tool.name).toMatch(/Costs \d+ credits?/); } }); diff --git a/src/server.ts b/src/server.ts index 4c2ed75..e81b58f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -11,17 +11,19 @@ import { registerReferenceTools } from "./tools/reference-tools"; */ const INSTRUCTIONS = `cloro scrapes AI answer engines (ChatGPT, Gemini, Google AI Mode, Bing AI Mode), Google Search and News, and Bing Search, geo-targeted by country. -Costs: every scrape tool calls the sync API and costs its base credits, plus any add-ons, plus a 2-credit sync surcharge. Each tool description states its cost. Each result carries credits.charged and credits.remaining. list_countries and list_states are free. resolve_google_redirect costs 1 credit and has no surcharge. +Costs: every scrape tool calls the sync API and costs its base credits, plus any add-ons, plus a 2-credit sync surcharge. Each tool description states its cost. Each result carries credits.charged and credits.remaining. list_countries, list_states, get_credits and resolve_google_redirect are free. get_google_product costs 1 credit plus the sync surcharge. Large or long-running jobs: these tools wait for the answer, up to about 5 minutes per call. For many prompts, or for scheduled runs, use the async API (POST /v1/async/task and /v1/async/task/batch, https://cloro.dev/docs) directly instead. It has no sync surcharge and returns results by webhook or polling. -Empty links: a Google result link can come back empty, missing, or as a google.com/goto URL, with a redirectLink beside it. Pass that redirectLink to resolve_google_redirect to get the destination. Do not open a /goto URL yourself.`; +Empty links: a Google result link can come back empty, missing, or as a google.com/goto URL, with a redirectLink beside it. Pass that redirectLink to resolve_google_redirect to get the destination. Do not open a /goto URL yourself. + +Product details: a Google or AI Mode shopping card or inline product can carry a productResultToken. Pass it to get_google_product within 5 minutes of the scrape that returned it. A 410 means the token expired; run the scrape again for a new token.`; export function buildServer(apiKey: string): McpServer { const server = new McpServer( { name: "cloro", - version: "0.7.0", + version: "0.9.0", }, { instructions: INSTRUCTIONS }, ); diff --git a/src/tools/monitor-tools.ts b/src/tools/monitor-tools.ts index 659d87d..4635154 100644 --- a/src/tools/monitor-tools.ts +++ b/src/tools/monitor-tools.ts @@ -6,6 +6,7 @@ import { geminiSchema, googleNewsSchema, googleGotoSchema, + googleProductSchema, googleSchema, } from "../schemas"; import { z } from "zod"; @@ -41,6 +42,14 @@ const CHATGPT_LEGACY_DOC = const CHATGPT_DISABLE_WEB_SEARCH_DOC = "Stop cloro from forcing web search, to get the answer ChatGPT gives on its own. ChatGPT then searches only when it decides to, so expect empty sources, citationPills and searchQueries. Defaults to false (web search forced). Same cost."; +// googleSchema is a ZodPipe (object -> transform) since url-mode decomposition +// (ENG-536); the tool advertises the pipe's input object, minus the internal +// datacenter flag. Filtering the shape avoids .omit(), which Zod rejects on +// refined objects. +const GOOGLE_INPUT_SHAPE = Object.fromEntries( + Object.entries(googleSchema.in.shape).filter(([key]) => key !== "datacenter"), +) as Omit; + const promptDoc = (engine: string) => `The prompt to submit to ${engine}.`; const QUERY_DOC = "The search query."; const LOCATION_DOC = @@ -142,12 +151,26 @@ const MONITOR_TOOLS: MonitorTool[] = [ shape: geminiSchema.shape, cost: costDoc(4, STATE_COST), }), + promptEngineTool({ + name: "scrape_bing_aimode", + path: "/v1/monitor/bing/aimode", + title: "Scrape Bing AI Mode", + engine: "Bing AI Mode", + description: + "Submit a prompt to Bing AI Mode from a chosen country (and optionally US state) and return the answer text, cited sources and inline citation pills. Use this to see how Bing AI Mode answers a prompt and which brands/sources it mentions.", + shape: bingAimodeSchema.shape, + cost: costDoc(4, STATE_COST), + extraDocs: { + prompt: BING_AIMODE_PROMPT_DOC, + include: BING_AIMODE_INCLUDE_DOC, + }, + }), { name: "scrape_google_ai_mode", path: "/v1/monitor/aimode", title: "Scrape Google AI Mode", description: - "Submit a prompt to Google AI Mode from a chosen country and return the AI answer with cited sources. Supports location or UULE targeting and desktop/mobile emulation." + + "Submit a prompt to Google AI Mode from a chosen country and return the AI answer with cited sources. Supports location or UULE targeting and desktop/mobile emulation. An entry in shoppingCards or inlineProducts can carry a productResultToken; pass it to get_google_product within 5 minutes to get the full product." + costDoc(4), // aimodeSchema is a ZodPipe (object -> transform) since geo // normalization; the tool advertises the pipe's input object. @@ -162,33 +185,17 @@ const MONITOR_TOOLS: MonitorTool[] = [ include: AIMODE_INCLUDE_DOC, }), }, - promptEngineTool({ - name: "scrape_bing_aimode", - path: "/v1/monitor/bing/aimode", - title: "Scrape Bing AI Mode", - engine: "Bing AI Mode", - description: - "Submit a prompt to Bing AI Mode from a chosen country (and optionally US state) and return the answer text, cited sources and inline citation pills. Use this to see how Bing AI Mode answers a prompt and which brands/sources it mentions.", - shape: bingAimodeSchema.shape, - cost: costDoc(4, STATE_COST), - extraDocs: { - prompt: BING_AIMODE_PROMPT_DOC, - include: BING_AIMODE_INCLUDE_DOC, - }, - }), { name: "scrape_google", path: "/v1/monitor/google", title: "Scrape Google Search", description: - "Run a Google search from a chosen country and return organic results, with optional AI Overview extraction (include.aioverview) and People-Also-Ask AI answers (include.paaAioverview). Two modes: structured (query + gl, with optional location/uule/pages) or url (a complete google.com/search URL that owns query, location, and pagination). Supports desktop, mobile, iOS, and Android emulation and multi-page results. A result link can come back empty with a redirectLink beside it; pass the redirectLink to resolve_google_redirect to get the destination." + + "Run a Google search from a chosen country and return organic results, with optional AI Overview extraction (include.aioverview) and People-Also-Ask AI answers (include.paaAioverview). Two modes: structured (query + gl, with optional location/uule/pages) or url (a complete google.com/search URL that owns query, location, and pagination). Supports desktop, mobile, iOS, and Android emulation and multi-page results. A result link can come back empty with a redirectLink beside it; pass the redirectLink to resolve_google_redirect to get the destination. An entry in shoppingCards or aioverview.inlineProducts can carry a productResultToken; pass it to get_google_product within 5 minutes to get the full product." + costDoc( 3, `include.aioverview and/or include.paaAioverview add 2 once; ${PAGES_COST}`, ), - // googleSchema is a ZodPipe (object -> transform) since url-mode - // decomposition (ENG-536); the tool advertises the pipe's input object. - inputSchema: describeFields(googleSchema.in.shape, { + inputSchema: describeFields(GOOGLE_INPUT_SHAPE, { query: "The search query. Required unless url is provided.", url: "A complete google.com/search URL to fetch instead of building one from structured fields. When set, query/location/uule/pages must be omitted (the URL owns them); gl and hl are read from the URL's gl/hl parameters; an explicit gl or hl must agree with the URL's copy.", country: GOOGLE_COUNTRY_DOC, @@ -202,6 +209,7 @@ const MONITOR_TOOLS: MonitorTool[] = [ uule: UULE_DOC, device: GOOGLE_DEVICE_DOC, pages: PAGES_DOC, + udm: "Optional. Set to 14 to search Google's Web tab, which lists web results only. No other value is accepted. In url mode, udm=14 inside the URL does the same.", include: "Optional flags. Set aioverview: true to extract Google's AI Overview (or { markdown: true } for markdown), paaAioverview: true to hydrate AI answers in People Also Ask. Leave unset for organic results only.", }), @@ -248,11 +256,23 @@ const MONITOR_TOOLS: MonitorTool[] = [ path: "/v1/monitor/google/goto", title: "Resolve a Google redirect link", description: - "Resolve one Google redirect link to its destination URL. Use it when a link or url field from scrape_google, scrape_google_news or scrape_google_ai_mode is empty, missing, or a google.com/goto URL: pass that result's redirectLink. Returns { url }. A link that does not resolve returns a 502; retry it later. Costs 1 credit, with no sync surcharge, and only when the destination is returned.", + "Resolve one Google redirect link to its destination URL. Use it when a link or url field from scrape_google, scrape_google_news or scrape_google_ai_mode is empty, missing, or a google.com/goto URL: pass that result's redirectLink. Returns { url }. A link that does not resolve returns a 502; retry it later. Costs 0 credits.", inputSchema: describeFields(googleGotoSchema.shape, { url: "The redirectLink value: an absolute https://www.google.com/goto?url=... or https://www.google.com/url?... link.", }), }, + { + name: "get_google_product", + path: "/v1/monitor/google/product", + title: "Get a Google product", + description: + "Get the full details of one Google shopping product: merchant offers, images, description, specifications, reviews and related products. Pass a productResultToken from scrape_google (result.shoppingCards[] or result.aioverview.inlineProducts[]) or scrape_google_ai_mode (result.shoppingCards[] or result.inlineProducts[]). A token lasts at most 5 minutes from the scrape that issued it, so call this tool directly after that scrape. Returns result.productResults with one product. A 410 (productResultTokenExpired) means the token expired: run the scrape again to get a new token. A 404 (productResultTokenUnknown) means the token is not recognized. A 502 means Google returned no usable product data." + + costDoc(1, "charged only when the product is returned"), + inputSchema: describeFields(googleProductSchema.shape, { + productResultToken: + "The productResultToken value from a shopping card or inline product of a scrape_google or scrape_google_ai_mode result. Send it unchanged.", + }), + }, ]; export function registerMonitorTools( diff --git a/src/tools/reference-tools.ts b/src/tools/reference-tools.ts index 9149e85..223981d 100644 --- a/src/tools/reference-tools.ts +++ b/src/tools/reference-tools.ts @@ -8,8 +8,8 @@ import { structuredToolResult } from "../lib/tool-result"; import type { CloroClient } from "../lib/cloro-client"; import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; -// Both tools read cloro's own fixed reference lists: no external entities, and -// repeat calls return the same data without charging credits. +// These tools read cloro's own data: no external entities, and repeat calls +// charge no credits and change nothing. const REFERENCE_ANNOTATIONS = { ...BASE_READ_ONLY_ANNOTATIONS, idempotentHint: true, @@ -28,6 +28,22 @@ const STATES_OUTPUT = { .array(z.object({ code: z.string(), name: z.string() })) .describe("States available for state-level targeting."), }; +// GET /v1/credits (apps/api/src/controllers/v1/fetch-credits.ts). The balance +// changes between calls, but a read charges nothing and changes nothing, so +// the tool keeps the reference annotations. +const CREDITS_OUTPUT = { + remaining: z.number().describe("Credits left in the organization."), + perCycle: z + .number() + .nullable() + .describe("Credits granted per billing cycle. Null on the free tier."), + cycleResetsAt: z + .string() + .nullable() + .describe( + "When the billing cycle ends and the credits reset (ISO 8601). Null on the free tier.", + ), +}; export function registerReferenceTools( server: McpServer, @@ -88,4 +104,28 @@ export function registerReferenceTools( }); }), ); + + server.registerTool( + "get_credits", + { + title: "Get the credit balance", + description: + "Get the organization's credit balance: credits remaining, credits per billing cycle, and when the cycle resets. Free. Call it before a large run to check that the credits cover it. The balance can lag by up to 60 seconds.", + inputSchema: {}, + outputSchema: CREDITS_OUTPUT, + annotations: REFERENCE_ANNOTATIONS, + _meta: toolMeta(), + }, + () => + observeToolCall("get_credits", async () => { + const { body } = await client.get("/v1/credits"); + return structuredToolResult( + body as { + remaining: number; + perCycle: number | null; + cycleResetsAt: string | null; + }, + ); + }), + ); }