"A One-Line Default Change Was Enough to Break My MCP Server's Tool Fingerprints"
The highest-scoring post on dev.to's mcp tag this week is about a problem I'd never actually sat down and measured against my own server: an MCP client approves a tool once, and after that it trusts whatever the server h
The highest-scoring post on dev.to's mcp tag this week is about a problem I'd never actually sat down and measured against my own server: an MCP client approves a tool once, and after that it trusts whatever the server hands back under that tool's name. Nothing re-checks that the tool is still the tool you looked at when you clicked "allow." For a third-party server you don't control, that's a supply-chain problem. For a server you wrote yourself, I assumed it wasn't a problem at all, since I'm the only one who can change it. That assumption turned out to be wrong in a way I could actually test.
My my-git-manager MCP server (server.py) exposes 8 tools over FastMCP: get_github_profile, list_repos, get_repo_stats, list_articles, create_article, update_article, get_article_stats, generate_commit_message. I approve this server once in Claude Desktop. After that, the client reads each tool's schema from whatever server.py currently defines, derived straight from the function's type hints, defaults, and docstring. There's no hash, no lockfile, no diff shown to me before a tool I already trust starts behaving differently. If a future edit to server.py โ mine, a contributor's, or an agent's โ quietly changes what a tool does, the approval I gave weeks ago still covers it.
This isn't hypothetical for this repo. docs/project_notes/bugs.md already has an entry (2026-08-07) where list_repos's docstring claimed limit: 1-100, but the code never enforced it โ passing limit=-1 fell through Python's own negative-index slicing and returned almost every repo instead of an error. The docstring and the behavior disagreed from the day the tool shipped, and nothing caught that because nothing was comparing the tool's stated contract to its actual one. The fix patched the bug. It didn't add anything that would catch the next mismatch, which is the actual gap the trending post is pointing at: a tool's definition can move, and the thing that's supposed to notice (the human who approved it) has no mechanism to.
I'm not going to solve the general MCP trust problem here โ that needs client-side support for pinning a remote server's tool definitions between sessions, and today's clients mostly don't do it. But for a server I maintain, I can at least give myself the equivalent of a lockfile: a fingerprint of every tool's contract that changes only when I mean it to.
FastMCP derives a tool's schema from the function signature and docstring, so that's exactly what needs to be fingerprinted โ not the whole file, just the part a client actually sees:
import ast, hashlib, json
def canonical_schema(func: ast.FunctionDef):
args = func.args
defaults = [None] * (len(args.args) - len(args.defaults)) + list(args.defaults)
params = []
for arg, default in zip(args.args, defaults):
ann = ast.unparse(arg.annotation) if arg.annotation else None
dflt = ast.unparse(default) if default is not None else None
params.append({"name": arg.arg, "type": ann, "default": dflt})
returns = ast.unparse(func.returns) if func.returns else None
doc = ast.get_docstring(func) or ""
return {"name": func.name, "params": params, "returns": returns, "doc": doc}
def hash_schema(schema: dict) -> str:
blob = json.dumps(schema, sort_keys=True).encode()
return hashlib.sha256(blob).hexdigest()[:16]
Walk the AST for every function decorated with @mcp.tool(), build its canonical schema, hash it. Run against the real file:
def extract_tools(path: str):
tree = ast.parse(open(path).read(), filename=path)
tools = {}
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
for dec in node.decorator_list:
if ast.unparse(dec) in ("mcp.tool()", "mcp.tool"):
schema = canonical_schema(node)
tools[node.name] = hash_schema(schema)
return tools
Running this against server.py as it stands today gives 8 stable hashes:
b110bb88249fd87e create_article
6e5e41c02eae14d2 generate_commit_message
f7f53a1920af55a7 get_article_stats
879ce144deeed35d get_github_profile
ad99a1b969686e05 get_repo_stats
242ce842430e6cda list_articles
85a598ebcc217681 list_repos
e871203f49f0442c update_article
Then I reproduced the exact shape of bug this repo already had once: changed list_repos's limit default from 10 to 100, the kind of one-line edit that's easy to wave through in a quick review because the diff looks trivial.
- def list_repos(sort: str = "updated", limit: int = 10) -> list:
+ def list_repos(sort: str = "updated", limit: int = 100) -> list:
Re-hashing shows exactly one line move:
7c7
< 85a598ebcc217681 list_repos
---
> 026d0c781df7ae0a list_repos
The other 7 tools are untouched, byte-identical hashes. list_repos moved, and it's the only one that did. That's the whole point: a diff I can check into git and fail a commit on, instead of a contract I re-approve by not noticing it changed.
The honest limits matter here. This only protects servers whose source I control and can diff โ it does nothing for a remote MCP server that changes its tool definitions between two calls, which is the actual rug-pull scenario the trending post describes, and that still needs the MCP client itself to pin and re-verify tool definitions across sessions, not something a server author can fix from their own side. What it does fix is the much more boring failure mode that already bit this repo once: a tool's docstring and its real behavior drifting apart because nothing was watching either of them. The npm/pip comparison is almost exact โ a package.json range tells you a dependency is compatible, a lockfile tells you it's identical. Right now every MCP client I've approved a server in is working off the equivalent of the range. My own server didn't even have the lockfile for itself.
I'm adding the hash check as a step before merging any future change to server.py's tool functions โ not a CI gate yet, since this repo doesn't have CI wired to it, but a command I run by hand the same way I'd run git diff before a commit. The script is 30 lines of stdlib ast and hashlib, no dependency on the mcp package itself, which means it works on any FastMCP server's source whether or not the mcp package is even installed in the environment checking it. That's worth more than it sounds: the fingerprint doesn't need to run the server to catch a contract change, it just needs to read the file.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.