INNER CODE UNIT · Python
_cap
tiliondev/fortress · mcp/server.py:221
def _cap(d: dict, limits: dict[str, int]) -> dict:
"""Trim oversized string fields so a tool response never floods the agent's
context. Drops the raw-HTML dump by default (agents want text/markdown), and
flags anything truncated."""
out = dict(d)
for field, n in limits.items():
v = out.get(field)
if isinstance(v, str) and len(v) > n:
out[field] = v[:n]
out[f"{field}_truncated"] = True
return out
@mcp.tool(annotations=_READ)
@_safe
async def fetch_protected_page(url: str) -> dict:
"""Fetch a web page that normal HTTP clients / headless browsers CAN'T get —
pages behind Cloudflare, DataDome, PerimeterX, Akamai, or that return 403 /