Skip to content

Commit 0a5b0ef

Browse files
Merge pull request #195 from oracle-samples/docs
Docs update for
2 parents 3e149f5 + 329bb1a commit 0a5b0ef

24 files changed

+243
-5
lines changed
129 KB
Loading
39.9 KB
Loading
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
+++
2+
title = 'Export as MCP Langchain server'
3+
weight = 1
4+
+++
5+
6+
<!--
7+
Copyright (c) 2024, 2025, Oracle and/or its affiliates.
8+
Licensed under the Universal Permissive License v1.0 as shown at http://oss.oracle.com/licenses/upl.
9+
-->
10+
11+
**Version:** *Developer preview*
12+
13+
## Introduction to the MCP Server for a tested AI Optimizer & Toolkit configuration
14+
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, through **Python/Langchain** framework. This early draft implementation utilizes the `stdio` and `sse` to interact between the agent dashboard, represented by the **Claude Desktop**, and the tool.
15+
16+
**NOTICE**: Only `Ollama` or `OpenAI` configurations are currently supported. Full support will come.
17+
18+
## Pre-requisites.
19+
You need:
20+
- Node.js: v20.17.0+
21+
- npx/npm: v11.2.0+
22+
- uv: v0.7.10+
23+
- Claude Desktop free
24+
25+
## Setup
26+
With **[`uv`](https://docs.astral.sh/uv/getting-started/installation/)** installed, run the following commands in your current project directory `<PROJECT_DIR>/src/client/mcp/rag/`:
27+
28+
```bash
29+
uv init --python=3.11 --no-workspace
30+
uv venv --python=3.11
31+
source .venv/bin/activate
32+
uv add mcp langchain-core==0.3.52 oracledb~=3.1 langchain-community==0.3.21 langchain-huggingface==0.1.2 langchain-openai==0.3.13 langchain-ollama==0.3.2
33+
```
34+
35+
## Export config
36+
In the **AI Optimizer & Toolkit** web interface, after tested a configuration, in `Settings/Client Settings`:
37+
38+
![Client Settings](./images/export.png)
39+
40+
* select the checkbox `Include Sensitive Settings`
41+
* press button `Download Settings` to download configuration in the project directory: `src/client/mcp/rag` as `optimizer_settings.json`.
42+
* in `<PROJECT_DIR>/src/client/mcp/rag/rag_base_optimizer_config_mcp.py` change filepath with the absolute path of your `optimizer_settings.json` file.
43+
44+
45+
## Standalone client
46+
There is a client that you can run without MCP via commandline to test it:
47+
48+
```bash
49+
uv run rag_base_optimizer_config.py
50+
```
51+
52+
## Quick test via MCP "inspector"
53+
54+
* Run the inspector:
55+
56+
```bash
57+
npx @modelcontextprotocol/inspector uv run rag_base_optimizer_config_mcp.py
58+
```
59+
60+
* connect to the port `http://localhost:6274/` with your browser
61+
* setup the `Inspector Proxy Address` with `http://127.0.0.1:6277`
62+
* test the tool developed.
63+
64+
65+
## Claude Desktop setup
66+
67+
* In **Claude Desktop** application, in `Settings/Developer/Edit Config`, get the `claude_desktop_config.json` to add the references to the local MCP server for RAG in the `<PROJECT_DIR>/src/client/mcp/rag/`:
68+
```json
69+
{
70+
"mcpServers": {
71+
...
72+
,
73+
"rag":{
74+
"command":"bash",
75+
"args":[
76+
"-c",
77+
"source <PROJECT_DIR>/src/client/mcp/rag/.venv/bin/activate && uv run <PROJECT_DIR>/src/client/mcp/rag/rag_base_optimizer_config_mcp.py"
78+
]
79+
}
80+
}
81+
}
82+
```
83+
* In **Claude Desktop** application, in `Settings/General/Claude Settings/Configure`, under `Profile` tab, update fields like:
84+
- `Full Name`
85+
- `What should we call you`
86+
87+
and so on, putting in `What personal preferences should Claude consider in responses?`
88+
the following text:
89+
90+
```
91+
#INSTRUCTION:
92+
Always call the rag_tool tool when the user asks a factual or information-seeking question, even if you think you know the answer.
93+
Show the rag_tool message as-is, without modification.
94+
```
95+
This will impose the usage of `rag_tool` in any case.
96+
97+
**NOTICE**: If you prefer, in this agent dashboard or any other, you could setup a message in the conversation with the same content of `Instruction` to enforce the LLM to use the rag tool as well.
98+
99+
* Restart **Claude Desktop**.
100+
101+
* You will see two warnings on rag_tool configuration: they will disappear and will not cause any issue in activating the tool.
102+
103+
* Start a conversation. You should see a pop up that ask to allow the `rag` tool usage to answer the questions:
104+
105+
![Rag Tool](./images/rag_tool.png)
106+
107+
If the question is related to the knowledge base content stored in the vector store, you will have an answer based on that information. Otherwise, it will try to answer considering information on which has been trained the LLM o other tools configured in the same Claude Desktop.
108+
109+
110+
## Make a remote MCP server the RAG Tool
111+
112+
In `rag_base_optimizer_config_mcp.py`:
113+
114+
* Update the absolute path of your `optimizer_settings.json`. Example:
115+
116+
```python
117+
rag.set_optimizer_settings_path("/Users/cdebari/Documents/GitHub/ai-optimizer-mcp-export/src/client/mcp/rag/optimizer_settings.json")
118+
```
119+
120+
* Substitute `Local` with `Remote client` line:
121+
122+
```python
123+
#mcp = FastMCP("rag", port=8001) #Remote client
124+
mcp = FastMCP("rag") #Local
125+
```
126+
127+
* Substitute `stdio` with `sse` line of code:
128+
```python
129+
mcp.run(transport='stdio')
130+
#mcp.run(transport='sse')
131+
```
132+
133+
* Start MCP server in another shell with:
134+
```bash
135+
uv run rag_base_optimizer_config_mcp.py
136+
```
137+
138+
139+
## Quick test
140+
141+
* Run the inspector:
142+
143+
```bash
144+
npx @modelcontextprotocol/inspector
145+
```
146+
147+
* connect the browser to `http://127.0.0.1:6274`
148+
149+
* set the Transport Type to `SSE`
150+
151+
* set the `URL` to `http://localhost:8001/sse`
152+
153+
* test the tool developed.
154+
155+
156+
157+
## Claude Desktop setup for remote/local server
158+
Claude Desktop, in free version, not allows to connect remote server. You can overcome, for testing purpose only, with a proxy library called `mcp-remote`. These are the options.
159+
If you have already installed Node.js v20.17.0+, it should work:
160+
161+
* replace `rag` mcpServer, setting in `claude_desktop_config.json`:
162+
```json
163+
{
164+
"mcpServers": {
165+
"remote": {
166+
"command": "npx",
167+
"args": [
168+
"mcp-remote",
169+
"http://127.0.0.1:8001/sse"
170+
]
171+
}
172+
}
173+
}
174+
```
175+
* restart Claude Desktop.
176+
177+
**NOTICE**: If you have any problem running, check the logs if it's related to an old npx/nodejs version used with mcp-remote library. Check with:
178+
```bash
179+
nvm -list
180+
```
181+
if you have any other versions available than the default. It could happen that Claude Desktop uses the older one. Try to remove any other nvm versions available to force the use the only one avalable, at minimum v20.17.0+.
182+
183+
* restart and test as remote server
184+
185+
186+
{{% notice style="code" title="Documentation is Hard!" icon="circle-info" %}}
187+
More information coming soon... 25-June-2025
188+
{{% /notice %}}

docs/content/advanced/springai.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,25 @@ You have simply to:
2929
chmod 755 ./start.sh
3030
```
3131

32-
* add the password for the user used to connect from the {{< short_app_ref >}} to the Oracle DB23ai used as vectorstore:
33-
34-
```bash
35-
export DB_PASSWORD=""
32+
* Edit `start.sh` to change the DB_PASSWORD or any other reference/credentials changed by the dev env, as in this example:
33+
```
34+
export SPRING_AI_OPENAI_API_KEY=$OPENAI_API_KEY
35+
export DB_DSN="jdbc:oracle:thin:@localhost:1521/FREEPDB1"
36+
export DB_USERNAME=<DB_USER_NAME>
37+
export DB_PASSWORD=<DB_PASSWORD>
38+
export DISTANCE_TYPE=COSINE
39+
export OPENAI_CHAT_MODEL=gpt-4o-mini
40+
export OPENAI_EMBEDDING_MODEL=text-embedding-3-small
41+
export OLLAMA_CHAT_MODEL="llama3.1"
42+
export OLLAMA_EMBEDDING_MODEL=mxbai-embed-large
43+
export OLLAMA_BASE_URL="http://<OLLAMA_SERVER>:11434"
44+
export CONTEXT_INSTR=" You are an assistant for question-answering tasks. Use the retrieved Documents and history to answer the question as accurately and comprehensively as possible. Keep your answer grounded in the facts of the Documents, be concise, and reference the Documents where possible. If you don't know the answer, just say that you are sorry as you don't haven't enough information. "
45+
export TOP_K=4
46+
export VECTOR_STORE=TEXT_EMBEDDING_3_SMALL_8191_1639_COSINE
47+
export PROVIDER=openai
48+
mvn spring-boot:run -P openai
3649
```
50+
3751
* The `<VECTOR_STORE>` created in the Oracle AI Optimizer and Toolkit will be automatically converted in a `<VECTOR_STORE>_SPRINGAI` table, and it will store the same data. If already exists it will be used without modification.
3852
If you want to start from scratch, drop the table `<VECTOR_STORE>_SPRINGAI`, running in sql:
3953

@@ -45,6 +59,7 @@ COMMIT;
4559
* This microservice will expose the following REST endpoints:
4660

4761
* `http://localhost:9090/v1/chat/completions`: to use RAG via OpenAI REST API
62+
* `http://localhost:9090/v1/models`: return models behind the RAG via OpenAI REST API
4863
* `http://localhost:9090/v1/service/llm` : to chat straight with the LLM used
4964
* `http://localhost:9090/v1/service/search/`: to search for document similar to the message provided
5065
* `http://localhost:9090/v1/service/store-chunks/`: to embedd and store a list of text chunks in the vectorstore
@@ -131,6 +146,37 @@ response will be a list of vector embeddings created:
131146
]
132147
```
133148

149+
### Get model name
150+
Return the name of model used. It's useful to integrate ChatGUIs that require the model list before proceed.
151+
152+
```
153+
curl http://localhost:9090/v1/models
154+
```
155+
156+
## MCP RagTool
157+
The completion service is also available as an MCP server based on the **SSE** transport protocol.
158+
To test it:
159+
160+
* Start as usual the microservice:
161+
```shell
162+
./start.sh
163+
```
164+
165+
* Start the **MCP inspector**:
166+
```shell
167+
export DANGEROUSLY_OMIT_AUTH=true
168+
npx @modelcontextprotocol/inspector
169+
```
170+
171+
* With a web browser open: http://127.0.0.1:6274
172+
173+
* Configure:
174+
* Transport Type: SSE
175+
* URL: http://localhost:9090/sse
176+
* set Request Timeout to: **200000**
177+
178+
* Test a call to `getRag` Tool.
179+
134180

135181
### Run in the Oracle Backend for Microservices and AI
136182

@@ -262,4 +308,8 @@ it should return something like:
262308
}
263309
]
264310
}
265-
```
311+
```
312+
313+
{{% notice style="code" title="Documentation is Hard!" icon="circle-info" %}}
314+
More information coming soon... 25-June-2025
315+
{{% /notice %}}
56.6 KB
Loading
35 KB
Loading
43.4 KB
Loading
55.1 KB
Loading
45.7 KB
Loading
71.3 KB
Loading

0 commit comments

Comments
 (0)