Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.55.11

### Fixed — GLM goes through Alpha.sh, and a reply cut off mid-reasoning is no longer passed off as the answer

- `mode:"glm"` now starts at `zai/glm-5.3`, the GLM that every gateway serves
through Alpha.sh first (Z.ai direct is the rescue leg). The list used to be
glm-5 / 5.2 / 5.1 / 5-Turbo, none of which Alpha carries, so `mode:"glm"`
never reached Alpha. `mode:"coding"` uses glm-5.3 in place of glm-5.2. Same
$1.4/$4.4 price, so no budget reserve moves.
- When a reasoning model spends the whole `max_tokens` budget thinking and emits
no content, `blockrun_chat` used to return that reasoning as the reply. A
half-finished analysis read as the model's verdict (seen with `zai/glm-5.3`,
twice), and the "spent the entire max_tokens budget on internal reasoning"
diagnosis never fired. It now fires. A reasoning-only reply that finished
normally still comes back as before.
- Replies carry `served_by`, the upstream the gateway names in
`x-blockrun-served-by` (e.g. `alpha.sh`), on the paths where response headers
reach the client and the gateway sends it.

## 0.55.10

### Fixed — chat costs are final only when the response proves a settlement
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ Package managers have shown install size for decades. Almost no MCP server shows

| Profile | Tools | Context |
|---------|-------|---------|
| `full` *(default)* | 19 | 14,265 |
| `full` *(default)* | 19 | 14,278 |
| `trading` | 8 | 5,471 |
| `media` | 7 | 7,016 |
| `research` | 5 | 2,807 |
| `chat` | 3 | 2,155 |
| `research` | 5 | 2,820 |
| `chat` | 3 | 2,168 |

Running `--profile trading` instead of the default costs **62% less context** for the same trading
workflow. If you only ever ask about markets, that is the single cheapest change you can make.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.55.10
0.55.11
6 changes: 3 additions & 3 deletions docs/mcp-schema-overhead.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Written 2026-09-01, verified against `@modelcontextprotocol/sdk` 1.29.0. Numbers

| Profile | Tools | Context |
|---------|-------|---------|
| `full` *(default)* | 19 | 14,265 |
| `full` *(default)* | 19 | 14,278 |
| `trading` | 8 | 5,471 |
| `media` | 7 | 7,016 |
| `research` | 5 | 2,807 |
| `chat` | 3 | 2,155 |
| `research` | 5 | 2,820 |
| `chat` | 3 | 2,168 |

