Skip to content

header ‘mcp-protocol-version’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response #80

@thomas-0816

Description

@thomas-0816

using llama.cpp webui, the firefox browser console gives:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8081/mcp. (Reason: header ‘mcp-protocol-version’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).

Describe the bug
StreamableHttpServerTransport::createRequestHandler() has
'Access-Control-Allow-Headers' => 'Content-Type, Mcp-Session-Id, Last-Event-ID, Authorization',

To Reproduce
create a mcp server and add it to llama.cpp webui
refresh llama.cpp webui, firefox browser console gives:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8081/mcp. (Reason: header ‘mcp-protocol-version’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:8081/mcp. (Reason: CORS request did not succeed). Status code: (null).

Expected behavior
no error

Logs
If applicable, add logs to help explain your problem.

Additional context

I changed

'Access-Control-Allow-Headers' => 'Content-Type, Mcp-Session-Id, Last-Event-ID, Authorization',

to

'Access-Control-Allow-Headers' => 'Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID, Authorization',

in server/src/Transports/StreamableHttpServerTransport.php to fix the issue (see

'Access-Control-Allow-Headers' => 'Content-Type, Mcp-Session-Id, Last-Event-ID, Authorization',
).

PHP code used

<?php

require_once __DIR__ . '/vendor/autoload.php';

use PhpMcp\Schema\ServerCapabilities;
use PhpMcp\Server\Server;
use PhpMcp\Server\Transports\StreamableHttpServerTransport;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;

try {
    $server = Server::make()
        ->withServerInfo('My Mcp Server', '0.1')
        ->withCapabilities(ServerCapabilities::make())
        ->withTool(
            fn (string $city): float => $city === 'Berlin' ? 21.42 : 0.0,
            name: 'get_weather',
            description: 'Get temperature of a city'
        )
        ->withPrompt(
            fn (string $city): array => [['role' => 'user', 'content' => "Get temperature in {$city}"]],
            name: 'weather_prompt'
        )
        ->withLogger(new class implements LoggerInterface {
            use LoggerTrait;

            public function log($level, string|Stringable $message, array $context = []): void
            {
                fwrite(STDERR, new DateTime()->format('Y-m-d H:i:s.u ') . json_encode(func_get_args()) . PHP_EOL);
            }
        })
        ->build()
        ->listen(new StreamableHttpServerTransport('127.0.0.1', 8081, '/mcp', stateless: true));
} catch (Throwable $exception) {
    fwrite(STDERR, 'error ' . (string) $exception . PHP_EOL);
    exit(1);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions