agentleFS
anrysysanrysys/tg-ai/.agents/skills/mcp-tool-authoring/SKILL.md

mcp-tool-authoring

Skill0 starsChanged 2 months agoMITView on GitHub

How to add or change an MCP tool in this repository. Use when adding a tool to server.py, changing a tool's parameters or return text, or debugging FastMCP registration.

The file

Files
SKILL.md

Authoring an MCP tool

Authority: docs/10-product/srs.md and docs/30-api/mcp-tools.md.

The shape

@mcp.tool()
@guarded_tool
async def tg_do_thing(target: str, limit: int = 10) -> str:
    """One line saying what this does for the user.

    When to use it rather than a neighbouring tool, and any consequence the
    agent must know about before calling.

    Args:
        target: What forms are accepted.
        limit: What range; note that it is clamped, not rejected.

    Returns:
        What the text contains, and what a failure looks like.
    """

Decorator order matters: @mcp.tool() outermost, @guarded_tool directly on the function.

Hard requirements

RuleWhy
Return str under all conditions; never raiseAn escaping exception can kill the stdio server mid-session (SPEC-SND-004)
No from __future__ import annotations in server.pyFastMCP inspects signatures at import time and cannot resolve string annotations. It fails with issubclass() arg 1 must be a class
Clamp limit, never reject itmax(1, min(int(limit), N)). An agent guessing 10000 should get an answer, not a round trip (SPEC-RCV-004)
raise ToolError(...) for expected failuresProduces ERROR: <message> without stack-trace noise
Never print()stdout is the protocol channel. Use log.* (stderr)
Acquire the client via await telegram(), the pool via await database()Both are lazy and shared. A DB-only tool must keep working with no Telegram session

The docstring is the agent's only manual

FastMCP publishes it verbatim as the tool description. Write it for an agent deciding which tool to call:

  • Say when to use this one rather than a similar one. tg_get_recent_messages sees the last minute; tg_search_local_history sees years but only to the last sync.
  • State consequences up front. "Blocks sends to strangers" belongs in the first paragraph, not in the return description.
  • Describe what failure text looks like, so the agent can react rather than retry blindly.

After adding or changing a tool

Required by the documentation map:

  1. A SPEC- clause in the SRS, naming its test.
  2. A schema entry in docs/30-api/mcp-tools.md.
  3. A row in the README tool table.
  4. A glossary entry if a new concept appeared.
  5. just check, then the DOCS SYNC block.

Verifying registration

.venv/bin/python -c "
import asyncio, server
print([t.name for t in asyncio.run(server.mcp.list_tools())])"

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.