Skip to content

Commit fa9f0be

Browse files
authored
Merge pull request #2062 from oracle-devrel/lsa-23092025-2
changed README, added minimal_mcp_server
2 parents c1d956d + 7e6ef60 commit fa9f0be

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

ai/gen-ai-agents/custom-rag-agent/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ This repository contains the code for the development of a **custom RAG Agent**,
33

44
**Author**: L. Saetta
55

6-
**Last updated**: 11/09/2025
6+
**Reviewed**: 23.09.2025
7+
8+
![UI](images/ui_image.png)
79

810
## Design and implementation
911
* The agent is implemented using **LangGraph**

ai/gen-ai-agents/custom-rag-agent/llm_with_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async def _list_tools(self):
102102
Fetch tools from the MCP server using FastMCP. Must be async.
103103
"""
104104
jwt = self.jwt_supplier()
105-
105+
106106
logger.info("Listing tools from %s ...", self.mcp_url)
107107

108108
# FastMCP requires async context + await for client ops.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""
2+
Minimal-but-solid MCP server with JWT hardening and sane defaults.
3+
4+
- Safe defaults for transports
5+
"""
6+
7+
from fastmcp import FastMCP
8+
9+
# to verify the JWT token
10+
# if you don't need to add security, you can remove this
11+
# in newer version of FastMCP should be replaced with
12+
# from fastmcp.server.auth.providers.jwt import JWTVerifier
13+
from fastmcp.server.auth import BearerAuthProvider
14+
15+
from config import (
16+
# first four needed only to manage JWT
17+
ENABLE_JWT_TOKEN,
18+
IAM_BASE_URL,
19+
ISSUER,
20+
AUDIENCE,
21+
TRANSPORT,
22+
# needed only if transport is stremable-http
23+
HOST,
24+
PORT,
25+
)
26+
27+
28+
#
29+
# if you don't need to add security, you can remove this part and set
30+
# AUTH = None, simply set ENABLE_JWT_TOKEN = False
31+
#
32+
AUTH = None
33+
34+
if ENABLE_JWT_TOKEN:
35+
# check that a valid JWT token is provided
36+
AUTH = BearerAuthProvider(
37+
# this is the url to get the public key from IAM
38+
# the PK is used to check the JWT
39+
jwks_uri=f"{IAM_BASE_URL}/admin/v1/SigningCert/jwk",
40+
issuer=ISSUER,
41+
audience=AUDIENCE,
42+
)
43+
44+
#
45+
# define the MCP server
46+
#
47+
mcp = FastMCP("MCP server with few lines of code, but secure", auth=AUTH)
48+
49+
50+
#
51+
# MCP tools definition
52+
# add and write the code for the tools here
53+
#
54+
@mcp.tool
55+
def say_the_truth(user: str) -> str:
56+
"""
57+
This tool, given the name of the user return one of the secret truths.
58+
59+
Args:
60+
user: The caller's display name or identifier.
61+
62+
Returns:
63+
A short truth string.
64+
"""
65+
# here you'll put the code that reads and return the info requested
66+
# mark each tool with the annotation
67+
return f"{user}: Less is more!"
68+
69+
70+
#
71+
# Run the MCP server
72+
#
73+
if __name__ == "__main__":
74+
# Validate transport
75+
if TRANSPORT not in {"stdio", "streamable-http"}:
76+
# don't use sse! it is deprecated!
77+
raise RuntimeError(f"Unsupported TRANSPORT: {TRANSPORT}")
78+
79+
if TRANSPORT == "stdio":
80+
# stdio doesn’t support host/port args
81+
mcp.run(transport=TRANSPORT)
82+
else:
83+
# For http/streamable-http transport, host/port are valid
84+
mcp.run(
85+
transport=TRANSPORT,
86+
host=HOST,
87+
port=PORT,
88+
)

ai/gen-ai-agents/custom-rag-agent/ui_mcp_agent.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
"""
44

55
import asyncio
6+
import traceback
67
import streamlit as st
78
from mcp_servers_config import MCP_SERVERS_CONFIG
89

910
# this one contains the backend and the test code only for console
1011
from llm_with_mcp import AgentWithMCP, default_jwt_supplier
12+
from utils import get_console_logger
13+
14+
logger = get_console_logger()
1115

1216
# ---------- Page setup ----------
1317
st.set_page_config(page_title="MCP UI", page_icon="🛠️", layout="wide")
@@ -50,6 +54,9 @@
5054
except Exception as e:
5155
st.session_state.agent = None
5256
st.error(f"Failed to connect: {e}")
57+
logger.error(e)
58+
stack_str = traceback.format_exc()
59+
logger.error(stack_str)
5360

5461
# ---------- Chat history (display) ----------
5562
for msg in st.session_state.chat:

0 commit comments

Comments
 (0)