Skip to content
LeitaguDocs

Loading…

Pages

Platform

AI assistants (MCP)

How Leitagu staff connect Claude and other AI assistants to the staff tools through the MCP server in the admin app; what the assistant can do, how sign-in works, and how to disconnect it.

Updated 18 October 2026View as Markdown

Leitagu staff can let an AI assistant, such as Claude, work in the research CRM as them: find and read leads, add new ones, change their facts and status, log notes, calls and tasks, add contacts and make a company a partner. The assistant connects to the staff MCP server in the admin app, using the Model Context Protocol. Each person signs in once and approves the connection; the assistant then has exactly the access that person's staff roles give, checked again on every request.

Connecting

The server's address is https://admin.leitagu.ee/api/mcp (locally http://localhost:3001/api/mcp). The admin app shows it under Connected apps (Ühendatud rakendused) for everyone whose roles allow it.

  • claude.ai, Claude Desktop and the mobile apps: add a custom connector (Settings → Connectors) with that address, then press Connect.
  • Claude Code: claude mcp add --transport http leitagu https://admin.leitagu.ee/api/mcp, then run /mcp in Claude Code and choose to authenticate.
  • Other MCP clients that support remote servers with OAuth work the same way.

The browser opens Leitagu's sign-in page. Log in with your staff account if you aren't already, check the page, and press Luba (Allow). The page shows:

  • who is asking. For Claude this is the host its client description comes from (claude.ai); apps that registered themselves show a name marked "not verified";
  • where you go next, and a warning when that is an app on your own computer (Claude Code): continue only if you just started it yourself;
  • who you are signed in as, with a way to use another account;
  • what it can do as you, based on your roles.

A person whose roles have no use for the tools (for example Support only) sees only Keela (Deny).

What the assistant can do

Tool Needs What it does
crm_search_leads crm.use Find leads by name, registry code, city, tag or brand, and filter by status, type, priority, confidence or owner
crm_get_lead crm.use One lead with its contacts, timeline, news and sources
crm_list_open_tasks crm.use Open tasks, soonest first, for all leads or one
crm_create_lead crm.use Add a lead; refuses a likely duplicate (same registry code or name) unless told otherwise
crm_update_lead crm.use Change facts; only the fields it sends change
crm_set_lead_status crm.use Move a lead along the pipeline (not to partner)
crm_log_activity crm.use Add a note, call, email, meeting or task with a due date
crm_complete_task crm.use Mark a task done or open it again
crm_add_contact crm.use Add a person at the company
crm_make_partner crm.convert Create the company's store for the partner app and set it to partner

Today the tools cover the CRM, so Sales, Admin and Owner can use them. Tools for other areas will be listed here as they are added. Nothing can be deleted through the server.

Everything the assistant changes is recorded under your name. Timeline entries in the CRM show "via" and the assistant's name, and the audit log has an entry per change (crm_mcp_create_lead, crm_mcp_update_lead and so on). Updates also record the old values, so a wrong change can be put back.

Lead text comes from web research and from other people. The server tells the assistant to treat it as data, not instructions, but read what an assistant proposes before you let it change many leads.

Disconnecting

Connected apps in the admin app lists your connections, with when each was made and last used. Katkesta ühendus (Disconnect) stops it at once. Owners see everyone's connections there too.

A connection also ends by itself:

  • after 90 days;
  • when the account is closed, or its password is reset;
  • when the person no longer has a role that uses the tools.

How sign-in works

The admin app is an OAuth 2.1 authorization server, and the MCP endpoint is its only protected resource. It follows the MCP authorization specification (2026-07-28) and Claude's connector requirements.

  • Discovery. A request without a token gets 401 with a pointer to /.well-known/oauth-protected-resource/api/mcp, which names the admin app as the authorization server. Its own metadata is at /.well-known/oauth-authorization-server.
  • Who the client is. Clients identify themselves with a Client ID Metadata Document, an https address that describes them (Claude uses this), or register themselves at /api/oauth/register.
  • Where codes may go. An authorization code is only ever sent to an app on the person's own computer (http://localhost, 127.0.0.1 or [::1], any port) or to claude.ai. A client that only claims to be Claude can't receive one.
  • Proof of the request. PKCE (S256) is required. Codes work once, for five minutes, and only together with the client, verifier and resource they were issued for. A code used twice ends the connection it made.
  • Tokens. Access tokens last an hour, refresh tokens 30 days and are replaced at each use; the connection lasts at most 90 days. Only hashes are stored. A refresh token used again later (not a quick retry) ends the connection.
  • Every request checks the token, that the connection is open, that the account isn't closed, and that the person's roles still allow the tool.

For developers

  • packages/core/src/server/oauth.ts: the authorization server (clients, consent, codes, tokens, connections).
  • packages/core/src/server/mcp.ts: the MCP endpoint (serveMcp), built on the MCP TypeScript SDK v2.
  • packages/core/src/server/mcpTools.ts: the tools. Each tool names the one permission it needs, and its input schema has no transforms so it can be described as JSON Schema; values are then checked with the same validation as the CRM's forms.
  • Admin routes: /.well-known/*, /oauth/authorize (consent), /api/oauth/{register,token,revoke,authorize}, /api/oauth/grants/[id], /api/mcp, and the Connected apps page.
  • A new tool needs a permission, an entry in MCP_PERMISSIONS if that permission is new (a unit test checks this), a unit test in packages/core/tests/mcp.test.ts, and a row in the table above.