开发框架对比

框架Spring AlLangChain4jLangchain
版本1.0.0-M71.0.0-beta30.3.56
Github Star4.9K+7.4K+(增速较快)107K+
官页https://docs.langchain4j.dev/
https://github.com/spring-projects/spring-ai
https://docs.langchain4j.dev/
https://github.com/langchain4j/langchain4j
https://python.langchain.com/docs/introduction/
https://github.com/langchain-ai/langchain
开发语言JavaJavaPython
环境需求JDK 17+、Spring Boot 3.xJDK 17+Python 3
支持的模型Anthropic Claude、Azure OpenAI、DeepSeek (OpenAI-proxy)、Google VertexAI Gemini、Groq (OpenAI-proxy)、HuggingFace、Mistral AI、MiniMax、Moonshot AI、NVIDIA (OpenAI-proxy)、OCI GenAI/Cohere、Ollama、OpenAI、Perplexity (OpenAI-proxy)、QianFan、ZhiPu AI、Watsonx.AI、Amazon Bedrock ConverseAmazon Bedrock、Anthropic、Azure OpenAl、ChatGLM、DashScope (Qwen)、GitHub Models、Google AI Gemini、 Google Vertex Al Gemini. Google Vertex AI PaLM 2、 Hugging Face、Jlama、LocalAl、MistralAl、 Ollama、OpenAl、OpenAIl Official SDK、Qianfan、Cloudflare Workers Al、ZhiPuAl、XinferenceAI21 Labs、Aleph Alpha、Alibaba Cloud PAI EAS、Amazon API Gateway、Anyscale、Aphrodite Engine、Arcee、Azure ML、Azure OpenAI、Baichuan LLM、Baidu Qianfan、Banana、Baseten、Beam、Bedrock、Bittensor、CerebriumAI、ChatGLM、Clarifai、Cloudflare Workers AI、Cohere、C Transformers、CTranslate2、Databricks、DeepInfra、DeepSparse、Eden AI、ExLlamaV2、Fireworks、ForefrontAI、Friendli、GigaChat、Google AI、Google Cloud Vertex AI、GooseAI、GPT4All、Gradient、Huggingface Endpoints、Hugging Face Local Pipelines、IBM watsonx.ai、IPEX-LLM、Javelin AI Gateway Tutorial、JSONFormer、KoboldAI API、Konko、Layerup Security、Llama.cpp、Llamafile、LM Format Enforcer、Manifest、Minimax、MLX Local Pipelines、Modal、ModelScope、MoonshotChat、MosaicML、NLP Cloud、NVIDIA、oci_generative_ai、OCI Data Science Model Deployment Endpoint、OctoAI、Ollama、OpaquePrompts、OpenAI、OpenLLM、OpenLM、OpenVINO、Outlines、Petals、PipelineAI、Pipeshift、Predibase、PredictionGuard、PromptLayer OpenAI、RELLM、Replicate、Runhouse、RunPod LLM、SageMakerEndpoint、SambaNovaCloud、SambaStudio、Solar、SparkLLM、StochasticAI、Nebula (Symbl.ai)、TextGen、Titan Takeoff、Together AI、Tongyi Qwen、vLLM、Volc Engine Maas、Intel Weight-Only Quantization、Writer LLM、Xorbits Inference (Xinference)、YandexGPT、Yi、Yuan2.0
Chat Memory支持 (基本功能不可能不支持)
https://docs.spring.io/spring-ai/reference/api/chat-memory.html
支持
https://docs.langchain4j.dev/tutorials/chat-memory
支持
RAG 支持Naive RAG
Advanced RAG (ETL Pipeline)
RAG 部分堪称简陋
https://docs.spring.io/spring-ai/reference/api/retrieval-augmented-generation.html
Easy RAG Naive RAG AdvancedRAG(基于元数据过滤、查询路由、文档切割、多格式文档解析。
向量存储Spring data 高级封装官方和社区提供大量实现, 基本市面上的数据库都支持, 堪称集大成者
https://python.langchain.com/docs/integrations/vectorstores/
MCP 支持服务端 客户端
https://docs.spring.io/spring-ai/reference/api/mcp/mcp-client-boot-starter-docs.html
服务端 客户端
提示词模版基本的链式代码调用的方式
AiService 通过注解@UserMessage({}) 引用
结构化输出还需要手动写 Schema 和 转换逻辑
https://docs.spring.io/spring-ai/reference/api/structured-output-converter.html

https://docs.langchain4j.dev/tutorials/structured-outputs
结合 Pydantic 的注解, 对输出甚至输入,都可以自动 Schema 进行解析, 还可以对数据有验证 约束.
https://python.langchain.com/docs/how_to/structured_output/#the-with_structured_output-method
编程式开发Chat Client APIBasics API
声明式注解开发Al Services

MCP widt Spring AI

参考- https://docs.spring.io/spring-ai/reference/api/mcp/mcp-overview.html

参考 MCP服务端- https://docs.spring.io/spring-ai/reference/api/mcp/mcp-server-boot-starter-docs.html

spring initializr

spring initializr - https://start.spring.io/

plugins {
	java
	id("org.springframework.boot") version "3.5.0"
	id("io.spring.dependency-management") version "1.1.7"
}
 
group = "com.example"
version = "0.0.1-SNAPSHOT"
 
java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(21)
	}
}
 
