10000 Add mcp api for maintainer sdk & support console deploy mode. by KomachiSion · Pull Request #13271 · alibaba/nacos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add mcp api for maintainer sdk & support console deploy mode. #13271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2025
Merged
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
10 changes: 5 additions & 5 deletions ai/src/main/java/com/alibaba/nacos/ai/constant/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class Constants {

public static final String ALL_PATTERN = com.alibaba.nacos.api.common.Constants.ALL_PATTERN;

public static final String MCP_SERVER_GROUP = "mcp_server";
public static final String MCP_SERVER_GROUP = "mcp-server";

public static final String MCP_SERVER_TOOL_GROUP = "mcp_server_tool";
public static final String MCP_SERVER_TOOL_GROUP = "mcp-tools";

public static final String MCP_SERVER_SPEC_DATA_ID_SUFFIX = "_mcp_server.json";
public static final String MCP_SERVER_SPEC_DATA_ID_SUFFIX = "-mcp-server.json";

public static final String MCP_SERVER_TOOL_DATA_ID_SUFFIX = "_mcp_server_tool.json";
public static final String MCP_SERVER_TOOL_DATA_ID_SUFFIX = "-mcp-server-tool.json";

public static final String MCP_SERVER_ENDPOINT_GROUP = "mcp_server_endpoint";
public static final String MCP_SERVER_ENDPOINT_GROUP = "mcp-endpoints";

public static final String MCP_SERVER_ENDPOINT_CLUSTER = com.alibaba.nacos.api.common.Constants.DEFAULT_CLUSTER_NAME;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public McpToolOperationService(ConfigQueryChainService configQueryChainService,
public void refreshMcpTool(String namespaceId, String mcpName, List<McpTool> toolSpecification)
throws NacosException {
ConfigRequestInfo configRequestInfo = new ConfigRequestInfo();
configRequestInfo.setUpdateForExist(false);
configOperationService.publishConfig(buildMcpToolConfigForm(namespaceId, mcpName, toolSpecification),
configRequestInfo, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class Mcp {

public static final String MCP_TYPE_SSE_REMOTE = "sse-remote";

public static final String MCP_TYPE_STREAM_REMOTE = "streamble-remote";
public static final String MCP_TYPE_STREAM_REMOTE = "streamable-remote";

public static final String MCP_ENDPOINT_TYPE_REF = "REF";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.alibaba.nacos.api.ai.model.mcp;

import com.alibaba.nacos.api.ai.constant.AiConstants;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -26,8 +28,23 @@
*/
public class McpEndpointSpec {

/**
* Endpoint type. Should be {@link AiConstants.Mcp#MCP_ENDPOINT_TYPE_DIRECT} or
* {@link AiConstants.Mcp#MCP_ENDPOINT_TYPE_REF}.
*/
private String type;

/**
* Endpoint data. Depend on the `type`, the data should be different.
* <p>
* If `type` is {@link AiConstants.Mcp#MCP_ENDPOINT_TYPE_DIRECT}, the data should be include `address` and `port` to
* spec mcp server endpoint.
* </p>
* <p>
* If `type` is {@link AiConstants.Mcp#MCP_ENDPOINT_TYPE_REF}, the data should be include `namespaceId`, `groupName` and `serviceName`
* to spec the ref server which already register into Nacos.
* </p>
*/
private Map<String, String> data = new HashMap<>();

public String getType() {
Expand Down
6DB6
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.alibaba.nacos.api.ai.model.mcp;

import com.alibaba.nacos.api.ai.constant.AiConstants;

import java.util.List;
import java.util.Map;

Expand All @@ -28,18 +30,32 @@ public class McpServerBasicInfo {

private String name;

/**
* It should be {@link AiConstants.Mcp#MCP_TYPE_LOCAL}, {@link AiConstants.Mcp#MCP_TYPE_SSE_REMOTE} or
* {@link AiConstants.Mcp#MCP_TYPE_STREAM_REMOTE}.
*/
private String type;

private String description;

private String version;

/**
* Should be set when `type` is {@link AiConstants.Mcp#MCP_TYPE_SSE_REMOTE} or
* {@link AiConstants.Mcp#MCP_TYPE_STREAM_REMOTE}.
*/
private McpServerRemoteServiceConfig remoteServerConfig;

/**
* Should be set when `type` is {@link AiConstants.Mcp#MCP_TYPE_LOCAL}.
*/
private Map<String, Object> localServerConfig;

private boolean enabled;

/**
* Auto discovery capabilities by Nacos. No need to set when create or update Mcp server.
*/
private List<McpCapability> capabilities;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alibaba.nacos.console.config;

import com.alibaba.nacos.auth.config.NacosAuthConfigHolder;
import com.alibaba.nacos.core.exception.NacosApiExceptionHandler;
import com.alibaba.nacos.console.filter.NacosConsoleAuthFilter;
import com.alibaba.nacos.console.filter.XssFilter;
import com.alibaba.nacos.core.code.ControllerMethodsCache;
Expand Down Expand Up @@ -140,4 +141,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
return http.build();
}

@Bean
public NacosApiExceptionHandler nacosApiExceptionHandler() {
return new NacosApiExceptionHandler();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.alibaba.nacos.core.cluster.Member;
import com.alibaba.nacos.core.cluster.MemberChangeListener;
import com.alibaba.nacos.core.cluster.MembersChangeEvent;
import com.alibaba.nacos.maintainer.client.ai.AiMaintainerFactory;
import com.alibaba.nacos.maintainer.client.ai.AiMaintainerService;
import com.alibaba.nacos.maintainer.client.config.ConfigMaintainerFactory;
import com.alibaba.nacos.maintainer.client.config.ConfigMaintainerService;
import com.alibaba.nacos.maintainer.client.naming.NamingMaintainerFactory;
Expand Down Expand Up @@ -52,6 +54,8 @@ public class NacosMaintainerClientHolder extends MemberChangeListener {

private volatile ConfigMaintainerService configMaintainerService;

private volatile AiMaintainerService aiMaintainerService;

public NacosMaintainerClientHolder(RemoteServerMemberManager memberManager) throws NacosException {
this.memberManager = memberManager;
buildMaintainerService();
Expand All @@ -65,6 +69,7 @@ private void buildMaintainerService() throws NacosException {
properties.setProperty(PropertyKeyConst.SERVER_ADDR, memberAddressString);
namingMaintainerService = NamingMaintainerFactory.createNamingMaintainerService(properties);
configMaintainerService = ConfigMaintainerFactory.createConfigMaintainerService(properties);
aiMaintainerService = AiMaintainerFactory.createAiMaintainerService(properties);
}

public NamingMaintainerService getNamingMaintainerService() {
Expand All @@ -75,6 +80,10 @@ public ConfigMaintainerService getConfigMaintainerService() {
return configMaintainerService;
}

public AiMaintainerService getAiMaintainerService() {
return aiMaintainerService;
}

@Override
public void onEvent(MembersChangeEvent event) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.console.handler.impl.remote.ai;

import com.alibaba.nacos.ai.constant.Constants;
import com.alibaba.nacos.api.ai.model.mcp.McpEndpointSpec;
import com.alibaba.nacos.api.ai.model.mcp.McpServerBasicInfo;
import com.alibaba.nacos.api.ai.model.mcp.McpServerDetailInfo;
Expand All @@ -24,6 +25,7 @@
import com.alibaba.nacos.api.model.Page;
import com.alibaba.nacos.console.handler.ai.McpHandler;
import com.alibaba.nacos.console.handler.impl.remote.EnabledRemoteHandler;
import com.alibaba.nacos.console.handler.impl.remote.NacosMaintainerClientHolder;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -37,31 +39,43 @@
@EnabledRemoteHandler
public class McpRemoteHandler implements McpHandler {

private final NacosMaintainerClientHolder clientHolder;

public McpRemoteHandler(NacosMaintainerClientHolder clientHolder) {
this.clientHolder = clientHolder;
}

@Override
public Page<McpServerBasicInfo> listMcpServers(String namespaceId, String mcpName, String search, int pageNo,
int pageSize) throws NacosException {
throw new UnsupportedOperationException("AI MCP API not support for console mode.");
if (Constants.MCP_LIST_SEARCH_ACCURATE.equalsIgnoreCase(search)) {
return clientHolder.getAiMaintainerService().listMcpServer(mcpName, pageNo, pageSize);
} else {
return clientHolder.getAiMaintainerService().searchMcpServer(mcpName, pageNo, pageSize);
}
}

@Override
public McpServerDetailInfo getMcpServer(String namespaceId, String mcpName) throws NacosException {
throw new UnsupportedOperationException("AI MCP API not support for console mode.");
return clientHolder.getAiMaintainerService().getMcpServerDetail(mcpName);
}

@Override
public void createMcpServer(String namespaceId, String mcpName, McpServerBasicInfo serverSpecification,
List<McpTool> toolSpecification, McpEndpointSpec endpointSpecification) throws NacosException {
throw new UnsupportedOperationException("AI MCP API not support for console mode.");
clientHolder.getAiMaintainerService()
.createMcpServer(mcpName, serverSpecification, toolSpecification, endpointSpecification);
}

@Override
public void updateMcpServer(String namespaceId, String mcpName, McpServerBasicInfo serverSpecification,
List<McpTool> toolSpecification, McpEndpointSpec endpointSpecification) throws NacosException {
throw new UnsupportedOperationException("AI MCP API not support for console mode.");
clientHolder.getAiMaintainerService()
.updateMcpServer(mcpName, serverSpecification, toolSpecification, endpointSpecification);
}

@Override
public void deleteMcpServer(String namespaceId, String mcpName) throws NacosException {
throw new UnsupportedOperationException("AI MCP API not support for console mode.");
clientHolder.getAiMaintainerService().deleteMcpServer(mcpName);
}
}
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test-autoconfigure</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -163,5 +168,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Result<Namespace> getNamespace(@RequestParam("namespaceId") String namesp
@PostMapping
@Secured(resource = Commons.NACOS_ADMIN_CORE_CONTEXT_V3
+ "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE, apiType = ApiType.ADMIN_API)
public Result<Boolean> createNamespace(NamespaceForm namespaceForm) throws NacosException {
public Result<Boolean> createNamespace(NamespaceForm namespaceForm) throws Exception {
namespaceForm.validate();

String namespaceId = namespaceForm.getNamespaceId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1999-2022 Alibaba Group Holding Ltd.
* Copyright 1999-2025 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.alibaba.nacos.console.exception;
package com.alibaba.nacos.core.exception;

import com.alibaba.nacos.api.annotation.NacosApi;
import com.alibaba.nacos.api.exception.NacosException;
Expand Down
28 changes: 28 additions & 0 deletions core/src/test/java/com/alibaba/nacos/core/CoreUtApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 1999-2025 Alibaba Group Holding Ltd.
*
* Licensed 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.
*/

package com.alibaba.nacos.core;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = "com.alibaba.nacos.core")
public class CoreUtApplication {

public static void main(String[] args) {
SpringApplication.run(CoreUtApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void testGetNamespace() throws NacosException {
}

@Test
void testCreateNamespace() throws NacosException {
void testCreateNamespace() throws Exception {
NamespaceForm form = new NamespaceForm();
form.setNamespaceId(TEST_NAMESPACE_ID);
form.setNamespaceName(TEST_NAMESPACE_NAME);
Expand Down
Loading
Loading
0