Skip to content

Commit 3994887

Browse files
committed
update MCP
1 parent 315d32d commit 3994887

2 files changed

Lines changed: 27 additions & 38 deletions

File tree

content/posts/mcp.md

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,42 @@ weight: 15 # The order in which the post appears in a list of posts. Lower nu
1616
- The AI model's response will be more context-ware if we provide it external source like databases, file systems, pictures ,...
1717
- MCP provides a standard way to connect AI-powered applications with external data sources.
1818
- ![image](/images/mcp_overview.png)<br>
19-
<br>
2019

2120
## 2. Model Context Protocol
2221
- Components overview:
2322
- ![image](/images/mcp_overview_diagram.png)<br>
23+
2424
- 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:
25+
- MCP provides **two transport channels**, with many transport types:
2926
- `stdio`: to enable communication through standard I/O streams
3027
- `SSE`: HTTP
28+
- ...
29+
- **MCP Host:** is the main application that integrates with an LLMs and required to connect with external data source.
30+
*e.g. You’re coding in Cursor and type: “Refactor this function and run tests.” - **Cursor = Host***
31+
- **MCP Client:** are components that establish/manage and maintain 1-1 connection with **MCP servers**
32+
e.g. Claude wants to read a file -> **File system client**. Git client .. (basically, we don't see them) -> call MCP Server read_file.
33+
- **MCP Servers:** are components that integrate with external data sources. They are the external programs that expose Tools, Resources and Prompts via API to the API model via Client.
34+
*e.g. Filesystem MCP Server*
35+
- **Tools:** functions that LLMs can call to perform specific actions. *e.g. read_file(path) write_file(path, content) list_directory(path)*
36+
- **Resources:** data source that LLMs can access
37+
*e.g. file:///src/auth/login.ts, file:///tests/login.test.ts*
38+
- **Prompts:** pre-defined templates to use tools or resource in the most optimize way.
39+
*e.g.prompt: refactor_typescript_project, prompt: fix_failing_tests*
3140

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
3641

37-
### 3.1. Dependency
38-
- Create an java maven / jdk 21 project.
39-
- Add the following dependencies to `pom.xml`:
42+
## 3. Flow
43+
- Here's a simplified flow
44+
- ![image](/images/mcp_overview_diagram_2.png)<br>
4045
```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>
46+
1. Initialization: When a Host application starts it creates N MCP Clients, which exchange information about capabilities and protocol versions via a handshake.
47+
2. Discovery: Clients requests what capabilities (Tools, Resources, Prompts) the server offers. The Server responds with a list and descriptions.
48+
3. Context Provision: The Host application can now make resources and prompts available to the user or parses the tools into a LLM compatible format, e.g. JSON Function calling
49+
4. Invocation: If the LLM determines it needs to use a Tool (e.g., based on the user's request like "What are the open issues in the 'X' repo?"), the Host directs the Client to send an invocation request to the appropriate Server.
50+
5. Execution: The Server receives the request (e.g., fetch_github_issues with repo 'X'), executes the underlying logic (calls the GitHub API), and gets the result.
51+
6. Response: The Server sends the result back to the Client.
52+
7. Completion: The Client relays the result to the Host, which incorporates it into the LLM's context, allowing the LLM to generate a final response for the user based on the fresh, external information.
53+
6254
```
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.
6655

67-
- Navigate to [Claud](https://platform.claude.com/settings/keys) and create an API key.
68-
-
56+
## 4. Example
57+
79.8 KB
Loading

0 commit comments

Comments
 (0)