Agent2Agent OMCP
MCP Server
The MCP (Model-Context-Protocol) server provides a set of tools for interacting with OMOP CDM databases and generating SQL queries using natural language processing. The server is built using FastMCP and integrates with Ollama for LLM capabilities.
Features
SQL Server Tools
Execute_SQL_Query: Execute SQL queries against an OMOP database and return results in CSV formatTest_Connection: Test if a database connection is validGet_OMOP_Schema: Get the OMOP CDM schema information for prompting
Validation Server Tools
Validate_SQL_Query: Validate SQL queries against OMOP CDM validation rules
Ollama Server Tools
Generate_SQL: Generate SQL from natural language using an LLM, incorporating medical concept codesGenerate_Explanation: Generate an explanation for an SQL queryGenerate_Answer: Generate a natural language answer based on query, SQL, and resultsList_Available_Models: List available LLM models from Ollama
Configuration
The server uses a configuration file (config/config.json) that specifies:
- Database connection strings
- Schema directory location
- Ollama API settings
- OMOP CDM validation rules and schema files
Medical Concept Integration
The SQL generation tool accepts medical concepts in the following format:
{
"conditions": [
{
"concept_id": 12345,
"concept_name": "Diabetes",
"vocabulary_id": "SNOMED"
}
],
"drugs": [
{
"concept_id": 11111,
"concept_name": "Metformin",
"vocabulary_id": "RxNorm"
}
],
"measurements": [
{
"concept_id": 22222,
"concept_name": "Blood Pressure",
"vocabulary_id": "LOINC"
}
]
}
Requirements
- Python 3.13 or higher
- PostgreSQL database with OMOP CDM schema
- Ollama running locally for LLM capabilities
Dependencies
- mcp
- httpx
- sqlalchemy
- pydantic
- pydantic-settings
- python-multipart
- sse-starlette
Usage
The MCP server can be used as a standalone service or integrated into other applications. To use it:
- Ensure all dependencies are installed:
uv pip install -e .
-
Configure the database connection and other settings in
config/config.json -
Start the server:
from src.unified_mcp import mcp
mcp.run(transport="stdio")
Example
# Generate SQL with medical concepts
medical_concepts = {
"conditions": [
{"concept_id": 12345, "concept_name": "Diabetes", "vocabulary_id": "SNOMED"}
]
}
schema = mcp.tools["Get_OMOP_Schema"]()
sql_query, confidence = await mcp.tools["Generate_SQL"](https://github.com/fastomop/omcp_a2a/blob/main/
prompt="Find all patients with diabetes",
medical_concepts=medical_concepts,
schema=schema
)
# Validate the generated SQL
validation_result = mcp.tools["Validate_SQL_Query"](https://github.com/fastomop/omcp_a2a/blob/main/sql_query)
# Execute the query if valid
if validation_result["is_valid"]:
results = mcp.tools["Execute_SQL_Query"](https://github.com/fastomop/omcp_a2a/blob/main/sql_query)
Recommend MCP Servers 💡
@gomomento/mcp-momento
A simple Model Context Protocol (MCP) server implementation for Momento Cache, providing tools to interact with Momento Cache for operations like get, set, list, create, and delete caches.
logfire-mcp@latest
This MCP server enables LLMs to retrieve your application's telemetry data, analyze distributed traces, and make use of the results of arbitrary SQL queries executed using the Pydantic Logfire APIs.
mariadb-mcp-server
The MCP MariaDB Server provides a Model Context Protocol (MCP) interface for managing and querying MariaDB databases, supporting both standard SQL operations and advanced vector/embedding-based search. Designed for use with AI assistants, it enables seamless integration of AI-driven data workflows with relational and vector databases.
mcp-server-weaviate
MCP (Model Context Protocol) server for Weaviate
mysql-mcp-server
A Model Context Protocol (MCP) server that enables secure interaction with MySQL databases
@gongrzhe/server-redis-mcp
A Redis MCP server implementation for interacting with Redis databases