MCP in Production, Secure Tools for AI Agents. 2027 Guide

MCP in Production, Secure Tools for AI Agents. 2027 Guide

Expose your product to AI agents over MCP safely. Google’s Gmail MCP server can send email, but only after a person approves each message.

By Bijay Ranjan Pati14 min read

Google's Gmail MCP server can send email, but only after a person approves each message. As of 1 December 2026, Google's documentation lists send_message, reply and forward among the tools that "require user confirmation through MCP form elicitation". AI apps that can't show that prompt can't use them.

It matters because Google's 25 November post says agents that access Workspace data must use its MCP servers or CLI, with enforcement from 1 February 2027. A Hacker News thread titled "Google Will Make AI Agents Use Its MCP Servers. The Gmail One Can't Send Email" read that as a ban on sending.

The takeaway? Running MCP in production means deciding each tool's risk and enforcing it on your own server.

Key Takeaways

  • Sort every action into read, low-stakes write and irreversible. Reads can skip prompts but need tight scopes, low-stakes writes need idempotency keys, and irreversible actions need a confirmation your server checks.
  • Tool annotations like readOnlyHint are hints, and the spec tells clients not to trust them from untrusted servers. Permissions and business rules belong in your handler code.
  • The current spec, 2026-07-28, made MCP stateless and changed how confirmations work. Much of what's online still describes the older protocol.

Should your product have an MCP server?

The Model Context Protocol is the standard way for AI apps like ChatGPT, Claude, Copilot, Cursor and Gemini to call tools in other products. Since December 2025 it has sat under the Linux Foundation's Agentic AI Foundation, so no single AI vendor controls it.

An MCP server sits on top of your existing API. It describes a set of tools that a language model can read and call. Customers can then use your product from inside the AI assistant they already work in.

Build one if:

  • customers already ask whether they can do things in your product "from ChatGPT" or "from Claude"
  • people do repetitive, multi-step jobs in your product that they'd happily hand off, like triaging tickets or reconciling invoices
  • your data is useful next to other tools, such as a CRM record next to an email thread

Skip it, or wait, if:

  • the value of your product is mostly its interface, like a design or editing tool
  • your key actions can't be undone and you have no safe way to confirm them
  • you can't yet run OAuth, per-user scopes and audit logging, because a public MCP server needs all three

If a step needs a real form or a chart, the official MCP Apps extension can show a sandboxed piece of your UI inside the chat. We covered the design side of agents as users in The Rise of MX.

Which actions should you expose to AI agents?

Start from jobs, not endpoints. Anthropic's guide to writing tools for agents puts it plainly: "More tools don't always lead to better outcomes." A thin wrapper per REST endpoint makes the model chain calls it could have avoided.

List the jobs your users would hand to an assistant. Then note what each one does to the world:

  • Read: lists, searches and reports. Nothing changes, but the agent sees your data.
  • Low-stakes write: creating a draft or sending a system-generated reminder. An email can't be unsent, but a duplicate reminder is an annoyance, not a loss.
  • Irreversible: deleting data, moving money, voiding an invoice or sending mail from a person's own account.

You don't have to show every user every tool. The spec's tools page lets tools/list return only the tools the caller's scopes permit. Hiding isn't enforcing, though: a client can still call a tool by name, so check the scope inside the handler too.

How to set approval rules for MCP tools

MCP gives each tool four optional behaviour hints. Their defaults assume the worst. A tool you don't annotate counts as one that writes, may destroy data, isn't safe to repeat and reaches outside your product.

AnnotationDefaultWhat it claims
readOnlyHintfalseThe tool doesn't change anything
destructiveHinttrueIt may delete or overwrite, not just add
idempotentHintfalseCalling it again with the same arguments has no extra effect
openWorldHinttrueIt reaches people or systems outside your product

Clients use these to decide how much friction to add. ChatGPT's developer mode confirms write actions by default and treats any tool without readOnlyHint as a write. VS Code offers Allow Once, In this Session and Always Allow.

The schema itself says annotations are "not guaranteed to provide a faithful description of tool behavior". Users can also click Always Allow on day one. So honest annotations cut friction for reads, but they're not a safety mechanism.

For irreversible actions, your server can ask for confirmation itself, using elicitation. That's MCP's way for a server to request input from the person through their AI app. It's what Google does for Gmail sends.

Diagram of three MCP tool risk tiers for production: read-only tools with tight scopes, low-stakes writes that need an idempotency key, and irreversible actions that need a confirmation the server checks

