agentleFS
james5101james5101/jobtrack/.claude/skills/add-mcp-tool/SKILL.md

add-mcp-tool

Skill2 starsChanged 6 months agoMITView on GitHub

Add a new tool to the jobtrack FastMCP server (src/jobtrack/mcp_server.py). Use this when the user asks to expose new functionality to Claude/AI clients via MCP — read tools for queries, write tools for mutations.

12 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 11 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Return JSON-serializable dicts: Never return ApplicationMeta or other pydantic objects directly.

    line 23
  2. Distinctive:

    All seven existing tests plus your new ones should pass.

    line 107

“Common” is measured: kept by at least 6 in 10 of the 11 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Add a new MCP tool

The FastMCP server lives in src/jobtrack/mcp_server.py. It currently exposes seven tools: four read (list_applications, get_application, search_applications, get_recent) and three write (update_status, add_note, edit_tags).

Tools are thin: business logic stays in core.py. The MCP layer translates between strings/dicts and domain objects, and shapes error envelopes for AI callers.

Decide: read tool or write tool

The distinction matters for resolution semantics:

  • Read tool — uses core.resolve(query) directly. On AmbiguousQuery, pick the most recent match and return its siblings in a siblings: [...] field. Reading the wrong record is recoverable; making the AI round-trip on ambiguity is annoying. See get_application for the canonical pattern.
  • Write tool — uses _resolve_strict(query). On ambiguity, returns an error dict with a candidates: [...] list and refuses to write. Writing to the wrong record is not recoverable. See update_status for the canonical pattern.

The pattern

  1. Add the tool function in mcp_server.py, decorated with @mcp.tool. Write the docstring as if it's the user manual — FastMCP passes the docstring (including Args: section) verbatim to the AI client. Be explicit about valid values and resolution behavior.
  2. Return JSON-serializable dicts. Never return ApplicationMeta or other pydantic objects directly. Use the _summary(meta) helper for list-style returns and _full(meta) when you want meta + file contents.
  3. Error envelope shape. Errors are returned as a dict, not raised:
    return {"error": "human-readable message", "<context_field>": <useful_data>}
    Examples in-tree:
    • {"error": "No application matches 'foo'"} — not found
    • {"error": "...ambiguous...", "candidates": [ids...]} — multiple matches on a write
    • {"error": "Invalid status 'bogus'", "valid_values": [...]} — bad enum input
  4. Validate enum-shaped inputs in the tool, not in core. The MCP boundary takes strings; converting ApplicationStatus(status) inside a try/except ValueError lets you return the valid_values error envelope instead of letting an exception bubble.
  5. Update the registration test. tests/test_mcp_server.py::test_mcp_lists_expected_tools hard-codes the expected tool name set. Add the new name. This test exists specifically to catch tools that get added but not surfaced.
  6. Add a round-trip test using the _call(name, args) helper in test_mcp_server.py and the isolated_home fixture (autouse, from conftest.py). At minimum cover happy path; for write tools also cover ambiguous-resolution and invalid-input cases.
  7. Update the README under ## MCP server. Bump the tool count in the description line ("four read tools and three write tools") and add a bullet under the appropriate Read/Write section.

Skeleton — read tool

@mcp.tool
def my_read_tool(query: str, optional_filter: Optional[str] = None) -> dict:
    """One-line summary. AI clients see this.

    Resolution: exact ID match wins, then company. On multiple matches,
    returns the most recent with `siblings: [...]` of other candidate IDs.

    Args:
        query: Application ID or company name.
        optional_filter: <describe>.
    """
    try:
        meta = core.resolve(query)
        siblings: list[str] = []
    except core.AmbiguousQuery as e:
        meta = e.matches[0]
        siblings = [m.id for m in e.matches[1:]]
    except core.NotFound:
        return {"error": f"No application matches {query!r}"}

    # ... do read work, build result dict ...
    return {"siblings": siblings, ...}

Skeleton — write tool

@mcp.tool
def my_write_tool(query: str, payload: str) -> dict:
    """One-line summary.

    Resolution is strict: requires an exact ID or a company name that uniquely
    identifies one application. On multiple company matches, returns an error
    with candidate IDs.

    Args:
        query: Application ID or company name.
        payload: <describe>.
    """
    meta = _resolve_strict(query)
    if isinstance(meta, dict):
        return meta  # error envelope from _resolve_strict

    # If payload is enum-shaped, validate here and return valid_values on failure.
    # Then call into core:
    updated = core.<the_business_logic>(meta.id, payload)
    return {"updated": _summary(updated), <relevant_extra_fields>}

Anti-patterns

  • ❌ Returning bare strings or raising exceptions from a tool. Always return a dict.
  • ❌ Doing filesystem work inside the tool function. That belongs in core.py / storage.py.
  • ❌ Forgetting to update the test_mcp_lists_expected_tools set — the test will fail and someone will spend two minutes wondering why.
  • ❌ Using strict resolution for a read tool. Reads should be ergonomic; the latest-plus-siblings pattern is the convention.

Verify

uv run pytest tests/test_mcp_server.py -v

All seven existing tests plus your new ones should pass.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.