Skip to content

Commit 845a25c

Browse files
Standalone MCP (#346)
* ADB/Readme added ADB support. Fixed Readme to run correctly the mcp/inspector * fix to ensure reachability * fix OCI model getting issue * Fixup OCI --------- Co-authored-by: corradodebari <[email protected]>
1 parent 14f207b commit 845a25c

File tree

7 files changed

+96
-2967
lines changed

7 files changed

+96
-2967
lines changed

src/client/mcp/rag/.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/client/mcp/rag/README.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
**Version:** *Developer preview*
55

66
## Introduction
7-
This document describe how to re-use the configuration tested in the **AI Optimizer & Toolkit** an expose it as an MCP tool to a local **Claude Desktop** and how to setup as a remote MCP server. This early draft implementation utilizes the `stdio` and `sse` to interact between the agent dashboard, represented by the **Claude Desktop**, and the tool.
7+
This document describe how to re-use the configuration tested in the **AI Optimizer & Toolkit** an expose it as an MCP tool to a local **Claude Desktop** and how to setup as a remote MCP server. This early draft implementation utilizes the `stdio`, `sse` and, by default, the `streamable-http` to interact between the agent dashboard, represented by the **Claude Desktop**, and the tool.
88

9-
**NOTICE**: Only `Ollama` or `OpenAI` configurations are currently supported. Full support will come.
9+
**NOTICE**: Only `Ollama`, `OpenAI`, `hosted_vllm` configurations are currently supported. Full support will come. `DB23ai`, `26ai` and `Autonomous DB` with wallet configuration is also supported.
1010

1111
## Pre-requisites.
1212
You need:
@@ -34,12 +34,14 @@ In the **AI Optimizer & Toolkit** web interface, after tested a configuration, i
3434
* press button `Download LangchainMCP` to download an VectorSearch MCP Agent built on current configuration.
3535
* unzip the file in a `<PROJECT_DIR>` dir.
3636

37+
**NOTICE**: if you want to run the application in another server, remember to change in the `optimizer_settings.json` any reference no more local, like hostname for LLM servers, Database, wallet dir and so on.
38+
3739

3840
## Standalone client
3941
There is a client that you can run without MCP via command-line to test it:
4042

4143
```bash
42-
uv run rag_base_optimizer_config.py "[YOUR_QUESTION]"
44+
uv run rag_base_optimizer_config_direct.py "[YOUR_QUESTION]"
4345
```
4446
In `rag_base_optimizer_config_mcp.py`:
4547

@@ -117,15 +119,15 @@ uv run rag_base_optimizer_config_mcp.py
117119
}
118120
}
119121
```
120-
* Set `Local` with `Remote client` line in `<PROJECT_DIR>/rag_base_optimizer_config_mcp.py`:
122+
* Set `Remote client` line of code with `Local` in `<PROJECT_DIR>/rag_base_optimizer_config_mcp.py`:
121123

122124
```python
123-
#mcp.run(transport='stdio')
124-
#mcp.run(transport='sse')
125-
mcp.run(transport='streamable-http')
125+
# Initialize FastMCP server
126+
#mcp = FastMCP("rag", port=9090) #Remote client
127+
mcp = FastMCP("rag") #Local
126128
```
127129

128-
* Substitute `stdio` with `streamable-http` line of code:
130+
* Substitute line of code `streamable-http` with `stdio`:
129131

130132
```python
131133
mcp.run(transport='stdio')
@@ -144,7 +146,7 @@ uv run rag_base_optimizer_config_mcp.py
144146
* Run the inspector:
145147

146148
```bash
147-
npx @modelcontextprotocol/inspector
149+
npx @modelcontextprotocol/inspector@0.15.0
148150
```
149151

150152
* connect the browser to `http://127.0.0.1:6274`
@@ -158,37 +160,37 @@ npx @modelcontextprotocol/inspector
158160

159161

160162
**Optional:** run with local **stdio** protocol
161-
* Set as shown before the protolo to run locally in `<PROJECT_DIR>/rag_base_optimizer_config_mcp.py`:
163+
* Set as shown before the protocol to run locally in `<PROJECT_DIR>/rag_base_optimizer_config_mcp.py`:
162164