Here's the irreversible tool from our test server, written with the official TypeScript SDK v2. It asks the person to type the invoice ID back before anything happens:

server.mjs

import { McpServer, createMcpHandler, inputRequired, acceptedContent, inputResponse } from '@modelcontextprotocol/server';
import { z } from 'zod';

const confirmSchema = z.object({ confirmId: z.string().describe('Type the invoice ID to confirm') });
const outcome = { decline: 'declined', cancel: 'cancelled', accept: 'typed the wrong ID' };
server.registerTool('void_invoice', {
  description: 'Void an invoice permanently. The user will be asked to confirm.',
  inputSchema: z.object({ invoiceId: z.string(), reason: z.string() }),
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
}, async ({ invoiceId, reason }, ctx) => {
  const user = currentUser();
  if (!user.scopes.includes('invoices:void')) return text('Missing scope invoices:void', true);
  const inv = db.invoices.get(invoiceId);
  if (!inv) return text(`No invoice ${invoiceId}`, true);
  if (inv.status === 'void') return text(`${invoiceId} is already void.`);

  const reply = inputResponse(ctx.mcpReq.inputResponses, 'confirm');
  if (reply.kind === 'missing') {
    // First round: hand a confirmation request back to the client.

    return inputRequired({
      inputRequests: {
        confirm: inputRequired.elicit({
          message: `Void ${invoiceId} (${inv.customer}, $${inv.amount})? Reason: "${reason}". This can't be undone.`,
          requestedSchema: confirmSchema,
        }),
      },
    });
  }
  // Second round: the client retried with the answer. Typing the ID back ties the "yes" to this invoice.

  const answer = acceptedContent(ctx.mcpReq.inputResponses, 'confirm', confirmSchema);
  if (answer?.confirmId !== invoiceId) return text(`Not voided: user ${outcome[reply.action] ?? 'did not confirm'}.`, true);

  db.invoices.update(invoiceId, { status: 'void' });
  db.audit.log({ user: user.id, tool: 'void_invoice', args: { invoiceId, reason }, confirmed: answer.confirmId });
  return text(`${invoiceId} voided.`);
});

Asking for the ID rather than a yes/no means a confirmation can't be replayed against a different invoice. In our test, a decline, a cancel and a wrong ID all left the invoice untouched. A client without elicitation support got error -32021, the same code Google's elicitation guide documents for Gmail.

Know the limit of this. The server asks, but the person's AI app shows the prompt and sends back the answer. Your server can't prove a human typed it. URL-mode elicitation closes that gap by sending the person to a page where your own login and confirmation run. The spec also requires URL mode for passwords, API keys and payment details.

We used form mode above to keep the example short; a real $1,200 void should use URL mode.

How to stop an AI agent repeating an action

Agents retry. A request times out and the app sends it again, or the model decides the first attempt failed. The 2026-07-28 spec removed stream resumability, so after a broken stream, clients must re-send the call as a brand-new request.

MCP has no idempotency key of its own; idempotentHint only describes the tool. So borrow what payments APIs do. With Stripe's idempotency keys, the caller sends a unique key per intended action, and a repeat of that key gets the saved result back.

server.mjs

async function sendReminder(user, invoiceId) {
  const inv = db.invoices.get(invoiceId);
  if (!inv) return text(`No invoice ${invoiceId}`, true);
  if (inv.status !== 'overdue') return text(`${invoiceId} is ${inv.status}, not overdue`, true);
  // One reminder per invoice per day, reserved atomically: a fresh key can't send a second one.

  if (!db.reminders.reserve(invoiceId, DAY)) {
    return text(`A reminder for ${invoiceId} was already sent in the last 24 hours.`, true);
  }
  try {
    await email.sendReminder(inv);
  } catch (err) {
    db.reminders.release(invoiceId);
    throw err;
  }
  db.audit.log({ user: user.id, tool: 'send_payment_reminder', args: { invoiceId } });
  return text(`Reminder sent to ${inv.customer} for ${invoiceId}`);
}

