Skip to content

HttpException: More than one value for header accept #44

@coolight7

Description

@coolight7

Hello,

  • I encountered an error when using simple Python code to call dart-mcp-server:
HttpException: More than one value for header accept
#0      _HttpHeaders.value (dart:_http/http_headers.dart:54:7)
#1      StreamableHTTPServerTransport._handleGetRequest (package:mcp_dart/src/server/streamable_https.dart:172:31)
#2      StreamableHTTPServerTransport.handleRequest (package:mcp_dart/src/server/streamable_https.dart:160:13)
......
  • line:
final acceptHeader = req.headers.value(HttpHeaders.acceptHeader)
  • We can replace req.headers.value(HttpHeaders.acceptHeader) with req.headers[HttpHeaders.acceptHeader] to fix it:
- final acceptHeader = req.headers.value(HttpHeaders.acceptHeader);
+ final acceptHeader = req.headers[HttpHeaders.acceptHeader];
  • print HttpRequest.header:
user-agent: python-httpx/0.28.1
connection: keep-alive
cache-control: no-store
mcp-protocol-version: 2025-03-26
accept: application/json, text/event-stream, text/event-stream
accept-encoding: gzip, deflate, br, zstd
host: localhost:54838
content-type: application/json
mcp-session-id: 0d3fd440-ca65-4e41-b99b-7a3dadbd8982
  • print accept info, It can be observed that the accept field in the request headers from python-mcp-client is a list. However, its length is 2, while its content appears to have 3 parts—there is also a duplicate entry of text/event-stream. While python-mcp-client seems not fully compliant, we can consider adding compatibility for it.:
    print(req.headers[HttpHeaders.acceptHeader]);
    print(req.headers[HttpHeaders.acceptHeader].runtimeType);
    print(req.headers[HttpHeaders.acceptHeader]?.length);
    print(req.headers[HttpHeaders.acceptHeader]?.first);
    print(req.headers[HttpHeaders.acceptHeader]?.last);
[application/json, text/event-stream, text/event-stream]
List<String>
2
application/json, text/event-stream
text/event-stream
  • python mcp client example, run pip install fastmcp and then python test.py :
import asyncio
from fastmcp import Client

client = Client("http://localhost:54838/mcp")

async def call_tool():
    async with client:
        print("call_tool:")
        result = await client.call_tool("funasr")
        print(result)

asyncio.run(call_tool())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions