You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/secure-mcp-cmd-client-server/README.md
+12-16Lines changed: 12 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,14 @@
1
1
# Secure MCP command line client-server example using the SSE transport protocol with Keycloak and AI Gemini.
2
2
3
-
This sample showcases how Quarkus MCP client can acquire OAuth2 client_credential grant tokens from Keycloak and use them to access secure Quarkus MCP server using the [SSE transport protocol](https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse) protocol.
3
+
This sample showcases how Quarkus MCP client can acquire OAuth2 client_credentials grant tokens from Keycloak and use them to access secure Quarkus MCP server using the [SSE transport protocol](https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse) protocol.
4
4
5
-
Quarkus MCP server gives the LLM a tool that can return a name of the logged-in user. AI Gemini uses this tool to create a poem about Java for the logged-in user.
6
-
7
-
# AI Gemini API key
8
-
9
-
Get [AI Gemini API key](https://aistudio.google.com/app/apikey). Use it to either set an `AI_GEMINI_API_KEY` environment property or update the `quarkus.langchain4j.ai.gemini.api-key=${ai_gemini_api_key}` property in `application.properties` by replacing `${ai_gemini_api_key}` with the API key value.
5
+
Quarkus MCP server gives the LLM a tool that can return a name of the service account. AI Gemini uses this tool to include a service account name in a poem about Java.
10
6
11
7
# Running the sample in dev mode
12
8
13
9
### MCP server
14
10
15
-
Start the mcp server component in the `secure-mcp-server` directory using `mvn quarkus:dev`.
11
+
Start the mcp server component in the `secure-mcp-cmd-server` directory using `mvn quarkus:dev`.
16
12
17
13
This will start the server on port 8080 and launch a Keycloak container on port 8081. Keycloak dev service creates a `quarkus` realm with a `quarkus-mcp-server` client.
18
14
@@ -25,32 +21,32 @@ Keycloak `quarkus` realm configuration must be updated to support MCP server req
25
21
Keycloak dev service has already created the `quarkus-mcp-server` client in the `quarkus` realm and is available on 8081 port. Go to `http://localhost:8081`, login as `admin:admin` and select the `quarkus` realm.
26
22
27
23
Create two more clients, `quarkus-mcp-client` that will represent Quarkus MCP client, and `quarkus-mcp-service` that will represent a protected REST server that the MCP `quarkus-mcp-server` server will call to complete the tool action.
28
-
Make sure both client only have `Client Authentication` and `Service Accounts Roles` client capabilities enabled.
24
+
Make sure both clients only have `Client Authentication` and `Service Accounts Roles` client capabilities enabled.
29
25
30
26
Copy the secret of the `quarkus-mcp-client`, you will need it later to run Quarkus MCP client.
31
27
32
-
Create two `Optional` client scopes, `quarkus-mcp-server-scope` and `quarkus-mcp-service-scope`, and create the `Audience` mapper for each of these scopes, selecting `quarkus-mcp-server` and `quarkus-mcp-client` clients as audiences respectively.
28
+
Create two `Optional` client scopes, `quarkus-mcp-server-scope` and `quarkus-mcp-service-scope`, and create the `Audience` mapper for each of these scopes, selecting `quarkus-mcp-server` and `quarkus-mcp-client` clients as included client audiences respectively.
33
29
34
30
Add `Optional``quarkus-mcp-server` client scope to the `quarkus-mcp-client` client and `Optional``quarkus-mcp-service` client scope to the `quarkus-mcp-server` client.
35
31
36
32
Finally, update the `quarkus-mcp-server` capabilities to support `Standard Token Exchange`.
37
33
38
-
This Keycloak configuration enables Quarkus MCP client to request an access token that can be used to access the Quarkus MCP server only but not the protected REST server. It also allows Quarkus MCP server to exchange the token targeted at it for another token that will only be valid for accessing the protected REST server.
34
+
This Keycloak configuration enables Quarkus MCP client to request an access token that can be used to access the Quarkus MCP server only. It also allows Quarkus MCP server to exchange the token targeted at it for another token that will only be valid for accessing the protected REST server.
39
35
40
36
### MCP Client
41
37
42
-
Make sure AI Gemini API key is available to the MCP client by exporting it as an environment property:
38
+
Make sure the MCP server is started and the Keycloak configuration is done.
39
+
40
+
Get [AI Gemini API key](https://aistudio.google.com/app/apikey) and export it as an `AI_GEMINI_API_KEY` environment property:
43
41
44
42
```shell
45
-
exportai_gemini_api_key=your_ai_gemini_api_key
43
+
exportAI_GEMINI_API_KEY=your_ai_gemini_api_key
46
44
```
47
45
48
-
Also make sure the MCP server is started and the Keycloak configuration is done.
49
-
50
-
Export the Keycloak `quarkus-mcp-client` secret that you copied when configuring Keycloak as an environment property:
46
+
Export the Keycloak `quarkus-mcp-client` secret that you copied when configuring Keycloak as an `OIDC_CLIENT_SECRET` environment property:
Copy file name to clipboardExpand all lines: samples/secure-mcp-cmd-client-server/secure-mcp-cmd-client/src/main/java/io/quarkiverse/langchain4j/sample/PoemService.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,8 @@
8
8
publicinterfacePoemService {
9
9
@UserMessage("""
10
10
Write a short 1 paragraph poem in {language} about a Java programming language.
11
-
Please use the service account name when creating the poem.""")
11
+
Provide a translation to English if the original poem language is not English.
12
+
Dedicate the poem to the service account, refer to this account by its name.""")
0 commit comments