163-
```
164165
* Set `Local` with `Remote client` line:
165166

166167
```python
167168
#mcp = FastMCP("rag", port=9090) #Remote client
168169
mcp = FastMCP("rag") #Local
169170
```
170171

171-
* Substitute `stdio` with `sse` line of code:
172+
* Substitute `streamable-http` with `stdio` line of code:
172173
```python
173174
mcp.run(transport='stdio')
174-
#mcp.run(transport='sse')
175+
#mcp.run(transport='sse')
176+
#mcp.run(transport='streamable-http')
175177
```
176178

177179
* Run the inspector:
178180

179-
```bash
180-
npx @modelcontextprotocol/inspector uv run rag_base_optimizer_config_mcp.py
181-
```
181+
```bash
182+
npx @modelcontextprotocol/inspector@0.15.0 uv run rag_base_optimizer_config_mcp.py
183+
```
182184

183185
* connect to the port `http://localhost:6274/` with your browser on the link printed, like in the following example:
184-
```bash
185-
..
186-
Open inspector with token pre-filled:
187-
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=cb2ef7521aaf2050ad9620bfb5e5df42dc958889e6e99ce4e9b18003eb93fffd
188-
..
189-
```
186+
```bash
187+
..
188+
Open inspector with token pre-filled:
189+
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=cb2ef7521aaf2050ad9620bfb5e5df42dc958889e6e99ce4e9b18003eb93fffd
190+
..
191+
```
190192

191-
* setup the `Inspector Proxy Address` with `http://127.0.0.1:6277`
193+
* setup the Transport Type: `STDIO`
192194
* test the tool developed.
193195

194196

src/client/mcp/rag/optimizer_utils/config.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,20 @@ def get_vectorstore(data, embeddings):
9797
user=db_config["user"]
9898
password=db_config["password"]
9999
dsn=db_config["dsn"]
100+
101+
# ADB connection with wallet
102+
103+
wallet_pwd= db_config["wallet_password"]
104+
wallet_location = db_config["wallet_location"]
100105

101106
logger.info(f"{db_table}: {user} - {dsn}")
102-
conn23c = oracledb.connect(user=user, password=password, dsn=dsn)
107+
108+
if wallet_pwd and wallet_location:
109+
logger.info("ADB connection starting..")
110+
conn23c = oracledb.connect(user=user, password=password, dsn=dsn,wallet_location=wallet_location,wallet_password=wallet_pwd)
111+
else:
112+
conn23c = oracledb.connect(user=user, password=password, dsn=dsn)
113+
103114

104115
logger.info("DB Connection successful!")
105116
metric = data["client_settings"]["vector_search"]["distance_metric"]
@@ -109,7 +120,7 @@ def get_vectorstore(data, embeddings):
109120
dist_strategy = DistanceStrategy.COSINE
110121
elif metric == "EUCLIDEAN":
111122
dist_strategy = DistanceStrategy.EUCLIDEAN
112-
123+
113124
logger.info(embeddings)
114125
knowledge_base = OracleVS(client=conn23c,table_name=db_table, embedding_function=embeddings, distance_strategy=dist_strategy)
115126

src/client/mcp/rag/pyproject.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
"""
5+
import sys
6+
from typing import List
7+
import os
8+
from dotenv import load_dotenv
9+
import logging
10+
logger = logging.getLogger(__name__)
11+
12+
logging.basicConfig(
13+
level=logging.INFO,
14+
format="%(name)s - %(levelname)s - %(message)s"
15+
)
16+
17+
18+
logger.info("Successfully imported libraries and modules")
19+
20+
from optimizer_utils import config
21+
22+
from optimizer_utils import rag
23+
24+
CHUNKS_DIR = "chunks_temp"
25+
data = {}
26+
27+
def similarity_search(question: str, max_results: int = 5) -> List[str]:
28+
"""
29+
Use this tool to get the top similar information to any question that may benefit from up-to-date or domain-specific information.
30+
31+
Args:
32+
question: The topic to search for
33+
max_results: Maximum number of results to retrieve (default: 5)
34+
35+
Returns:
36+
List of information related to the question
37+
"""
38+
39+
logger.info(f"Results provided for question: {question} with top {max_results}")
40+
chunks=["first chunk", "second chunk"]
41+
42+
return chunks
43+
44+
if __name__ == "__main__":
45+
# Initialize and run the server
46+
# Load JSON file
47+
file_path = os.path.join(os.getcwd(), "optimizer_settings.json")
48+
logger.info(file_path)
49+
rag.set_optimizer_settings_path(file_path)
50+
51+
if len(sys.argv) > 1:
52+
question = sys.argv[1]
53+
print(question)
54+
logger.info(f"Question: {sys.argv[1]}")
55+
logger.info(f"\n\nAgent Answer: {rag.rag_tool_base(question)}")
56+
else:
57+
logger.info("No question provided.")

src/client/mcp/rag/rag_base_optimizer_config_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
data = {}
3030

3131
# Initialize FastMCP server
32-
mcp = FastMCP("rag", port=9090) #Remote client
32+
mcp = FastMCP("rag",host="0.0.0.0", port=9090) #Remote client
3333
#mcp = FastMCP("rag") #Local
3434

3535

0 commit comments

Comments
 (0)