Skip to content

Commit 3da883c

Browse files
Merge pull request #237 from oracle-samples/236-langchain-mcp-export
236 langchain mcp export
2 parents 6ed70f4 + dbebfab commit 3da883c

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

src/client/content/config/settings.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,36 @@ def spring_ai_zip(provider, ll_config, embed_config):
228228
zip_buffer.seek(0)
229229
return zip_buffer
230230

231+
def langchain_mcp_zip(settings):
232+
"""Create LangChain MCP Zip File"""
233+
234+
# Source directory that you want to copy
235+
src_dir = Path(__file__).resolve().parents[2] / "mcp/rag"
236+
237+
# Using TemporaryDirectory
238+
with tempfile.TemporaryDirectory() as temp_dir:
239+
dst_dir = os.path.join(temp_dir, "langchain_mcp")
240+
logger.info("Starting langchain mcp zip processing: %s", dst_dir)
241+
242+
shutil.copytree(src_dir, dst_dir)
243+
244+
data=save_settings(settings)
245+
settings_path = os.path.join(dst_dir, "optimizer_settings.json")
246+
with open(settings_path, "w") as f:
247+
f.write(data)
248+
249+
zip_buffer = io.BytesIO()
250+
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zip_file:
251+
for foldername, _, filenames in os.walk(dst_dir):
252+
for filename in filenames:
253+
file_path = os.path.join(foldername, filename)
254+
255+
arc_name = os.path.relpath(file_path, dst_dir) # Make the path relative
256+
zip_file.write(file_path, arc_name)
257+
zip_buffer.seek(0)
258+
return zip_buffer
259+
260+
231261

232262
#####################################################
233263
# MAIN
@@ -284,7 +314,7 @@ def main():
284314
else:
285315
st.info("Please upload a Settings file.")
286316

287-
st.header("SpringAI Settings", divider="red")
317+
st.header("Export source code templates", divider="red")
288318
# Merge the User Settings into the Model Config
289319
model_lookup = st_common.state_configs_lookup("model_configs", "id")
290320
try:
@@ -307,13 +337,23 @@ def main():
307337
- Embedding Model: **{embed_config.get("model", "Unset")}**
308338
""")
309339
else:
310-
st.download_button(
340+
col_left, col_centre, _ = st.columns([3, 4, 3])
341+
with col_left:
342+
st.download_button(
311343
label="Download SpringAI",
312344
data=spring_ai_zip(spring_ai_conf, ll_config, embed_config), # Generate zip on the fly
313345
file_name="spring_ai.zip", # Zip file name
314346
mime="application/zip", # Mime type for zip file
315347
disabled=spring_ai_conf == "hybrid",
316348
)
349+
with col_centre:
350+
st.download_button(
351+
label="Download LangchainMCP",
352+
data=langchain_mcp_zip(settings), # Generate zip on the fly
353+
file_name="langchain_mcp.zip", # Zip file name
354+
mime="application/zip", # Mime type for zip file
355+
disabled=spring_ai_conf == "hybrid",
356+
)
317357

318358

319359
if __name__ == "__main__" or "page.py" in inspect.stack()[1].filename:

src/client/mcp/rag/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ rag.set_optimizer_settings_path("/Users/cdebari/Documents/GitHub/ai-optimizer-mc
120120
* Substitute `Local` with `Remote client` line:
121121

122122
```python
123-
#mcp = FastMCP("rag", port=8001) #Remote client
123+
#mcp = FastMCP("rag", port=9001) #Remote client
124124
mcp = FastMCP("rag") #Local
125125
```
126126

@@ -148,7 +148,7 @@ npx @modelcontextprotocol/inspector
148148

149149
* set the Transport Type to `SSE`
150150

151-
* set the `URL` to `http://localhost:8001/sse`
151+
* set the `URL` to `http://localhost:9001/sse`
152152

153153
* test the tool developed.
154154

@@ -166,7 +166,7 @@ If you have already installed Node.js v20.17.0+, it should work:
166166
"command": "npx",
167167
"args": [
168168
"mcp-remote",
169-
"http://127.0.0.1:8001/sse"
169+
"http://127.0.0.1:9001/sse"
170170
]
171171
}
172172
}

src/client/mcp/rag/rag_base_optimizer_config_mcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
data = {}
2525

2626
# Initialize FastMCP server
27-
#mcp = FastMCP("rag", port=8001) #Remote client
27+
#mcp = FastMCP("rag", port=9001) #Remote client
2828
mcp = FastMCP("rag") #Local
2929

3030

tests/client/content/config/test_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_spring_ai_section_exists(self, app_server, app_test):
5555
assert app_server is not None
5656
at = app_test(self.ST_FILE).run()
5757

58-
# Check for SpringAI across all text elements - could be in title, header, markdown, etc.
58+
# Check for Export source code templates across all text elements - could be in title, header, markdown, etc.
5959
page_text = []
6060

6161
# Check in markdown elements
@@ -85,8 +85,8 @@ def test_spring_ai_section_exists(self, app_server, app_test):
8585
if hasattr(div, "label"):
8686
page_text.append(div.label)
8787

88-
# Assert that SpringAI is mentioned somewhere in the page
89-
assert any("SpringAI" in text for text in page_text), "SpringAI section not found in page"
88+
# Assert that Export source code templates is mentioned somewhere in the page
89+
assert any("Export source code templates" in text for text in page_text), "Export source code templates section not found in page"
9090

9191
def test_compare_with_uploaded_json(self, app_server, app_test):
9292
"""Test the compare_with_uploaded_json function for finding differences in settings"""

0 commit comments

Comments
 (0)