How we connected customers' MCP servers and GitHub repos to our research agent

Investment teams keep their best work in places we don't run: risk code on GitHub, data behind their own servers, positions at a broker. We built two ways for our agent to reach them. The hard part was keeping their tools from filling the model's context, and keeping every token out of the model and the sandbox.

Summary

An investment team's best work usually sits where an AI agent can't see it: a GitHub repository of signals, optimisers and risk code, data behind the team's own servers, positions at a broker. We built two ways in. Teams can connect GitHub, so our agent can check out a repository, run it, change it and open a pull request, and they can link any remote server that speaks the Model Context Protocol (MCP), an open standard for offering tools to AI models. Both run into the same problem: every tool a model can call is sent with every request, and the definitions crowd out the work. On our own MCP server we solve that with Code Mode, which lets the model write a short script against typed functions instead of choosing from a long tool list; it cuts the tool definitions for our API from 117,931 characters to 17,146. Customer credentials stay with WorkOS, and code outside the sandbox adds them to each request, so no token reaches the model.

Part 1

Why we built it.

Why does a research agent need the team's own tools?

Ask a portfolio manager where their edge lives and they will rarely point at a vendor. It sits in a repository: signal code built up over years, an optimiser with the team's constraints baked in, a risk model tuned to how they trade, backtests they trust because they wrote them. Our agent can run our own factor risk model and our own backtests, but an answer from our model is a second opinion. The team still has to square it with theirs by hand.

Data and positions are the same story. Teams pay for feeds we don't carry and keep estimates and notes in their own systems, and the real book sits at a broker. An agent that can't reach any of it ends up researching a copy of the portfolio, and copies go stale.

Writing one integration per vendor was never going to work. There are too many vendors, and it would still leave out everything a team built for itself. Two open routes cover most of it: GitHub, where the code already lives, and MCP, which a growing number of data vendors and software tools publish. Before building either, we set four rules. Connecting a server takes a URL and nothing else. Linking 80 tools must not push the team's question out of the model's working memory. The model and the sandbox never see a token. And a write we can't confirm is never sent twice.

What does that look like in practice?

Say a team's covariance estimate looks noisy, and an analyst asks the agent to try shrinking it toward a simpler target. The agent mounts the repository, reads the code and runs the existing tests. It makes a branch, adds the change, and runs the team's own backtest on both versions, using our market data where the code expects prices. Then it pushes and opens a draft pull request with the comparison, which the team reviews like any other change. The same loop works for a signal that has stopped paying, an optimiser that keeps hitting the same constraint, or a backtest someone suspects of looking ahead.

With a data server linked, the agent finds the right tool, pulls the series it needs, joins them with our market data and records where each number came from. With a broker or portfolio platform linked, it reads positions and cash and runs exposure and risk analysis on the real book. Trading 212 connects through our own broker integration; for other brokers, such as Interactive Brokers, the route is an MCP server that exposes the account.

Part 2

How it works.

Why do tool definitions crowd out the research?

Every tool a model can call goes out with every request, used or not: a name, a description and a JSON schema for its arguments. We measured what that costs on our own public API, which has 145 operations. Written out as one tool per operation, with every parameter and request body spelled out, the definitions come to 117,931 characters, roughly 29,000 tokens, on every turn and before the model reads the question.

For our 145-operation API, one tool per operation takes 117,931 characters of tool definitions per request; Code Mode's three tools take 17,146, about one seventh.
Characters of tool definitions sent with each request for the same 145 operations. Code Mode's size does not grow when we add operations.

Customer servers add tools we don't control. A team that links a data vendor, a broker and an issue tracker can bring a hundred or more, and the model API behind our chat agent documents a ceiling of 128 tools per request. Results pile on too: a tool that returns 2 MB of JSON puts all of it in front of the model, which then hunts for the three numbers it wanted.

What is Code Mode, and how does it work?

