Agent skill

Testing With API Mocks

by stacklok in stacklok/toolhive-studio

Start here for all API mocking in tests. An agent skill from stacklok/toolhive-studio.

Apache-2.0Auto-check passedDevelopment

Install Testing With API Mocks

skills CLI
$ npx skills add stacklok/toolhive-studio --skill testing-with-api-mocks -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install stacklok/toolhive-studio testing-with-api-mocks --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/stacklok/toolhive-studio.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.codex/skills/testing-with-api-mocks .claude/skills/testing-with-api-mocks && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
testing-with-api-mocks
GitHub stars
170
Token cost
~1.5k tokens
SKILL.md length
343 words
Files
1
Skills in repo
9
Repo updated
First seen
Licence
Apache-2.0

At a glance

Start here for all API mocking in tests. An agent skill from stacklok/toolhive-studio.

  • Works in 4 steps: Run a test that triggers an API call… → Mock auto-generates if no fixture exists… → Fixture saved to… → …
  • Tasks that involve MCP servers
  • SKILL.md covers How It Works, Fixture Location, Fixture Structure and Writing a Basic Test, plus 6 more sections
  • Calls pnpm

What it does

Testing With API Mocks is an agent skill from stacklok/toolhive-studio. Start here for all API mocking in tests. Covers auto-generation, fixtures, and when to use other skills. Required reading before creating, refactoring, or modifying any test involving API calls.

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering MCP servers and Refactoring. It works with Model Context Protocol. The repository describes itself as: ToolHive is an application that allows you to install, manage and run MCP servers and connect them to AI agents. The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve MCP servers
  • Tasks that involve Refactoring

Example prompts

  • “/testing-with-api-mocks”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. Run a test that triggers an API call (e.g., a component that fetches data)
  2. Mock auto-generates if no fixture exists for that endpoint
  3. Fixture saved to renderer/src/common/mocks/fixtures//.ts
  4. Subsequent runs use the saved fixture

What it can do on your machine

Read from SKILL.md and the folder at commit fc76b24. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pnpm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pnpm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Testing With API Mocks loads about 1.5k tokens when it runs. Until then it costs about 54 tokens; SKILL.md has 343 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~54
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from stacklok/toolhive-studio at commit fc76b24, republished under its Apache-2.0 licence (© stacklok). 343 words, ~1,459 tokens.

