使用说明
第一台MCP服务器
用于访问首次演示的模型上下文协议服务器
First MCP Server是一个轻量级的Java应用程序,它实现了模型上下文协议(MCP),允许AI模型访问有关First会议演示文稿的信息。该服务器通过标准化的MCP工具公开演示数据,使其易于与支持该协议的AI助手集成。
项目要求
- Java 24
- Maven 3.8+
- 模型上下文协议SDK 0.9.0
- SLF4J用于测井
依赖项
该项目依赖于以下关键组成部分:
<!-- MCP SDK -->
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp</artifactId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
入门指南
克隆存储库后,您可以使用Maven构建项目:
mvn clean package
这将在 target 包含所有依赖项的目录。
如何运行应用程序
执行JAR文件以启动MCP服务器:
java -jar target/first-mcp-0.0.2.jar
应用程序启动MCP服务器,该服务器通过标准输入/输出(STDIO)进行通信,并提供对First演示数据的访问。
了解项目结构
核心组件
- 应用程序.java:配置和启动MCP服务器的主要入口点
- 演示文稿.java:表示第一个演示文稿的数据模型
- 演示工具.java:提供演示数据和操作的服务
MCP服务器配置
服务器配置了:
- STDIO通信传输提供商
- 服务器信息(名称和版本)
- 用于访问演示文稿数据的工具功能
McpSyncServer syncServer = McpServer.sync(transportProvider)
.serverInfo("First-mcp-server", "0.0.1")
.capabilities(McpSchema.ServerCapabilities.builder()
.tools(true)
.logging()
.build())
.tools(syncToolSpecification)
.build();
可用工具
服务器公开以下MCP工具:
- get_presences:返回所有First演示文稿的列表
MCP检验员测试
MCP检查器是测试和调试MCP服务器的有用工具。按照以下步骤测试您的第一台MCP服务器:
- 如果你还没有安装Node.js
- 导航到项目目录并获取JAR文件的绝对路径:
# On Linux/macOS
FULL_PATH=$(pwd)/target/first-mcp-0.0.2.jar
echo $FULL_PATH
# On Windows PowerShell
$FULL_PATH="$(Get-Location)\target\first-mcp-0.0.2.jar"
echo $FULL_PATH
- 使用完整路径在服务器上运行MCP检查器:
npx @modelcontextprotocol/inspector java -jar $FULL_PATH
- 在检查器界面中:
- 在连接窗格中验证服务器连接
- 导航到“工具”选项卡以查看
get_presentations工具 - 通过单击工具并查看响应来测试该工具
- 监视“通知”窗格中的日志
与Claude Desktop集成
要将此MCP服务器与Claude Desktop一起使用,请添加以下配置:
- 首先,获取JAR文件的绝对路径:
# On Linux/macOS
FULL_PATH=$(pwd)/target/first-mcp-0.0.2.jar
echo $FULL_PATH
# On Windows PowerShell
$FULL_PATH="$(Get-Location)\target\first-mcp-0.0.2.jar"
echo $FULL_PATH
- 打开克劳德桌面首选项
- 导航到“MCP服务器”部分
- 添加具有以下配置的新服务器(用实际完整路径替换路径):
{
"mcpServers": {
"javaone-mcp": {
"command": "java",
"args": ["-jar", "$FULL_PATH"]
}
}
}
扩展项目
您可以通过多种方式增强此项目:
添加更多演示文稿数据
修改 PresentationTools 课堂包括额外的演示文稿:
// In the PresentationTools constructor
var newPresentation = new Presentation(
"Spring Boot 3.5 Deep Dive",
"https://example.com/spring-boot",
2025
);
this.presentations.add(newPresentation);
创建其他MCP工具
实施更多工具以展示不同的功能:
// Example of adding a tool to search presentations by title
var searchToolSpec = new McpServerFeatures.SyncToolSpecification(
new McpSchema.Tool("search_presentations", "Search presentations by title", searchSchema),
(exchange, arguments) -> {
String query = arguments.get("query").asText();
List<Presentation> results = presentationTools.searchPresentations(query);
// Convert results to MCP content and return
}
);
实现高级功能
- 添加资源订阅以进行实时更新
- 为长时间运行的操作实现异步工具
- 添加身份验证和授权机制
贡献
欢迎投稿!请随时提交拉取请求。
许可证
该项目是开源的,可在 MIT许可证.
