diff --git a/app/mcp/route.ts b/app/mcp/route.ts index 585cf2f..7f61597 100644 --- a/app/mcp/route.ts +++ b/app/mcp/route.ts @@ -99,20 +99,29 @@ function acceptedMcpRequestNeedsNormalization(request: Request) { return null } -function normalizedMcpRequest(request: Request) { +async function normalizedMcpRequest(request: Request) { const needsNormalization = acceptedMcpRequestNeedsNormalization(request) if (needsNormalization === null) { return null } - if (!needsNormalization) { - return request + const body = await request.text() + const headers: Record = {} + + request.headers.forEach((value, key) => { + headers[key] = value + }) + + if (needsNormalization) { + headers.accept = NORMALIZED_ACCEPT } - const headers = new Headers(request.headers) - headers.set('accept', NORMALIZED_ACCEPT) - return new Request(request, { headers }) + return new Request(request.url, { + method: request.method, + headers, + body, + }) } function isCanonicalMcpRootRequest(request: Request) { @@ -188,7 +197,7 @@ export async function POST(request: Request) { return jsonRpcError(request, 415, -32600, 'Content-Type must be application/json') } - const mcpRequest = normalizedMcpRequest(request) + const mcpRequest = await normalizedMcpRequest(request) if (!mcpRequest) { return jsonRpcError(request, 406, -32600, 'Accept must include application/json or */*; text/event-stream alone is not supported for JSON responses') diff --git a/lib/ella-registry.ts b/lib/ella-registry.ts index 10474f5..713ee1a 100644 --- a/lib/ella-registry.ts +++ b/lib/ella-registry.ts @@ -9,7 +9,7 @@ import { } from './entity-data' export const ELLA_CANONICAL_ENTITY_ID = 'https://ellaentity.ai/#ella' as const -export const ELLA_MCP_SERVER_INFO = { name: 'ellaentity-mcp', version: '1.1.3' } as const +export const ELLA_MCP_SERVER_INFO = { name: 'ellaentity-mcp', version: '1.1.4' } as const export const ELLA_MCP_PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18'] as const export const ELLA_MCP_DEFAULT_PROTOCOL_VERSION = ELLA_MCP_PROTOCOL_VERSIONS[0] export const ELLA_REGISTRY_DATA_VERSION = '2026-07-13.mcp-v1-1' as const diff --git a/tests/mcp.test.ts b/tests/mcp.test.ts index 7b44507..c313a6e 100644 --- a/tests/mcp.test.ts +++ b/tests/mcp.test.ts @@ -82,14 +82,21 @@ async function pingWithHeaders(headers: HeadersInit, includeDefaultAccept = true } test('POST validates content negotiation and origins', async () => { + const jsonOnly = await pingWithHeaders({ accept: 'Application/Json; charset=utf-8' }) const accepted = [ await pingWithHeaders({}, false), await pingWithHeaders({ accept: '' }), await pingWithHeaders({ accept: '*/*' }), - await pingWithHeaders({ accept: 'Application/Json; charset=utf-8' }), + jsonOnly, await pingWithHeaders({ accept }), ] + assert.deepEqual(jsonOnly.body, { + jsonrpc: '2.0', + id: 'ping-accept', + result: {}, + }) + for (const result of accepted) { assert.equal(result.response.status, 200) assert.deepEqual(result.body.result, {})