MCP:基于Java SDK 实现一个 Mcp Server

在上一篇文章中介绍了 Java SDK Client 源码,并实现一个 Mcp Client 调用现成的 @modelcontextprotocol/server-filesystem,本文将实现一个 Mcp Server。

什么 Mcp Server

Mcp Server 是一个轻量级程序,每个程序都通过标准化的 Model Context Protocol 公开特定功能。可以向Mcp Client 三项核心能力 tools、resources 以及 templates。

Mcp Server 三项核心能力

能力 说明
tools 工具,提供给应用使用
resources 资源,提供数据,提供给大模型使用,比如数据库、文件等
templates 模版,提供给用户使用

Mcp Server 提供通信方式

  • stdio
  • sse

Java SDK 源码

  • transport 通信协议
    • HttpServletSseServerTransport sse方式
    • StdioServerTransport 本地标准方式
  • Mcp Server Mcp server 通用接口 内部 AsyncSpec 和 SyncSpec 类分别创建异步和同步 Mcp Server
  • McpAsyncServer 创建异步 mcp server
  • McpSyncServer 创建同步 mcp server
  • McpServerFeatures Mcp Server 特性定义,比如服务器的版本、能力、工具、提示词等管理
相关推荐
mCell7 小时前
你以为短链接只是 Hash + 301/302?
后端·算法·架构
咖啡八杯7 小时前
GoF设计模式——迭代器模式
java·后端·设计模式·迭代器模式
IT_陈寒11 小时前
SpringBoot自动配置不是你以为的那样的智能
前端·人工智能·后端
森叶12 小时前
从 MCP 到扣子:Agent 平台化演化路径
人工智能·大模型·agent·ai agent·mcp
Darling噜啦啦13 小时前
远程MCP实战:高德地图 + Chrome DevTools + File System 三大 Server 联动打造 AI 超级 Agent
mcp
程序员张313 小时前
SpringBoot集成BCrypt密码加密库
java·spring boot·后端
CaffeinePro13 小时前
FastAPI数据库集成SQLAlchemy异步ORM全方案
后端·fastapi
小旭Coding13 小时前
凌晨告警轰炸!Go 服务协程只增不减,内存持续暴涨直至 OOM
后端
半个落月13 小时前
用 LangChain.js 手写一个能读写文件和执行命令的 Mini Cursor
javascript·人工智能·后端
9523614 小时前
RabbitMQ-基础操作
java·spring boot·分布式·后端·spring·rabbitmq