MCP and agent connections
- 01Connect Claude, ChatGPT, or Codex
- 02Production endpoint
- 03What you need
- 04Minimal JSON-RPC exchange
- 05Abilities and access boundaries
Connect Claude, ChatGPT, or Codex
Open Settings -> API & MCP -> MCP Connections. The Connect an AI client panel provides buttons for Claude and ChatGPT, plus the Codex command:
codex mcp add --transport http psylab https://psylab-research.org/mcp/psylab
For a client without OAuth connector support, use manual setup: create an agent connection, copy the Bearer token, and store it as a secret. Start with the Default preset and add scopes only when needed.

Write access requires mcp:write and the relevant domain scope. Individual respondent data is enabled separately: name the AI client, select a specific study or test, and confirm the disclosure basis.
\n\n# MCP and agent connections
Psylab provides an authenticated MCP server for studies, tests, questions, analytics, and administrative content. MCP is intended for integrations and AI agents; a participant does not need to take a test through this endpoint.
Production endpoint
https://psylab-research.org/mcp/psylab
For another environment, use the same application host with the /mcp/psylab path.
What you need
- Open /settings/api-mcp.
- Create an agent token and enable mcp:use.
- For writes, add mcp:write and the abilities for the domains that must change.
- For participant data, configure mcp:respondent-data separately and select concrete disclosure targets.
- Copy the plaintext token once and pass it to your MCP client as a secret.
The token must have the mcp audience and the plan capability mcp_access. A REST API token with the api audience is not valid for this endpoint.
Minimal JSON-RPC exchange
An MCP client performs initialize, stores the returned Mcp-Session-Id header, and sends that header with subsequent requests. A minimal tools-list check looks like this:
MCP_URL="https://psylab-research.org/mcp/psylab"
MCP_TOKEN="TOKEN_HERE"
MCP_SESSION_ID="SESSION_ID_FROM_INITIALIZE"
curl -sS -X POST "$MCP_URL" \
-H "Authorization: Bearer $MCP_TOKEN" \
-H "Mcp-Session-Id: $MCP_SESSION_ID" \
-H "Accept: application/json, text/event-stream" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
A tool call looks like this:
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "psylab.list_tests",
"arguments": { "limit": 20 }
}
}
The response contains a JSON-RPC result; tool errors normally arrive as result.isError: true. Never print the bearer token in logs.
Abilities and access boundaries
Every call passes through the token audience, plan capability, mcp:use, object access, and the ability required by the specific tool.
| Scenario | Requirements |
|---|---|
| Profile and structure reads | mcp:use + profile:read / studies:read / tests:read / questions:read. |
| Create or update a study | mcp:use + mcp:write + studies:write. |
| Create or update a test | mcp:use + mcp:write + tests:write. |
| Create or update a question | mcp:use + mcp:write + questions:write. |
| Publish a version | The same domain write abilities; publishing creates an immutable version. |
| Aggregate analytics | mcp:use + analytics:read. |
| Respondents/results | The relevant read/write ability and mcp:respondent-data, plus a separate grant. |
| Documentation, blog, media, changelog | An admin account and the relevant content abilities; writes also require mcp:write. |
Tools
Studies and versions
- psylab.list_studies, psylab.get_study
- psylab.create_study, psylab.update_study
- psylab.list_study_versions, psylab.publish_study_version
Tests and questions
- psylab.list_tests, psylab.get_test
- psylab.create_test, psylab.update_test
- psylab.list_test_versions, psylab.publish_test_version
- psylab.attach_test_to_study
- psylab.list_questions, psylab.create_question, psylab.update_question, psylab.reorder_questions
Supported question types are single, multiple, open, range, rating, boolean, dropdown, nps, scale, email, phone, date, and matrix.
Participant data and analytics
- psylab.list_respondents, psylab.create_respondent, psylab.update_respondent
- psylab.list_results
- psylab.get_test_analytics, psylab.get_study_analytics
list_respondents requires study_id; list_results requires test_id. Analytics remains aggregate: for a sample below five, the result is returned without disclosed statistics.
Administrative content
- Blog: list_blog_articles, get_blog_article, create_blog_article, update_blog_article, publish_blog_article
- Documentation: list_documentation_pages, get_documentation_page, create_documentation_page, update_documentation_page, publish_documentation_page
- Media: list_media, create_media_upload
- Changelog: list_changelog_entries, get_changelog_entry, create_changelog_entry, update_changelog_entry, publish_changelog_entry
Resources
Available resource URIs:
| URI | Purpose |
|---|---|
| psylab://me | Current account and token abilities; requires profile:read. |
| psylab://studies | Recent accessible studies; requires studies:read. |
| psylab://studies/{study_id} | One study with tests and counts; requires studies:read. |
| psylab://studies/{study_id}/analytics | Privacy-filtered study analytics; requires analytics:read. |
| psylab://tests/{test_id} | One test with questions and options; requires tests:read. |
| psylab://tests/{test_id}/questions | Questions and options; requires questions:read. |
| psylab://tests/{test_id}/results | Minimized results with results access and a disclosure grant. |
| psylab://respondents/{respondent_id} | Minimized respondent context with respondent access and a disclosure grant. |
Prompts
The server publishes prompts for common research tasks:
- create-study-plan
- generate-test-questions
- review-test-quality
- improve-question-wording
- analyze-study-results
- prepare-research-summary
Prompts help prepare a payload, but they do not replace a researcher's methodological review.
Recommended write flow
- Call psylab.list_tests and psylab.list_studies to avoid duplicates.
- Create a test with psylab.create_test.
- Read the current draft revision with psylab.list_test_versions.
- Add questions with psylab.create_question; send the current revision with each write.
- Configure scoring version 2 when needed.
- Publish the test with psylab.publish_test_version.
- Create or update the study, attach the test, and publish the study version.
- After any concurrent change, read the revision again: a stale revision is rejected to protect newer edits.
Creating an entity and publishing it are separate operations. Always verify the published version before sharing a public link.
Upload images for documentation
Only an admin MCP token with mcp:write and media:write can call psylab.create_media_upload. The tool returns a one-use ticket valid for 10 minutes for PNG, JPEG, or WebP images up to 8 MiB.
Then send the bytes directly:
curl -sS -X POST "https://psylab-research.org/media/agent-upload" \
-H "X-Media-Upload-Ticket: TICKET_FROM_MCP" \
-H "Content-Type: image/jpeg" \
--data-binary @screenshot.jpg
Multipart with the image field is also supported. A successful upload returns a public asset URL; the ticket is one-use, so do not repeat an uncertain request without checking the media library.

Privacy and audit
Do not put participant contact details, free text, or real secrets into prompts or tool arguments unless the task requires them. Every tool/resource call writes a technical audit row, and revoking a token stops future access but cannot retract data already sent to an agent.