Skip to content

fix(prompt/custom): parse typed MCP argument strings - #4433

Open
feiiiiii5 wants to merge 2 commits into
googleapis:mainfrom
feiiiiii5:codex/parse-prompt-arguments
Open

feiiiiii5 wants to merge 2 commits into
googleapis:mainfrom
feiiiiii5:codex/parse-prompt-arguments

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Description

Fixes #4432.

The prompt configuration supports every Parameter type, but MCP clients send prompts/get values as strings. An integer argument such as {"count":"3"} currently fails parameter parsing instead of producing the prompt.

Decode non-string prompt parameters from their JSON representation in the existing Argument wrapper, then use the existing parameter parser. This also preserves parameter-source selection, defaults and declared validation. Document the wire representation and cover the actual HTTP request path.

Validation on Go 1.27.3:

  • Original implementation: 10 unit cases fail with type errors; the HTTP integration fails with JSON-RPC -32602 for the integer argument.
  • Updated implementation: go test -race ./internal/prompts/... -count=1 and go test ./tests/prompts/custom -run TestMCPPromptsIntegration -count=1 -timeout=10m pass.
  • Golangci-lint 2.15.0 reports 0 issues for both affected packages; formatting and git diff --check pass. go.mod and go.sum are unchanged.
  • Tests cover typed scalars, false/zero values, arrays/maps, defaults, valueFromParam, and JSON-looking literal strings. Full repository and external database suites were not run.

PR Checklist

  • Reviewed CONTRIBUTING.md.
  • Opened Non-string prompt arguments reject string-valued MCP input #4432 before writing code.
  • Reviewed the entire diff.
  • Relevant tests and linter pass.
  • Relevant unit-package coverage increased from 85.3% to 86.7% (prompts: 95.0% to 95.6%).
  • Updated the prompt argument documentation.
  • Breaking change (!): not applicable.

@feiiiiii5
feiiiiii5 requested a review from a team as a code owner November 6, 2026 16:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for parsing and converting string-encoded arguments passed by MCP clients into their declared parameter types (such as integers, floats, booleans, arrays, and maps) using JSON decoding. It updates the Argument.Parse method to handle this conversion, adds comprehensive unit tests covering various data types and edge cases, and integrates a new typed prompt test in the integration test suite. There are no review comments, and the implementation looks solid, so I have no feedback to provide.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-string prompt arguments reject string-valued MCP input

2 participants