本项目实现了一个可定制的MCP服务器来执行RTE协议。



编译项目 ./mvnw clean package
在SSE模式下运行服务器
java -jar target/rte-mcp-server-0.0.1-SNAPSHOT.jar
在STDIO模式下运行服务器
java -jar -Dspring.ai.mcp.server.stdio=true rte-mcp-server-0.0.1-SNAPSHOT.jar
该项目旨在易于扩展。你可以通过使用RteUtils类添加自己的MCP工具。
还需要以yaml格式定义RTE连接参数和RTE流程。
RteUtils实现了以下方法:
static RteProtocolClient connect(RteConfig config): 使用提供的yaml连接到RTE服务器。static String executeSteps(RteProtocolClient client, List<RteStep> steps): 在RTE服务器上执行提供的步骤,并返回屏幕结果字符串,使用提供的yaml。作为MCP工具公开的方法应标注为@Tool,并且类应标注为@Services,如下例所示:
@Service
public class RteServiceLoginTool implements RteTool {
private static final Logger logger = LoggerFactory.getLogger(RteServiceLoginTool.class);
@Tool(description = "在给定服务器上执行一个RTE事务", name = "TN5250 登录")
public String executeRteTransaction(String server, int port) {
try {
RteFlow flow = RteYamlLoader.load("/flow.yaml");
RteProtocolClient client = RteTool.connect(flow.getConfig(), server, port);
return RteTool.executeSteps(client, flow.getSteps());
} catch (IOException | RteIOException | InterruptedException | TimeoutException e) {
logger.error("执行RTE流程时出错", e);
return "执行RTE流程时出错: " + e.getMessage();
}
}
}
yaml定义了连接参数和在RTE服务器上执行的步骤。此yaml文件应具有以下结构
config:
server: localhost
port: 2324
protocol: TN5250
terminalType: 'IBM-3477-FC: 27x132'
sslType: None
steps:
- actions:
- label: 用户
input: TESTUSR
- label: 密码
input: TESTPSW
attentionKey: ENTER
可以在yaml文件中定义任意数量的步骤。
server: 连接到RTE服务器的服务器地址。
port: 连接到RTE服务器的端口。
protocol: 支持的协议有TN5250、TN3270 和 VT420
terminalType: 下表显示了每种协议支持的终端类型:
| 协议 | 终端类型 |
|---|---|
| TN5250 | IBM-3477-FC: 27x132 |
| IBM-3179-2: 24x80 | |
| TN3270 | IBM-3278-M2: 24x80 |
| IBM-3278-M2-E: 24x80 | |
| IBM-3278-M3: 32x80 | |
| IBM-3278-M3-E: 32x80 | |
| IBM-3278-M4: 43x80 | |
| IBM-3278-M4-E: 43x80 | |
| IBM-3278-M5: 27x132 | |
| IBM-3278-M5-E: 27x132 | |
| VT420 | VT420-7: 24x80 |
sslType: 支持的ssl类型有None TLS 和 SSLv3。
steps: 在RTE服务器上执行的一系列动作。
actions: 当前屏幕上要执行的所有动作,可以添加任意数量的label/input对。
在RteServiceLoginToolTest类中提供了一个集成测试示例,该测试使用MCPClient验证工具列表并执行它。
注意:为了测试工具的行为,建议生成要执行的RTE流程的转储,并使用wiresham模拟它
有关如何测试和调试服务器的更多信息,请参阅这里