Build an MCP AI Agent for Your Laboratory | FlaskTrack
Skip to content
Sign In<br>Start Building
Build with FlaskTrack · MCP · AI agents · laboratory automation
Build your first FlaskTrack MCP agent
Give an AI agent controlled access to real laboratory operations with FlaskTrack's<br>organization-scoped MCP tool interface.
In this walkthrough, you will create a small Python agent that discovers FlaskTrack tools,<br>searches laboratory records, executes a tool, and uses structured results to continue safely.
Dynamic tool discovery Read the live MCP registry instead of hard-coding the API<br>surface
Typed laboratory records Work with workflows, protocols, batches, samples, species,<br>and more
Organization scoped Every action is evaluated in the authenticated FlaskTrack<br>organization
Permission aware Agent calls remain subject to roles, validation, and compliance<br>controls
Structured results Use returned record IDs and metadata to safely continue multi-step<br>work
Build the agent ↓<br>API & MCP overview
OpenAPI Documentation ↗
What you are building
The agent will discover the tools exposed by your FlaskTrack deployment,<br>choose a read operation, execute it through the MCP interface, and use the<br>structured result as context for the next decision.
Discover tools Load the current FlaskTrack tool<br>catalog from /mcp/tools.
Choose a tool Give the model names, descriptions,<br>schemas, and semantic record metadata.
Execute through FlaskTrack Send one registered<br>tool name and schema-valid input to /mcp/call.
Continue from the result Use the concrete<br>returned record ID instead of guessing or inventing identifiers.
Before you start
Create a FlaskTrack API credential for the integration and keep it outside your prompt,<br>source code, browser JavaScript, and model context.
🔑
API key Use a dedicated machine credential for<br>the agent.
🏢
Organization Every request includes the<br>FlaskTrack organization context.
🐍
Python 3.10+ The example uses Python,<br>requests, and any model client you prefer.
🧠
LLM provider OpenAI, Anthropic, a local model, or<br>another provider can drive the decision loop.
Step 1<br>Configure FlaskTrack credentials
Keep credentials in environment variables so the model never sees them.
export FLASKTRACK_URL="https://flasktrack.com"<br>export FLASKTRACK_ORGANIZATION="YOUR_ORGANIZATION_ID"<br>export FLASKTRACK_API_KEY="YOUR_API_KEY"
Step 2<br>Install the tiny client
python -m pip install requests
Step 3<br>Connect to FlaskTrack
Keep credentials in the HTTP layer rather than the prompt.
import os<br>import requests
BASE_URL = os.environ["FLASKTRACK_URL"].rstrip("/")
HEADERS = {<br>"x-organization": os.environ["FLASKTRACK_ORGANIZATION"],<br>"x-api-key": os.environ["FLASKTRACK_API_KEY"],<br>"accept": "application/json",
def flasktrack_get(path):<br>response = requests.get(<br>f"{BASE_URL}{path}",<br>headers=HEADERS,<br>timeout=30,<br>response.raise_for_status()<br>return response.json()
def flasktrack_post(path, payload):<br>response = requests.post(<br>f"{BASE_URL}{path}",<br>headers={**HEADERS, "content-type": "application/json"},<br>json=payload,<br>timeout=60,<br>response.raise_for_status()<br>return response.json()
Step 4<br>Discover the live MCP tool catalog
Do not hard-code every FlaskTrack action. Ask the running deployment what tools are currently registered.
tools = flasktrack_get("/mcp/tools")
for tool in tools:<br>print(<br>tool["name"],<br>tool["effect"],<br>tool.get("output_entity"),
💡
Why discovery matters
FlaskTrack's tool surface evolves with the platform. Runtime discovery lets an agent adapt<br>to the deployed version instead of relying on a stale list copied into a prompt.
Step 5<br>Give the model a compact tool list
def compact_tools(tools):<br>return [<br>"name": tool["name"],<br>"description": tool["description"],<br>"effect": tool["effect"],<br>"input_schema": tool["input_schema"],<br>"entity_fields": tool.get("entity_fields", []),<br>"output_entity": tool.get("output_entity"),<br>for tool in tools
agent_tools = compact_tools(tools)
Keep authentication headers, API keys, cookies, and unrelated organization data outside model-visible context.
Step 6<br>Ask the model for one tool call
Keep the first agent intentionally simple: the model returns one registered tool name and one JSON input object.
import json
SYSTEM_PROMPT = """<br>You are a FlaskTrack laboratory assistant.
Choose exactly one FlaskTrack tool for the user's request.
Rules:<br>- Use only tool names supplied to you.<br>- Match the tool input schema exactly.<br>- Never invent FlaskTrack UUIDs.<br>- Treat Workflow, Protocol, Batch, Sample, Species, Tool,<br>Ingredient, Plasmid, and other entity IDs as distinct types.<br>- Prefer read tools when you still need to identify a record.<br>- Return JSON only:
"name": "tool_name",<br>"input": {}<br>"""
def choose_tool(llm, user_request, tools):<br>raw = llm(<br>system=SYSTEM_PROMPT,<br>user=json.dumps({<br>"request": user_request,<br>"tools": tools,<br>}),
return json.loads(raw)
The llm function is provider-agnostic. Wrap your preferred model SDK and make it return the model's<br>text response.
Step 7<br>Execute the...