Code Mode swaps the long tool list for a small programming environment. The model finds the operations it needs, reads their types, and writes a short JavaScript function that calls them. The function runs in a sandbox, and only what it returns goes back to the model. The idea comes from Cloudflare's Code Mode and Anthropic's work on code execution with MCP. Cloudflare's argument is that models have read far more code than tool-call transcripts, so they handle typed functions better than a long menu.

Our MCP server, the one teams add to Claude, ChatGPT, Codex, Cursor and other assistants, has three tools. search runs a small script against the API catalog, where codemode.search(q) returns up to 50 ranked matches and codemode.describe(path) returns TypeScript types for one operation, generated on demand from our OpenAPI document. execute runs the script that does the work, calling functions such as api.get_portfolios(), or agent.runTurn() to start a long research run. workspace_list browses a chat's workspace folders. Together they take 17,146 characters.

Asked "which of my portfolios are most concentrated?", the model reads two types and writes something like this:

async () => {
  const { portfolios } = await api.get_portfolios({});
  const rows = [];
  for (const p of portfolios) {
    const detail = await api.get_portfoliosid({ id: p.portfolio_id });
    const values = detail.holdings.map((h) => Number(h.current_value_usd ?? 0));
    const total = values.reduce((a, b) => a + b, 0);
    const top3 = values.sort((a, b) => b - a).slice(0, 3).reduce((a, b) => a + b, 0);
    rows.push({ name: p.name, holdings: values.length, top3Share: total ? top3 / total : null });
  }
  return rows.sort((a, b) => (b.top3Share ?? 0) - (a.top3Share ?? 0));
}

Without Code Mode, that is one tool call per portfolio, and every full holdings list lands in the model's context. With it, the model sees one short table.

The model searches and reads types, then sends one script to a sandbox with no network; API calls go through a host that adds a signed context, and only the script's return value goes back to the model.
One Code Mode request. The script sees full API responses; the model sees only what the script returns.

What keeps the script safe?

The script runs in a Cloudflare Dynamic Worker, a fresh, isolated JavaScript sandbox created for the call. It has no network: fetch() and connect() don't exist. It gets 60 seconds and at most 100,000 characters of code. The api functions are stubs that pass each call over RPC to our host process, which talks only to our own API, strips any authorization headers or cookies the script tries to set, attaches a short-lived context signed by our gateway, and refuses redirects. The script can't leak the user's Itoflow token because it never has it.

What did we get wrong first?

Our first version capped each API response at 24 KB on its way into the sandbox. A larger response became an error, so a script that asked for a long trade history got nothing to filter. We moved the limit to the other end: scripts now read full responses and summarise them in code, and only the value they return is cut, at 24,000 characters, with a note asking the model for a narrower result. Search had a sharper edge. It matches words, and one reported query, "credits balance usage billing consumption account credits", found nothing because the repeated word counted twice. Each word now counts once.

How does the agent use a team's own MCP server?

A team adds the server's URL under Profile → Integrations → MCP servers and signs in if the server asks; the developer docs cover the rest. Inside our chat agent, we don't hand the linked tools to the model one by one. It gets two tools instead: a catalog it can search and page through, and a call tool that takes an action ID. It searches by keyword, loads the original schema of the one tool it picked, and calls it. The catalog search reuses Cloudflare's Code Mode runtime, with the network off and no model-written code.

Two bugs shaped the catalog. A large search result ran into our chat runtime's 20,000-character cut and lost its paging details, so the model couldn't ask for the rest; pages now stay under 16,000 characters and 10 tools. And a server that failed to answer once made its tools vanish for the whole turn; we now retry within the turn and mark the catalog incomplete while a server is down, so the model doesn't decide a tool is missing. Each action ID is a hash tied to the tool's schema, so if a server changes a tool, the model has to read the new schema before it can call it.

We keep each provider's tokens exactly as issued and pass its schemas to the model unchanged. One rule stays strict: if a call is sent and the answer never comes back, we mark it "outcome unknown" and never retry it, because for a tool that places orders a retry could mean a duplicate trade.

