Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@
"SHENYU.MCP.CONFIG.EXPLANATION.TRANSPORT": "Transport protocol type",
"SHENYU.MCP.CONFIG.JSON.TITLE": "JSON Configuration (Copy Ready):",
"SHENYU.MCP.CONFIG.COPY.JSON": "Copy JSON",
"SHENYU.MCP.SWAGGER.IMPORT": "Swagger Import",
"SHENYU.MCP.SWAGGER.SWAGGER_URL": "Swagger URL",
"SHENYU.MCP.SWAGGER.SWAGGER_URL.INPUT": "Please input the Swagger URL",
"SHENYU.MCP.SWAGGER.PROJECT_NAME": "Project Name",
"SHENYU.MCP.SWAGGER.PROJECT_NAME.INPUT": "Please input the Project Name",
"APIPROXY.APIKEY.MANAGE": "API Key Manage",
"APIPROXY.APIKEY.CREATE": "Create API Key",
"APIPROXY.APIKEY.EDIT": "Edit API Key",
Expand Down
5 changes: 5 additions & 0 deletions src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@
"SHENYU.MCP.CONFIG.EXPLANATION.TRANSPORT": "传输协议类型",
"SHENYU.MCP.CONFIG.JSON.TITLE": "JSON配置(可直接复制):",
"SHENYU.MCP.CONFIG.COPY.JSON": "复制JSON",
"SHENYU.MCP.SWAGGER.IMPORT": "导入Swagger",
"SHENYU.MCP.SWAGGER.SWAGGER_URL": "Swagger URL",
"SHENYU.MCP.SWAGGER.SWAGGER_URL.INPUT": "请输入 Swagger URL",
"SHENYU.MCP.SWAGGER.PROJECT_NAME": "项目名称",
"SHENYU.MCP.SWAGGER.PROJECT_NAME.INPUT": "请输入项目名称",
"APIPROXY.APIKEY.MANAGE": "API Key 管理",
"APIPROXY.APIKEY.CREATE": "新增 API Key",
"APIPROXY.APIKEY.EDIT": "编辑 API Key",
Expand Down
11 changes: 11 additions & 0 deletions src/models/mcpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
addMcpServer,
updateMcpServer,
deleteMcpServer,
mcpSwaggerImport,
} from "../services/api";
import { getIntlContent } from "../utils/IntlUtils";

Expand Down Expand Up @@ -69,6 +70,16 @@ export default {
payload: { currentPage, pageSize },
});
},
*swaggerImport({ payload, callback }, { call, put }) {
const json = yield call(mcpSwaggerImport, payload);
if (json.code === 200) {
message.success(json.message);
yield put({ type: "reload" });
if (callback) callback();
} else {
message.warn(json.message);
}
},
},

reducers: {
Expand Down
112 changes: 112 additions & 0 deletions src/routes/Plugin/McpServer/SwaggerImportModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React, { Component } from "react";
import { Form, Input, Modal } from "antd";
import { getIntlContent } from "../../../utils/IntlUtils";

const FormItem = Form.Item;

class SwaggerImportModal extends Component {
constructor(props) {
super(props);
this.state = {};
}

handleSubmit = (e) => {
const { form, handleOk } = this.props;
e.preventDefault();
form.validateFieldsAndScroll((err, values) => {
if (!err) {
let { swaggerUrl, projectName } = values;
handleOk({ swaggerUrl, projectName });
}
});
};

render() {
let { handleCancel, form } = this.props;
const { getFieldDecorator } = form;
const formItemLayout = {
labelCol: {
sm: { span: 7 },
},
wrapperCol: {
sm: { span: 17 },
},
};
return (
<Modal
width={520}
centered
title={getIntlContent("SHENYU.MCP.SWAGGER.IMPORT")}
visible
okText={getIntlContent("SHENYU.COMMON.SURE")}
cancelText={getIntlContent("SHENYU.COMMON.CALCEL")}
onOk={this.handleSubmit}
onCancel={handleCancel}
>
<Form onSubmit={this.handleSubmit} className="login-form">
<FormItem
label={getIntlContent("SHENYU.MCP.SWAGGER.SWAGGER_URL")}
{...formItemLayout}
>
{getFieldDecorator("swaggerUrl", {
rules: [
{
required: true,
message: getIntlContent(
"SHENYU.MCP.SWAGGER.SWAGGER_URL.INPUT",
),
},
],
initialValue: "",
})(
<Input
allowClear
placeholder={getIntlContent("SHENYU.MCP.SWAGGER.SWAGGER_URL")}
/>,
)}
</FormItem>
<FormItem
label={getIntlContent("SHENYU.MCP.SWAGGER.PROJECT_NAME")}
{...formItemLayout}
>
{getFieldDecorator("projectName", {
rules: [
{
required: true,
message: getIntlContent(
"SHENYU.MCP.SWAGGER.PROJECT_NAME.INPUT",
),
},
],
initialValue: "",
})(
<Input
allowClear
placeholder={getIntlContent("SHENYU.MCP.SWAGGER.PROJECT_NAME")}
/>,
)}
</FormItem>
</Form>
</Modal>
);
}
}

export default Form.create()(SwaggerImportModal);
31 changes: 31 additions & 0 deletions src/routes/Plugin/McpServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getUpdateModal,
updateNamespacePluginsEnabledByNamespace,
} from "../../../utils/namespacePlugin";
import SwaggerImportModal from "./SwaggerImportModal";

const { Search } = Input;
const { Title } = Typography;
Expand Down Expand Up @@ -419,6 +420,31 @@ export default class McpServer extends Component {
});
};

swaggerImportClick = () => {
const { dispatch, currentNamespaceId } = this.props;
this.setState({
popup: (
<SwaggerImportModal
handleOk={(values) => {
const { swaggerUrl, projectName } = values;
dispatch({
type: "mcpServer/swaggerImport",
payload: {
swaggerUrl,
projectName,
namespaceId: currentNamespaceId,
},
callback: () => {
this.closeModal();
},
});
}}
handleCancel={this.closeModal}
/>
),
});
};

getTypeValueByPluginName = (name) => {
return name === "divide"
? "http"
Expand Down Expand Up @@ -1331,6 +1357,11 @@ export default class McpServer extends Component {
minHeight: 32,
}}
>
<AuthButton perms="system:plugin:edit">
<Button type="primary" onClick={this.swaggerImportClick}>
{getIntlContent("SHENYU.MCP.SWAGGER.IMPORT")}
</Button>
</AuthButton>
<Switch
checked={this.state.isPluginEnabled ?? false}
onChange={this.togglePluginStatus}
Expand Down
12 changes: 12 additions & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,18 @@ export async function importSwagger(params) {
});
}

/* mcpServer import swagger */
export async function mcpSwaggerImport(params) {
return request(`${baseUrl}/swagger/import/mcp`, {
method: `POST`,
body: {
swaggerUrl: params.swaggerUrl,
projectName: params.projectName,
namespaceId: params.namespaceId,
},
});
}

/* findInstance */
export async function findInstanceAnalysis(params) {
return request(`${baseUrl}/instance/analysis/${params.namespaceId}`, {
Expand Down
Loading