Export as MCP Langchain server
Version: Developer preview
Introduction to the MCP Server for a tested AI Optimizer & Toolkit configuration
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.
NOTICE: Only Ollama or OpenAI configurations are currently supported. Full support will come.
Pre-requisites.
You need:
- Node.js: v20.17.0+
- npx/npm: v11.2.0+
- uv: v0.7.10+
- Claude Desktop free
Setup
With uv installed, run the following commands in your current project directory <PROJECT_DIR>/src/client/mcp/rag/:
uv init --python=3.11 --no-workspace
uv venv --python=3.11
source .venv/bin/activate
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.2Export config
In the AI Optimizer & Toolkit web interface, after tested a configuration, in Settings/Client Settings:
- select the checkbox
Include Sensitive Settings - press button
Download Settingsto download configuration in the project directory:src/client/mcp/ragasoptimizer_settings.json. - in
<PROJECT_DIR>/src/client/mcp/rag/rag_base_optimizer_config_mcp.pychange filepath with the absolute path of youroptimizer_settings.jsonfile.
Standalone client
There is a client that you can run without MCP via commandline to test it:
uv run rag_base_optimizer_config.py Quick test via MCP “inspector”
- Run the inspector:
npx @modelcontextprotocol/inspector uv run rag_base_optimizer_config_mcp.py- connect to the port
http://localhost:6274/with your browser - setup the
Inspector Proxy Addresswithhttp://127.0.0.1:6277 - test the tool developed.
Claude Desktop setup
- In Claude Desktop application, in
Settings/Developer/Edit Config, get theclaude_desktop_config.jsonto add the references to the local MCP server for RAG in the<PROJECT_DIR>/src/client/mcp/rag/:
{
"mcpServers": {
...
,
"rag":{
"command":"bash",
"args":[
"-c",
"source <PROJECT_DIR>/src/client/mcp/rag/.venv/bin/activate && uv run <PROJECT_DIR>/src/client/mcp/rag/rag_base_optimizer_config_mcp.py"
]
}
}
}- In Claude Desktop application, in
Settings/General/Claude Settings/Configure, underProfiletab, update fields like:
Full NameWhat should we call youand so on, putting in
What personal preferences should Claude consider in responses?the following text:
#INSTRUCTION:
Always call the rag_tool tool when the user asks a factual or information-seeking question, even if you think you know the answer.
Show the rag_tool message as-is, without modification.This will impose the usage of rag_tool in any case.
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.
Restart Claude Desktop.
You will see two warnings on rag_tool configuration: they will disappear and will not cause any issue in activating the tool.
Start a conversation. You should see a pop up that ask to allow the
ragtool usage to answer the questions:
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.
Make a remote MCP server the RAG Tool
In rag_base_optimizer_config_mcp.py:
- Update the absolute path of your
optimizer_settings.json. Example:
rag.set_optimizer_settings_path("/Users/cdebari/Documents/GitHub/ai-optimizer-mcp-export/src/client/mcp/rag/optimizer_settings.json")- Substitute
LocalwithRemote clientline:
#mcp = FastMCP("rag", port=8001) #Remote client
mcp = FastMCP("rag") #Local- Substitute
stdiowithsseline of code:
mcp.run(transport='stdio')
#mcp.run(transport='sse')- Start MCP server in another shell with:
uv run rag_base_optimizer_config_mcp.pyQuick test
- Run the inspector:
npx @modelcontextprotocol/inspector connect the browser to
http://127.0.0.1:6274set the Transport Type to
SSEset the
URLtohttp://localhost:8001/ssetest the tool developed.
Claude Desktop setup for remote/local server
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.
If you have already installed Node.js v20.17.0+, it should work:
- replace
ragmcpServer, setting inclaude_desktop_config.json:
{
"mcpServers": {
"remote": {
"command": "npx",
"args": [
"mcp-remote",
"http://127.0.0.1:8001/sse"
]
}
}
}- restart Claude Desktop.
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:
nvm -listif 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+.
- restart and test as remote server
Documentation is Hard!
More information coming soon… 25-June-2025

