Skip to content
Closed
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
16 changes: 16 additions & 0 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@
-http-headers string optional headers for config URL: 'Key1:Value1;Key2:Value2'
-http-timeout int timeout (seconds) for remote config fetch (default 10)
-insecure skip TLS verification for remote config
-check-config load and validate the config, then exit without starting the server
-version print version and exit
-help print help and exit
```

### Validating config

Use `-check-config` to load and validate the configured config (local file or
remote URL, exactly as normal startup does) without binding the HTTP server. On
success it prints the number of configured MCP servers and exits `0`; on an
invalid config it prints an error and exits non-zero.

```bash
mcp-proxy -config config.json -check-config
# Config OK: 3 MCP server(s) configured
```

This is handy for CI, init containers, deployment scripts, and dashboards that
want to validate a generated config before restarting a live proxy.

## Endpoints

Given `mcpProxy.baseURL = https://mcp.example.com` and a server key `fetch`:
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func main() {
expandEnv := flag.Bool("expand-env", true, "expand environment variables in config file")
httpHeaders := flag.String("http-headers", "", "optional HTTP headers for config URL, format: 'Key1:Value1;Key2:Value2'")
httpTimeout := flag.Int("http-timeout", 10, "HTTP timeout in seconds when fetching config from URL")
checkConfig := flag.Bool("check-config", false, "load and validate the config, then exit without starting the server")

version := flag.Bool("version", false, "print version and exit")
help := flag.Bool("help", false, "print help and exit")
Expand All @@ -30,6 +31,10 @@ func main() {
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}
if *checkConfig {
fmt.Printf("Config OK: %d MCP server(s) configured\n", len(config.McpServers))
return
Comment on lines +34 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Run the same per-server validation in check mode

Because this branch returns immediately after load(), -check-config skips the per-server validation that normal startup performs through startHTTPServer/newMCPClient/newMCPServer. For example, a config containing a server with transportType: "stdio" but no command will still print Config OK here, while normal startup fails in parseMCPClientConfigV2 with command is required for stdio transport, so CI or init containers can approve configs that the proxy cannot start with.

Useful? React with 👍 / 👎.

}
Comment on lines +34 to +37

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The -check-config flag is intended to validate the configuration, but currently it only loads the JSON file and checks if mcpProxy is present. It does not validate the individual MCP server configurations (e.g., checking if a stdio transport has a command specified, or if the transport type is valid), which are validated via parseMCPClientConfigV2 during normal startup.

To ensure that invalid server configurations are caught during the config check, we should iterate over the configured servers and validate each one using parseMCPClientConfigV2.

	if *checkConfig {
		for name, server := range config.McpServers {
			if _, err := parseMCPClientConfigV2(server); err != nil {
				log.Fatalf("Failed to validate config for server %q: %v", name, err)
			}
		}
		fmt.Printf("Config OK: %d MCP server(s) configured\n", len(config.McpServers))
		return
	}

err = startHTTPServer(config)
if err != nil {
log.Fatalf("Failed to start server: %v", err)
Expand Down