Production Access for Coding Agents Through MCP
Quick answer: Give a coding agent production access through MCP by keeping the credentials out of the agent's environment entirely. Put the secret on a server you control, let the agent call tools through it, scope each tool to the least it needs, prefer read-only access, and record every call. An agent that never holds a token cannot leak one, even when a prompt injection convinces it to try.
Let an agent earn its place on your team
Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.
What is an MCP server, and why does a coding agent need one?
The Model Context Protocol (MCP) is an open protocol for connecting AI applications to tools and data. An MCP server exposes a set of tools, such as "search errors", "run a read-only query" or "fetch a ticket", and an MCP client, which here is the coding agent, discovers those tools and calls them while it works. The official specification defines two standard transports: stdio, where the client starts the server as a local process and talks to it over standard input and output, and Streamable HTTP, where the server runs elsewhere and the client sends it HTTP requests.
A coding agent that can only read the repository is guessing about production. To fix a real bug it wants the stack trace from the error tracker, the slow query from the database, the ticket that describes what the customer saw, and the metric that shows when the problem began. MCP made that easy to wire up: there is a server for almost every product, and connecting one is a few lines of configuration.
That ease is the problem. Every one of those servers needs a credential: an API token for the error tracker, a connection string for the database, an OAuth grant for the ticket system. The usual setup puts that credential in an environment variable or a config file next to the agent. The agent is then a process that reads untrusted text all day, runs code it just wrote, and holds the keys to production. This article is about separating those two things.
How do credentials leak when a coding agent uses MCP?
The specification itself is clear about one part of this. For the stdio transport, the MCP authorization documentation says credentials should come from the environment rather than from the HTTP authorization flow. In practice that means the token sits in an environment variable of a process that the agent can usually inspect, and that the agent's own shell commands inherit. A model that has been told to "print the environment to debug the connection" will do it.
The second path is prompt injection. A coding agent reads issues, pull request descriptions, comments, logs and tool output, and it cannot reliably tell an instruction from its operator apart from text an attacker wrote. This is not hypothetical. In "Comment and Control", published on April 15, 2026 by researcher Aonan Guan and documented by the Cloud Security Alliance in August 2026, one prompt-injection pattern hidden in GitHub issue or pull request text (one variant inside an HTML comment) led AI agents running in GitHub workflows from several vendors to expose CI secrets. In "GitLost", Noma Labs reported in July 2026 that a crafted issue led GitHub Agentic Workflows to read a private repository and publish its contents; that is the researchers' claim. In both cases the agent had access it did not need for the task and a way to send data out.
The third path is in how MCP servers handle tokens. The MCP security best practices name "token passthrough" as an anti-pattern: a server that accepts a token from the client without checking that it was issued for that server, then forwards it to an upstream API. The specification says servers must not accept tokens that were not explicitly issued for them. A passthrough server makes any token the agent holds more useful to whoever controls the agent.
The last path is the boring one: logs, transcripts and caches. Agent sessions are often saved in full for debugging. If a credential ever appeared in a tool argument, a command line or an error message, it is now in a file that more people can read than the secret store ever allowed.
What should production access for a coding agent look like?
Start from a simple rule: the agent may use a credential, but it never holds one. The secret lives on a server that the agent cannot run code on. The agent asks that server to call a tool, the server adds the credential, makes the call and returns the result. If the agent is hijacked, the attacker can ask for what the agent could already ask for, but cannot walk away with a token that keeps working after the run ends.
Then shrink what "could already ask for" means. Give each tool the narrowest scope its provider supports: a read-only database role on a replica, an error-tracker token limited to one project, an analytics key that cannot export raw events. A Bug Fixer reading production rarely needs to write to it. Where a write is the point of the job, such as updating a ticket or publishing an article in a CMS, give that one write and nothing next to it.
Finally, record every call. Not just for incident response, but because what an agent did through a tool is part of what it changed. A run that reports "nothing to do" but made three write calls to a production system did something, and the record should say so in facts, not in the agent's summary.
| Leak path | What happens | Control that helps |
|---|---|---|
| Token in the agent's environment | The agent or code it runs reads and prints the variable | Keep the credential on a server the agent cannot run code on |
| Prompt injection | Attacker text in an issue or log steers the agent to exfiltrate | No secrets in reach; limit where data can be sent |
| Token passthrough | A server forwards whatever token it receives upstream | Servers accept only tokens issued for them |
| Over-broad scopes | A read task holds a write-capable key | One narrow scope per tool, read-only by default |
| Logs and transcripts | A secret lands in a saved session or error message | Credentials never enter the agent's context at all |
How does Factorik connect agents to production tools?
Factorik agents can use production and product tools: Sentry, Datadog, Cloudflare, PostHog, Mixpanel, Google Analytics, Google Search Console, Linear, Jira, Confluence, Notion, Intercom, Postgres, Supabase, Stripe, PayPal, any MCP server, any HTTP API, and your own web app signed in. Tool credentials stay on Factorik's server. The agent's calls go through a gateway on that server, which adds the credential and records each call.
That gateway is the separation described above. The agent works in an isolated sandbox with a short-lived, read-only token for one repository; it never receives the Sentry token or the Postgres password. When it wants the latest events for an error, it calls the tool, and the gateway makes the request on its behalf. If a hostile issue convinces the agent to dump its environment, there is no production secret in it to dump.
The same principle covers GitHub itself. The sandbox never writes to GitHub; Factorik's server publishes what the run changed as one commit on a branch it names, never force-pushed and never directly to the default branch. Text from issues, comments and Slack is treated as data, not instructions. Our article on prompt injection through GitHub issues walks through why that architecture matters more than any wording in a prompt.
There is one exception worth knowing before you connect anything. An MCP server that runs as a command (the stdio kind, started as a process alongside the agent) is not called through the gateway. Treat whatever you give such a server as something the agent itself can reach, and prefer a remote MCP server or a direct tool connection whenever the tool holds a production credential.
What does a production-aware bug fix look like, step by step?
Here is an illustration, not a customer story. A team runs a Bug Fixer agent on the repository acme/billing-api, with Sentry and a read-only Postgres connection attached as tools, and a Sentry alert set to call the agent's incoming webhook.
First, Sentry reports a spike in TypeError: Cannot read properties of undefined (reading 'currency') in src/invoices/totals.ts and calls the webhook. The agent wakes, and its sandbox starts with a fresh clone of the repository and nothing else.
Second, the agent calls the Sentry tool for the issue's recent events. The gateway adds the Sentry token on the server, makes the request and records the call. The agent sees stack traces and request context; it never sees the token.
Third, it queries Postgres through the gateway for invoices whose line items have no currency set, and finds that a recent import left a few hundred rows with a null currency. That call is recorded too, as a read.
Fourth, it writes a failing test in src/invoices/totals.test.ts that builds an invoice with a line item missing its currency, fixes totals.ts to fall back to the invoice's currency, and runs the tests in the sandbox until they pass.
Fifth, Factorik's server reads the change out of the sandbox and publishes it as one commit on a new branch, then opens a pull request that explains the cause and the fix. Checks run. At the first level a person merges it; an agent that has earned more may merge it itself when the merge policy allows.
At no point did the sandbox hold a production credential. If the error message in Sentry had contained an attacker's instructions, the worst the agent could do was ask the gateway for more of what it could already read.
Let an agent earn its place on your team
Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.
What does a credential gateway not protect you from?
Keeping secrets out of the sandbox closes the worst outcome, a stolen key that works after the run, but it does not make tool access harmless. An agent can still misuse whatever the tool allows during the run. If you connect a write-capable Stripe or database credential, a confused or hijacked agent can make writes through the gateway, and the record will show it afterwards rather than prevent it. Scope is still your job.
Data that comes back from a tool enters the agent's context. Customer emails in a support ticket, user ids in an error event or rows from a production table are now part of the run. Choose tools and scopes with that in mind, and prefer aggregates and replicas where the job allows.
Tool output is also untrusted text. A ticket, a log line or a CMS draft can carry injected instructions just like a GitHub issue. The gateway limits what a hijacked agent can take; it does not stop the agent from being misled about what to do. That is why changes still go through pull requests, checks, review and a merge policy, and why a problem traced to a merged change moves the agent down a level at once. The article on watching AI-written changes in production covers that side.
And command-based MCP servers, as above, sit outside the gateway. They are convenient for local, low-stakes tools; they are the wrong place for a production key.
- +No production secret in the sandbox to print, copy or exfiltrate
- +A stolen session ends with the run; nothing reusable is taken
- +Every call recorded, reads and writes alike
- +One place to rotate or revoke a tool's credential
- −An agent can still misuse whatever scope you granted during a run
- −Tool results, including customer data, still enter the agent's context
- −Tool output can carry prompt injection
- −Command-based MCP servers are outside it
How do I connect a production tool to a coding agent safely? A checklist
- Decide what the agent's job needs from the tool before you connect it. A Bug Fixer needs to read errors and maybe query data; it rarely needs to change either. Write the job down first and derive the access from it, not the other way round.
- Create a dedicated credential for the agent at the provider, never a person's personal token. Give it the narrowest scope available: one project, one database role on a replica, read-only wherever possible. A dedicated credential can be revoked without locking a person out.
- Keep the credential off the agent's machine. Use a server-side gateway or a remote MCP server that authenticates the agent separately from the upstream API. Avoid setups where the agent's environment holds the upstream token.
- Check that any MCP server you run does not pass tokens through. It should accept only tokens issued for it and use its own credential upstream.
- Record every call and look at the record. Writes in particular should be visible next to the code the run changed.
- Treat what tools return as data. Keep the change flowing through a pull request, checks and review, so a misled agent still has to convince the process, not just the tool.
- Revisit scopes when the job changes. An agent that was given write access for one task keeps it until someone takes it away.
Try it on your own repository
The safest first step is a narrow one: one repository, one agent, one or two read-only tools. Start a Bug Fixer or a Change Watcher with Sentry or your analytics connected, let it work at the first level where a person merges every pull request, and read both the changes and the record of tool calls for a couple of weeks. When its record of merged changes clears the bar, promote it; if a problem is traced to one of its changes, it moves down a level at once. The page on autonomous coding agents that earn the right to merge explains that model in one place.
You can try it with a free 7-day trial of the Team plan, with no payment details needed. Connect a tool, define an agent, and see what it does when the credentials are somewhere it cannot reach.
Frequently asked questions
Is it safe to give a coding agent an MCP server with production credentials?
It is safe only if the agent never holds the credential itself. Put the secret on a server the agent cannot run code on, scope it narrowly, prefer read-only access and record every call. A token in the agent's environment can be printed or exfiltrated by a hijacked agent.
What is MCP token passthrough?
The MCP security best practices describe token passthrough as an anti-pattern where a server accepts a token from the client without checking it was issued for that server, then forwards it upstream. The specification says servers must not accept tokens that were not explicitly issued for them.
Are stdio MCP servers riskier than remote ones?
For credentials, often yes. The MCP specification says stdio servers should get credentials from the environment, so the secret usually sits in a process next to the agent. A remote server can keep the upstream credential on its own side and authenticate the agent separately.
Does Factorik give agents my tool credentials?
No. Tool credentials stay on Factorik's server and the agent's calls go through a gateway that records each one. The exception is an MCP server that runs as a command alongside the agent, which is not called through the gateway, so it should not hold a production credential.
Can a gateway stop prompt injection?
No. It limits what a hijacked agent can take, but it cannot stop the agent from being misled. That is why changes still go through pull requests, checks, review and a merge policy, and why tool scopes should be as narrow as the job allows.
Let an agent earn its place on your team
Define a Factorik agent once and it wakes on an issue, a failed build or a schedule, works in an isolated sandbox and ships a pull request. It starts with a person merging its work and earns more autonomy on its record. Try it free for 7 days, no payment details needed.