Back to MCP directory
publicPublicdnsLocal runtime

mcp_hello_world

使用Java编写的MCP服务器Hello World示例项目

article

README

🚀 使用Java创建MCP服务器并显示“Hello World”

本项目通过Java语言创建一个MCP服务器,并且能够在运行时显示“Hello World”,帮助开发者快速了解MCP服务器的基础搭建。

🚀 快速开始

环境准备

确保你已经安装了Java开发环境(JDK),并且配置好了环境变量。

步骤

  1. 创建一个Java项目。
  2. 编写代码创建MCP服务器并显示“Hello World”。
  3. 运行代码,查看结果。

代码示例

// 这里假设你有具体的代码来创建MCP服务器并显示Hello World
// 以下是示例代码结构,你可以根据实际情况替换
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MCPServer {
    public static void main(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(8080)) {
            System.out.println("MCP服务器已启动,等待连接...");
            while (true) {
                try (Socket socket = serverSocket.accept()) {
                    OutputStream output = socket.getOutputStream();
                    String response = "Hello World";
                    output.write(response.getBytes());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

运行结果

运行代码后,你将看到类似如下的结果: 展示结果

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client