bug: openapi-to-mcp appends a second ? to a query-suffixed path template

Open Beginner friendly
#14,161 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
lua, openapi

Research direction

Read apisix/plugins/openapi-to-mcp/tools/handler.lua, focusing on build_path() and _M.call(), where the issue identifies the query suffix and serialized parameters being joined. Check the existing tests added in PR #14154 for query-suffixed templates. Done means the example request uses /b?acl&prefix=logs and the declared parameter reaches the upstream under its own name.

Written by the indexing model from the issue text.

Description

Current Behavior

openapi-to-mcp sends a second literal ? upstream when a path template carries a query
suffix and the operation also declares query parameters.

build_path() returns the template with its substitutions, query suffix included, and
_M.call() then appends the serialized query parameters with its own ?:

local url = base_url .. path
if query then
    url = url .. "?" .. query
end

For a template of /{Bucket}?acl with a declared prefix query parameter, a call with
Bucket=b and prefix=logs is sent as:

/b?acl?prefix=logs

The upstream parses everything after the first ? as the query string, so it sees one
parameter spelled acl?prefix, and the declared prefix parameter never arrives under
its own name. Query-suffixed path templates are used by S3-style documents.

Verified at runtime against the official test harness on master; the output is identical
on #14154, so the behavior is pre-existing and that PR neither introduces nor changes it.
It surfaced while reviewing #14154, which added the first test coverage for query-suffixed
templates: https://github.com/apache/apisix/pull/14154#discussion_r4475591464

Expected Behavior

The template's query suffix and the serialized query parameters should be merged into one
query string joined by &, so the example above is sent as /b?acl&prefix=logs and every
declared parameter reaches the upstream under its own name.

Steps to Reproduce

  1. Serve an OpenAPI document whose path is /{Bucket}?acl, with Bucket as a required
    path parameter and prefix as a query parameter.
  2. Configure an openapi-to-mcp Route using that document.
  3. Call the generated tool with Bucket=b and prefix=logs.
  4. Observe the upstream request path /b?acl?prefix=logs rather than /b?acl&prefix=logs.

Environment

  • APISIX: current master, reproduced at 6205e4a56
  • Component: apisix/plugins/openapi-to-mcp/tools/handler.lua, build_path() and _M.call()
Dominant language
Lua
Stars
17.3k
Forks
3k
Avg merge
3d 12h
Merged PRs (30d)
58

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/apisix

All issues in apache/apisix

Similar issues

More Lua issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.