fix: Fixed issue with mcp externalUrl config failed (#10331)

Refs https://github.com/1Panel-dev/1Panel/issues/10323
This commit is contained in:
CityFun 2025-09-10 17:06:51 +08:00 committed by GitHub
parent c5f70eae4c
commit 7742e3da38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 21 deletions

View file

@ -111,11 +111,14 @@ func (m McpServerService) Update(req request.McpServerUpdate) error {
mcpServer.Port = req.Port
mcpServer.Command = req.Command
mcpServer.BaseURL = req.BaseURL
mcpServer.SsePath = req.SsePath
mcpServer.HostIP = req.HostIP
mcpServer.StreamableHttpPath = req.StreamableHttpPath
mcpServer.OutputTransport = req.OutputTransport
mcpServer.Type = req.Type
if req.OutputTransport == "sse" {
mcpServer.SsePath = req.SsePath
} else {
mcpServer.StreamableHttpPath = req.StreamableHttpPath
}
if err := handleCreateParams(mcpServer, req.Environments, req.Volumes); err != nil {
return err
}
@ -163,19 +166,23 @@ func (m McpServerService) Create(create request.McpServerCreate) error {
}
mcpDir := path.Join(global.Dir.McpDir, create.Name)
mcpServer := &model.McpServer{
Name: create.Name,
ContainerName: create.ContainerName,
Port: create.Port,
Command: create.Command,
Status: constant.StatusStarting,
BaseURL: create.BaseURL,
SsePath: create.SsePath,
Dir: mcpDir,
HostIP: create.HostIP,
StreamableHttpPath: create.StreamableHttpPath,
OutputTransport: create.OutputTransport,
Type: create.Type,
Name: create.Name,
ContainerName: create.ContainerName,
Port: create.Port,
Command: create.Command,
Status: constant.StatusStarting,
BaseURL: create.BaseURL,
Dir: mcpDir,
HostIP: create.HostIP,
OutputTransport: create.OutputTransport,
Type: create.Type,
}
if create.OutputTransport == "sse" {
mcpServer.SsePath = create.SsePath
} else {
mcpServer.StreamableHttpPath = create.StreamableHttpPath
}
if err := handleCreateParams(mcpServer, create.Environments, create.Volumes); err != nil {
return err
}
@ -445,8 +452,14 @@ func addProxy(server *model.McpServer) {
if !ok {
return
}
location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, server.SsePath)})
location.ChangePath("^~", server.SsePath)
var proxyPath string
if server.OutputTransport == "sse" {
proxyPath = server.SsePath
} else {
proxyPath = server.StreamableHttpPath
}
location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, proxyPath)})
location.ChangePath("^~", proxyPath)
if err = nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
global.LOG.Errorf("write config failed, err: %v", buserr.WithErr("ErrUpdateBuWebsite", err))
return
@ -497,8 +510,14 @@ func addMCPProxy(websiteID uint) error {
err = errors.New("error")
return err
}
location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, server.SsePath)})
location.ChangePath("^~", server.SsePath)
var proxyPath string
if server.OutputTransport == "sse" {
proxyPath = server.SsePath
} else {
proxyPath = server.StreamableHttpPath
}
location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, proxyPath)})
location.ChangePath("^~", proxyPath)
if err = nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
return buserr.WithErr("ErrUpdateBuWebsite", err)
}

View file

@ -2,7 +2,7 @@
<div>
<RouterMenu />
<LayoutContent :title="'Servers'" v-loading="loading">
<template #toolbar>
<template #leftToolBar>
<div class="flex flex-wrap gap-3">
<el-button type="primary" @click="openCreate">
{{ $t('aiTools.mcp.create') }}
@ -12,6 +12,9 @@
</el-button>
</div>
</template>
<template #rightToolBar>
<TableRefresh @search="search()" />
</template>
<template #main>
<ComplexTable :pagination-config="paginationConfig" :data="items" @search="search()">
<el-table-column
@ -29,8 +32,8 @@
</el-table-column>
<el-table-column :label="$t('aiTools.mcp.externalUrl')" prop="baseUrl" min-width="200px">
<template #default="{ row }">
{{ row.baseUrl + row.ssePath }}
<CopyButton :content="row.baseUrl + row.ssePath" />
{{ getUrl(row) }}
<CopyButton :content="getUrl(row)" />
</template>
</el-table-column>
<el-table-column :label="$t('commons.table.status')" prop="status" width="120px">
@ -125,6 +128,14 @@ const mobile = computed(() => {
return globalStore.isMobile();
});
const getUrl = (row: AI.McpServer) => {
if (row.outputTransport == 'sse') {
return row.baseUrl + row.ssePath;
} else {
return row.baseUrl + row.streamableHttpPath;
}
};
const buttons = [
{
label: i18n.global.t('menu.config'),