Give your company data to agents, safely
For engineers
Scenario lesson and practice set combining Building an MCP server, Remote MCP servers and authorization, Workplace confidentiality and AI governance in organizations. Completing it counts as evidence for every listed skill.
Giving an AI agent access to company data is four decisions, not one: whether it should, what it may touch, how it proves who it is, and who watches it afterwards. This scenario follows one realistic case from request to rollout.
The case
Northwind Logistics' support team spends hours looking up contract terms. Dana Okafor, who leads support, asks for an AI agent that answers questions such as "When does Oceanfresh renew, and on which plan?" The data sits in a contracts database. Many contracts carry pricing covered by NDAs. The agent will use a hosted model such as Claude, ChatGPT or Gemini, and will reach the data through an MCP server, the open protocol that lets assistants call tools and read resources.
Why this matters
Most leaks from agents are not hacks. They are ordinary access given too widely: a tool that returns whole rows, a shared key, a token accepted by the wrong server, a personal chatbot used because the approved one is slow. Each choice looks small. Together they decide whether one wrong reply discloses another client's pricing.
Step 1: Register the use before building (governance)
Add the agent to the AI inventory with an owner, purpose, data classes and a risk tier. Contract data plus an agent puts it in the high tier, so it gets a fuller review. Decision rights matter here. Low-risk uses should be approved by the owner's management and recorded. The AI committee should spend its time on uses like this one.
Step 2: Decide what data may leave (workplace confidentiality)
Read the NDAs. Most bar disclosure to third parties without written consent, and a model provider that processes the text can count as one. Check the provider's plan terms too: retention, training use and sub-processors. If the contracts do not permit it, the agent can still serve questions that do not need NDA content, or Northwind can ask clients for consent. Do this before anyone writes code, and never test with real contracts in a personal account.
Step 3: Build a narrow server (MCP server)
Expose one read-only tool, get_contract_summary(contractId). Validate the id with a pattern, select only the three fields the task needs, set readOnlyHint, and return isError with a readable message when a contract is missing. Keep stdout for protocol messages when running over stdio and send logs to stderr. Test in MCP Inspector and with a scripted client before any model sees it.
Step 4: Protect the remote endpoint (remote MCP and authorization)
Serve the tool over Streamable HTTP. Return 401 with protected resource metadata, so the client can find the authorization server and run OAuth with PKCE. Validate every token for signature, issuer, expiry and audience, and check scopes per tool. Validate the Origin header. Never forward a client's token to another API; use a separate credential for downstream calls. Unattended jobs use client credentials with a dedicated identity, revocable at the company identity provider.
Step 5: Pilot, watch and learn (governance again)
Start with ten support agents, per-user tokens and a weekly audit of logged calls and sampled replies. Test revocation before launch. Re-review when the model or tools change. Write an incident path in advance: disable the connector, revoke tokens, keep logs, assess severity and any duty to notify.
Before and after
Before: one shared API key, a run_sql tool, 7-day logs and a yearly review. After: per-user tokens, a narrow tool returning three fields, audited weekly, with a tested kill switch.
What goes wrong
- Leaky tools.
SELECT *sends margins and bank details to the model. Fix the tool, not the prompt. - Weak tokens. Accepting a token issued for another service, or passing it through, turns one theft into many.
- Shadow AI. If the approved path is slow, staff will use a personal account. Fix the path and report the gap.
- Quiet governance. An inventory nobody updates and logs nobody reads give false comfort.
Treat the model's instructions as a request, not a control. The controls are in the server, the tokens and the process around them.
Steps
Register the use and set its review level
Create the inventory entry before any build: owner (Dana Okafor), purpose (answer contract-term questions), data (client contracts, NDA pricing), tier (High). Triage decides the review path, and a high-tier use goes to the AI committee while low-risk uses are approved by management and recorded.
Check the NDAs and the provider's terms
Read the disclosure clause of each NDA and the hosted provider's plan terms. If a processor counts as a third party and there is no consent, either obtain written consent, use an approved plan with the right terms, or limit the agent to non-NDA fields. Use synthetic contracts for development.
Build one narrow, read-only tool
Expose
get_contract_summary(contractId)with a pattern-validated id, three selected columns,readOnlyHint: true, and anisErrorresult for unknown ids.Narrow tool with an explicit not-found error src/tools/contract.ts
server.registerTool("get_contract_summary", { description: "Return term, renewal date and plan for one contract", inputSchema: { contractId: z.string().regex(/^C-\d{5}$/) }, annotations: { readOnlyHint: true }}, async ({ contractId }) => { const row = await db.oneOrNone(SQL_SUMMARY, [contractId]); if (!row) return { isError: true, content: [{ type: "text", text: `No contract found for ${contractId}. Check the id.` }] }; return { content: [{ type: "text", text: JSON.stringify(row) }] };});Serve it over HTTP with OAuth
Return 401 with protected resource metadata, run the authorization flow with PKCE, validate issuer, expiry, audience and per-tool scope on every request, check Origin, and use a separate credential for the ledger API.
Test before a model sees it
Run the server in MCP Inspector over stdio (logs on stderr), then run scripted client tests for valid ids, malformed ids, unknown ids and an over-scoped token. Read failures as schema, handler or transport problems.
Pilot with audit, kill switch and re-review
Pilot with ten agents for eight weeks. Review logged calls and a sample of replies weekly, test token revocation before launch, and re-review on any model or tool change. Keep an incident path: disable, revoke, preserve logs, assess severity and notice duties.
Skills this scenario uses
Where to study
- MCP specification: Authorization (opens in a new tab)StandardFree
The normative flow: 401, protected resource metadata, PKCE, audience validation, no token passthrough.
- MCP transports (specification) (opens in a new tab)StandardFree
Stdio and Streamable HTTP rules, including stdout-only protocol messages and Origin validation.
- Build an MCP server (official tutorial) (opens in a new tab)DocsFree
A working server with tool definitions, plus how to run and connect it.
- Understanding authorization in MCP (tutorial) (opens in a new tab)DocsFree
A walk-through of the OAuth steps for an MCP server.
- Enterprise-Managed Authorization extension (opens in a new tab)DocsFree
How a company identity provider grants and revokes agent access.
- NIST AI RMF Playbook (opens in a new tab)ArticleFree
Governance, mapping and monitoring actions to adapt for an inventory and review process.
- AI and cyber security: what you need to know (NCSC) (opens in a new tab)DocsFreeUK
Plain-language security guidance on using AI tools with organizational data.
- Trade secrets (WIPO) (opens in a new tab)DocsFree
What counts as a trade secret and why careless disclosure weakens protection.