fix(mcp): http 传输支持跳过 TLS 证书校验(自签证书)
MCP server 走 HTTPS 且用自签证书时,客户端 TLS 校验失败,报 "tls: failed to verify certificate" 无法连接。 mcp_servers 增加 insecure 开关(默认 false),置 true 时远程 MCP 客户端使用 InsecureSkipVerify 的 transport。stdio 传输不受影响。 - mcphttp.New 增加 insecure 参数 - db: MCPServer.Insecure 字段 + schema 加列(补 ALTER 兼容旧库) - create_mcp/update_mcp 工具与前端 http 配置项增加勾选框 Closes #108
This commit is contained in:
1 parent
cde3ce9b25
commit
25b82f2544
8 files changed
+42
-12
No files matched your search
+9
-2
@@ -12,6 +12,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -65,12 +66,18 @@ type Client struct {
|
||||
|
||||
// New connects to a remote MCP endpoint and performs the initialize handshake.
|
||||
// headers are sent on every request (Authorization, custom API keys, …).
|
||||
func New(ctx context.Context, server, url string, headers map[string]string) (*Client, error) {
|
||||
// When insecure is true, TLS certificate verification is skipped so servers that
|
||||
// present a self-signed certificate can still be reached (issue #108).
|
||||
func New(ctx context.Context, server, url string, headers map[string]string, insecure bool) (*Client, error) {
|
||||
hc := &http.Client{Timeout: 120 * time.Second}
|
||||
if insecure {
|
||||
hc.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
|
||||
}
|
||||
c := &Client{
|
||||
server: server,
|
||||
url: url,
|
||||
headers: headers,
|
||||
http: &http.Client{Timeout: 120 * time.Second},
|
||||
http: hc,
|
||||
}
|
||||
if err := c.initialize(ctx); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in new issue
Block a user