Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions pkgs/mcpx/internal/e2e/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,3 +661,83 @@ func TestTheDaemonReportsItsRevisionPolicy(t *testing.T) {
t.Errorf("strict %v, want 2026-07-28 lenient and the rest strict", strict)
}
}

// The policy decides what a relayed progress notification looks like on the
// wire. 2024-11-05 has no `message` on progress and every later revision
// does, so a message-relaying daemon talking to a 2024-11-05 client must
// strip it only when that revision's rule governs -- by default it does not,
// with --mcp-spec 2024-11-05 it does. The unit precedent is
// TestProgressMessagePrecedence; this is the same decision through the
// daemon, a real upstream and a real client (#307, #2212).
func TestTheRevisionPolicyDecidesWhetherProgressKeepsItsMessage(t *testing.T) {
for _, c := range []struct {
name string
serveArg []string
want bool
}{
{"default", nil, true},
{"mcp-spec-2024-11-05", []string{"--mcp-spec", "2024-11-05"}, false},
} {
t.Run(c.name, func(t *testing.T) {
e := newEnv(t, oneServer)
e.run("refresh")
notes, res := relaySessionAs(t, e, "2024-11-05", c.serveArg,
map[string]any{}, "info", map[string]any{"progressToken": "policy-tok"})
if res["result"] == nil {
t.Fatalf("the call should still answer:\n%s", dumpJSON(t, res))
}
var progress int
for _, n := range notes {
if n["method"] != "notifications/progress" {
continue
}
progress++
p, _ := n["params"].(map[string]any)
msg, has := p["message"]
if has != c.want {
t.Errorf("message present=%v, want %v: %s", has, c.want, dumpJSON(t, n))
}
if has {
if s, _ := msg.(string); !strings.Contains(s, "step") {
t.Errorf("the upstream's message should be relayed verbatim when kept: %v", msg)
}
}
if p["progressToken"] != "policy-tok" {
t.Errorf("the client's own token should survive: %v", p)
}
}
if progress != 2 {
t.Errorf("want both progress frames, got %d (%v)", progress, notes)
}
})
}
}

// A 2026-07-28 server has no server-initiated requests: the client MUST NOT
// answer one. mcpx drops it while that revision is strict, and answers it
// with MCPX_SPEC_LENIENT=2026-07-28, for a server that has not caught up
// with its own revision. The unit precedent is
// TestLenient2026AnswersServerRequests; this is the same decision through
// the daemon (#307, #2212).
func TestTheRevisionPolicyDecidesWhetherAServerInitiatedRequestIsAnswered(t *testing.T) {
for _, c := range []struct {
name string
env []string
want string
}{
{"default", nil, "dropped"},
{"lenient-2026-07-28", []string{"MCPX_SPEC_LENIENT=2026-07-28"}, "answered"},
} {
t.Run(c.name, func(t *testing.T) {
e, _ := eraEnv(t, "modern", "", c.env...)
out := e.run("call", "era.ask-server", "{}")
if !strings.Contains(out, c.want) {
t.Fatalf("want %q, got:\n%s", c.want, out)
}
row := upstreamRow(t, e)
if row["era"] != "modern" {
t.Errorf("the upstream must be a 2026-07-28 server for this decision: %v", row)
}
})
}
}
14 changes: 12 additions & 2 deletions pkgs/mcpx/internal/e2e/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ import (
// the call's response, and the response.
func relaySession(t *testing.T, e *env, caps map[string]any, level string, meta map[string]any) (notes []map[string]any, result map[string]any) {
t.Helper()
cmd := exec.Command(e.mcpx, "serve", "--passthrough", "demo")
return relaySessionAs(t, e, "2025-11-25", nil, caps, level, meta)
}

// relaySessionAs is relaySession for a client that states protocolVersion
// and for a daemon started with extra flags (--mcp-spec), so the revision
// policy can be demonstrated against a real daemon (#2212).
func relaySessionAs(t *testing.T, e *env, protocolVersion string, serveArgs []string, caps map[string]any, level string, meta map[string]any) (notes []map[string]any, result map[string]any) {
t.Helper()
args := append([]string{"serve"}, serveArgs...)
args = append(args, "--passthrough", "demo")
cmd := exec.Command(e.mcpx, args...)
cmd.Dir = e.dir
cmd.Env = e.envVars
stdin, err := cmd.StdinPipe()
Expand Down Expand Up @@ -68,7 +78,7 @@ func relaySession(t *testing.T, e *env, caps map[string]any, level string, meta
}
}
send(map[string]any{"jsonrpc": "2.0", "id": 1, "method": "initialize",
"params": map[string]any{"protocolVersion": "2025-11-25", "capabilities": caps,
"params": map[string]any{"protocolVersion": protocolVersion, "capabilities": caps,
"clientInfo": map[string]any{"name": "t", "version": "1"}}})
init := await(1)
send(map[string]any{"jsonrpc": "2.0", "method": "notifications/initialized"})
Expand Down
38 changes: 38 additions & 0 deletions pkgs/mcpx/internal/testsupport/eramcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ var (
// initialized is set once this process has answered initialize: the
// session is legacy from then on.
initialized atomic.Bool
// answered receives a reply to a request this server sent. handle()
// tells such a frame from a request by its empty method, which it used
// to answer with -32601.
answered = make(chan struct{}, 1)
)

func textResult(s string) map[string]any {
return map[string]any{"content": []any{map[string]any{"type": "text", "text": s}}}
}

func main() {
if s := os.Getenv("ERAMCP_SUPPORTED"); s != "" {
supported = strings.Split(s, ",")
Expand Down Expand Up @@ -118,6 +126,14 @@ func handle(f frame) {
if len(f.ID) == 0 {
return // a notification
}
if f.Method == "" {
// A reply to a request this server sent: ask-server reports it.
select {
case answered <- struct{}{}:
default:
}
return
}
switch f.Method {
case "initialize":
if !legacy() {
Expand Down Expand Up @@ -173,6 +189,9 @@ func handle(f frame) {
}, map[string]any{
"name": "ask", "description": "asks a question, the 2026-07-28 way",
"inputSchema": map[string]any{"type": "object"},
}, map[string]any{
"name": "ask-server", "description": "sends one server-initiated request and says whether the client answered",
"inputSchema": map[string]any{"type": "object"},
}}}
if v := os.Getenv("ERAMCP_TTL_MS"); v != "" {
if n, err := strconv.ParseInt(v, 10, 64); err == nil {
Expand All @@ -190,6 +209,25 @@ func handle(f frame) {
InputResponses map[string]json.RawMessage `json:"inputResponses"`
}
_ = json.Unmarshal(f.Params, &call)
if call.Name == "ask-server" {
// One server-initiated request, the mechanism 2026-07-28 forbids
// the client to answer. Under the default policy mcpx drops it
// and this ends "dropped"; with 2026-07-28 lenient, "answered"
// (#2212, spec.Governs).
select {
case <-answered: // a stale reply from an earlier call
default:
}
send(map[string]any{"jsonrpc": "2.0", "id": 9001,
"method": "roots/list", "params": map[string]any{}})
select {
case <-answered:
ok(f.ID, textResult("answered"))
case <-time.After(2 * time.Second):
ok(f.ID, textResult("dropped"))
}
return
}
if call.Name == "ask" && !initialized.Load() {
// The 2026-07-28 way to ask: answer input_required and expect
// the same request again with the answer attached.
Expand Down
7 changes: 6 additions & 1 deletion pkgs/mcpx/internal/testsupport/fakemcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,13 @@ func callTool(r req) map[string]any {
_ = json.Unmarshal(r.Params, &m)
if tok, ok := m.Meta["progressToken"]; ok {
for i := 1; i <= 2; i++ {
// With a message, as every revision from 2025-03-26 defines
// it: relaying to a 2024-11-05 client is where the two
// schemas disagree, and the e2e revision-policy tests need
// the field that gets stripped (#307, #2212).
notify(map[string]any{"jsonrpc": "2.0", "method": "notifications/progress",
"params": map[string]any{"progressToken": tok, "progress": i, "total": 2}})
"params": map[string]any{"progressToken": tok, "progress": i, "total": 2,
"message": fmt.Sprintf("step %d of 2", i)}})
}
}
for _, lvl := range []string{"debug", "warning"} {
Expand Down
Loading