Skip to content

feat(use-case): compose_query accepts GraphQL variables - #148

Merged
allmonday merged 3 commits into
masterfrom
024-compose-query-variables
Sep 8, 2026
Merged

feat(use-case): compose_query accepts GraphQL variables#148
allmonday merged 3 commits into
masterfrom
024-compose-query-variables

Conversation

@allmonday

Copy link
Copy Markdown
Collaborator

概要

MCP Layer 3 compose_query / execute_compose_query 接受 GraphQL variables——字符串参数经 variables 传入而非内联 GraphQL 字面量,规避引号/反斜杠/换行转义这一 agent 语法错误的最大来源。声明变量缺值时 fail-fast 并给出明确指路。

改动

  • execute_compose_query 新增 variables 参数,经既有 QueryParser.parse_operations 路径解析(与 GraphQLHandler 同一机制)
  • 变量契约检查:声明未传 → 指路 variables 参数;部分缺失 → 列出缺失名
  • 变量默认值($t: String = "x")不支持——报错注明该限制(仅在查询确实声明默认值时附加),docstring 同步说明
  • demo GraphiQL 端点透传 variables(原 400 守卫已过时,GraphiQL 变量面板现在可用)
  • MCP 工具 docstring 增加 variables 用法示例
  • changelog 6.3.0 条目
  • 顺带:tests 的 ruff --fix 机械修复(独立 commit)

测试

  • 新增回归:带引号/反斜杠/换行字符串经 variables 往返、声明未传、部分缺失、默认值报错注明限制
  • 全量 1690 passed / 6 skipped;ruff(改动文件)与 mypy(改动文件)干净

🤖 Generated with Claude Code

allmonday and others added 3 commits September 9, 2026 06:11
- tool signature: variables: dict | None, forwarded to the executor;
  docstring teaches agents to pass string args via variables instead of
  inline literals (quotes/backslashes/newlines = #1 parse-error source)
- executor: parse_operations(document, variables) — the plumbing already
  existed (QueryParser resolves $vars), only the tool layer never exposed it
- friendly contract check: declared-but-missing variables fail fast with a
  hint instead of dying later as graphql Undefined inside argument coercion

Co-Authored-By: Claude <noreply@anthropic.com>
Mechanical fixes only — unused imports removed (F401), import blocks
sorted (I001), blank lines normalized. No semantic changes; full test
suite passes with them. The 8 remaining ruff findings (E501/F841/E741)
are manual-only and untouched.

Co-Authored-By: Claude <noreply@anthropic.com>
…s note

Review follow-ups to 7a72f2c:

- demo GraphiQL endpoint forwards variables to execute_compose_query
  (the stale 400 guard predated executor support; GraphiQL's variables
  pane was unusable against it)
- variable-default omission ($t: String = "x") appends a note naming
  the limitation — only when the query actually declares a default, so
  plain $t: String! misses keep a to-the-point message; docstrings on
  both the executor and the MCP tool state every declared variable must
  be passed explicitly
- regression tests: defaulted-var error names the limitation / required-
  var error stays clean
- changelog 6.3.0 entry
- fix E501 in the new variables tests

Co-Authored-By: Claude <noreply@anthropic.com>
@allmonday
allmonday merged commit 66f321e into master Sep 8, 2026
5 checks passed
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.

1 participant