Skip to content

fix: resolve --host flag in MCP serve mode#29

Merged
eskp merged 1 commit intomainfrom
fix/mcp-serve-host-flag
Mar 16, 2026
Merged

fix: resolve --host flag in MCP serve mode#29
eskp merged 1 commit intomainfrom
fix/mcp-serve-host-flag

Conversation

@eskp
Copy link
Copy Markdown
Contributor

@eskp eskp commented Mar 16, 2026

Summary

  • MCP serve mode (kh serve --mcp --host <url>) ignored the --host flag for API requests. tools.go and schemas.go called ResolveHost(nil, cfg) with a nil cobra command, so the flag was invisible and all URLs resolved to the default prod host.
  • Add BaseURL func() string to Factory using the same priority chain as HTTPClient (flag > env > config > default). Replace inline ResolveHost calls in serve mode with f.BaseURL().

Changes

  • pkg/cmdutil/factory.go -- add BaseURL field
  • cmd/kh/main.go -- extract resolveActiveHost() helper, wire BaseURL using same priority chain
  • cmd/serve/tools.go -- replace ResolveHost(nil, cfg) with f.BaseURL()
  • cmd/serve/schemas.go -- same
  • cmd/serve/serve_test.go -- wire BaseURL in test factory

Test plan

  • All 29 Go test packages pass
  • Manually verified: kh serve --mcp --host http://localhost:3000 returns real data from local dev
  • Manually verified: kh serve --mcp --host https://app-staging.keeperhub.com returns real data from staging (with CF headers)
  • Full MCP CRUD + execute tested on all 3 envs (dev, staging, prod)
  • All CLI commands tested on all 3 envs (workflow list/create/get/update/delete/run)

MCP serve mode ignored the --host flag for API requests because
tools.go and schemas.go called ResolveHost(nil, cfg) with a nil cobra
command, making the flag invisible. All API URLs resolved to the
default prod host regardless of --host value.

Add BaseURL func to Factory that uses the same priority chain as
HTTPClient (flag > env > config > default). Replace inline
ResolveHost calls in serve mode with f.BaseURL().
@eskp eskp merged commit aabc8db into main Mar 16, 2026
4 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