Download SKILL.mdSave it as .claude/skills/testing-with-api-mocks/SKILL.md (or your agent's skills folder).
name
testing-with-api-mocks
description
Start here for all API mocking in tests. Covers auto-generation, fixtures, and when to use other skills. Required reading before creating, refactoring, or modifying any test involving API calls.

Testing with API Mocks

This is the starting point for all API mocking in tests. Read this skill first before working on any test that involves API calls.

This project uses MSW (Mock Service Worker) with auto-generated schema-based mocks. When writing tests for code that calls API endpoints, mocks are created automatically.

How It Works

  1. Run a test that triggers an API call (e.g., a component that fetches data)
  2. Mock auto-generates if no fixture exists for that endpoint
  3. Fixture saved to renderer/src/common/mocks/fixtures/<endpoint>/<method>.ts
  4. Subsequent runs use the saved fixture

No manual mock setup is required for basic tests.

Fixture Location

Fixtures are organized by endpoint path and HTTP method:

renderer/src/common/mocks/fixtures/
├── groups/
│   ├── get.ts          # GET /api/v1beta/groups
│   └── post.ts         # POST /api/v1beta/groups
├── workloads/
│   └── get.ts          # GET /api/v1beta/workloads
├── workloads_name/
│   └── get.ts          # GET /api/v1beta/workloads/:name
└── ...

Path parameters like :name become _name in the directory name.

Fixture Structure

Generated fixtures use the AutoAPIMock wrapper with types from the OpenAPI schema:

typescript
// renderer/src/common/mocks/fixtures/groups/get.ts
import type {
  GetApiV1BetaGroupsResponse,
  GetApiV1BetaGroupsData,
} from '@common/api/generated/types.gen'
import { AutoAPIMock } from '@mocks'

export const mockedGetApiV1BetaGroups = AutoAPIMock<
  GetApiV1BetaGroupsResponse,
  GetApiV1BetaGroupsData
>({
  groups: [
    { name: 'default', registered_clients: ['client-a'] },
    { name: 'research', registered_clients: ['client-b'] },
  ],
})

The second type parameter (*Data) provides typed access to request parameters (query, path, body) for conditional overrides.

Naming Convention

Export names follow the pattern: mocked + HTTP method + endpoint path in PascalCase.

  • GET /api/v1beta/groups → mockedGetApiV1BetaGroups
  • POST /api/v1beta/workloads → mockedPostApiV1BetaWorkloads
  • GET /api/v1beta/workloads/:name → mockedGetApiV1BetaWorkloadsByName

Writing a Basic Test

For most tests, just render the component and the mock handles the rest:

typescript
import { render, screen, waitFor } from '@testing-library/react'

it('displays groups from the API', async () => {
  render(<GroupsList />)

  await waitFor(() => {
    expect(screen.getByText('default')).toBeVisible()
  })
})

The auto-generated mock provides realistic fake data based on the OpenAPI schema.

Customizing Fixture Data

If the auto-generated data doesn't suit your test, edit the fixture file directly:

typescript
// renderer/src/common/mocks/fixtures/groups/get.ts
export const mockedGetApiV1BetaGroups = AutoAPIMock<
  GetApiV1BetaGroupsResponse,
  GetApiV1BetaGroupsData
>({
  groups: [
    { name: 'production', registered_clients: ['claude-code'] }, // Custom data
    { name: 'staging', registered_clients: [] },
  ],
})

This becomes the new default for all tests using this endpoint.

Regenerating a Fixture

To regenerate a fixture with fresh schema-based data:

  1. Delete the fixture file
  2. Run a test that calls that endpoint
  3. New fixture auto-generates
bash
rm renderer/src/common/mocks/fixtures/groups/get.ts
pnpm test -- --run <test-file>

Key Imports

typescript
// Types for API responses and request parameters
import type {
  GetApiV1BetaGroupsResponse,
  GetApiV1BetaGroupsData,
} from '@common/api/generated/types.gen'

// AutoAPIMock wrapper
import { AutoAPIMock } from '@mocks'

// Fixture mocks (for test-scoped overrides, see: testing-api-overrides skill)
import { mockedGetApiV1BetaGroups } from '@mocks/fixtures/groups/get'

204 No Content Endpoints

For endpoints that return 204, create a minimal AutoAPIMock fixture and override the handler in each test:

typescript
// renderer/src/common/mocks/fixtures/health/get.ts
import type {
  GetHealthResponse,
  GetHealthData,
} from '@common/api/generated/types.gen'
import { AutoAPIMock } from '@mocks'

export const mockedGetHealth = AutoAPIMock<GetHealthResponse, GetHealthData>(
  '' as unknown as GetHealthResponse
)

Then in tests, use .overrideHandler() to return the appropriate response:

typescript
import { mockedGetHealth } from '@mocks/fixtures/health/get'
import { HttpResponse } from 'msw'

it('navigates on health check success', async () => {
  mockedGetHealth.overrideHandler(() => new HttpResponse(null, { status: 204 }))
  // ...
})

it('handles health check failure', async () => {
  mockedGetHealth.overrideHandler(() => HttpResponse.error())
  // ...
})

Custom Mocks (Text/Plain Endpoints)

Custom mocks are only needed for text/plain endpoints. The only current example is the logs endpoint:

typescript
// renderer/src/common/mocks/customHandlers/index.ts
export const customHandlers = [
  http.get(mswEndpoint('/api/v1beta/workloads/:name/logs'), ({ params }) => {
    const { name } = params
    const logs = getMockLogs(name as string)
    return new HttpResponse(logs, { status: 200 })
  }),
]

To override the logs response in tests, use the exported getMockLogs mock:

typescript
import { getMockLogs } from '@/common/mocks/customHandlers'

getMockLogs.mockReturnValueOnce('Custom log content for this test')
  • testing-api-overrides - Test-scoped overrides and conditional responses for testing filters/params
  • testing-api-assertions - Verifying API calls for mutations (create/update/delete)

© stacklok, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .codex/skills/testing-with-api-mocks of stacklok/toolhive-studio.

Open the folder on GitHubat commit fc76b24

Compare with similar skills

Testing With API Mocks next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Testing With API Mocks compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Testing With API Mocks this skillstacklok/toolhive-studio170—~1.5kAutomated safety check: PassApache-2.0
Memtrace Decision Memorysyncable-dev/memtrace-public487—~1.9kAutomated safety check: PassCustom licence
Edt MCP Project Local FixDitriXNew/EDT-MCP295—~507Automated safety check: PassAGPL-3.0
Harness Engineering LifecycleArenukvern/mcp_flutter386—~1.6kAutomated safety check: PassMIT
Roslynkmrpmorris/Roslynk125—~3.1kAutomated safety check: PassMIT
Idea MCPdtprj/dongting208—~698Automated safety check: PassApache-2.0

Similar skills

  • Memtrace Decision Memory

    syncable-dev/memtrace-public

    Use Cortex decision memory through the normal Memtrace MCP tools.

    487 GitHub stars~1.9k tokensUpdated today
    DevelopmentAuto-check passed
  • Edt MCP Project Local Fix

    DitriXNew/EDT-MCP

    Apply one bounded BSL correction through EDT-MCP with lost-update protection, targeted validation, and minimal diff.

    295 GitHub stars~507 tokensUpdated today
    DevelopmentAuto-check passed
  • Harness Engineering Lifecycle

    Arenukvern/mcp_flutter

    Design, implement, and integrate generalized validation harnesses across a producer-consumer boundary after a local harness contract exists.

    386 GitHub stars~1.6k tokensUpdated 4 days ago
    Agent WorkflowsAuto-check passed
  • Roslynk

    mrpmorris/Roslynk

    How to use the Roslynk MCP tools (mcproslynk) effectively for .NET work.

    125 GitHub stars~3.1k tokensUpdated today
    DevelopmentAuto-check passed
  • Idea MCP

    dtprj/dongting

    IntelliJ IDEA MCP for Java code analysis, testing, refactoring, and project navigation.

    208 GitHub stars~698 tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • MCP Refactoring

    adeze/raindrop-mcp

    Refactoring MCP Tools for Better LLM Integration and Usability

    188 GitHub stars~972 tokensUpdated 2 mo ago
    DevelopmentAuto-check passed

More from stacklok/toolhive-studio

All 9 skills in this repo
  • Deep Links

    stacklok/toolhive-studio

    Deep links in ToolHive Studio. An agent skill from stacklok/toolhive-studio.

    170 GitHub stars~1.6k tokensUpdated today
    Auto-check: notes
  • Bug Fix TDD

    stacklok/toolhive-studio

    Reproduce and fix bugs using TDD. An agent skill from stacklok/toolhive-studio.

    170 GitHub stars~1.7k tokensUpdated today
    Auto-check: notes
  • Devcontainer Dev

    stacklok/toolhive-studio

    Spin up and interact with ToolHive Studio's containerized dev environment (Xvfb + noVNC + DinD).

    170 GitHub stars~3.8k tokensUpdated today
    Auto-check: notes
  • Security Vuln Remediation

    stacklok/toolhive-studio

    Remediate security vulnerabilities found by Grype or pnpm audit.

    170 GitHub stars~2.3k tokensUpdated today
    Auto-check: notes
  • Skill Creator

    stacklok/toolhive-studio

    Create new AI agent skills for Claude Code, Codex, and Cursor.

    170 GitHub stars~677 tokensUpdated today
    Auto-check passed
  • Testing API Assertions

    stacklok/toolhive-studio

    Verify API requests in tests. An agent skill from stacklok/toolhive-studio.

    170 GitHub stars~993 tokensUpdated today
    Auto-check passed

Questions about Testing With API Mocks

What does Testing With API Mocks do?

Start here for all API mocking in tests. An agent skill from stacklok/toolhive-studio. Testing With API Mocks is an agent skill from stacklok/toolhive-studio. Start here for all API mocking in tests.

When should I use Testing With API Mocks?

Testing With API Mocks fits situations like: tasks that involve MCP servers; tasks that involve Refactoring.

How do I install Testing With API Mocks in Claude Code?

Run `npx skills add stacklok/toolhive-studio --skill testing-with-api-mocks -a claude-code`. Or copy the skill folder (.codex/skills/testing-with-api-mocks in stacklok/toolhive-studio) into .claude/skills/testing-with-api-mocks in your project. Claude Code loads it when a task matches its description.

How do I install Testing With API Mocks in Codex?

Run `npx skills add stacklok/toolhive-studio --skill testing-with-api-mocks -a codex`. Or copy the skill folder (.codex/skills/testing-with-api-mocks in stacklok/toolhive-studio) into .agents/skills/testing-with-api-mocks in your project. Codex loads it when a task matches its description.

Can I use Testing With API Mocks in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add stacklok/toolhive-studio --skill testing-with-api-mocks -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/testing-with-api-mocks, .gemini/skills/testing-with-api-mocks, .github/skills/testing-with-api-mocks and .opencode/skills/testing-with-api-mocks in your project.

What does Testing With API Mocks need to run?

Going by SKILL.md and its folder, Testing With API Mocks needs the command-line tools its instructions call (pnpm).

Does Testing With API Mocks access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Testing With API Mocks safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Testing With API Mocks use?

Testing With API Mocks is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Testing With API Mocks use?

About 1.5k tokens (SKILL.md is roughly 5.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Testing With API Mocks?

Skills that share tags, products or a category with Testing With API Mocks: Memtrace Decision Memory (syncable-dev/memtrace-public, 487 stars), Edt MCP Project Local Fix (DitriXNew/EDT-MCP, 295 stars), Harness Engineering Lifecycle (Arenukvern/mcp_flutter, 386 stars) and Roslynk (mrpmorris/Roslynk, 125 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Testing With API Mocks?

stacklok (a GitHub organization) maintains it in stacklok/toolhive-studio, which has 170 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on October 7, 2026.

Source: stacklok/toolhive-studio on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.