|
| 1 | +--- |
| 2 | +author: "Phong Nguyen" |
| 3 | +title: "Model Context Protocol (MCP)" |
| 4 | +date: "2026-02-10" |
| 5 | +description: "Model Context Protocol (MCP)" |
| 6 | +tags: ["mcp"] #tags search |
| 7 | +FAcategories: ["syntax"] #The category of the post, similar to tags but usually for broader classification. |
| 8 | +FAseries: ["Themes Guide"] #indicates that this post is part of a series of related posts |
| 9 | +aliases: ["migrate-from-jekyl"] #Alternative URLs or paths that can be used to access this post, useful for redirects from old posts or similar content. |
| 10 | +ShowToc: true # Determines whether to display the Table of Contents (TOC) for the post. |
| 11 | +TocOpen: true # Controls whether the TOC is expanded when the post is loaded. |
| 12 | +weight: 15 # The order in which the post appears in a list of posts. Lower numbers make the post appear earlier. |
| 13 | +--- |
| 14 | +## 1. Introduce |
| 15 | +- Modern applications are integrating with Large Language Models (LLMs) to build AI solution. |
| 16 | +- The AI model's response will be more context-ware if we provide it external source like databases, file systems, pictures ,... |
| 17 | +- MCP provides a standard way to connect AI-powered applications with external data sources. |
| 18 | + - <br> |
| 19 | +<br> |
| 20 | + |
| 21 | +## 2. Model Context Protocol |
| 22 | +- Components overview: |
| 23 | + - <br> |
| 24 | +- MCP follows a client-server architecture, that included: |
| 25 | + - **MCP Host:** is the main application that integrates with an LLMs and required to connect with external data source |
| 26 | + - **MCP Client:** are components that establish and maintain 1-1 connection with **MCP servers** |
| 27 | + - **MCP Servers:** are components that integrate with external data sources and expose apis to interact with them |
| 28 | + - MCP provides **two transport channels**, with many transport types: |
| 29 | + - `stdio`: to enable communication through standard I/O streams |
| 30 | + - `SSE`: HTTP |
| 31 | + |
| 32 | +## 3. Java Example - Creating an MCP Host |
| 33 | +Building an application (MCP Host): |
| 34 | + - act as a chatbot using a Claude LLMs model. |
| 35 | + - enable to use a local LLM |
| 36 | + |
| 37 | +### 3.1. Dependency |
| 38 | +- Create an java maven / jdk 21 project. |
| 39 | +- Add the following dependencies to `pom.xml`: |
| 40 | +```xml |
| 41 | +<dependency> |
| 42 | + <groupId>org.springframework.ai</groupId> |
| 43 | + <artifactId>spring-ai-starter-model-anthropic</artifactId> |
| 44 | + <version>1.0.1</version> |
| 45 | +</dependency> |
| 46 | +<dependency> |
| 47 | + <groupId>org.springframework.ai</groupId> |
| 48 | + <artifactId>spring-ai-starter-mcp-client</artifactId> |
| 49 | + <version>1.0.1</version> |
| 50 | +</dependency> |
| 51 | +<dependencyManagement> |
| 52 | + <dependencies> |
| 53 | + <dependency> |
| 54 | + <groupId>org.springframework.ai</groupId> |
| 55 | + <artifactId>spring-ai-bom</artifactId> |
| 56 | + <version>1.0.1</version> |
| 57 | + <type>pom</type> |
| 58 | + <scope>import</scope> |
| 59 | + </dependency> |
| 60 | + </dependencies> |
| 61 | +</dependencyManagement> |
| 62 | +``` |
| 63 | +- Notes: |
| 64 | + - `spring-ai-starter-model-anthropic`: to interact with the Claud model |
| 65 | + - `spring-ai-starter-mcp-client`: to configure clients in the application to maintain 1-1 connection with the MCP servers. |
| 66 | + |
| 67 | +- Navigate to [Claud](https://platform.claude.com/settings/keys) and create an API key. |
| 68 | +- |
0 commit comments