Skip to content

feat(mcp): connect Reactome MCP server to LangGraph agent with LangChain tool wrappers#137

Open
GovindhKishore wants to merge 2 commits intoreactome:mainfrom
GovindhKishore:feat/mcp-langchain-tools
Open

feat(mcp): connect Reactome MCP server to LangGraph agent with LangChain tool wrappers#137
GovindhKishore wants to merge 2 commits intoreactome:mainfrom
GovindhKishore:feat/mcp-langchain-tools

Conversation

@GovindhKishore
Copy link
Copy Markdown

Summary

Integrates the Reactome MCP server into the LangGraph agent by wrapping MCP tools as LangChain StructuredTool objects and connecting them to the React-to-Me chat profile. Builds directly on the MCP client foundation from #127.

Changes

New - src/mcp/mcp_tools.py

  • create_mcp_tools() async factory that starts the MCP server and returns LangChain tool wrappers
  • Five tools covering the most impactful MCP capabilities:
    • search_reactome - search pathways, proteins, genes by keyword
    • get_pathway - retrieve pathway details by stable ID (e.g. R-HSA-109582)
    • analyze_identifiers - run pathway enrichment analysis on a gene/protein list
    • get_database_info - get current Reactome release version
    • get_species - list all species available in Reactome
  • Returns ([], None) when no server path provided - chatbot works unchanged without MCP

Modified - src/agent/graph.py

  • MCP server started in initialize() controlled by MCP_SERVER_PATH environment variable
  • Graphs built individually per profile - React-to-Me receives mcp_tools, Cross-Database unaffected
  • MCP server stopped cleanly in close_pool() on app shutdown
  • llm, embedding, profiles stored as instance variables so initialize() can access them

Modified - src/agent/profiles/react_to_me.py

  • create_reactome_graph() and ReactToMeGraphBuilder accept optional mcp_tools parameter
  • Tools bound to LLM once at init time via bind_tools() - not re-bound on every message
  • call_model implements tool-calling loop with 15 iteration guard against infinite loops
  • Falls back gracefully to existing reactome_rag behaviour when mcp_tools is empty

How It Works

User message arrives
-> LLM receives message + tool schemas via bind_tools()
-> LLM decides: answer directly or call an MCP tool
-> if tool call requested -> LangChain executes matching @tool function
-> MCPClient sends JSON-RPC to Node.js reactome-mcp server
-> Node.js calls Reactome REST API and returns result
-> result sent back to LLM as ToolMessage
-> LLM generates final answer using tool result
-> loop repeats if LLM requests another tool, up to 15 iterations max
-> if no tools available -> existing reactome_rag behaviour unchanged

Usage

Set MCP_SERVER_PATH to the compiled MCP server entry point:

MCP_SERVER_PATH=/path/to/reactome-mcp/dist/index.js

Leave unset to run in existing RAG-only mode with zero behaviour change.

Relation to Previous Work

AI Transparency

AI Tools (Claude) were used to assist with drafting code and documentation. All changes were reviewed and verified by me.

closes #136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: integrate Reactome MCP tools into LangGraph agent via LangChain tool wrappers

1 participant