Skip to content

Streamable MCP run normally and return results, but soon get unexpected status 400 Bad Request error #6540

Open

Description

@zxzxzxzzy0119

What version of Codex is running?

0.57.0

What subscription do you have?

use azure api Key, model = "gpt-5-codex" model_provider = "azure"

Which model were you using?

gpt-5-codex, azure

What platform is your computer?

windows 11 wsl

What issue are you seeing?

The configuration in config.toml is as follows:

[mcp_servers.mymcp]
url = "http://ip:port/sse"
http_headers = { "live" = "true", "user" = "tom" }

MCP can run normally and return results, but soon messages like
Reconnecting... 1/5, Reconnecting... 2/5, Reconnecting... 3/5, Reconnecting... 4/5, Reconnecting... 5/5
appear, followed by the following error:

unexpected status 400 Bad Request: {
"error": {
"message": "Invalid 'input[3].name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.",
"type": "invalid_request_error",
"param": "input[3].name",
"code": "invalid_value"
}
}

What steps can reproduce the bug?

config.toml

[mcp_servers.mymcp]
url = "http://ip:port/sse"
http_headers = { "live" = "true", "user" = "tom" }

then call mcp server in prompt

What is the expected behavior?

No response

Additional information

Normal Q&A、coding works fine, but this problem occurs when using the MCP server.

Activity

  1. added
    bug
    on Nov 12, 2025
  2. added
    CLI
    mcp
    on Nov 12, 2025
  3. zxzxzxzzy0119 commented on Nov 18, 2025

    @zxzxzxzzy0119
    Author

    0.58.0 also have this problem, error info:

    ■ unexpected status 400 Bad Request: { "error": { "message": "Invalid 'input[4].name': string does not match pattern. Expected a string that matches the pattern '^[a- zA-Z0-9_-]+$'.", "type": "invalid_request_error", "param": "input[4].name", "code": "invalid_value" } }

  4. illanes00 commented on Jan 18, 2026

    @illanes00

    I was able to reproduce this on a VPS with a recorded session whose transcript contains tool calls with names that include '.' (e.g. functions.exec_command, legacy container.exec). When Codex sends that history back to the OpenAI Responses API, the request fails with a 400:

    'Invalid 'input[N].name': string does not match pattern '^[a-zA-Z0-9_-]+$'

    I opened PR #9447 to address this by normalizing tool call names in the transcript before sending request history (and in compaction payloads too):

    • container.exec -> shell
    • strip namespace prefixes like functions. when the suffix matches a known tool
    • otherwise sanitize invalid chars to '_'

    Includes unit tests + manual verification via resuming the failing session (no more input[*].name validation error).

  5. yoavram commented on Jan 28, 2026

    @yoavram

    I'm also getting a similar error, I don't know why it's happening, but it has something to do with tool/mcp:
    {
    "error": {
    "message": "Invalid 'input[25].name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.",
    "type": "invalid_request_error",
    "param": "input[25].name",
    "code": "invalid_value"
    }
    }
    what should I do? I see that the PR #9447 was closed.

    What version of Codex is running?

    codex-cli 0.91.0

    What subscription do you have?

    OpenAI Edu

    Which model were you using?

    gpt-5.2-codex Medium

    What platform is your computer?

    MacOS 26.2 (25C56) Apple M4 Pro

    Additional information

    MCP servers
    tooluniverse 1.0.16
    Zotero MCP v0.1.2

  6. RongNianXin commented on Oct 13, 2026

    @RongNianXin

    An observation from a recovered Codex Desktop session may help narrow this down, although it is not a universal fix.

    In our case, a conversation stopped working after a model/provider switch. Its persisted history contained three function_call.name values with ::. The endpoint allowed dots but rejected colons, unlike the pattern in this issue. One invalid name was still present in the post-compaction history. A comparison conversation with the same switch direction had valid names and continued normally, so switching models alone was not enough to cause the failure.

    For this specific session, after preserving a complete backup and preventing concurrent writes, we repaired only those three name fields using a verified equal-length replacement (six bytes total). All other bytes, arguments, call IDs, original failed tool outputs and byte-based history cutoffs were preserved. The history parsed afterward, and the operator confirmed the conversation could continue. We did not capture the raw outgoing request, so we cannot prove which saved item became input[N] or assign sole responsibility to the model, client or gateway. This is not evidence that replacing :: with __ is a valid mapping for other tools or versions.

    Before attempting a repair, check the actual saved or outgoing function_call.name against the exact pattern in your error. The request index is not necessarily a session-file line number. If no invalid name is found, this workaround does not apply. Preserve the original history and use only an unambiguous, verified tool-name mapping; do not globally replace punctuation, strip all namespaces or delete tool outputs. Repairs that change file length can also break byte-based history offsets in some versions. A running client may still hold the old history in memory.

    PR #9447 was closed without being merged, and the maintainers explicitly declined it as the correct fix. It should not be treated as a released upstream solution.

    If you can share the offending name, exact error pattern and client version in a minimal redacted example—not a full session or credentials—that would help determine whether this is the same history-validation mechanism or a different MCP/namespace problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions