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
110 changes: 55 additions & 55 deletions pkgs/mcpx/docs/environment.md

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions pkgs/mcpx/internal/cli/adapter_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os/exec"
"path/filepath"
"regexp"
"sort"
"strings"
"time"
"unicode"
Expand Down Expand Up @@ -733,13 +732,3 @@ func versionDrift(s adapter.Spec) (declared, found string, drift bool) {
}
return s.Provenance.BinaryVersion, found, found != s.Provenance.BinaryVersion
}

// sortedFlagNames is a small deterministic-order helper for notes.
func sortedFlagNames(flags []importFlag) []string {
var names []string
for _, f := range flags {
names = append(names, f.flag())
}
sort.Strings(names)
return names
}
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/cli/adapter_import_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func firstSentence(s string) string {
}

var helpRowRE = regexp.MustCompile(`^\s{1,6}(\S+)\s{2,}(\S.*)$`)
var usageBracketRE = regexp.MustCompile("\\[([^\\[\\]]*)\\]")
var usageBracketRE = regexp.MustCompile(`\[([^\[\]]*)\]`)

// optionalPositionalNames extracts the positional names a help text's
// usage block marks optional: the bracketed [name] form (argparse
Expand Down
20 changes: 10 additions & 10 deletions pkgs/mcpx/internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int {
// to be reached for mid-command ("...actually, show me") as
// chosen up front.
if err := app.CmdTUI(ctx, nil); err != nil {
fmt.Fprintln(stdio.err(), "mcpx:", err)
_, _ = fmt.Fprintln(stdio.err(), "mcpx:", err)
return 1
}
return 0
Expand Down Expand Up @@ -198,7 +198,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int {
config.SetPathsConfigSeed(splitList(strings.TrimPrefix(args[0], "--paths-config=")))
args = args[1:]
case args[0] == "--version" || args[0] == "-v":
fmt.Fprintln(stdio.out(), "mcpx", Version)
_, _ = fmt.Fprintln(stdio.out(), "mcpx", Version)
return 0
case args[0] == "--help" || args[0] == "-h":
_ = app.CmdHelp(ctx, nil)
Expand All @@ -209,14 +209,14 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int {
// `mcpx ls --plumbing-strict-unknown-keys` does.
rest, err := app.ApplyGlobalSettingFlags(args)
if err != nil {
fmt.Fprintln(stdio.err(), "mcpx:", err)
_, _ = fmt.Fprintln(stdio.err(), "mcpx:", err)
return 2
}
if len(rest) < len(args) {
args = rest
continue
}
fmt.Fprintf(stdio.err(), "unknown global flag %q\n", args[0])
_, _ = fmt.Fprintf(stdio.err(), "unknown global flag %q\n", args[0])
return 2
}
}
Expand All @@ -233,7 +233,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int {
// terminal the TUI cannot have been meant, and help with
// success stays the answer for a pipe.
if isTerminal(os.Stdin) && isTerminal(os.Stdout) {
fmt.Fprintln(stdio.err(), "mcpx:", err)
_, _ = fmt.Fprintln(stdio.err(), "mcpx:", err)
return 1
}
_ = app.CmdHelp(ctx, nil)
Expand All @@ -260,7 +260,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int {
h, rest = app.CmdExec, args
}
} else {
fmt.Fprintf(stdio.err(), "unknown command %q\n\n", cmd)
_, _ = fmt.Fprintf(stdio.err(), "unknown command %q\n\n", cmd)
_ = app.CmdHelp(ctx, nil)
return 2
}
Expand All @@ -270,7 +270,7 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int {
// file is reported once, up front, rather than by whichever command
// happens to read the offending value first.
if err := app.SettingsErr(); err != nil {
fmt.Fprintln(stdio.err(), "mcpx:", err)
_, _ = fmt.Fprintln(stdio.err(), "mcpx:", err)
return 2
}

Expand All @@ -288,14 +288,14 @@ func Run(ctx context.Context, args []string, env Env, stdio Stdio) int {
// prefix with "mcpx:" -- only the status carries over.
var se *exitStatusError
if !errors.As(err, &se) {
fmt.Fprintln(stdio.err(), "mcpx:", err)
_, _ = fmt.Fprintln(stdio.err(), "mcpx:", err)
}
return ec.ExitCode()
}
if errors.Is(err, ErrNoDaemon) {
fmt.Fprintln(stdio.err(), "mcpx: daemon is not running and could not be started")
_, _ = fmt.Fprintln(stdio.err(), "mcpx: daemon is not running and could not be started")
} else {
fmt.Fprintln(stdio.err(), "mcpx:", err)
_, _ = fmt.Fprintln(stdio.err(), "mcpx:", err)
}
return 1
}
Expand Down
6 changes: 0 additions & 6 deletions pkgs/mcpx/internal/cli/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ func scriptResolver() scriptresolve.Resolver {
}
}

// scriptPath resolves the configured search path, splicing the built-in list
// wherever the user left a null.
func scriptPath() searchpath.Resolved {
return scriptResolver().Path()
}

// scriptSearchDirs is the flat list, kept for the environment variable the
// runner passes to scripts.
func scriptSearchDirs() []string {
Expand Down
16 changes: 8 additions & 8 deletions pkgs/mcpx/internal/codegen/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ func toolDecl(t Tool, indent string) string {
return b.String()
}

// Module renders the importable client module for the TypeScript target
// (the TypeScript entry in the Language table, language.go). Scripts do:
//
// import { fff, chrome_devtools } from "./.mcpx/client.ts";
//
// or use the default `tools` object. The module is written to disk, so the
// JavaScript runtime's own module cache applies and startup stays at tens of
// milliseconds.
// RecipeMeta is one saved script (a recipe), as search() surfaces it
// beside tools (CODE-36): the script's name, its summary as the
// description, and its placeholder names. The daemon renders the
Expand All @@ -138,6 +130,14 @@ type RecipeMeta struct {
Required []string
}

// Module renders the importable client module for the TypeScript target
// (the TypeScript entry in the Language table, language.go). Scripts do:
//
// import { fff, chrome_devtools } from "./.mcpx/client.ts";
//
// or use the default `tools` object. The module is written to disk, so the
// JavaScript runtime's own module cache applies and startup stays at tens of
// milliseconds.
// Module renders the client with no saved scripts in search().
func Module(nss []Namespace, endpoint, session string) string {
return ModuleWithRecipes(nss, endpoint, session, nil)
Expand Down
4 changes: 4 additions & 0 deletions pkgs/mcpx/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func TestAnUnknownKeyInTheMcpxBlockIsRefused(t *testing.T) {
}

func TestServerKeysAnotherHostWritesAreRecordedNotRefused(t *testing.T) {
// MCPX_CONFIG short-circuits the search path (chain.go); the devshell
// sets it, so without this the merged load below reads that file
// instead of the test fixtures and the ignored key is lost.
t.Setenv("MCPX_CONFIG", "")
// A server entry is shared with every other MCP host. Claude Code
// writes "type" and Cline writes "alwaysAllow"; refusing them would
// make a config that works everywhere else fail here.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/daemon/routes_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ func (s *Server) handleAPIsAdd(w http.ResponseWriter, r *http.Request) {
writeErr(w, http.StatusBadRequest, err)
return
}
if err := req.apiDeclaration.Validate(); err != nil {
if err := req.Validate(); err != nil {
writeErr(w, http.StatusBadRequest, err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/e2e/feature_coverage_guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func TestFeatureCoverageGuardSkipsPartialExecutionModes(t *testing.T) {
t.Fatalf("set %s: %v", name, err)
}
if violations := featureCoverageGuardViolations(0, nil); violations != nil {
flag.Set(name, orig)
_ = flag.Set(name, orig)
t.Fatalf("with %s set, guard returned %v, want nil (evaluation excluded)", name, violations)
}
if err := flag.Set(name, orig); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkgs/mcpx/internal/mcpauth/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ func Classify(err error) Block {
if !errors.As(err, &ae) {
return BlockHard
}
switch {
case ae.Status == 429:
switch ae.Status {
case 429:
return BlockSoft
case ae.Status == 403:
case 403:
if ae.RetryAfter > 0 {
return BlockSoft
}
Expand Down Expand Up @@ -456,7 +456,7 @@ func (m *Minter) Mint(ctx context.Context, keyPEM []byte, appID, installationID
if err != nil {
return "", time.Time{}, err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return "", time.Time{}, &APIError{Status: resp.StatusCode, Body: string(body)}
Expand Down
4 changes: 2 additions & 2 deletions pkgs/mcpx/internal/mcpauth/failover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestMintInstallationToken(t *testing.T) {
gotPath = req.URL.Path
gotJWT = strings.TrimPrefix(req.Header.Get("Authorization"), "Bearer ")
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, `{"token":"installation-token-xyz","expires_at":"2030-01-01T00:00:00Z"}`)
_, _ = fmt.Fprint(w, `{"token":"installation-token-xyz","expires_at":"2030-01-01T00:00:00Z"}`)
}))
defer srv.Close()

Expand Down Expand Up @@ -241,7 +241,7 @@ func TestAppIdentityMintsAndCaches(t *testing.T) {
mints := 0
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
mints++
fmt.Fprint(w, `{"token":"minted-1","expires_at":"2999-01-01T00:00:00Z"}`)
_, _ = fmt.Fprint(w, `{"token":"minted-1","expires_at":"2999-01-01T00:00:00Z"}`)
}))
defer srv.Close()

Expand Down
8 changes: 4 additions & 4 deletions pkgs/mcpx/internal/mcpclient/redirect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestHTTPStreamClientRefusesCrossOriginRedirect(t *testing.T) {

body, err := tr.get(context.Background(), "")
if body != nil {
body.Close()
_ = body.Close()
}
assertCrossOriginRedirectReturned(t, err, http.StatusFound)
assertRedirectTargetNotReached(t, seen)
Expand All @@ -114,7 +114,7 @@ func TestLegacySSEInitialGETRefusesCrossOriginRedirect(t *testing.T) {

tr, err := NewLegacySSE(context.Background(), HTTPOptions{URL: source.URL, Headers: map[string]string{"X-API-Key": redirectTestAPIKey}})
if tr != nil {
tr.Close()
_ = tr.Close()
}
assertCrossOriginRedirectReturned(t, err, http.StatusFound)
assertRedirectTargetNotReached(t, seen)
Expand All @@ -126,7 +126,7 @@ func TestLegacySSEPOSTRefusesCrossOriginRedirect(t *testing.T) {
switch r.URL.Path {
case "/sse":
w.Header().Set("Content-Type", "text/event-stream")
fmt.Fprint(w, "event: endpoint\ndata: /post\n\n")
_, _ = fmt.Fprint(w, "event: endpoint\ndata: /post\n\n")
w.(http.Flusher).Flush()
<-r.Context().Done()
case "/post":
Expand All @@ -141,7 +141,7 @@ func TestLegacySSEPOSTRefusesCrossOriginRedirect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer tr.Close()
defer func() { _ = tr.Close() }()

err = tr.Send(context.Background(), []byte(`{"jsonrpc":"2.0","id":1,"method":"tools/list"}`))
assertCrossOriginRedirectReturned(t, err, http.StatusTemporaryRedirect)
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/mcpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ func (s *Server) handle(ctx context.Context, c *Conn, req request) *response {
if version == "" && c != nil {
version = c.Version()
}
if version != "" && !(capName == "completions" && !Defines(version, FeatCompletions)) {
if version != "" && (capName != "completions" || Defines(version, FeatCompletions)) {
// The completions exemption: 2024-11-05 has no completions
// capability to advertise with, but completion/complete
// itself is older than the capability (see FeatCompletions),
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/pluginsession/hooks.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Manifest-hook resolution for plugin sessions (#1873 slice 2,
// Package pluginsession provides manifest-hook resolution for plugin sessions (#1873 slice 2,
// #10046): the declarations Registry.Open records become live bus
// subscribers, owned by the session and dropped by its Close.
//
Expand Down
10 changes: 5 additions & 5 deletions pkgs/mcpx/internal/pool/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ func RequestedCallTimeout(ctx context.Context) (time.Duration, bool) {
return d, ok && d > 0
}

// callTimeout is the effective budget for one upstream request: the
// pool's configured CallTimeout, lowered by a caller's per-call request
// when one is present and smaller. A configured value of zero or less
// means the operator set no bound, so a per-call request then applies
// exactly as asked.
// CallTimeout is the pool's resolved per-call budget for ctx: the
// configured CallTimeout, lowered by a caller's per-call request when
// one is present and smaller. It is the same value upstream calls are
Expand All @@ -83,6 +78,11 @@ func (p *Pool) CallTimeout(ctx context.Context) time.Duration {
return p.callTimeout(ctx)
}

// callTimeout is the effective budget for one upstream request: the
// pool's configured CallTimeout, lowered by a caller's per-call request
// when one is present and smaller. A configured value of zero or less
// means the operator set no bound, so a per-call request then applies
// exactly as asked.
func (p *Pool) callTimeout(ctx context.Context) time.Duration {
cfg := p.cfg.CallTimeout
req, ok := RequestedCallTimeout(ctx)
Expand Down
16 changes: 0 additions & 16 deletions pkgs/mcpx/internal/recipes/recipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,6 @@ func scanCode(src string) []bool {
return code
}

// refs finds every `@name` in the body, ignoring declarations, comments and
// anything inside a string.
func refs(src string) []string { return refsFor(src, langJS) }

// refsFor is refs with the code mask of the body's own language: a
// Python or shell comment is not JavaScript, and an `@name` inside one
// ('# Contact @alice') is text, not a placeholder -- while Parse used
Expand Down Expand Up @@ -587,14 +583,6 @@ func (r Recipe) Render(values map[string]any) (string, error) {
return strings.TrimRight(b.String(), "\n") + "\n", nil
}

// substitute replaces `@name` placeholders on one line. code is the
// scanCode mask for exactly this line's bytes: an `@name` outside code
// position (in a comment or a string) is copied through untouched, so a
// filled value is never spliced into a literal.
func substitute(line string, code []bool, lits map[string]string) string {
return substituteFor(line, code, lits, langJS)
}

// substituteFor is substitute in the body's language: a Python
// decorator (an `@name` as the first thing on its line, at a statement
// boundary) is language syntax, never a placeholder, so it is copied
Expand Down Expand Up @@ -630,10 +618,6 @@ func substituteFor(line string, code []bool, lits map[string]string, lang string
return b.String()
}

// literal renders one value as a JavaScript literal; literalFor is
// the language-aware form Render uses.
func literal(p Placeholder, v any) (string, error) { return literalFor(langJS, p, v) }

func literalFor(lang string, p Placeholder, v any) (string, error) {
switch p.Type {
case TypeNumber:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func Run(ctx context.Context, opts Options) (*Result, error) {
rt.Bin = abs
}
}
if rt.Kind == KindNode && !(devshellIsFlake(opts.Devshell) && rt.Bin == rt.Invoke) {
if rt.Kind == KindNode && (!devshellIsFlake(opts.Devshell) || rt.Bin != rt.Invoke) {
// A devshell-deferred runtime has no host binary to probe: Bin
// is still the bare name the shell will resolve. Probing it
// here would fail the run before the shell gets its chance.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/runner/runtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func checkNodeTransformTypes(bin string) error {
return fmt.Errorf("probe node runtime %s for --experimental-transform-types: create temporary TypeScript script: %w", bin, err)
}
probePath := probe.Name()
defer os.Remove(probePath)
defer func() { _ = os.Remove(probePath) }()
if _, err := probe.WriteString("enum McpxTransformTypesProbe { Supported }; void McpxTransformTypesProbe.Supported;\n"); err != nil {
_ = probe.Close()
return fmt.Errorf("probe node runtime %s for --experimental-transform-types: write temporary TypeScript script: %w", bin, err)
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/testsupport/childenv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// The test child environment: an allowlist, not an inheritance.
// Package testsupport provides the test child environment: an allowlist, not an inheritance.
//
// Every end-to-end test starts a real mcpx binary as a child process. That
// child used to inherit the developer's whole environment minus MCPX_*
Expand Down