learning-it by example

#231 Enterprise architecture and AI agents 5.5 min

MCP Gateway: Per-Tool Policy for Agent Tools (Python)

Seven tool calls worked directly. Through a small gateway, four were blocked.

1. What are the three decisions an MCP gateway makes for an agent's tool calls?
2. In the MCP gateway demo, what did the same seven tool calls do when sent straight to the shop's tools, and then through the gateway?
3. In the MCP gateway demo, the shop's export_all_customers tool has no rule in the policy. What happens when an agent calls it?
4. In the MCP gateway demo, why does the policy check that a refund amount is a number before comparing it with the range?
5. Which of these does the small MCP policy gateway not do?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Test the edges of the refund range

    Copy the code folder first. The policy.py file needs no packages. From the copy, run python -c "import policy; print(policy.check('refund', {'order_id': 7, 'amount': 50.01}))" and then again with 50, 0.01 and 0.009. Predict each answer first. When I ran them, 50 and 0.01 gave (True, 'ok'), and 50.01 and 0.009 were refused with a message such as amount 50.01 is outside 0.01 to 50.

    A hint

    The rule uses low <= value <= high, so both ends are allowed.

  2. Allow a second email domain

    In policy.py, add "example.org" to the domains list of send_email. Then run python -c "import policy; print(policy.check('send_email', {'to': 'x@example.org', 'body': 'hi'}))". Predict the answer before and after your change. When I ran it, it was refused before the change with recipient is outside the allowed domains, and gave (True, 'ok') after.

    A hint

    The domain is the part of the address after the at sign.

  3. Try to trick the type check

    Run python -c "import policy; print(policy.check('refund', {'order_id': 7, 'amount': '20'}))" and then the same call with True as the amount. Predict both answers before running. When I ran the text version, it was refused with amount must be a number. Explain why the check looks at the type before it compares the number with the range.

    A hint

    Read the isinstance lines at the start of the range check in policy.py. The video says a true or false is refused before any comparison.

  4. Allow the delete tool and see what changes

    In policy.py, change the decision for delete_customer from deny to allow. Without running the gateway, run python -c "import policy; print(policy.check('delete_customer', {'customer_id': 3}), policy.allowed('export_all_customers'))". Predict the two answers. When I ran this, the first was (True, 'ok') and the second was False. Write one sentence on what this shows about a policy with no limit on the arguments of a risky tool.

    A hint

    The delete rule has no range or domains to check, so a decision of allow lets every call through.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

A made-up shop and no model. No caller identity, rate limit, output cleaning or human approval, a crude email check, and an audit log that keeps arguments. Nothing here forces calls through the gateway.

Up next in Enterprise architecture and AI agents

More in Enterprise architecture and AI agents

All Enterprise architecture and AI agents videos

Related videos