mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-11-10 03:30:53 +08:00
fix: Fixed issue with mcp externalUrl config failed (#10331)
Refs https://github.com/1Panel-dev/1Panel/issues/10323
This commit is contained in:
parent
c5f70eae4c
commit
7742e3da38
2 changed files with 51 additions and 21 deletions
|
|
@ -111,11 +111,14 @@ func (m McpServerService) Update(req request.McpServerUpdate) error {
|
||||||
mcpServer.Port = req.Port
|
mcpServer.Port = req.Port
|
||||||
mcpServer.Command = req.Command
|
mcpServer.Command = req.Command
|
||||||
mcpServer.BaseURL = req.BaseURL
|
mcpServer.BaseURL = req.BaseURL
|
||||||
mcpServer.SsePath = req.SsePath
|
|
||||||
mcpServer.HostIP = req.HostIP
|
mcpServer.HostIP = req.HostIP
|
||||||
mcpServer.StreamableHttpPath = req.StreamableHttpPath
|
|
||||||
mcpServer.OutputTransport = req.OutputTransport
|
mcpServer.OutputTransport = req.OutputTransport
|
||||||
mcpServer.Type = req.Type
|
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 {
|
if err := handleCreateParams(mcpServer, req.Environments, req.Volumes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -163,19 +166,23 @@ func (m McpServerService) Create(create request.McpServerCreate) error {
|
||||||
}
|
}
|
||||||
mcpDir := path.Join(global.Dir.McpDir, create.Name)
|
mcpDir := path.Join(global.Dir.McpDir, create.Name)
|
||||||
mcpServer := &model.McpServer{
|
mcpServer := &model.McpServer{
|
||||||
Name: create.Name,
|
Name: create.Name,
|
||||||
ContainerName: create.ContainerName,
|
ContainerName: create.ContainerName,
|
||||||
Port: create.Port,
|
Port: create.Port,
|
||||||
Command: create.Command,
|
Command: create.Command,
|
||||||
Status: constant.StatusStarting,
|
Status: constant.StatusStarting,
|
||||||
BaseURL: create.BaseURL,
|
BaseURL: create.BaseURL,
|
||||||
SsePath: create.SsePath,
|
Dir: mcpDir,
|
||||||
Dir: mcpDir,
|
HostIP: create.HostIP,
|
||||||
HostIP: create.HostIP,
|
OutputTransport: create.OutputTransport,
|
||||||
StreamableHttpPath: create.StreamableHttpPath,
|
Type: create.Type,
|
||||||
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 {
|
if err := handleCreateParams(mcpServer, create.Environments, create.Volumes); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -445,8 +452,14 @@ func addProxy(server *model.McpServer) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, server.SsePath)})
|
var proxyPath string
|
||||||
location.ChangePath("^~", server.SsePath)
|
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 {
|
if err = nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
|
||||||
global.LOG.Errorf("write config failed, err: %v", buserr.WithErr("ErrUpdateBuWebsite", err))
|
global.LOG.Errorf("write config failed, err: %v", buserr.WithErr("ErrUpdateBuWebsite", err))
|
||||||
return
|
return
|
||||||
|
|
@ -497,8 +510,14 @@ func addMCPProxy(websiteID uint) error {
|
||||||
err = errors.New("error")
|
err = errors.New("error")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
location.UpdateDirective("proxy_pass", []string{fmt.Sprintf("http://127.0.0.1:%d%s", server.Port, server.SsePath)})
|
var proxyPath string
|
||||||
location.ChangePath("^~", server.SsePath)
|
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 {
|
if err = nginx.WriteConfig(config, nginx.IndentedStyle); err != nil {
|
||||||
return buserr.WithErr("ErrUpdateBuWebsite", err)
|
return buserr.WithErr("ErrUpdateBuWebsite", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<div>
|
<div>
|
||||||
<RouterMenu />
|
<RouterMenu />
|
||||||
<LayoutContent :title="'Servers'" v-loading="loading">
|
<LayoutContent :title="'Servers'" v-loading="loading">
|
||||||
<template #toolbar>
|
<template #leftToolBar>
|
||||||
<div class="flex flex-wrap gap-3">
|
<div class="flex flex-wrap gap-3">
|
||||||
<el-button type="primary" @click="openCreate">
|
<el-button type="primary" @click="openCreate">
|
||||||
{{ $t('aiTools.mcp.create') }}
|
{{ $t('aiTools.mcp.create') }}
|
||||||
|
|
@ -12,6 +12,9 @@
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<template #rightToolBar>
|
||||||
|
<TableRefresh @search="search()" />
|
||||||
|
</template>
|
||||||
<template #main>
|
<template #main>
|
||||||
<ComplexTable :pagination-config="paginationConfig" :data="items" @search="search()">
|
<ComplexTable :pagination-config="paginationConfig" :data="items" @search="search()">
|
||||||
<el-table-column
|
<el-table-column
|
||||||
|
|
@ -29,8 +32,8 @@
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('aiTools.mcp.externalUrl')" prop="baseUrl" min-width="200px">
|
<el-table-column :label="$t('aiTools.mcp.externalUrl')" prop="baseUrl" min-width="200px">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ row.baseUrl + row.ssePath }}
|
{{ getUrl(row) }}
|
||||||
<CopyButton :content="row.baseUrl + row.ssePath" />
|
<CopyButton :content="getUrl(row)" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('commons.table.status')" prop="status" width="120px">
|
<el-table-column :label="$t('commons.table.status')" prop="status" width="120px">
|
||||||
|
|
@ -125,6 +128,14 @@ const mobile = computed(() => {
|
||||||
return globalStore.isMobile();
|
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 = [
|
const buttons = [
|
||||||
{
|
{
|
||||||
label: i18n.global.t('menu.config'),
|
label: i18n.global.t('menu.config'),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue