LabKey MCP Server (Model Context Protocol)

Documentation
Premium Feature — Available in the Professional and Enterprise Editions of LabKey SDMS. Learn more or contact LabKey.

LabKey’s MCP (Model Context Protocol) Server provides a standardized way for AI agents and external tools to securely interact with LabKey Server. The MCP Server defines how systems expose data, metadata, and actions in a structured, machine-readable form, making it possible for intelligent clients to discover datasets, run queries, and author reports.

MCP Server Set Up

Set up an MCP-driven development environment for working with LabKey Server.

Enable the MCP Server

  • Go to Gear > Site > Admin Console.
  • Click Experimental Features.
  • Place a checkmark next to Enable MCP Server. (You do not need to press a confirmation button--simply adding the checkmark is sufficient to enable the server.)

Configure Your Desktop App or IDE

Note that browser agents can't typically connect to MCP servers. Users need a desktop client application such as Claude Code CLI, Gemini CLI, OpenAI Codex, or an IDE such as IntelliJ and VS Code with appropriate extensions added, to interact with LabKey’s MCP. Some vendors restrict the use of MCPs via their desktop apps. For example, some require "developer mode" to configure MCPs and limit certain subscription levels to read-only interactions.

To configure your application to connect to the MCP server: create a file named .mcp.json in your project directory with the following contents:

{
"mcpServers": {
"labkey": {
"type": "http",
"url": "https://MY_SERVER/mcp",
"headers": {
"apikey": "MY_API_KEY"
}
}
}
}
  • Replace MY_SERVER with your server URL.
  • Replace MY_API_KEY with your LabKey API key.
Note that the MCP Server does not restrict users with write access from modifying or deleting data on the server. For example, it may suggest client API calls that change data on the server. Consider providing API keys with read-only access to users who do not require write access. (To do this, generate the API key from an account with Reader access only.)

Using the MCP Server

Once connected, an AI agent can help you explore your LabKey data, write scripts, and build queries -- all by chatting in plain language.

What You Can Do

The MCP server lets an AI assistant:

  • Browse your data -- discover what schemas, tables, and columns exist in any folder
  • Help write scripts -- generate Python or R code to retrieve and analyze your data
  • Write and check SQL -- draft LabKey SQL queries and validate them before you run them
  • Build file-based modules -- help you create queries, views, reports, and web parts
The AI assistant can explore your data model and write code, but it does not retrieve or modify data itself. To actually pull or change data, you run the script it generates using a LabKey client library (such as the Python labkey package or the R Rlabkey package).

Getting Started

Every session starts the same way: tell the AI which folder (container) you want to work in. A container path looks like MyProject/MyFolder. If you are not sure of the path, ask the AI to list available folders for you.

From there, describe what you want to do in plain language. For example:

  • "Show me what tables are in the study schema."
  • "Write a Python script to pull all samples created this month."
  • "Help me write a SQL query that joins Samples to Results."
  • "Create a file-based module with a custom grid view."

Common Workflows

  • Explore your data: "What schemas and tables are available in this folder?"
  • Write a Python script: "Write a Python script to retrieve all rows from the Samples table."
  • Write an R script: "Write an R script to pull data from the assay results table."
  • Write or fix a SQL query: "Help me write a LabKey SQL query to count samples by type."
  • Build a module: "Help me create a file-based module with a custom query and grid view."

Tips

  • Start with the folder. The AI needs a container path before it can do anything. If you skip this, it will ask you for one.
  • Scripts need authentication. Generated Python and R scripts connect to LabKey using a .netrc (Mac/Linux) or _netrc (Windows) credentials file. The AI can walk you through setting this up.
  • Read-only API keys are safer. Only provide Editor and Administrator access when necessary. If you only need to read data, use an API key from a Reader-only account.

Was this content helpful?

Log in or register an account to provide feedback


previousnext
 
expand allcollapse all