feat(mcpgen,mcpserver): @mcpToolArg for tool-only arguments#35
Merged
Conversation
Shortcut tools that need an argument-driven selection (e.g. signals
time-series where each {name, agg} pair becomes a sub-field) currently
require that argument to exist on the GraphQL field itself — which
forces a schema change on queries that have been stable for years.
Add a repeatable @mcpToolArg directive that declares arguments belonging
only to the MCP tool. They feed SelectionTemplate via the same args map,
and mcpserver strips them from the variables map before the GraphQL
executor is called, so the underlying field never sees them.
Usage:
signals(tokenId: Int!, interval: String!, from: Time!, to: Time!, filter: SignalFilter): [SignalAggregations!]
@mcptool(
name: "get_signals_time_series"
description: "..."
selection: "timestamp{{range .signalRequests}} {{.name}}(agg: {{.agg}}){{end}}"
)
@mcpToolArg(
name: "signalRequests"
type: "[SignalAggregationRequest!]!"
description: "..."
)
The GraphQL field keeps its existing arguments and return type. The MCP
tool gets `signalRequests` as a required input. At call time the
template renders it into the selection, and `signalRequests` is dropped
from the variables map before executing.
ArgDefinition gets a `ToolOnly bool` field; mcpgen emits it alongside
the other ArgDefinition fields and reuses the existing JSON-schema
mapping via a small ad-hoc type-string parser so the `type:` argument
of the directive can name any loaded GraphQL type (e.g.
"[SignalAggregationRequest!]!", "[String!]!", "Int").
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
Builds on the templated selections from #34 (v0.2.0). That release exposed a new problem: to feed the template, the arg had to live on the GraphQL field, which means every repo adopting this pattern has to modify long-standing query signatures. For telemetry-api's `signals` / `signalsLatest`, that's a non-starter. `@mcpToolArg` keeps the change at the MCP layer where it belongs.
Example
```graphql
signals(tokenId: Int!, interval: String!, from: Time!, to: Time!, filter: SignalFilter): [SignalAggregations!]
@mcptool(
name: "get_signals_time_series"
description: "..."
selection: "timestamp{{range .signalRequests}} {{.name}}(agg: {{.agg}}){{end}}"
)
@mcpToolArg(
name: "signalRequests"
type: "[SignalAggregationRequest!]!"
description: "..."
)
```
The GraphQL field and its arguments are unchanged. The MCP tool gets `signalRequests` as a required input. On each call the template expands it into a per-signal selection set; `signalRequests` is dropped before the GraphQL executor runs.
Changes
Test plan