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 💡
iceberg-mcp-server
A Model Context Protocol server by Cloudera that provides read-only access to Iceberg tables via Apache Impala, enabling LLMs to inspect database schemas and execute read-only SQL queries.
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.
mcp-jdbc-server
Java-based MCP Server for JDBC, compatible with Virtuoso and other JDBC-compliant DBMS.
Pratye/MEC-Postgres
A Model Context Protocol server providing read and write access to PostgreSQL databases, enabling LLMs to inspect schemas and execute queries.
@modelcontextprotocol/server-postgres
A Model Context Protocol server providing read-only access to PostgreSQL databases, enabling LLMs to inspect schemas and execute queries.
opensearch-mcp-server-py
opensearch-mcp-server-py is a Model Context Protocol (MCP) server for OpenSearch that enables AI assistants to interact with OpenSearch clusters. It provides a standardized interface for AI models to perform operations like searching indices, retrieving mappings, and managing shards through both stdio and streaming (SSE/Streamable HTTP) protocols.