Skip to content

fix: java template #12

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
106 changes: 106 additions & 0 deletions start-mcp-java-hello-world-sse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

> 注:当前项目为 Serverless Devs 应用,由于应用中会存在需要初始化才可运行的变量(例如应用部署地区、函数名等等),所以**不推荐**直接 Clone 本仓库到本地进行部署或直接复制 s.yaml 使用,**强烈推荐**通过 `s init ${模版名称}` 的方法或应用中心进行初始化,详情可参考[部署 & 体验](#部署--体验) 。

# start-mcp-java-hello-world-sse 帮助文档

<description>

基于 Java 的 FC MCP SSE Server 案例

</description>


## 资源准备

使用该项目,您需要有开通以下服务并拥有对应权限:

<service>



| 服务/业务 | 权限 | 相关文档 |
| --- | --- | --- |
| 函数计算 | AliyunFCFullAccess | [帮助文档](https://help.aliyun.com/product/2508973.html) [计费文档](https://help.aliyun.com/document_detail/2512928.html) |

</service>

<remark>



</remark>

<disclaimers>



</disclaimers>

## 部署 & 体验

<appcenter>

- :fire: 通过 [云原生应用开发平台 CAP](https://cap.console.aliyun.com/template-detail?template=start-mcp-java-hello-world) ,[![Deploy with Severless Devs](https://img.alicdn.com/imgextra/i1/O1CN01w5RFbX1v45s8TIXPz_!!6000000006118-55-tps-95-28.svg)](https://cap.console.aliyun.com/template-detail?template=start-mcp-java-hello-world) 该应用。

</appcenter>
<deploy>


</deploy>

## 案例介绍

<appdetail id="flushContent">

这是一个部署到 FC 的 MCP Server 的 Java hello world 样例。您可以通过这个模版初始化一个简单的、开箱即用的、可进行二次开发的 MCP Server。

此样例包含一个名为 `helloWorld` 的 Tool,您可基于此样例 Tool 进行二次开发。

</appdetail>







## 使用流程

<usedetail id="flushContent">

部署完成拿到 URL 后,准备好支持 SSE 或 STDIO 的 MCP Client,通过 Transport 进行连接。

</usedetail>

## 二次开发指南

<development id="flushContent">

此样例包含一个名为 `helloWorld` 的 Tool,您可基于此样例 Tool 进行二次开发。
```java
@Service
public class McpService {
public McpService() {}
/**
* A sample tool. Return string 'Hello World!'
* @return String
*/
@Tool(description = "Return string 'Hello World!'")
public String helloWorld() {
return "Hello World!";
}

public static void main(String[] args) {
McpService client = new McpService();
System.out.println(client.helloWorld());
}
}
```

</development>






42 changes: 42 additions & 0 deletions start-mcp-java-hello-world-sse/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Edition: 3.0.0
Type: Project
Name: fcai-start-mcp-java-hello-world-sse
Version: dev
Provider:
- 阿里云 # 取值内容参考:https://api.devsapp.cn/v3/common/args.html
Description: 基于 Java 的 FC MCP SSE Server 案例
HomePage: https://github.com/devsapp/fcai-mcp-servers/tree/main/start-mcp-java-hello-world-sse
Tags: #标签详情
- MCP
- Develop
Category: MCP服务 # 取值内容参考:https://api.devsapp.cn/v3/common/args.html
Service: # 使用的服务
函数计算: # 取值内容参考:https://api.devsapp.cn/v3/common/args.html
Authorities: #权限描述
- AliyunFCFullAccess # 所需要的权限,例如AliyunFCFullAccess
Organization: 阿里云函数计算(FC) # 所属组织
Effective: Public # 是否公开,取值:Public,Private,Organization
Parameters:
type: object
additionalProperties: false # 不允许增加其他属性
required: # 必填项
- region
properties:
region:
title: 地域
type: string
default: cn-hangzhou
description: 创建应用所在的地区
required: true
enum:
- cn-beijing
- cn-hangzhou
- cn-shanghai
- cn-shenzhen
- ap-southeast-1
functionName:
title: 函数名
type: string
pattern: "^[a-zA-Z_][a-zA-Z0-9-_]{0,127}$"
default: start-mcp-server-java-${default-suffix}
description: 函数名,支持字母、数字、下划线、连字符,不能以数字或连字符开头,长度为1~64个字符。
3 changes: 3 additions & 0 deletions start-mcp-java-hello-world-sse/src/.signore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./code/node_modules/
./code/dist
./code/target/
8 changes: 8 additions & 0 deletions start-mcp-java-hello-world-sse/src/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
start-mcp-java-hello-world:
default:
rootPath: ./code
languages:
- java21
steps:
- run: chmod +x ./mvnw
- run: ./mvnw clean install -DskipTests
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
Loading