server.registerTool('send_payment_reminder', {
  description: 'Email a payment reminder for an overdue invoice. ' +
    'Use a new idempotencyKey for each reminder you intend to send; reuse it when retrying.',
  inputSchema: z.object({ invoiceId: z.string(), idempotencyKey: z.string().min(8) }),
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
}, async ({ invoiceId, idempotencyKey }) => {
  const user = currentUser();
  if (!user.scopes.includes('invoices:remind')) return text('Missing scope invoices:remind', true);

  // Claim the key before doing any work. In SQL: an INSERT with a unique index on (user_id, tool, key).

  const claim = db.idempotency.claim(`${user.id}:send_payment_reminder:${idempotencyKey}`, hash({ invoiceId }));
  if (claim.conflict) return text('This idempotencyKey was already used with different arguments.', true);
  if (claim.existing) return claim.existing.result ?? text('That reminder is still being sent. Check again shortly.', true);

  try {
    const result = await sendReminder(user, invoiceId);
    db.idempotency.complete(claim.key, result);
    return result;
  } catch (err) {
    db.idempotency.release(claim.key);   // the provider reported a failure, so let a retry with the same key try again

    return text(`Not sent: ${err.message}. Retry with the same idempotencyKey.`, true);
  }
});

Here's what held up when we tested it:

  • Claim the key before working. We fired the same call three times at once. One sent the reminder, and the other two got an error saying it was still being sent, so the agent doesn't mistake them for success.
  • Release the claim if the work fails. When our stand-in email provider timed out, the call returned an error, and a retry with the same key then sent the reminder.
  • Scope the key by user and tool, and store a hash of the arguments. Reusing a key for a different invoice got an error instead of a silent "sent".
  • Reserve a business-level slot. Keys only catch the app's retries; a model that "tries again" may mint a fresh key. Our one-reminder-per-day rule blocked that, including two simultaneous calls with different keys.

If you already handle webhook retries, this is the same idea pointed the other way.

Why every check has to run on your MCP server

Treat the model as an untrusted caller, even when it acts for a trusted user. It can be manipulated, and it will call tools with arguments nobody intended.

The spec's tools page makes four things mandatory for servers:

  • Validate inputs. Our test sent a one-character idempotency key, and the SDK's schema check rejected it with an input validation error.
  • Enforce access control. Check scopes and business rules in the handler. Our server refused a reminder for an invoice that was already paid, even though the call asked for it.
  • Rate limit tool calls. An agent in a loop can call a tool hundreds of times. Our guide to API rate limiting covers the patterns.
  • Sanitise outputs. Reduce anything in tool results that the model might read as an instruction, and don't return more data than the job needs.

Never treat an ID the agent hands back as proof of access; the security best practices say servers "MUST NOT treat possession of a state handle as authentication". And keep an audit log of who called which tool, with which arguments and what they confirmed.

How OAuth works when an agent acts as your user

For remote servers, MCP uses OAuth 2.1, and your MCP server is a resource server rather than the login system. The 2026-07-28 authorisation spec sets out the rules:

  • Publish Protected Resource Metadata (RFC 9728) so clients can find your authorisation server.
  • Reject tokens issued for anyone else. Clients name your server using resource indicators (RFC 8707), and your server must check the audience.
  • Never pass the client's token on to another API. Servers "MUST NOT accept or transit any other tokens", so get your own token for any downstream call.
  • When an action needs more permission, the server should return 403 with insufficient_scope, so the client can ask the user for it.
  • Expect clients to identify themselves with Client ID Metadata Documents. Dynamic Client Registration is deprecated, though Claude and ChatGPT still support it.

Scopes are also the cleanest way to tier tools by role. A support rep's token gets the read tools; a finance lead's token also gets void_invoice.

How to defend against prompt injection and tool poisoning

Two widely reported MCP attacks didn't break any code. They hid instructions in data the agent read.

In May 2025, Invariant Labs showed a malicious GitHub issue getting an agent to leak private repository contents into a public pull request. The researchers called it an architectural problem, not a bug in GitHub's server. In July 2025, General Analysis showed a support ticket tricking an agent that had a Supabase service-role key into leaking tokens. "No permissions were violated," they wrote.

Both attacks came in through reads. That's why the read tier still needs tight scopes. Invariant also described tool poisoning, where a malicious server hides instructions in its tool descriptions. It's the reason clients don't trust your annotations either.

You can't fully stop a model following text it reads. You can limit the damage:

  • Give tokens the least access the job needs, scoped to one workspace or project.
  • Don't let one permission cover both reading untrusted content and sending data out.
  • Label user-written content as data in tool output, and keep instructions out of it.
  • Version your tool descriptions, so any change shows up in review.

OWASP's MCP Top 10, still in beta, is a useful checklist for the rest.

What changed in MCP 2026-07-28 for production teams

The current revision shipped on 28 July 2026, and the MCP team calls it its most important release since remote MCP launched. If a guide mentions Mcp-Session-Id or the initialize handshake, it describes the previous version.

  • Stateless: every request carries its own protocol version and client capabilities, and servers must answer a new server/discover request.
  • Confirmations are round trips: the server returns an input_required result, and the client asks the person, then calls the tool again.
  • Deprecated: Roots, Sampling, Logging and Dynamic Client Registration, with removal no earlier than July 2027.

