WEEK 1 · TASKS VS. AGENTS WEEK 2 · HELLO, MASTRA WEEK 3 · THE ACCESS AGENT
Advanced · Week 3

The GitHub Access Agent

Week 2 gave us the workbench: a Mastra project on the LiteLLM proxy. This week we build our own agent on it — the access-review agent from week 1, joining a fake HR system with real GitHub data over MCP.

🚧 Draft. This week is still being assembled — the material below is ported from an earlier cut and will change.

1Spike the risky pieces

Before structuring anything, two throwaway scripts prove the parts we're least sure about (run from the repo's week2/ directory):

2First tool: the HR lookup

Tools are functions with a Zod schema on both ends. Create src/mastra/tools/who-is.ts — a fake HR system, deliberately separate from GitHub so the agent has to join data across two systems:

import { createTool } from '@mastra/core/tools';
import { z } from 'zod';

const ORG: Record<string, { team: string; role: string; type: string }> = {
  priya: { team: 'data', role: 'analytics engineer', type: 'employee' },
  jake: { team: 'marketing', role: 'campaign contractor', type: 'contractor' },
};

export const whoIs = createTool({
  id: 'who_is',
  description: 'Look up a person in the company HR system: team, role, employment type.',
  inputSchema: z.object({ person: z.string().describe('first name, lowercase') }),
  outputSchema: z.object({
    found: z.boolean(),
    team: z.string().optional(),
    role: z.string().optional(),
    type: z.string().optional(),
  }),
  execute: async ({ person }) => {
    const rec = ORG[person.toLowerCase()];
    return rec ? { found: true, ...rec } : { found: false };
  },
});

3Second tool source: GitHub over MCP

We don't hand-write GitHub tools — we connect to GitHub's remote MCP server and take theirs. Create src/mastra/tools/github-mcp.ts:

import { MCPClient } from '@mastra/mcp';

const token = process.env.GITHUB_TOKEN;

export const githubMcp = new MCPClient({
  servers: {
    github: {
      url: new URL('https://api.githubcopilot.com/mcp/'),
      requestInit: { headers: { Authorization: `Bearer ${token}` } },
    },
  },
  timeout: 60000,
});

// The server exposes ~44 tools; hand the agent only what the job needs.
const KEEP = ['github_get_file_contents', 'github_search_repositories', 'github_get_me'];

export async function getGithubTools() {
  if (!token) {
    console.warn('GITHUB_TOKEN not set — access agent will run without GitHub tools.');
    return {};
  }
  try {
    const all = await githubMcp.listTools();
    return Object.fromEntries(Object.entries(all).filter(([k]) => KEEP.includes(k)));
  } catch (e) {
    console.warn('GitHub MCP unavailable:', String(e).slice(0, 200));
    return {};
  }
}

Two deliberate choices: the server exposes ~44 tools and we keep 3 — a focused toolset beats a big one (less for the model to get confused by, less it can do by accident) — and if GitHub is unreachable we degrade to an agent without GitHub tools instead of crashing the whole Studio boot.

4The agent

Create src/mastra/agents/access-agent.ts. The access-review policy lives in its instructions; the model rides the same LiteLLM gateway config as week 2's weather agent; the tools are HR + GitHub:

import { Agent } from '@mastra/core/agent';
import { whoIs } from '../tools/who-is';
import { getGithubTools } from '../tools/github-mcp';

const githubTools = await getGithubTools();

export const accessAgent = new Agent({
  id: 'access-agent',
  name: 'Access Agent',
  description:
    'Reviews GitHub repo access requests by joining HR data with the repo itself.',
  instructions: `You review GitHub repo access requests for the company.
Policy:
- Team members get read access to repos their team maintains: recommend GRANT.
- Write access always needs the maintaining team's sign-off: recommend ROUTE TO OWNER.
- Admin is never automated: recommend ESCALATE.
- Contractors never get access to repos containing customer data without sign-off.
To decide, look the requester up in HR (who_is) and read the repo's README to
learn what it is and who maintains it. State your reasoning, then a one-word
verdict: GRANT, ROUTE, or ESCALATE.`,
  model: {
    id: `litellm/${process.env.LITELLM_MODEL ?? 'anthropic.claude-sonnet-5-global'}`,
    url: process.env.LITELLM_BASE_URL,
    apiKey: process.env.LITELLM_API_KEY,
  },
  tools: { who_is: whoIs, ...githubTools },
});

5Register it

src/mastra/index.ts is the registry — anything listed here shows up in Studio. Registration is the whole trick:

import { Mastra } from '@mastra/core/mastra';
import { accessAgent } from './agents/access-agent';

export const mastra = new Mastra({
  agents: { accessAgent },
});

Add GITHUB_TOKEN to .env alongside the LiteLLM vars. The demo target is chug2k/churn-dashboard — a private fixture repo whose README declares the data team as maintainer.

Mastra Studio agents list showing the Access Agent
Registered → visible.

6Test it

Ask: "Priya is asking for read access to the repo chug2k/churn-dashboard. What do you recommend?"

The agent calls who_is (HR: employee, data team), then github_get_file_contents (the repo's README: maintained by the data team), joins the two against the policy — Verdict: GRANT

The Access Agent reasoning through the request and answering Verdict: GRANT
One agent, two systems, a policy — and Studio to watch it think.