repositories {
	mavenCentral()
}
 
extra["springAiVersion"] = "1.0.0"
 
dependencies {
	implementation("org.springframework.boot:spring-boot-starter-web")
	implementation("org.springframework.ai:spring-ai-starter-mcp-server-webmvc")
	testImplementation("org.springframework.boot:spring-boot-starter-test")
	testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
 
dependencyManagement {
	imports {
		mavenBom("org.springframework.ai:spring-ai-bom:${property("springAiVersion")}")
	}
}
 
tasks.withType<Test> {
	useJUnitPlatform()
}
 

Transport Options

The MCP Server supports three transport mechanisms, each with its dedicated starter:

  • Standard Input/Output (STDIO) - spring-ai-starter-mcp-server
  • Spring MVC (Server-Sent Events) - spring-ai-starter-mcp-server-webmvc
  • Spring WebFlux (Reactive SSE) - spring-ai-starter-mcp-server-webflux

Features and Capabilities

The MCP Server Boot Starter allows servers to expose tools, resources, and prompts to clients. It automatically converts custom capability handlers registered as Spring beans to sync/async specifications based on server type:

Tools

Allows servers to expose tools that can be invoked by language models. The MCP Server Boot Starter provides:

  • Change notification support
  • Spring AI Tools are automatically converted to sync/async specifications based on server type
  • Automatic tool specification through Spring beans: in short 要提供MCP 工具要用ToolCallbackProvider 装饰一下, 注册给容器
@Bean
public ToolCallbackProvider myTools(...) {
    List<ToolCallback> tools = ...
    return ToolCallbackProvider.from(tools);
}

or using the low-level API:

@Bean
public List<McpServerFeatures.SyncToolSpecification> myTools(...) {
    List<McpServerFeatures.SyncToolSpecification> tools = ...
    return tools;
}

The auto-configuration will automatically detect and register all tool callbacks from: * Individual ToolCallback beans * Lists of ToolCallback beans * ToolCallbackProvider beans

Tools are de-duplicated by name, with the first occurrence of each tool name being used.

Tool Context Support

The ToolContext is supported, allowing contextual information to be passed to tool calls. It contains an McpSyncServerExchange instance under the exchange key, accessible via McpToolUtils.getMcpExchange(toolContext).

See this example demonstrating exchange.loggingNotification(…​) and exchange.createMessage(…​).

Provides a standardized way for servers to expose resources to clients.

  • Static and dynamic resource specifications
  • Optional change notifications
  • Support for resource templates
  • Automatic conversion between sync/async resource specifications
  • Automatic resource specification through Spring beans:
@Bean
public List<McpServerFeatures.SyncResourceSpecification> myResources(...) {
    var systemInfoResource = new McpSchema.Resource(...);
    var resourceSpecification = new McpServerFeatures.SyncResourceSpecification(systemInfoResource, (exchange, request) -> {
        try {
            var systemInfo = Map.of(...);
            String jsonContent = new ObjectMapper().writeValueAsString(systemInfo);
            return new McpSchema.ReadResourceResult(
                    List.of(new McpSchema.TextResourceContents(request.uri(), "application/json", jsonContent)));
        }
        catch (Exception e) {
            throw new RuntimeException("Failed to generate system info", e);
        }
    });
 
    return List.of(resourceSpecification);
}

Example Applications

一个 node 开发的MCP客户端

npx @modelcontextprotocol/inspector