fix(MCPService):修复MCP server 请求头不生效 (#5072)

This commit is contained in:
lossercode 2025-04-20 11:18:34 +08:00 committed by GitHub
parent 60680936d3
commit cf61ae927c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,6 +46,21 @@ const PipRegistry: Registry[] = [
type TabKey = 'settings' | 'tools' | 'prompts' | 'resources' type TabKey = 'settings' | 'tools' | 'prompts' | 'resources'
const parseKeyValueString = (str: string): Record<string, string> => {
const result: Record<string, string> = {}
str.split('\n').forEach((line) => {
if (line.trim()) {
const [key, ...value] = line.split('=')
const formatValue = value.join('=').trim()
const formatKey = key.trim()
if (formatKey && formatValue) {
result[formatKey] = formatValue
}
}
})
return result
}
const McpSettings: React.FC<Props> = ({ server }) => { const McpSettings: React.FC<Props> = ({ server }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { deleteMCPServer, updateMCPServer } = useMCPServers() const { deleteMCPServer, updateMCPServer } = useMCPServers()
@ -211,31 +226,11 @@ const McpSettings: React.FC<Props> = ({ server }) => {
// set env variables // set env variables
if (values.env) { if (values.env) {
const env: Record<string, string> = {} mcpServer.env = parseKeyValueString(values.env)
values.env.split('\n').forEach((line) => {
if (line.trim()) {
const [key, ...chunks] = line.split('=')
const value = chunks.join('=')
if (key && value) {
env[key.trim()] = value.trim()
}
}
})
mcpServer.env = env
} }
if (values.headers) { if (values.headers) {
const headers: Record<string, string> = {} mcpServer.headers = parseKeyValueString(values.headers)
values.headers.split('\n').forEach((line) => {
if (line.trim()) {
const [key, ...chunks] = line.split(':')
const value = chunks.join(':')
if (key && value) {
headers[key.trim()] = value.trim()
}
}
})
mcpServer.headers = headers
} }
try { try {