Skip to content

PUT /api/experimental/mcp/:server returns 404 for server names over 100 chars (router maxParamLength) #53401

Done
saurav-shakya/opencode
#2

Description

@nkoynov

Description

PUT /api/experimental/mcp/:server returns 404 when the server name is longer than 100 characters, so the handler never runs. Effect's HttpRouter uses find-my-way, whose maxParamLength defaults to 100, and packages/server/src/routes.ts doesn't set HttpRouter.RouterConfig. T3 Code hits this for delegated threads: its server name t3-code-<threadId> is over 100 chars there, so those sessions get no MCP tools.

Possible one-line fix in routes.ts (untested), the same thing HttpRouter.serve({ routerConfig }) does:

Layer.provideMerge(HttpRouter.layer.pipe(Layer.provide(Layer.succeed(HttpRouter.RouterConfig)({ maxParamLength: 512 })))),

T3 Code's own server sets maxParamLength: 512 for the same reason. Names over 64 chars still lose their tools after this fix (separate issue: #53400).

Plugins

none

OpenCode version

2.0.22. routes.ts is the same in 2.0.23 and on v2 @ ef07075.

Steps to reproduce

OPENCODE_PASSWORD=pw opencode serve --hostname 127.0.0.1 --port 4917 &
B='{"config":{"type":"local","command":["python3","mcp_server.py"]}}'
for n in 100 101; do
  name=p$(printf 'b%.0s' $(seq 2 $n))
  curl -s -o /dev/null -w "$n %{http_code}\n" -u opencode:pw -X PUT \
    -H 'content-type: application/json' --data "$B" \
    "http://127.0.0.1:4917/api/experimental/mcp/$name?directory=$PWD"
done
# 100 204
# 101 404

Screenshot and/or share link

n/a

Operating System

NixOS 26.11 (Linux 6.18)

Terminal

n/a (opencode serve)

Activity

  1. opencodejr commented on Oct 27, 2026

    @opencodejr
    Contributor

    Thanks for the clear report. I reproduced this on 2.0.22, and it still happens on the latest dev (f7d0ce1), run from source.

    The script below starts opencode serve and sends PUT /api/experimental/mcp/<name> with names of 100, 101 and 150 characters. On both versions the 100-character name returns 204 and the longer ones return 404. On dev, packages/server/src/routes.ts still doesn't set HttpRouter.RouterConfig, so the router's default maxParamLength of 100 applies, as you described.

    Related:

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Usage: repro.sh [opencode command...]   (default: opencode)
    # Starts `opencode serve` and PUTs MCP servers whose names are 100 and 101 chars long.
    set -u
    PORT=${PORT:-4917}
    CMD=("${@:-opencode}")
    [ $# -eq 0 ] && CMD=(opencode)
    DIR=$(mktemp -d)
    cd "$DIR"
    OPENCODE_PASSWORD=pw "${CMD[@]}" serve --hostname 127.0.0.1 --port $PORT >"$DIR/serve.log" 2>&1 &
    PID=$!
    for i in $(seq 1 60); do curl -s -o /dev/null -u opencode:pw "http://127.0.0.1:$PORT/" && break; sleep 1; done
    B='{"config":{"type":"local","command":["true"],"enabled":false}}'
    for n in 100 101 150; do
      name=p$(printf 'b%.0s' $(seq 2 $n))
      curl -s -o /dev/null -w "name length $n -> HTTP %{http_code}\n" -u opencode:pw -X PUT \
        -H 'content-type: application/json' --data "$B" \
        "http://127.0.0.1:$PORT/api/experimental/mcp/$name?directory=$DIR"
    done
    kill $PID 2>/dev/null; wait $PID 2>/dev/null

    Run it: bash repro.sh

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions