Skip to content

Connect an AI agent (MCP)

Connect an AI agent to Affinity with MCP. The agent finds medications and prepares orders, and you approve each order before it goes to the pharmacy.

Updated View as Markdown

Affinity has an MCP server. An AI agent that supports MCP can use Affinity for you, for example Claude, ChatGPT, Cursor or your own agent. The agent gets the access that you have in your organizations. It cannot do more than you can do in the Affinity app.

Server URL

https://api.affinityrx.com/v1/mcp

Connect an agent

  1. In your agent, add a custom MCP server. Some agents call it a connector. Enter the server URL.
  2. The agent opens an Affinity sign-in page. Sign in with your email address and the code that Affinity emails you.
  3. Read the page. It shows the name of the agent and the site that you return to. If you know the agent and the site, click Allow.

You do not need an API key. The agent signs in as you.

In Claude Code, run this command:

claude mcp add --transport http affinity https://api.affinityrx.com/v1/mcp

What the agent can do

  • Read your organizations, practices, patients, medications and orders.
  • Create an order that waits for your approval. The agent gives you a link to the order.
  • Cancel an order.
  • Change your first name, last name or NPI.
  • Read your webhook endpoints and send a test event to an endpoint.
  • For a platform: create a practice, change a practice, and turn Live orders on or off for a practice.

Each request from the agent names an organization and a mode, Test or Live. Use Test to try your agent. Test orders do not go to a pharmacy and Affinity does not bill them.

Approve an order

An order that an agent creates does not go to the pharmacy immediately. The order waits for you.

  1. Open the link that the agent gives you. The link opens the order in the Affinity app.
  2. Check the order.
  3. Click Send to send the order to the pharmacy, or click Cancel.

Only an admin of the organization can send an order that waits for approval. If you are not an admin, the order page tells you that the order waits for an admin. Anyone who can cancel orders can cancel it, also with an API key or the agent.

Nothing goes to the pharmacy before an admin clicks Send.

Prescriber

If your profile has your NPI, the agent can sign an order as you. Then the agent does not send a prescriber. To add your NPI, open Settings, then Profile.

To order for a different prescriber, the agent sends the prescriber object with that prescriber’s first name, last name and NPI.

If your profile has no NPI and the agent does not send a prescriber, Affinity returns 403 npi_required.

Disconnect an agent

Open Settings, then Security & access. The MCP section shows the server URL and the agents that you allowed. Click Disconnect to remove an agent.

The connection also stops when you sign out of the browser where you allowed the agent, or 30 days after you signed in there. Then connect the agent again.

Navigation

Send feedback

Don't include patient information.

Type to search…

↑↓ navigate ↵ select Esc close