eemario opened a new pull request, #1492:
URL: https://github.com/apache/flink-agents/pull/1492

   Fixes #1490
   
   ### Purpose of change
   
   Explicit optional MCP prompt arguments such as `language="French"` now reach 
the server. Python previously filtered out every argument whose `required` flag 
was false or unset, so a successful call could silently use the server's 
default instead.
   
   #### Runtime flow
   
   `format_string()` delegates to `format_messages()`, which calls 
`_check_arguments()` before `MCPServer.get_prompt()`. The preparation loop now 
copies each declared argument present in the caller's input and checks 
requiredness only when that argument is absent.
   
   #### Key decisions
   
   Use key presence rather than value truthiness to preserve explicit empty 
strings. Continue iterating declared arguments to preserve the existing 
handling of undeclared inputs. This matches Java's optional-argument forwarding 
without changing the formatting API.
   
   ### Behavioral Semantics
   
   #### Interaction decisions
   
   | Declared argument | Supplied | Result |
   |---|---|---|
   | Required | Yes | Forward the supplied value |
   | Required | No | Raise before calling the server |
   | Optional (`required=False` or `None`) | Yes | Forward the value, including 
`""` |
   | Optional | No | Omit it so the server can apply its default |
   | Undeclared input | Yes | Ignore it |
   
   #### Behavioral contracts
   
   1. Both formatting entry points forward supplied required and optional 
values unchanged.
   2. Omitted optional values remain absent from the request.
   3. Undeclared input names are not forwarded.
   4. Missing required arguments raise `RuntimeError` before any server call.
   
   #### Failure behavior
   
   The missing-required exception and message remain unchanged. A prompt 
without a server reference still raises `ValueError`. Server errors continue to 
propagate through the existing call path; this change adds no fallback or retry.
   
   ### Tests
   
   | Contract | Regression coverage |
   |---|---|
   | 1. Supplied values reach the server, including empty strings | 
`test_mcp_prompt_optional_arguments`: both methods × false/unset requiredness × 
French/empty string |
   | 2. Omitted optional values remain absent | Same test with no language 
input |
   | 3. Undeclared names are ignored | Same test supplies 
`undeclared="ignored"` |
   | 4. Missing required values fail before a server call | 
`test_mcp_prompt_missing_required_argument`: both methods and 
`assert_not_called()` |
   
   All **71 MCP tests pass**. The 14 new cases include 8 that fail on the 
original implementation. Ruff, formatting, and `git diff --check` pass.
   
   The new regression cases exercise the production formatting methods and mock 
the server boundary. Optional-value behavior over a real MCP transport, Java 
execution, cross-language jobs, and the full repository suite were not verified 
for this change.
   
   <details>
   <summary>Verification commands and scope</summary>
   
   Run from `python/` using the existing virtual environment and source 
checkout, with `PYTHONPATH` set to the active environment's 
`sysconfig.get_paths()["purelib"]`:
   
   ```sh
   .venv/bin/python -m pytest flink_agents/integrations/mcp/tests -q --tb=short
   .venv/bin/python -m ruff check flink_agents/integrations/mcp/mcp.py 
flink_agents/integrations/mcp/tests/test_mcp.py
   .venv/bin/python -m ruff format --check flink_agents/integrations/mcp/mcp.py 
flink_agents/integrations/mcp/tests/test_mcp.py
   git diff --check
   ```
   
   This is focused pytest verification of the MCP module, narrowed from the 
Python suite used by `tools/ut.sh`. The changed code is imported from source; 
no generated Java artifacts are involved in the new regression cases.
   </details>
   
   ### API
   
   No signature, schema, or YAML changes. Existing callers that explicitly pass 
optional values will now have them honored instead of silently discarded. 
Required-argument validation, omission of unsupplied optionals, and handling of 
undeclared inputs are preserved. Java already forwards supplied optional values.
   
   ### Documentation
   
   - [ ] `doc-needed`
   - [x] `doc-not-needed`
   - [ ] `doc-included`
   
   Restores expected behavior of existing optional arguments; no new 
configuration or API.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   - [x] Yes
   - [ ] No
   
   Generated-by: Codex CLI 0.171.0-alpha.13.2 (GPT-6)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to