Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit e860ed8

Browse files
committed
Add --tls-insecure to make TLS useless
Fixes #1
1 parent 7378233 commit e860ed8

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

cmd/openapi-mcp/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type cliFlags struct {
3131
docFormat string
3232
postHookCmd string
3333
noConfirmDangerous bool
34+
tlsInsecure bool // Disable TLS certificate verification
3435
args []string
3536
mounts mountFlags // slice of mountFlag
3637
functionListFile string // Path to file listing functions to include (for filter command)
@@ -87,6 +88,7 @@ func parseFlags() *cliFlags {
8788
flag.StringVar(&flags.docFormat, "doc-format", "markdown", "Documentation format: markdown (default) or html")
8889
flag.StringVar(&flags.postHookCmd, "post-hook-cmd", "", "Command to post-process the generated tool schema JSON (used in --dry-run or --doc mode)")
8990
flag.BoolVar(&flags.noConfirmDangerous, "no-confirm-dangerous", false, "Disable confirmation prompt for dangerous (PUT/POST/DELETE) actions in tool descriptions")
91+
flag.BoolVar(&flags.tlsInsecure, "tls-insecure", false, "Disable TLS certificate verification for HTTP calls to remote APIs")
9092
flag.Var(&flags.mounts, "mount", "Mount an OpenAPI spec at a base path: /base:path/to/spec.yaml (repeatable, can be used multiple times)")
9193
flag.StringVar(&flags.functionListFile, "function-list-file", "", "File with list of function (operationId) names to include (one per line, for filter command)")
9294
flag.StringVar(&flags.logFile, "log-file", "", "File path to log all MCP requests and responses for debugging")
@@ -191,6 +193,7 @@ Flags:
191193
--doc-format Documentation format: markdown (default) or html
192194
--post-hook-cmd Command to post-process the generated tool schema JSON
193195
--no-confirm-dangerous Disable confirmation for dangerous actions
196+
--tls-insecure Disable TLS certificate verification for HTTP calls to remote APIs
194197
--summary Print a summary for CI
195198
--tag Only include tools with the given tag
196199
--diff Compare generated tools with a reference file

cmd/openapi-mcp/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func main() {
2424
// Set env vars from flags if provided
2525
setEnvFromFlags(flags)
2626

27+
// Configure HTTP client TLS settings globally if flag is set
28+
if flags.tlsInsecure {
29+
openapi2mcp.SetHTTPClientTLSConfig(true)
30+
}
31+
2732
args := flags.args
2833

2934
// If --mount is used with --http, do not require a positional argument

cmd/openapi-mcp/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
// startServer starts the MCP server in stdio or HTTP mode, based on CLI flags.
2121
// It registers all OpenAPI operations as MCP tools and starts the server.
2222
func startServer(flags *cliFlags, ops []openapi2mcp.OpenAPIOperation, doc *openapi3.T) {
23+
// Configure HTTP client TLS settings
24+
if flags.tlsInsecure {
25+
openapi2mcp.SetHTTPClientTLSConfig(true)
26+
}
2327
if flags.httpAddr != "" && len(flags.mounts) > 0 {
2428
// Check for duplicate base paths
2529
basePathCount := make(map[string]int)

pkg/openapi2mcp/register.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package openapi2mcp
44
import (
55
"bytes"
66
"context"
7+
"crypto/tls"
78
"encoding/base64"
89
"encoding/json"
910
"fmt"
@@ -22,6 +23,27 @@ import (
2223
"github.com/xeipuuv/gojsonschema"
2324
)
2425

26+
// httpClient is the HTTP client used for making OpenAPI calls.
27+
// It can be configured with custom TLS settings.
28+
var httpClient = http.DefaultClient
29+
30+
// SetHTTPClientTLSConfig configures the HTTP client with custom TLS settings.
31+
// If tlsInsecure is true, TLS certificate verification will be disabled.
32+
func SetHTTPClientTLSConfig(tlsInsecure bool) {
33+
if tlsInsecure {
34+
transport := &http.Transport{
35+
TLSClientConfig: &tls.Config{
36+
InsecureSkipVerify: true,
37+
},
38+
}
39+
httpClient = &http.Client{
40+
Transport: transport,
41+
}
42+
} else {
43+
httpClient = http.DefaultClient
44+
}
45+
}
46+
2547
// getParameterValue retrieves a parameter value from args using the escaped parameter name.
2648
// It tries the escaped name first, then falls back to the original name if not found.
2749
func getParameterValue(args map[string]any, paramName string, paramNameMapping map[string]string) (any, bool) {
@@ -1063,7 +1085,7 @@ func RegisterOpenAPITools(server *mcpserver.MCPServer, ops []OpenAPIOperation, d
10631085
logHTTPRequest(httpReq, body)
10641086
}
10651087

1066-
resp, err := http.DefaultClient.Do(httpReq)
1088+
resp, err := httpClient.Do(httpReq)
10671089
if err != nil {
10681090
return nil, err
10691091
}

0 commit comments

Comments
 (0)