Descriptions are ~54% of it, input schemas ~42%. `--profile trading` costs 62% less than the
default for the same workflow.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockrun/mcp",
"version": "0.55.10",
"version": "0.55.11",
"mcpName": "io.github.BlockRunAI/blockrun-mcp",
"description": "BlockRun MCP Server - Give your AI agent web search, deep research, prediction markets, and crypto data. Pay per call from a USDC wallet (Solana or Base) or a BlockRun API key.",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion scripts/verify-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const PROBES: Probe[] = [
["reasoning", "anthropic/claude-opus-5"], // gpt-5.6-sol cut to $4/$20 2026-08-21
["coding", "anthropic/claude-opus-5"],
["fast", "google/gemini-3.5-flash"],
["glm", "zai/glm-5.2"],
["glm", "zai/glm-5.3"], // Alpha-served primary; same $1.4/$4.4 as glm-5.2
["cheap", "deepseek/deepseek-v4-pro"],
] as Array<[string, string]>).map(([mode, worstMember]) => {
const message = "word ".repeat(20_000); // 100k chars
Expand Down
7 changes: 5 additions & 2 deletions src/tools/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ function servedNotes(requested: string, outcome: ChatOutcome, maxTokens: number
let text = "";
const served = outcome.servedModel;
if (served) fields.served_model = served;
// Which UPSTREAM answered (e.g. alpha.sh vs api.z.ai for zai/glm-5.3), from
// the gateway's x-blockrun-served-by. Only the Response paths carry headers.
if (outcome.servedBy) fields.served_by = outcome.servedBy;
if (served && canonicalChatModel(served) !== canonicalChatModel(requested)) {
text += `\n\n(Served by ${served} — the gateway answered the requested id ${requested} with this model instead: retired, aliased, or at capacity.)`;
}
Expand Down Expand Up @@ -467,9 +470,9 @@ export function registerChatTool(server: McpServer, budget: BudgetState): void {
Notable modes:
- mode:"powerful" → Claude Opus 5, Claude Opus 4.8, GPT-5.6-sol, Claude Fable 5 (frontier, 1M context)
- mode:"reasoning" → Claude Opus 5, GPT-5.6-sol, Kimi K3, Grok 4.3, deepseek-v4-pro
- mode:"coding" → Claude Opus 5, GPT-5.3-codex, Kimi K3, Grok Build, GLM-5.2
- mode:"coding" → Claude Opus 5, GPT-5.3-codex, Kimi K3, Grok Build, GLM-5.3
- mode:"cheap" → deepseek-v4-pro, Qwen3.7 Flash, MiniMax M3, Gemini 2.5 Flash, DeepSeek Chat / V4.1 Flash
- mode:"glm" → Zhipu GLM-5 / 5.2 / 5.1 / 5-Turbo (strong at coding)
- mode:"glm" → Zhipu GLM-5.3 (served via Alpha.sh), then GLM-5 / 5.2 / 5.1 / 5-Turbo (strong at coding)
- mode:"free" → free models (no cost)

Pick directly: model:"anthropic/claude-opus-5.5", model:"openai/gpt-6-sol", model:"xai/grok-4.7", model:"moonshot/kimi-k3", model:"nvidia/gpt-oss-120b" (free).
Expand Down
24 changes: 21 additions & 3 deletions src/utils/chat-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface ChatUsage {
export interface ChatOutcome {
text: string;
servedModel: string | null;
/** The upstream that answered, from `x-blockrun-served-by` (e.g. "alpha.sh"); null where no headers reach us. */
servedBy: string | null;
finishReason: string | null;
usage: ChatUsage | null;
settledUsd: number | null;
Expand Down Expand Up @@ -141,6 +143,15 @@ export function settledCostFromHeaders(headers: { get(name: string): string | nu
* them as final (`cost_is_estimate: false`), because the SDK's counter adds
* the signed amount on every paid 2xx.
*/
/**
* The gateway's `x-blockrun-served-by`: which upstream actually answered (for
* zai/glm-5.3, "alpha.sh" or the Z.ai rescue leg). A name, never an id.
*/
export function servedByFromHeaders(headers: { get(name: string): string | null } | null | undefined): string | null {
if (typeof headers?.get !== "function") return null;
return headers.get("x-blockrun-served-by")?.trim() || null;
}

export function settlementTxFromHeaders(headers: { get(name: string): string | null } | null | undefined): string | null {
if (typeof headers?.get !== "function") return null;
if ((headers.get("x-payment-settled") ?? "").trim().toLowerCase() === "false") return null;
Expand Down Expand Up @@ -244,7 +255,13 @@ class ChatAccumulator {
}

result(): Omit<ChatOutcome, "settledUsd" | "settlementTx"> {
return { text: this.text || this.reasoning, finishReason: this.finishReason, servedModel: this.servedModel, usage: this.usage };
// Reasoning stands in only for a reply that FINISHED without content. Cut
// at max_tokens with no content, it is thinking that never reached an
// answer: returning it as the reply passed a half-finished analysis off as
// the model's verdict (zai/glm-5.3, 2026-11-17, twice) and skipped the
// max_tokens diagnosis in rejectEmptyLength. Leave text empty so it fires.
const text = this.text || (this.finishReason === "length" ? "" : this.reasoning);
return { text, finishReason: this.finishReason, servedModel: this.servedModel, servedBy: null, usage: this.usage };
}
}

Expand Down Expand Up @@ -377,6 +394,7 @@ export async function streamChatText(
const resp = await client.chatCompletionStream(model, messages, options);
const settledUsd = settledCostFromHeaders(resp.headers);
const settlementTx = settlementTxFromHeaders(resp.headers);
const servedBy = servedByFromHeaders(resp.headers);
return afterAccept(async () => {
// A provider/route that ignores `stream:true` answers with a plain JSON
// completion. Feeding that to the SSE parser would "succeed" with an empty
Expand All @@ -388,11 +406,11 @@ export async function streamChatText(
acc.fold(data);
const out = acc.result();
rejectEmptyLength(model, out);
return { ...out, settledUsd, settlementTx };
return { ...out, servedBy, settledUsd, settlementTx };
}
const out = await assembleSseChatStream(resp, idleTimeoutMs);
rejectEmptyLength(model, out);
return { ...out, settledUsd, settlementTx };
return { ...out, servedBy, settledUsd, settlementTx };
}, settlementTx);
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ export const MODEL_TIERS = {
"nvidia/gpt-oss-20b", "nvidia/nemotron-3-super-120b", "nvidia/llama-3.2-11b-vision",
"nvidia/nemotron-3-nano-omni-30b-a3b-reasoning",
],
coding: ["anthropic/claude-opus-5", "openai/gpt-5.3-codex", "moonshot/kimi-k3", "xai/grok-build-0.1", "zai/glm-5.2", "qwen/qwen3.7-max", "anthropic/claude-sonnet-5"],
glm: ["zai/glm-5", "zai/glm-5.2", "zai/glm-5.1", "zai/glm-5-turbo"],
// GLM goes through Alpha.sh: zai/glm-5.3 is the one SKU the gateway routes
// there (ALPHA_MODEL_MAP in blockrun model-maps.ts, Z.ai direct as rescue).
// So it leads the glm tier and is coding's GLM member; the rest of the glm
// tier is the Z.ai-direct fallback. Same $1.4/$4.4 as glm-5.2, so no reserve moves.
coding: ["anthropic/claude-opus-5", "openai/gpt-5.3-codex", "moonshot/kimi-k3", "xai/grok-build-0.1", "zai/glm-5.3", "qwen/qwen3.7-max", "anthropic/claude-sonnet-5"],
glm: ["zai/glm-5.3", "zai/glm-5", "zai/glm-5.2", "zai/glm-5.1", "zai/glm-5-turbo"],
} as const;

export type RoutingMode = keyof typeof MODEL_TIERS;
Expand Down
50 changes: 50 additions & 0 deletions test/chat-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,53 @@ test("Solana frame path: a stream that ends with no frames is a post-acceptance
(err: Error) => err instanceof AcceptedThenFailedError && /no frames/.test(err.message),
);
});

// zai/glm-5.3, 2026-11-17: the model spent max_tokens reasoning and never
// produced content. The reasoning fallback handed that unfinished analysis back
// as the reply, so a caller read thinking as a verdict, and the max_tokens
// diagnosis never fired because text was non-empty.
test("reasoning cut off at max_tokens is not passed off as the answer", async () => {
const { streamChatText } = await import("../src/utils/chat-stream.js");
const sse = [
`data: ${JSON.stringify({ model: "zai/glm-5.3", choices: [{ delta: { reasoning_content: "Let me carefully analyze…" } }] })}\n\n`,
`data: ${JSON.stringify({ model: "zai/glm-5.3", choices: [{ delta: {}, finish_reason: "length" }] })}\n\n`,
"data: [DONE]\n\n",
];
const fakeClient = {
chatCompletionStream: async () =>
new Response(new ReadableStream<Uint8Array>({
start(c) { for (const s of sse) c.enqueue(enc.encode(s)); c.close(); },
}), { headers: { "content-type": "text/event-stream" } }),
};
await assert.rejects(
streamChatText(fakeClient as never, "zai/glm-5.3", [{ role: "user", content: "review" }], {}),
/entire max_tokens budget on internal reasoning/,
);
});

test("reasoning-only reply that finished normally still comes back", async () => {
const out = await assembleSseChatStream(bodyFrom([
chunk({ choices: [{ delta: { reasoning_content: "the answer, in reasoning" } }] }),
chunk({ choices: [{ delta: {}, finish_reason: "stop" }] }),
]));
assert.equal(out.text, "the answer, in reasoning");
});

// Which upstream answered: the gateway names it in x-blockrun-served-by. For
// zai/glm-5.3 that is how a caller tells Alpha.sh from the Z.ai rescue leg.
test("x-blockrun-served-by is surfaced as servedBy", async () => {
const { streamChatText } = await import("../src/utils/chat-stream.js");
const mk = (headers: Record<string, string>) => ({
chatCompletionStream: async () =>
new Response(new ReadableStream<Uint8Array>({
start(c) {
c.enqueue(enc.encode(`data: ${JSON.stringify({ model: "zai/glm-5.3", choices: [{ delta: { content: "ok" }, finish_reason: "stop" }] })}\n\n`));
c.close();
},
}), { headers: { "content-type": "text/event-stream", ...headers } }),
});
const viaAlpha = await streamChatText(mk({ "x-blockrun-served-by": "alpha.sh" }) as never, "zai/glm-5.3", [{ role: "user", content: "hi" }], {});
assert.equal(viaAlpha.servedBy, "alpha.sh");
const none = await streamChatText(mk({}) as never, "zai/glm-5.3", [{ role: "user", content: "hi" }], {});
assert.equal(none.servedBy, null);
});
9 changes: 9 additions & 0 deletions test/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,12 @@ test("deepseek-v4.1-flash is priced like deepseek-chat and follows it in fast an
estimateChatCost(1024, undefined, "deepseek/deepseek-chat", undefined, 100_000),
);
});

// GLM goes through Alpha.sh, and zai/glm-5.3 is the only SKU the gateway maps
// there (blockrun ALPHA_MODEL_MAP). mode:"glm" used to start at glm-5 and never
// listed 5.3, so it could not reach Alpha at all.
test('mode:"glm" and mode:"coding" use zai/glm-5.3, the Alpha-served GLM', () => {
assert.equal(MODEL_TIERS.glm[0], "zai/glm-5.3");
assert.ok((MODEL_TIERS.coding as readonly string[]).includes("zai/glm-5.3"));
assert.ok(!(MODEL_TIERS.coding as readonly string[]).includes("zai/glm-5.2"));
});
Loading