Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(mcp-host): specify the grok image family and Grok source identity

Alfredo Lopez772929283548
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 2b1b9f464..69a172cf9 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.440",
+ "version": "0.1.441",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.440",
+ "version": "0.1.441",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 893808369..efdd06341 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.440",
+ "version": "0.1.441",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/agent/__tests__/taskExecutor.test.ts b/mcp-host/src/agent/__tests__/taskExecutor.test.ts
index f5da8ec55..629964ec8 100644
--- a/mcp-host/src/agent/__tests__/taskExecutor.test.ts
+++ b/mcp-host/src/agent/__tests__/taskExecutor.test.ts
@@ -995,43 +995,48 @@ describe('TaskExecutor', () => {
expect(deps.onComplete).toHaveBeenCalledTimes(1)
})
- it.each(['openai', 'claude', 'zai', 'bailian', 'codex-subscription'] as const)(
- 'injects text+image contentParts for %s provider',
- async providerType => {
- vi.mocked(runToolUseLoop).mockResolvedValueOnce({ type: 'response', content: 'ok' } as any)
- const deps = createDeps({
- llmProvider: {
- completeSingleTurn: vi.fn(),
- completeSingleTurnWithTools: vi.fn(),
- getProviderType: () => providerType,
- } as any,
- })
- const task = createTask('Analyze this image')
- task.sourceMessage!.attachments = [createImageAttachment()]
+ it.each([
+ 'openai',
+ 'claude',
+ 'zai',
+ 'bailian',
+ 'codex-subscription',
+ 'grok-subscription',
+ ] as const)('injects text+image contentParts for %s provider', async providerType => {
+ // Codex V2 (#650) and Grok V2 (#784) hash each image source.
+ const bindsSource =
+ providerType === 'codex-subscription' || providerType === 'grok-subscription'
+ vi.mocked(runToolUseLoop).mockResolvedValueOnce({ type: 'response', content: 'ok' } as any)
+ const deps = createDeps({
+ llmProvider: {
+ completeSingleTurn: vi.fn(),
+ completeSingleTurnWithTools: vi.fn(),
+ getProviderType: () => providerType,
+ } as any,
+ })
+ const task = createTask('Analyze this image')
+ task.sourceMessage!.attachments = [createImageAttachment()]
- const executor = new TaskExecutor(task, deps)
- await executor.run()
+ const executor = new TaskExecutor(task, deps)
+ await executor.run()
- const userMessage = getLastUserMessageFromLoopCall()
- expect(vi.mocked(runToolUseLoop).mock.calls[0][0].imageSourceIdentity).toBe(
- providerType === 'codex-subscription'
- )
- const parts = userMessage.contentParts ?? []
- expect(parts).toHaveLength(2)
- // The prompt-cache turn-context block rides with the text part, so
- // `content` and its text parts stay equal for the Codex V2 contract.
- expect(parts[0]).toEqual({ type: 'text', text: userMessage.content })
- expect(userMessage.content.endsWith('Analyze this image')).toBe(true)
- expect(parts[1]).toEqual({
- type: 'image',
- mimeType: 'image/jpeg',
- data: 'ZmFrZS1pbWFnZS1iYXNlNjQ=',
- ...(providerType === 'codex-subscription'
- ? { source: { kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' } }
- : {}),
- } satisfies MessageContentPart)
- }
- )
+ const userMessage = getLastUserMessageFromLoopCall()
+ expect(vi.mocked(runToolUseLoop).mock.calls[0][0].imageSourceIdentity).toBe(bindsSource)
+ const parts = userMessage.contentParts ?? []
+ expect(parts).toHaveLength(2)
+ // The prompt-cache turn-context block rides with the text part, so
+ // `content` and its text parts stay equal for the Codex V2 contract.
+ expect(parts[0]).toEqual({ type: 'text', text: userMessage.content })
+ expect(userMessage.content.endsWith('Analyze this image')).toBe(true)
+ expect(parts[1]).toEqual({
+ type: 'image',
+ mimeType: 'image/jpeg',
+ data: 'ZmFrZS1pbWFnZS1iYXNlNjQ=',
+ ...(bindsSource
+ ? { source: { kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' } }
+ : {}),
+ } satisfies MessageContentPart)
+ })
it('falls back to default text when source message content is empty', async () => {
vi.mocked(runToolUseLoop).mockResolvedValueOnce({ type: 'response', content: 'ok' } as any)
@@ -1079,7 +1084,7 @@ describe('TaskExecutor', () => {
} satisfies MessageContentPart)
})
- it.each(['claude', 'codex-subscription'])(
+ it.each(['claude', 'codex-subscription', 'grok-subscription'])(
'selects image identity from the configured fallback %s',
async fallback => {
vi.mocked(runToolUseLoop).mockResolvedValueOnce({ type: 'response', content: 'ok' } as any)
@@ -1093,7 +1098,7 @@ describe('TaskExecutor', () => {
})
await new TaskExecutor(createTask('hello'), deps).run()
expect(vi.mocked(runToolUseLoop).mock.calls[0][0].imageSourceIdentity).toBe(
- fallback === 'codex-subscription'
+ fallback === 'codex-subscription' || fallback === 'grok-subscription'
)
}
)
diff --git a/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.ts b/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.ts
index 8cd494706..d9dd4fe57 100644
--- a/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.ts
+++ b/mcp-host/src/core/adapters/__tests__/llmImageCompatibility.test.ts
@@ -24,6 +24,7 @@ import {
} from '../../../llm/codexSubscription'
import { FailoverEngine } from '../../../llm/failover/engine'
import type { LlmPolicy } from '../../../llm/failover/types'
+import { type GrokSubscriptionDeps, GrokSubscriptionProvider } from '../../../llm/grokSubscription'
import type { ImageInputResolver } from '../../../llm/imageInput'
import { CodexAuthorizeError } from '../../../llm/providerAttemptAuthorizer'
import { LlmErrorCode } from '../../errors'
@@ -613,6 +614,46 @@ describe('mixed-chain pruning recovery (#650)', () => {
})
})
+describe('Grok source identity (#784)', () => {
+ it('opts the Grok class into source identity so the adapter forwards every frame', async () => {
+ // Infrastructure stand-ins: the authorize gateway and the proxy stream. The
+ // provider's network method is spied below, so neither is reached.
+ const provider = new GrokSubscriptionProvider('grok-4.5', {
+ authorizer: { authorize: vi.fn() },
+ proxy: { stream: vi.fn() },
+ attemptContext: () => ({
+ policyRevision: 1,
+ policyHash: 'b'.repeat(64),
+ hostRef: 'chatllm',
+ }),
+ } as unknown as GrokSubscriptionDeps)
+ expect(provider.requiresImageSourceIdentity).toBe(true)
+ const sent = vi.spyOn(provider, 'completeSingleTurnWithTools').mockResolvedValue({
+ content: null,
+ tool_calls: null,
+ usage: { input_tokens: 1, output_tokens: 1, total_tokens: 2 },
+ finish_reason: FinishReason.Stop,
+ })
+
+ const { messages } = repeatedFrameMessages()
+ // The canonical loop view marks the repeated identity...
+ expect(imagePartsOf(messages)[1].sourceIdentityOnly).toBe(true)
+
+ await adapterFor(provider, 'grok-4.5', 'grok-subscription').completeWithTools({
+ messages,
+ tools: TOOLS,
+ })
+
+ // ...and the class opt-in (not a test-side trait stub) keeps both frames in
+ // the view the provider receives, as the Codex V2 transport does.
+ expect(sent).toHaveBeenCalledTimes(1)
+ expect(imagePartsOf(sent.mock.calls[0][0]).map(image => image.source)).toEqual([
+ { kind: 'tool', attachmentId: 'att-first', toolCallId: 'tc_first' },
+ { kind: 'tool', attachmentId: 'att-second', toolCallId: 'tc_second' },
+ ])
+ })
+})
+
describe('Codex V2 transport wiring (#650)', () => {
it('authorizes every source identity and never serializes the internal marker', async () => {
const authorize = vi.fn(async (_input: { request: CodexCompletionRequest }) => ({
diff --git a/mcp-host/src/llm/__tests__/imageInput.test.ts b/mcp-host/src/llm/__tests__/imageInput.test.ts
index dab4ba3a4..2256259e1 100644
--- a/mcp-host/src/llm/__tests__/imageInput.test.ts
+++ b/mcp-host/src/llm/__tests__/imageInput.test.ts
@@ -66,6 +66,13 @@ const EXPECTED_MATRIX: Record<string, Record<ImageTransportOperation, boolean>>
completeAndCache: false,
completeWithToolsAndCache: false,
},
+ // #784: Grok V2 carries ordered user image parts; no cache variants.
+ 'grok-subscription': {
+ complete: true,
+ completeWithTools: true,
+ completeAndCache: false,
+ completeWithToolsAndCache: false,
+ },
}
function userImageMessage(): ChatMessage {
@@ -123,6 +130,7 @@ describe('#654 transport matrix', () => {
expect(imageWireFamilyFor('zai')).toBe('openai-compatible')
expect(imageWireFamilyFor('claude')).toBe('claude')
expect(imageWireFamilyFor('codex-subscription')).toBe('codex')
+ expect(imageWireFamilyFor('grok-subscription')).toBe('grok')
})
it('authorizes NO transport for an unregistered or invented provider id', () => {
@@ -150,6 +158,7 @@ describe('#654 transport matrix', () => {
'vertex',
'bedrock',
'codex-subscription',
+ 'grok-subscription',
].includes(provider)
// `provider` is interpolated into the assertion message by the expect
// failure, so a future divergent provider that inherits coverage fails
@@ -167,6 +176,8 @@ describe('#654 transport matrix', () => {
expect(chatTransportSupportsImageInput('bedrock')).toBe(true)
// #650: Codex V2 carries images on the chat tool-bearing path.
expect(chatTransportSupportsImageInput('codex-subscription')).toBe(true)
+ // #784: Grok V2 carries images on the same paths.
+ expect(chatTransportSupportsImageInput('grok-subscription')).toBe(true)
})
it('rejects assistant/system images and honors per-family role support', () => {
@@ -177,6 +188,9 @@ describe('#654 transport matrix', () => {
expect(roleReason('vertex', 'assistant')).toBe('transport_unsupported')
expect(roleReason('codex-subscription', 'user')).toBe('supported')
expect(roleReason('codex-subscription', 'tool')).toBe('transport_unsupported')
+ expect(roleReason('grok-subscription', 'user')).toBe('supported')
+ expect(roleReason('grok-subscription', 'tool')).toBe('transport_unsupported')
+ expect(roleReason('grok-subscription', 'assistant')).toBe('transport_unsupported')
})
})
@@ -336,6 +350,58 @@ describe('#654 decideImageInput intersection', () => {
})
})
+ it('treats a live Grok catalog row with no imageInput as supported (#784)', () => {
+ // The recorded Grok catalog carries no modality field, like Codex.
+ expect(
+ decideImageInput({
+ providerType: 'grok-subscription',
+ method: 'completeWithTools',
+ roles: ['user'],
+ capability: undefined,
+ })
+ ).toEqual({ state: 'supported', reason: 'supported' })
+ // The upgrade needs transport support: a tool-role image is still refused.
+ expect(
+ decideImageInput({
+ providerType: 'grok-subscription',
+ method: 'completeWithTools',
+ roles: ['tool'],
+ capability: undefined,
+ }).state
+ ).not.toBe('supported')
+ })
+
+ it('does not upgrade a stored unknown or curated-unsupported Grok imageInput (#784)', () => {
+ expect(
+ decideImageInput({
+ providerType: 'grok-subscription',
+ method: 'completeWithTools',
+ roles: ['user'],
+ capability: { state: 'unknown' },
+ })
+ ).toEqual({ state: 'unknown', reason: 'model_unknown' })
+ const unsupported = {
+ state: 'unsupported' as const,
+ evidence: {
+ source: 'curated' as const,
+ reference: 'evidence:grok-text-only',
+ checkedAt: '2026-09-24T00:00:00Z',
+ },
+ }
+ expect(
+ decideImageInput({
+ providerType: 'grok-subscription',
+ method: 'completeWithTools',
+ roles: ['user'],
+ capability: unsupported,
+ })
+ ).toEqual({
+ state: 'unsupported',
+ reason: 'model_unsupported',
+ evidence: unsupported.evidence,
+ })
+ })
+
it('treats absent or malformed evidence as unknown, never as support', () => {
for (const capability of [undefined, null, {}, { state: 'maybe' }, { state: 'supported' }]) {
expect(