A Model Context Protocol server that enables Claude Desktop to search clinicaltrials.gov for matching clinical trials based on genetic mutations provided in natural language queries.
A Model Context Protocol (MCP) server that enables Claude Desktop to search for matches in clincialtrials.gov based on mutations.
This is currently first phase of development. It works to retreive trials based on given mutations in the claude query. However, there are still bugs and further refinements and additions to be implemented.
This project follows the Agentic Coding principles to create a system that integrates Claude Desktop with the clinicaltrials.gov API. The server allows for natural language queries about genetic mutations and returns summarized information about relevant clinical trials.
flowchart LR Claude[Claude Desktop] |MCP Protocol| Server[MCP Server] subgraph Flow[PocketFlow] QueryNode[Query Node] -->|trials_data| SummarizeNode[Summarize Node] end Server -->|mutation| Flow QueryNode -->|API Request| API[Clinicaltrials.gov API] API -->|Trial Data| QueryNode Flow -->|summary| Server Server -->|Return| Claude
Each node in the flow follows the PocketFlow Node pattern with prep
, exec
, and post
methods:
This project is organized according to the Agentic Coding paradigm:
Requirements (Human-led):
Flow Design (Collaborative):
Utilities (Collaborative):
clinicaltrials/query.py
: Handles API calls to clinicaltrials.govutils/call_llm.py
: Utilities for working with ClaudeNode Design (AI-led):
utils/node.py
: Implements base Node and BatchNode classes with prep/exec/post patternclinicaltrials/nodes.py
: Defines specialized nodes for querying and summarizingclinicaltrials_mcp_server.py
: Orchestrates the flow executionImplementation (AI-led):
clinicaltrials_mcp_server.py
)The main server that implements the Model Context Protocol interface, using the official Python SDK. It:
clinicaltrials/query.py
)Responsible for querying the clinicaltrials.gov API with:
llm/summarize.py
)Processes and formats the clinical trials data:
This project implements the PocketFlow Node pattern, which provides a modular, maintainable approach to building AI workflows:
utils/node.py
)prep
, exec
, and post
methods for processing dataclinicaltrials/nodes.py
)QueryTrialsNode:
# Queries clinicaltrials.gov API def prep(self, shared): return shared["mutation"] def exec(self, mutation): return query_clinical_trials(mutation) def post(self, shared, mutation, result): shared["trials_data"] = result shared["studies"] = result.get("studies", []) return "summarize"
SummarizeTrialsNode:
# Formats trial data into readable summaries def prep(self, shared): return shared["studies"] def exec(self, studies): return format_trial_summary(studies) def post(self, shared, studies, summary): shared["summary"] = summary return None # End of flow
The MCP server creates and runs the flow:
# Create nodes query_node = QueryTrialsNode() summarize_node = SummarizeTrialsNode() # Create flow flow = Flow(start=query_node) flow.add_node("summarize", summarize_node) # Run flow with shared context shared = {"mutation": mutation} result = flow.run(shared)
This pattern separates preparation, execution, and post-processing, making the code more maintainable and testable. For more details, see the design document.
Install dependencies with uv:
uv pip install -r requirements.txt
Configure Claude Desktop:
~/Library/Application Support/Claude/claude_desktop_config.json
should already be set upStart Claude Desktop and ask questions like:
Use resources by asking:
You can configure this project as a Claude Desktop MCP tool. Use path placeholders in your configuration, and substitute them with your actual paths:
"mutation-clinical-trials-mcp": { "command": "{PATH_TO_VENV}/bin/python", "args": [ "{PATH_TO_PROJECT}/clinicaltrials_mcp_server.py" ], "description": "Matches genetic mutations to relevant clinical trials and provides summaries." }
Path Variables:
{PATH_TO_VENV}
: Full path to your virtual environment directory.{PATH_TO_PROJECT}
: Full path to the directory containing your project files.Installation Instructions:
curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux # or iwr -useb https://astral.sh/uv/install.ps1 | iex # Windows PowerShell
uv venv .venv uv pip install -r requirements.txt
source .venv/bin/activate # macOS/Linux .venv\Scripts\activate # Windows
Examples:
"command": "/Users/username/projects/mutation_trial_matcher/.venv/bin/python"
"command": "C:\\Users\\username\\projects\\mutation_trial_matcher\\.venv\\Scripts\\python.exe"
Path Finding Tips:
which python
(macOS/Linux)where python
(Windows, after activating the venv)clinicaltrials_mcp_server.py
.For a comprehensive list of planned enhancements and future work, please see the future_work.md document.
This project relies on the following key dependencies:
pocketflow>=0.0.1
) - Framework for building modular AI workflows with the Node patternmcp[cli]>=1.0.0
) - Official Model Context Protocol SDK for building Claude Desktop toolsrequests==2.31.0
) - HTTP library for making API calls to clinicaltrials.govpython-dotenv==1.1.0
) - For loading environment variables from .env filesAll dependencies can be installed using uv as described in the installation instructions.
If Claude Desktop disconnects from the MCP server:
~/Library/Logs/Claude/mcp-server-clinicaltrials-mcp.log
This project was developed using an AI-assisted coding approach, following the Agentic Coding principles where humans design and AI agents implement. The original program on main built on 2025-04-30. The implementation was created through pair programming with:
These AI assistants were instrumental in translating high-level design requirements into functional code, helping with API integration, and structuring the project according to best practices.
.windsurfrules
Character LimitThe PocketFlow .windsurfrules
file from the template repository contains comprehensive project rules, but Windsurf enforces a 6,000 character limit on rules files. This means you cannot include the entire set of guidelines directly in your project, and important rules may be omitted or truncated.
To address this, there are two recommended solutions:
You can leverage Windsurf’s memory feature to store the full set of PocketFlow rules, even if they exceed the .windsurfrules
file limit. This approach allows you to reference all project conventions and best practices in conversation with Windsurf, ensuring nothing is lost due to truncation. For step-by-step instructions and a detailed comparison of memory vs. rules files, see docs/memory_vs_windsurfrules.md.
Important Note: This project is based on the PocketFlow-Template-Python repository, which includes a comprehensive .windsurfrules
file. However, Windsurf has a 6,000 character limit for rules files, meaning the complete PocketFlow guidelines cannot be fully loaded into Windsurf's memory.
To address this limitation, we've created detailed instructions on using the Context7 MCP server to access PocketFlow guidelines during development. This approach allows you to leverage the full power of PocketFlow's design patterns and best practices without being constrained by the character limit.
For comprehensive instructions on using Context7 with PocketFlow, please refer to our Context7 Guide. This guide includes:
By following this guide, you can maintain alignment with PocketFlow's Agentic Coding principles while developing and extending this project.
This project was built using the PocketFlow-Template-Python as a starting point. Special thanks to the original contributors of that project for providing the foundation and structure that made this implementation possible.
The project follows the Agentic Coding methodology as outlined in the original template.
This project is licensed under the MIT License - see the LICENSE file for details.
⚠️ Disclaimer
This project is a prototype and is intended for research and demonstration purposes only. It should not be used to make medical decisions or as a substitute for professional medical advice, diagnosis, or treatment. Due to the limitations of large language models (LLMs), the information provided by this tool may be incomplete, inaccurate, or outdated. Users should exercise caution and consult qualified healthcare professionals before making any decisions based on the outputs of this system.
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!