Flow of an MCP elicitation confirmation under the 2026-07-28 spec: the AI app calls a tool, the server returns input_required, the app shows the prompt, and the app retries the call with the person's answer

Stateless means a fresh server instance can answer every request. Anything that must survive between calls, like idempotency keys or a half-finished workflow, belongs in your database.

Three things tripped us up in testing:

  • Package: the old @modelcontextprotocol/sdk (1.32.2) stops at protocol 2025-11-25. The new spec needs the v2 packages, @modelcontextprotocol/server and @modelcontextprotocol/client.
  • Client default: the v2 client still connects on 2025-11-25 unless you set versionNegotiation.
  • Serving: through createMcpHandler, a client pinned to 2026-07-28 connected. When we connected the same server with server.connect() over the SDK's in-memory transport, negotiation failed. We didn't test server.connect() over HTTP.

Keep serving 2025-11-25 as well. A client built on the old v1 SDK called our endpoint on 2025-11-25 without any changes.

What MCP won't solve for you

Elicitation only works in AI apps that support it, so your irreversible tools won't run everywhere. That's the right failure, but expect support questions about it.

Prompts wear people down. If every reminder asks for approval, users stop reading and click yes. Keep server-side confirmations for actions that are truly irreversible, and make each message specific about the customer and the amount.

Idempotency has a gap too. A timeout doesn't prove nothing went out. If the provider delivered the email and then timed out, our code releases the claim and a retry sends a second one. Where your email provider accepts an idempotency key, pass yours through; otherwise accept that a rare duplicate may slip through.

And an MCP server is a product surface to maintain, with its own auth, versioning and support load. The spec is still moving: its elicitation page says URL mode "may change in future protocol revisions". Pin your SDK versions and re-test when you upgrade.

How we checked this

We built a small invoices server with the MCP TypeScript SDK 2.4.0 on Node 24.12.0, served by createMcpHandler and called in-process over Streamable HTTP. On 1 December 2026 we ran 20 scenarios, with a scripted SDK client standing in for the agent, and the snippets above are excerpts of that code.

Spec details, client behaviour and the incidents come from the linked primary sources. We didn't test against ChatGPT, Claude or VS Code.

Frequently Asked Questions

Is MCP safe to use in production?

Yes, if your server enforces its own rules. The protocol carries tool calls but doesn't decide what an agent may do. Scope tokens tightly, validate every input, confirm irreversible actions and assume anything the model reads could contain instructions.

What is the difference between MCP and an API?

An API is how software talks to your product; MCP is how AI apps discover and call it. An MCP server usually wraps your existing API in a few task-sized tools, with standard auth and confirmation prompts. Your API stays as it is underneath.

What is readOnlyHint in MCP?

readOnlyHint is a tool annotation telling clients a tool doesn't change anything. ChatGPT uses it to skip confirmation for reads. It defaults to false, and the spec treats it as an untrusted hint, so it never replaces checks on your server.

How do I stop an AI agent from deleting data through MCP?

Give the delete permission only to users who need it, and check that scope inside the handler on every call. For those users, ask for confirmation through elicitation, and refuse if the AI app can't ask or the person declines. For high-stakes deletes, use a page you control.

Should my SaaS build an MCP server?

Build one if customers want to use your product from AI assistants and your key jobs are repetitive and multi-step. Wait if your actions can't be undone safely, or if you can't yet run OAuth, per-user scopes and audit logging.

Start with a read-only server

Ship your read tools first, behind OAuth with tight scopes, and see which jobs people actually give the agent. Then add writes one at a time with idempotency keys. Leave irreversible actions for last, each behind a confirmation your server checks.

Google's Workspace rule takes effect on 1 February 2027, and other platforms may follow. Our AI development team can build an MCP server or agent features for your SaaS product. Get in touch.

Written by

Bijay Ranjan PatiAuthor

More from Bijay

Published on

Got an Idea for a Digital Product?

We help you turn ideas into scalable, high-performing digital products using the right technology and strategy.

Let's get in touch

Whether you’re redesigning or starting fresh, we help you align in strategy,design,andtechnology.

What you get when you work with us

  • NDA signed before you share anything
  • We learn the business, not just the brief
  • Brainstorm directly with our founders
  • Progress you can see, daily and weekly
  • Pricing that stays honest as scope moves
Let’s work together
Rough notes are fine. We read every one.