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 SQL queries, and perform analysis.

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 Optional Features.
  • Place a checkmark next to Enable the 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.
The MCP Server itself only exposes read-only tools: browsing schemas and metadata, drafting and validating SQL, and generating script or module code. None of its tool calls insert, update, or delete data.

The AI agent or IDE you connect to the MCP Server, such as Claude Code, Gemini CLI, OpenAI Codex, or an IDE extension, is not limited to read-only behavior, though. It is a general-purpose coding agent that can run the scripts it generates against LabKey using a client library, and depending on your setup it may do so on its own rather than waiting for you to run the script yourself. Those scripts can write or delete data if the credentials they use allow it. What limits the agent, in other words, is the API key you give it, not anything built into the MCP Server.

When generating the API key you place in .mcp.json, use a role-restricted key appropriate to what the agent needs to do. Use the Reader role if the agent should only read data. Use Editor without Delete if the agent needs to insert or update data but should not be able to delete it.

Use 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

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.
  • Use a Role Restricted API key. The MCP Server's own tools are read-only, but the agent using them is not. Restrict the API key's role so that any script the agent runs -- whether you run it or the agent does -- can't do more than it should.
  • 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. Make sure you populate your netrc file with role-restricted API keys as credentials, otherwise the agent may have unrestricted ability to modify data in your server.

Search LabKey Documentation with an AI Agent

Separately from the MCP Server feature described above, LabKey also runs a public MCP server on labkey.org that lets desktop AI agents answer questions directly from this documentation site. Connecting to it doesn't require a LabKey Server license, an API key, or the Enable MCP Server setting--it's available to anyone.

To connect, add an entry like the following to your agent's .mcp.json:

"labkey.org": {
"type": "http",
"url": "https://www.labkey.org/mcp"
}

Once connected, you can ask your agent questions about LabKey Server directly, and it will search this documentation site to answer.

Was this content helpful?

Log in or register an account to provide feedback


previousnext
 
expand allcollapse all