How does the agent work on a team's GitHub repository?

The team installs our GitHub App on the repositories it chooses. The App can read and write code and pull requests and read CI results, and nothing else: no Actions, workflows, administration, secrets or bypass of branch rules, so branch protection applies to the agent as it does to people. Setup is in the developer docs.

The agent mounts only the repository a task needs. We use Cloudflare's ArtifactFS, which presents the repository as a file system and fetches file contents only when something reads them, so a large repository opens without a full clone. Git's own state, the branch, the index and any unfinished merge, is saved with the workspace to Cloudflare R2, so the work carries over between turns and survives a container restart. From there the agent branches, commits and pushes with ordinary git, and uses API tools to open pull requests, read CI results and comment.

The container never holds a GitHub token. A handler outside it intercepts git traffic, checks that the request came from this chat's container, that the repository is attached to this chat, and that the user and the App still have access, and only then adds the token. Every GitHub tool tells the model to treat what it reads in a repository, a pull request or a comment as information, never as instructions. And every merge is pinned to the commit the agent checked, so GitHub refuses it if anyone has pushed since.

How do we keep the credentials safe?

A database full of customers' GitHub and MCP tokens would be an obvious target, so we chose not to build one. WorkOS, whose business is storing secrets, holds them. WorkOS Pipes runs the whole GitHub sign-in: it stores the App's client secret and each user's tokens, refreshes them, and hands us the current token when we ask. For MCP we use WorkOS Vault, because Pipes doesn't yet send the resource parameter that MCP sign-in needs; our connections service runs sign-in and refresh, and every secret it receives goes straight to Vault. Our own tables keep the owner, the server URL, public OAuth settings and an opaque reference, and the table's comment spells out the rule: "No OAuth tokens, secrets, auth codes, PKCE or MCP session IDs."

Nothing caches a token. Each git request and each MCP request asks WorkOS for the current one, after checking that the chat still belongs to the user who linked the connection, and the token lives in memory only for that request. MCP requests also go out through a restricted fetch: HTTPS on port 443, public addresses only, no redirects and no cookies.

Credentials for customer MCP servers and GitHub are added only after an ownership check at the network edge; they never enter the model, the sandbox, chat state, a cache or our database.
The two paths a credential takes. For MCP, a credential check reads the token from WorkOS Vault for each request. For GitHub, a handler outside the container adds the token to git traffic.

What does this make possible?

The agent can now run a team's own signals, optimisers and risk models on the team's data and real positions, propose a change, and put the evidence in a pull request for a person to review. It works in the other direction too: through our MCP server, a team can bring Itoflow into the assistant it already uses. If you want to try either, start with connecting GitHub and MCP servers or using Itoflow from your assistant. To see how the agent's research gets checked once it has the data, read how we use a second AI agent to review investment research.

How did we measure and source this?

Measurement conditions

We measured tool-definition sizes on 7 October 2026, against our MCP server code and the public OpenAPI document in our repository. Code Mode's size is the JSON length of the server's live tools/list response. The one-tool-per-operation size gives each of the 145 operations its name, summary, description and an input schema with every reference expanded. A second conversion, built from Code Mode's own per-operation descriptions, came to 103,666 characters. Either way, one tool per operation costs six to seven times as much as Code Mode.

What should you take away?

  • A team's own code, data and positions are the context that matters most, and GitHub and MCP reach most of it without one integration per vendor.
  • Tool definitions cost space on every turn. Code Mode exposes our 145-operation API as three tools: 17,146 characters against 117,931.
  • In Code Mode the model writes a script that runs with no network; the host adds credentials, and only the return value reaches the model.
  • WorkOS Pipes and WorkOS Vault hold every GitHub and MCP credential. We fetch the current one for each request and never store or cache it.

For research and informational purposes only; not investment advice. This post describes software design, not trading results.